Skip to content

Commit f8a4b67

Browse files
authored
reduce mpc retry interval (#21)
1 parent bcaff5a commit f8a4b67

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

solana/mvm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"math/big"
99
"slices"
1010
"strings"
11-
"time"
1211

1312
"github.com/MixinNetwork/bot-api-go-client/v3"
1413
solanaApp "github.com/MixinNetwork/computer/apps/solana"
@@ -588,7 +587,7 @@ func (node *Node) processObserverRequestSign(ctx context.Context, req *store.Req
588587
if call == nil || call.Signature.Valid || call.State == common.RequestStateFailed {
589588
return node.failRequest(ctx, req, "")
590589
}
591-
if call.RequestSignerAt.Valid && call.RequestSignerAt.Time.Add(20*time.Minute).After(req.CreatedAt) {
590+
if call.RequestSignerAt.Valid && call.RequestSignerAt.Time.Add(mpcRetryInterval).After(req.CreatedAt) {
592591
return node.failRequest(ctx, req, "")
593592
}
594593

solana/observer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
)
2525

2626
const (
27-
loopInterval = time.Second * 5
28-
BalanceLimit = 500000000
27+
loopInterval = time.Second * 5
28+
mpcRetryInterval = time.Minute * 5
29+
BalanceLimit = 500000000
2930
)
3031

3132
func (node *Node) bootObserver(ctx context.Context, version string) {
@@ -662,7 +663,7 @@ func (node *Node) processUnsignedCalls(ctx context.Context) error {
662663
}
663664
for _, call := range calls {
664665
now := time.Now().UTC()
665-
if call.RequestSignerAt.Valid && call.RequestSignerAt.Time.Add(20*time.Minute).After(now) {
666+
if call.RequestSignerAt.Valid && call.RequestSignerAt.Time.Add(mpcRetryInterval).After(now) {
666667
continue
667668
}
668669
logger.Printf("observer.processUnsignedCalls(%s %d)", call.RequestId, len(calls))

solana/signer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ func (node *Node) loopPendingSessions(ctx context.Context) {
164164
panic(fmt.Errorf("store.ReadSystemCallByRequestId(%s) => %v %v", s.RequestId, call, err))
165165
}
166166
if call.Signature.Valid || call.State != common.RequestStatePending {
167-
err = node.store.MarkSessionDone(ctx, s.Id)
168-
logger.Printf("node.MarkSessionDone(%v) => %v", s, err)
167+
err = node.store.MarkSessionDone(ctx, s.Id, call.RequestId)
168+
logger.Printf("node.MarkSessionDone(%v %s) => %v", s, call.RequestId, err)
169169
if err != nil {
170170
panic(err)
171171
}
@@ -192,7 +192,7 @@ func (node *Node) loopPendingSessions(ctx context.Context) {
192192
if err != nil {
193193
break
194194
}
195-
err = node.store.MarkSessionDone(ctx, op.Id)
195+
err = node.store.MarkSessionDone(ctx, op.Id, "")
196196
logger.Printf("node.MarkSessionDone(%v) => %v", op, err)
197197
if err != nil {
198198
break

store/session.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (s *SQLite3Store) MarkSessionPreparedWithRequest(ctx context.Context, req *
192192
return tx.Commit()
193193
}
194194

195-
func (s *SQLite3Store) MarkSessionDone(ctx context.Context, sessionId string) error {
195+
func (s *SQLite3Store) MarkSessionDone(ctx context.Context, sessionId string, callId string) error {
196196
s.mutex.Lock()
197197
defer s.mutex.Unlock()
198198

@@ -202,12 +202,21 @@ func (s *SQLite3Store) MarkSessionDone(ctx context.Context, sessionId string) er
202202
}
203203
defer common.Rollback(tx)
204204

205+
now := time.Now().UTC()
205206
err = s.execOne(ctx, tx, "UPDATE sessions SET state=?, updated_at=? WHERE session_id=? AND state=?",
206-
common.RequestStateDone, time.Now().UTC(), sessionId, common.RequestStatePending)
207+
common.RequestStateDone, now, sessionId, common.RequestStatePending)
207208
if err != nil {
208209
return fmt.Errorf("SQLite3Store UPDATE sessions %v", err)
209210
}
210211

212+
if callId != "" {
213+
_, err = tx.ExecContext(ctx, "UPDATE sessions SET state=?, updated_at=? WHERE session_id!=? AND state=? AND request_id=?",
214+
common.RequestStateFailed, now, sessionId, common.RequestStatePending, callId)
215+
if err != nil {
216+
return fmt.Errorf("SQLite3Store UPDATE sessions %v", err)
217+
}
218+
}
219+
211220
return tx.Commit()
212221
}
213222

0 commit comments

Comments
 (0)