fix(submit): robust nonce recovery via chain re-query#51
fix(submit): robust nonce recovery via chain re-query#51pthmas wants to merge 1 commit intoevstack:mainfrom
Conversation
Replace fragile error-string parsing for sequence mismatch recovery with a direct re-query of the chain via AccountInfo. Detect ErrWrongSequence using ABCI code 32 instead of text patterns. Increase max retry rounds from 2 to 3 and add attempt/address context to mismatch errors. Closes evstack#8 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughRefactored sequence mismatch recovery in direct transaction submission. Replaced error text parsing with ABCI code detection (Code 32). Introduced Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/submit/direct.go (1)
462-464: Consider extracting ABCI code 32 as a named constant.While code 32 is the well-known Cosmos SDK code for sequence mismatch, extracting it as a named constant would improve readability and make it easier to find all sequence-mismatch related logic.
💡 Suggested constant definition
const ( defaultFeeDenom = "utia" defaultPollInterval = time.Second maxSequenceRetryRounds = 3 + // abciCodeSequenceMismatch is the Cosmos SDK ABCI code for account sequence mismatch. + abciCodeSequenceMismatch = 32 )Then at line 462:
- if tx.Code == 32 { + if tx.Code == abciCodeSequenceMismatch {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/submit/direct.go` around lines 462 - 464, Extract the literal ABCI code 32 into a named constant (e.g., SequenceMismatchCode = 32) and replace the magic number check in the submit logic (the tx.Code == 32 comparison) with that constant; update the error-return branch that references errSequenceMismatch so it uses the new constant for clarity and to centralize sequence-mismatch logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/submit/direct.go`:
- Around line 462-464: Extract the literal ABCI code 32 into a named constant
(e.g., SequenceMismatchCode = 32) and replace the magic number check in the
submit logic (the tx.Code == 32 comparison) with that constant; update the
error-return branch that references errSequenceMismatch so it uses the new
constant for clarity and to centralize sequence-mismatch logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c0fe5c5b-f748-409d-8d7a-9c915780e180
📒 Files selected for processing (2)
pkg/submit/direct.gopkg/submit/direct_test.go
Summary
Fixes fragile sequence mismatch handling in
DirectSubmitter(closes #8).The previous implementation detected
ErrWrongSequenceby scanning error strings and recovered by regex-parsing the expected sequence number out of the message. This broke silently if Celestia changed error message wording.Changes
checkTxStatus: detect sequence mismatch via ABCI code 32 instead of string pattern matching — stable across node versionsrecoverSequenceLocked: re-query chain viaAccountInfoon mismatch instead of parsing the expected sequence from the error string; signature changes to(ctx context.Context) errorbroadcastTx: threadctxthrough to recovery; add attempt number and address to mismatch error contextmaxSequenceRetryRounds: increased from 2 → 3 per specexpectedSequenceFromMismatchTextandstrconvimport — no longer neededisSequenceMismatchTextfor the gRPC error path (whenBroadcastTxreturns a non-nil error rather than aTxStatus)New tests:
TestDirectSubmitterMismatchDetectedByABCICode— code 32 with no parseable log triggers retryTestDirectSubmitterMismatchReQueryFails— re-query error surfaces correctlyTestDirectSubmitterExhaustsAllRetries— confirms 3 attempts then returnserrSequenceMismatchSummary by CodeRabbit
Release Notes
Bug Fixes
Tests