Skip to content

Enhance error handle when signing with duplicate tx_id (Issue #60)#68

Merged
anhthii merged 6 commits intofystack:masterfrom
Azzurriii:master
Aug 5, 2025
Merged

Enhance error handle when signing with duplicate tx_id (Issue #60)#68
anhthii merged 6 commits intofystack:masterfrom
Azzurriii:master

Conversation

@Azzurriii
Copy link
Contributor

Issue

When signing through mpcClient.SignTransaction, if the same tx_id is used multiple times, mpcClient.OnSignResult could not receive all results reliably. This happened because:

  1. Each node generates its own signing session for the same tx_id
  2. All nodes publish results to NATS with the same idempotent key (just the tx_id)
  3. NATS drops subsequent messages with the same idempotent key, causing some results to be lost
  4. The client only receives one response instead of all expected responses, and other request will be time out.

The issue was in the idempotent key generation for NATS messages. The signing sessions used only the tx_id as the idempotent key:

How the Fix Works

  1. When a signing request comes in, the event consumer extracts the SessionID from the NATS message header
  2. It creates a composite idempotent key: {tx_id}:{session_id}
  3. This composite key is passed to the signing sessions during creation
  4. When publishing results (both success and error), the sessions use this composite key
  5. Now each session's results have unique idempotent keys, allowing all responses to reach the client

NATS Message

Raw Data:

{
  "result_type": "error",
  "error_code": "ERROR_SESSION_DUPLICATE",
  "error_reason": "Duplicate session: duplicate signing request detected for walletID=244924ee-f604-4ebb-a2bf-f844a9888e2c:0 txID=duplicate-test-1754222214845",
  "is_timeout": false,
  "network_internal_code": "solana:devnet",
  "wallet_id": "244924ee-f604-4ebb-a2bf-f844a9888e2c:0",
  "tx_id": "duplicate-test-1754222214845",
  "r": null,
  "s": null,
  "signature_recovery": null,
  "signature": null
}

Headers: Nats-Msg-Id: duplicate-test-1754222214845:b7325da2-abd9-4c08-b889-88fddb657af7

Testing

From my end, I tested by sending 5 signing requests with the same tx_id.
Only the first request succeeded
The others correctly returned ERROR_SESSION_DUPLICATE

@anhthii
Copy link
Contributor

anhthii commented Aug 3, 2025

Can we implement a composeIdempotentKey that both keygen and signing can reuse @Azzurriii please?

@Azzurriii
Copy link
Contributor Author

That's a good idea @anhthii - I'll implement it.
But before that, could you help me verify whether reshareResultQueue also needs to use composeIdempotentKey?
If so, I’ll include it in the implementation as well.

key := fmt.Sprintf(mpc.TypeReshareWalletResultFmt, walletID)

err = ec.reshareResultQueue.Enqueue(key, reshareResultBytes, &messaging.EnqueueOptions{
    IdempotententKey: key,
})

@anhthii
Copy link
Contributor

anhthii commented Aug 3, 2025

yes, we can apply apply for reshare as well

@Azzurriii
Copy link
Contributor Author

Thanks! I’ve implemented it. Please take a look!

yes, we can apply apply for reshare as well

@anhthii anhthii merged commit 05418f5 into fystack:master Aug 5, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments