Skip to content

Nonce management for transaction submission #8

@tac0turtle

Description

@tac0turtle

Summary

Implement local nonce (sequence number) tracking and correction for blob transaction submission.

Context

Parent: #4

Cosmos chains use account sequence numbers as nonces. Correct nonce management is critical — wrong sequence = rejected tx.

celestia-node's approach (query once at startup, increment locally, regex-parse error strings on mismatch) works but is fragile. We should rebuild this simpler and more robust.

Design

Core behavior

  1. Startup: Query on-chain account sequence via auth.QueryAccount gRPC
  2. On broadcast: Use local sequence, increment optimistically
  3. On success: Keep incremented value
  4. On ErrWrongSequence: Re-query on-chain sequence (don't regex-parse error strings), re-sign, retry (max 3 attempts)
  5. On other failure: Do not increment, return error to caller

Thread safety

Interface

type NonceManager interface {
    // NextSequence returns the next sequence number for the given address.
    // Blocks if another tx is in-flight for this address.
    NextSequence(ctx context.Context, address string) (uint64, error)

    // Commit confirms the sequence was used successfully.
    Commit(address string)

    // Rollback indicates the sequence was not used (tx failed).
    Rollback(address string)

    // Reset re-queries the on-chain sequence for the given address.
    Reset(ctx context.Context, address string) error
}

Error handling

  • Check ABCI error codes directly where possible, not error string patterns
  • Wrap errors with context: address, expected sequence, actual sequence, attempt number

Non-goals

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions