fix: reconcile account info on broadcast failure#65
Conversation
WalkthroughThis PR refactors wallet transaction handling to cache and reconcile blockchain account sequence state. It updates IBC channel types in the REST client with explicit enum mappings, introduces an AccountSequenceTracker utility for managing sequence caching and error reconciliation, integrates the tracker into WalletWorker, and adds comprehensive integration tests validating sequence reconciliation across multiple failure scenarios. ChangesAccount Sequence Tracking and Reconciliation
Sequence Diagram(s)sequenceDiagram
participant Client
participant WalletWorker
participant AccountSequenceTracker
participant Chain
Client->>WalletWorker: handlePackets(messages)
activate WalletWorker
WalletWorker->>AccountSequenceTracker: ensureInitialized()
activate AccountSequenceTracker
AccountSequenceTracker->>Chain: fetch account sequence
deactivate AccountSequenceTracker
WalletWorker->>WalletWorker: signAndBroadcast(msgs)
WalletWorker->>Chain: broadcast signed tx
alt Broadcast Success
WalletWorker->>AccountSequenceTracker: markBroadcastSuccess()
else TxError with Log
WalletWorker->>AccountSequenceTracker: reconcileTxError(rawLog)
else Broadcast Exception
WalletWorker->>AccountSequenceTracker: reconcileBroadcastException()
end
deactivate WalletWorker
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 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 docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/workers/walletSequence.spec.ts (1)
68-77: ⚡ Quick winFail fast when mocked
accountInforesponses are exhausted.Returning
undefinedhere can trigger indirect TypeErrors later (getSequenceNumberon undefined), which makes test failures harder to diagnose.Proposed patch
const authAccountInfo = jest .fn() .mockImplementation(() => { const response = options.accountInfoResponses.shift() + if (response === undefined) { + throw new Error('No mocked accountInfo response left') + } if (response instanceof Error) { return Promise.reject(response) } return Promise.resolve(response) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/workers/walletSequence.spec.ts` around lines 68 - 77, The mock for authAccountInfo currently returns undefined when options.accountInfoResponses is exhausted, causing downstream TypeErrors; update the authAccountInfo mock (the jest.fn() implementation that consumes options.accountInfoResponses) to detect when shift() yields undefined and immediately return a rejected Promise (or throw) with a clear error message like "No more mocked accountInfo responses" so tests fail fast and show a clear cause instead of later getSequenceNumber on undefined failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/workers/walletSequence.spec.ts`:
- Around line 68-77: The mock for authAccountInfo currently returns undefined
when options.accountInfoResponses is exhausted, causing downstream TypeErrors;
update the authAccountInfo mock (the jest.fn() implementation that consumes
options.accountInfoResponses) to detect when shift() yields undefined and
immediately return a rejected Promise (or throw) with a clear error message like
"No more mocked accountInfo responses" so tests fail fast and show a clear cause
instead of later getSequenceNumber on undefined failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c00d1e9b-bd1a-4221-aeef-ae09d8646c08
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (10)
package.jsonsrc/lib/restClient.spec.tssrc/lib/restClient.tssrc/msgs/channelOpenTry.spec.tssrc/msgs/channelOpenTry.tssrc/test/testSetup.tssrc/workers/accountSequence.spec.tssrc/workers/accountSequence.tssrc/workers/wallet.tssrc/workers/walletSequence.spec.ts
AccountSequenceTrackerto reconcile sequence on broadcast failure, recovering fromaccount sequence mismatchwithout a restartSummary by CodeRabbit
Release Notes
New Features
Improvements
Chores
@initia/initia.jsdependency to v1.1.0.