Skip to content

Commit

Permalink
feat(txpool) - add flag for local tx propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xprames committed Jul 28, 2023
1 parent d8677b4 commit 143de80
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ pub struct EthTransactionValidatorBuilder {
///
/// Default is 1
additional_tasks: usize,
/// Toggle to determine if a local transaction should be propagated
propagate_local_transactions: bool,
}

impl EthTransactionValidatorBuilder {
Expand All @@ -153,6 +155,8 @@ impl EthTransactionValidatorBuilder {
block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
minimum_priority_fee: None,
additional_tasks: 1,
// default to true, can potentially take this as a param in the future
propagate_local_transactions: true,
}
}

Expand Down Expand Up @@ -188,6 +192,23 @@ impl EthTransactionValidatorBuilder {
self.eip1559 = eip1559;
self
}
/// Sets toggle to propagate transactions received locally by this client (e.g
/// transactions from eth_Sendtransaction to this nodes' RPC server)
///
/// If set to false, only transactions received by network peers (via
/// p2p) will be marked as propagated in the local transaction pool and returned on a
/// GetPooledTransactions p2p request
pub fn set_propagate_local_transactions(mut self, propagate_local_txs: bool) -> Self {
self.propagate_local_transactions = propagate_local_txs;
self
}
/// Disables propagating transactions recieved locally by this client
///
/// For more information, check docs for set_propagate_local_transactions
pub fn no_local_transaction_propagation(mut self) -> Self {
self.propagate_local_transactions = false;
self
}

/// Sets a minimum priority fee that's enforced for acceptance into the pool.
pub fn with_minimum_priority_fee(mut self, minimum_priority_fee: u128) -> Self {
Expand Down Expand Up @@ -222,6 +243,7 @@ impl EthTransactionValidatorBuilder {
block_gas_limit,
minimum_priority_fee,
additional_tasks,
propagate_local_transactions,
} = self;

let inner = EthTransactionValidatorInner {
Expand All @@ -232,6 +254,7 @@ impl EthTransactionValidatorBuilder {
eip1559,
block_gas_limit,
minimum_priority_fee,
propagate_local_transactions,
_marker: Default::default(),
};

Expand Down Expand Up @@ -277,6 +300,8 @@ struct EthTransactionValidatorInner<Client, T> {
minimum_priority_fee: Option<u128>,
/// Marker for the transaction type
_marker: PhantomData<T>,
/// Toggle to determine if a local transaction should be propagated
propagate_local_transactions: bool,
}

// === impl EthTransactionValidatorInner ===
Expand Down Expand Up @@ -435,7 +460,9 @@ where
balance: account.balance,
state_nonce: account.nonce,
transaction,
propagate: true,
// by this point assume all external transactions should be propagated
propagate: matches!(origin, TransactionOrigin::External) ||
self.propagate_local_transactions,
}
}
}

0 comments on commit 143de80

Please sign in to comment.