diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index b499f0ac42..d72b657bff 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -1480,7 +1480,7 @@ enum PropagateTransactionsBuilder { Full(FullTransactionsBuilder), } -impl PropagateTransactionsBuilder { +impl PropagateTransactionsBuilder { /// Create a builder for pooled transactions fn pooled(version: EthVersion) -> Self { Self::Pooled(PooledTransactionsHashesBuilder::new(version)) @@ -1491,6 +1491,26 @@ impl PropagateTransactionsBuilder { Self::Full(FullTransactionsBuilder::new(version)) } + /// Returns true if no transactions are recorded. + fn is_empty(&self) -> bool { + match self { + Self::Pooled(builder) => builder.is_empty(), + Self::Full(builder) => builder.is_empty(), + } + } + + /// Consumes the type and returns the built messages that should be sent to the peer. + fn build(self) -> PropagateTransactions { + match self { + Self::Pooled(pooled) => { + PropagateTransactions { pooled: Some(pooled.build()), full: None } + } + Self::Full(full) => full.build(), + } + } +} + +impl PropagateTransactionsBuilder { /// Appends all transactions fn extend<'a>(&mut self, txs: impl IntoIterator) { for tx in txs { @@ -1505,24 +1525,6 @@ impl PropagateTransactionsBuilder { Self::Full(builder) => builder.push(transaction), } } - - /// Returns true if no transactions are recorded. - fn is_empty(&self) -> bool { - match self { - Self::Pooled(builder) => builder.is_empty(), - Self::Full(builder) => builder.is_empty(), - } - } - - /// Consumes the type and returns the built messages that should be sent to the peer. - fn build(self) -> PropagateTransactions { - match self { - Self::Pooled(pooled) => { - PropagateTransactions { pooled: Some(pooled.build()), full: None } - } - Self::Full(full) => full.build(), - } - } } /// Represents how the transactions should be sent to a peer if any. @@ -1547,9 +1549,7 @@ struct FullTransactionsBuilder { pooled: PooledTransactionsHashesBuilder, } -// === impl FullTransactionsBuilder === - -impl FullTransactionsBuilder { +impl FullTransactionsBuilder { /// Create a builder for the negotiated version of the peer's session fn new(version: EthVersion) -> Self { Self { @@ -1559,6 +1559,20 @@ impl FullTransactionsBuilder { } } + /// Returns whether or not any transactions are in the [`FullTransactionsBuilder`]. + fn is_empty(&self) -> bool { + self.transactions.is_empty() && self.pooled.is_empty() + } + + /// Returns the messages that should be propagated to the peer. + fn build(self) -> PropagateTransactions { + let pooled = Some(self.pooled.build()).filter(|pooled| !pooled.is_empty()); + let full = Some(self.transactions).filter(|full| !full.is_empty()); + PropagateTransactions { pooled, full } + } +} + +impl FullTransactionsBuilder { /// Appends all transactions. fn extend(&mut self, txs: impl IntoIterator) { for tx in txs { @@ -1600,18 +1614,6 @@ impl FullTransactionsBuilder { self.total_size = new_size; self.transactions.push(Arc::clone(&transaction.transaction)); } - - /// Returns whether or not any transactions are in the [`FullTransactionsBuilder`]. - fn is_empty(&self) -> bool { - self.transactions.is_empty() && self.pooled.is_empty() - } - - /// Returns the messages that should be propagated to the peer. - fn build(self) -> PropagateTransactions { - let pooled = Some(self.pooled.build()).filter(|pooled| !pooled.is_empty()); - let full = Some(self.transactions).filter(|full| !full.is_empty()); - PropagateTransactions { pooled, full } - } } /// A helper type to create the pooled transactions message based on the negotiated version of the