Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/eventconsumer/event_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (ec *eventConsumer) consumeTxSigningEvent() error {
}

var session mpc.SigningSession
idempotentKey := composeSigningIdempotentKey(msg.TxID, natMsg)
switch msg.KeyType {
case types.KeyTypeSecp256k1:
session, err = ec.node.CreateSigningSession(
Expand All @@ -344,6 +345,7 @@ func (ec *eventConsumer) consumeTxSigningEvent() error {
msg.TxID,
msg.NetworkInternalCode,
ec.signingResultQueue,
idempotentKey,
)
case types.KeyTypeEd25519:
session, err = ec.node.CreateSigningSession(
Expand All @@ -352,6 +354,7 @@ func (ec *eventConsumer) consumeTxSigningEvent() error {
msg.TxID,
msg.NetworkInternalCode,
ec.signingResultQueue,
idempotentKey,
)

}
Expand Down Expand Up @@ -477,7 +480,7 @@ func (ec *eventConsumer) handleSigningSessionError(walletID, txID, networkIntern
return
}
err = ec.signingResultQueue.Enqueue(event.SigningResultCompleteTopic, signingResultBytes, &messaging.EnqueueOptions{
IdempotententKey: txID,
IdempotententKey: composeSigningIdempotentKey(txID, natMsg),
})
if err != nil {
logger.Error("Failed to enqueue signing result event", err,
Expand Down Expand Up @@ -809,3 +812,11 @@ func composeKeygenIdempotentKey(walletID string, natMsg *nats.Msg) string {
}
return fmt.Sprintf(mpc.TypeGenerateWalletResultFmt, uniqueKey)
}

func composeSigningIdempotentKey(txID string, natMsg *nats.Msg) string {
sid := natMsg.Header.Get("SessionID")
if sid != "" {
return fmt.Sprintf("%s:%s", txID, sid)
}
return txID
}
Comment thread
Azzurriii marked this conversation as resolved.
4 changes: 3 additions & 1 deletion pkg/mpc/ecdsa_signing_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func newECDSASigningSession(
keyinfoStore keyinfo.Store,
resultQueue messaging.MessageQueue,
identityStore identity.Store,
idempotentKey string,
) *ecdsaSigningSession {
return &ecdsaSigningSession{
session: session{
Expand Down Expand Up @@ -81,6 +82,7 @@ func newECDSASigningSession(
getRoundFunc: GetEcdsaMsgRound,
resultQueue: resultQueue,
identityStore: identityStore,
idempotentKey: idempotentKey,
},
endCh: make(chan *common.SignatureData),
txID: txID,
Expand Down Expand Up @@ -178,7 +180,7 @@ func (s *ecdsaSigningSession) Sign(onSuccess func(data []byte)) {
}

err = s.resultQueue.Enqueue(event.SigningResultCompleteTopic, bytes, &messaging.EnqueueOptions{
IdempotententKey: s.txID,
IdempotententKey: s.idempotentKey,
})
if err != nil {
s.ErrCh <- errors.Wrap(err, "Failed to publish sign success message")
Expand Down
4 changes: 3 additions & 1 deletion pkg/mpc/eddsa_signing_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func newEDDSASigningSession(
keyinfoStore keyinfo.Store,
resultQueue messaging.MessageQueue,
identityStore identity.Store,
idempotentKey string,
) *eddsaSigningSession {
return &eddsaSigningSession{
session: session{
Expand Down Expand Up @@ -72,6 +73,7 @@ func newEDDSASigningSession(
getRoundFunc: GetEddsaMsgRound,
resultQueue: resultQueue,
identityStore: identityStore,
idempotentKey: idempotentKey,
},
endCh: make(chan *common.SignatureData),
txID: txID,
Expand Down Expand Up @@ -167,7 +169,7 @@ func (s *eddsaSigningSession) Sign(onSuccess func(data []byte)) {
}

err = s.resultQueue.Enqueue(event.SigningResultCompleteTopic, bytes, &messaging.EnqueueOptions{
IdempotententKey: s.txID,
IdempotententKey: s.idempotentKey,
})
if err != nil {
s.ErrCh <- errors.Wrap(err, "Failed to publish sign success message")
Expand Down
3 changes: 3 additions & 0 deletions pkg/mpc/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (p *Node) CreateSigningSession(
txID string,
networkInternalCode string,
resultQueue messaging.MessageQueue,
idempotentKey string,
) (SigningSession, error) {
version := p.getVersion(sessionType, walletID)
keyInfo, err := p.getKeyInfo(sessionType, walletID)
Expand Down Expand Up @@ -211,6 +212,7 @@ func (p *Node) CreateSigningSession(
p.keyinfoStore,
resultQueue,
p.identityStore,
idempotentKey,
), nil

case SessionTypeEDDSA:
Expand All @@ -228,6 +230,7 @@ func (p *Node) CreateSigningSession(
p.keyinfoStore,
resultQueue,
p.identityStore,
idempotentKey,
), nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/mpc/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ type session struct {
getRoundFunc GetRoundFunc
mu sync.Mutex
// After the session is done, the key will be stored pubkeyBytes
pubkeyBytes []byte
sessionType SessionType
pubkeyBytes []byte
sessionType SessionType
idempotentKey string
}

func (s *session) PartyID() *tss.PartyID {
Expand Down
Loading