Skip to main content

Module tx_manager

Module tx_manager 

Source
Expand description

Transaction manager for dYdX v4 protocol.

This module provides centralized transaction management including:

  • Atomic sequence number tracking for stateful (long-term/conditional) orders
  • Transaction building and signing
  • Chain synchronization for sequence recovery

§Sequence Management

dYdX has two transaction types with different sequence behavior:

  • Stateful orders (long-term, conditional): Use Cosmos SDK sequences for replay protection. Each transaction requires a unique, incrementing sequence number.
  • Short-term orders: Use Good-Til-Block (GTB) for replay protection. The chain’s ClobDecorator ante handler skips sequence checking, so sequences are not consumed. Use TransactionManager::get_cached_sequence for these — it returns the current value without incrementing.

For stateful orders, this module provides:

  1. AtomicU64 for lock-free sequence allocation via TransactionManager::allocate_sequence
  2. Lazy initialization from chain on first use
  3. TransactionManager::resync_sequence for recovery after mismatch errors
  4. Batch allocation via TransactionManager::allocate_sequences for parallel stateful broadcasts

Structs§

TransactionManager
Transaction manager responsible for wallet, sequence tracking, and transaction building.

Constants§

SEQUENCE_UNINITIALIZED
Sentinel value indicating sequence is uninitialized.