Skip to content

Commit b0d4050

Browse files
committed
fixes
1 parent 3202dfa commit b0d4050

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

server/internal/core/application/service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,9 @@ func (s *covenantlessService) startFinalization(roundTiming roundTiming, request
17631763
thirdOfRemainingDuration := roundTiming.finalizationDuration()
17641764

17651765
defer func() {
1766-
s.liveStore.TreeSigingSessions().Delete(roundId)
1766+
if err := s.liveStore.TreeSigingSessions().Delete(roundId); err != nil {
1767+
log.WithError(err).Warn("failed to delete tree signing session")
1768+
}
17671769

17681770
if err := s.saveEvents(ctx, roundId, s.liveStore.CurrentRound().Get().Events()); err != nil {
17691771
log.WithError(err).Warn("failed to store new round events")

server/internal/core/ports/live_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type ConfirmationSessionsStore interface {
6767
type TreeSigningSessionsStore interface {
6868
New(roundId string, uniqueSignersPubKeys map[string]struct{}) *MusigSigningSession
6969
Get(roundId string) (*MusigSigningSession, bool)
70-
Delete(roundId string)
70+
Delete(roundId string) error
7171
AddNonces(ctx context.Context, roundId string, pubkey string, nonces tree.TreeNonces) error
7272
AddSignatures(ctx context.Context, roundId string, pubkey string, nonces tree.TreePartialSigs) error
7373
NoncesCollected(roundId string) <-chan struct{}

server/internal/infrastructure/live-store/inmemory/tree_signing_session.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ func (s *treeSigningSessionsStore) Get(roundId string) (*ports.MusigSigningSessi
4949
sess, ok := s.sessions[roundId]
5050
return sess, ok
5151
}
52-
func (s *treeSigningSessionsStore) Delete(roundId string) {
52+
func (s *treeSigningSessionsStore) Delete(roundId string) error {
5353
s.lock.Lock()
5454
defer s.lock.Unlock()
5555

56-
if ch, exists := s.nonceCollectedCh[roundId]; exists {
57-
close(ch)
56+
if _, exists := s.nonceCollectedCh[roundId]; !exists {
57+
return fmt.Errorf(`nonce collected channel not found for round "%s"`, roundId)
5858
}
59-
if ch, exists := s.sigsCollectedCh[roundId]; exists {
60-
close(ch)
59+
if _, exists := s.sigsCollectedCh[roundId]; !exists {
60+
return fmt.Errorf(`signatures collected channel not found for round "%s"`, roundId)
6161
}
6262

63+
close(s.nonceCollectedCh[roundId])
64+
close(s.sigsCollectedCh[roundId])
65+
6366
delete(s.nonceCollectedCh, roundId)
6467
delete(s.sigsCollectedCh, roundId)
6568
delete(s.sessions, roundId)
69+
70+
return nil
6671
}
6772

6873
func (s *treeSigningSessionsStore) AddNonces(
@@ -122,19 +127,9 @@ func (s *treeSigningSessionsStore) AddSignatures(
122127
}
123128

124129
func (s *treeSigningSessionsStore) NoncesCollected(roundId string) <-chan struct{} {
125-
s.lock.RLock()
126-
defer s.lock.RUnlock()
127-
if ch, exists := s.nonceCollectedCh[roundId]; exists {
128-
return ch
129-
}
130-
return nil
130+
return s.nonceCollectedCh[roundId]
131131
}
132132

133133
func (s *treeSigningSessionsStore) SignaturesCollected(roundId string) <-chan struct{} {
134-
s.lock.RLock()
135-
defer s.lock.RUnlock()
136-
if ch, exists := s.sigsCollectedCh[roundId]; exists {
137-
return ch
138-
}
139-
return nil
134+
return s.sigsCollectedCh[roundId]
140135
}

server/internal/infrastructure/live-store/live_store_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ func runLiveStoreTests(t *testing.T, store ports.LiveStore) {
308308
}
309309

310310
// Delete
311-
store.TreeSigingSessions().Delete(roundId)
311+
err = store.TreeSigingSessions().Delete(roundId)
312+
require.NoError(t, err)
312313

313314
// Get
314315
sigSession, exists := store.TreeSigingSessions().Get(roundId)

server/internal/infrastructure/live-store/redis/tree_signing_session.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"encoding/hex"
1111
"encoding/json"
1212
"fmt"
13-
log "github.com/sirupsen/logrus"
1413
"strings"
1514
"time"
1615

16+
log "github.com/sirupsen/logrus"
17+
1718
"github.com/ark-network/ark/common/tree"
1819
"github.com/ark-network/ark/server/internal/core/ports"
1920
"github.com/redis/go-redis/v9"
@@ -113,7 +114,7 @@ func (s *treeSigningSessionsStore) Get(roundId string) (*ports.MusigSigningSessi
113114
return sess, true
114115
}
115116

116-
func (s *treeSigningSessionsStore) Delete(roundId string) {
117+
func (s *treeSigningSessionsStore) Delete(roundId string) error {
117118
ctx := context.Background()
118119
metaKey := fmt.Sprintf(treeSessMetaKeyFmt, roundId)
119120
noncesKey := fmt.Sprintf(treeSessNoncesKeyFmt, roundId)
@@ -127,6 +128,7 @@ func (s *treeSigningSessionsStore) Delete(roundId string) {
127128
close(s.sigsCh)
128129
s.sigsCh = nil
129130
}
131+
return nil
130132
}
131133

132134
func (s *treeSigningSessionsStore) AddNonces(ctx context.Context, roundId string, pubkey string, nonces tree.TreeNonces) error {

0 commit comments

Comments
 (0)