pub struct TxBroadcaster { /* private fields */ }Expand description
Transaction broadcaster responsible for gRPC transmission with retry logic.
Works with TransactionManager to handle sequence mismatch errors gracefully.
Uses [RetryManager] with exponential backoff for reliable delivery.
§Broadcast Modes
§Stateful Orders (long-term/conditional): broadcast_with_retry
Serialized through a semaphore to prevent sequence races. Cosmos SDK requires stateful transactions to have unique, incrementing sequence numbers. The semaphore ensures allocate → build → broadcast happens atomically for each operation.
On sequence mismatch (Cosmos SDK error code 32 or dYdX code 104):
- The
should_retrycallback sets a flag indicating resync is needed - The
RetryManagerapplies exponential backoff - On next attempt, the operation checks the flag and resyncs sequence from chain
- A new transaction is built with the fresh sequence and broadcast
§Short-term Orders: broadcast_short_term
dYdX short-term orders use Good-Til-Block (GTB) for replay protection instead of
Cosmos SDK sequences. The chain’s ClobDecorator ante handler skips sequence
checking for short-term messages. This means:
- No semaphore needed (fully concurrent)
- Cached sequence used (no increment, no allocation)
- No sequence-based retry logic needed
Implementations§
Source§impl TxBroadcaster
impl TxBroadcaster
Sourcepub fn new(grpc_client: DydxGrpcClient) -> Self
pub fn new(grpc_client: DydxGrpcClient) -> Self
Creates a new transaction broadcaster.
Sourcepub async fn broadcast_with_retry(
&self,
tx_manager: &TransactionManager,
msgs: Vec<Any>,
operation_name: &str,
) -> Result<String, DydxError>
pub async fn broadcast_with_retry( &self, tx_manager: &TransactionManager, msgs: Vec<Any>, operation_name: &str, ) -> Result<String, DydxError>
Broadcasts a prepared transaction with automatic retry on sequence mismatch.
Serialization: Acquires a semaphore permit before allocating sequence, building, and broadcasting. This ensures transactions are broadcast in sequence order, preventing “sequence mismatch” errors from concurrent calls.
On sequence mismatch (code=32), resyncs from chain, allocates new sequence, rebuilds the transaction, and retries with exponential backoff.
§Arguments
tx_manager- Transaction manager for sequence resync and rebuildingmsgs- Original messages to rebuild on retryoperation- Human-readable operation name for logging
§Returns
The transaction hash on success.
§Errors
Returns error if all retries are exhausted or a non-retryable error occurs.
Sourcepub async fn broadcast_short_term(
&self,
tx_manager: &TransactionManager,
msgs: Vec<Any>,
operation_name: &str,
) -> Result<String, DydxError>
pub async fn broadcast_short_term( &self, tx_manager: &TransactionManager, msgs: Vec<Any>, operation_name: &str, ) -> Result<String, DydxError>
Broadcasts a short-term order transaction without sequence management.
§Errors
Returns error if building or broadcasting fails.
Sourcepub async fn broadcast_once(
&self,
prepared: &PreparedTransaction,
) -> Result<String, DydxError>
pub async fn broadcast_once( &self, prepared: &PreparedTransaction, ) -> Result<String, DydxError>
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TxBroadcaster
impl !RefUnwindSafe for TxBroadcaster
impl Send for TxBroadcaster
impl Sync for TxBroadcaster
impl Unpin for TxBroadcaster
impl UnsafeUnpin for TxBroadcaster
impl !UnwindSafe for TxBroadcaster
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].