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 f3a7ae1 commit 2ac06c3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/transaction-pool/src/validate/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub struct EthTransactionValidatorBuilder {
///
/// Default is 1
additional_tasks: usize,
/// Toggle to determine if a local transaction should be propagated
local_tx_propagation: bool,
}

impl EthTransactionValidatorBuilder {
Expand All @@ -150,6 +152,7 @@ impl EthTransactionValidatorBuilder {
block_gas_limit: ETHEREUM_BLOCK_GAS_LIMIT,
minimum_priority_fee: None,
additional_tasks: 1,
local_tx_propagation: true, // default to true, can potentially take this as a param
}
}

Expand Down Expand Up @@ -185,6 +188,11 @@ impl EthTransactionValidatorBuilder {
self.eip1559 = eip1559;
self
}
/// Sets the local transaction propagation toggle
pub fn set_local_tx_propagation(mut self, propagate_local_txs: bool) -> Self {
self.local_tx_propagation = propagate_local_txs;
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 @@ -219,6 +227,7 @@ impl EthTransactionValidatorBuilder {
block_gas_limit,
minimum_priority_fee,
additional_tasks,
local_tx_propagation,
} = self;

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

Expand Down Expand Up @@ -274,6 +284,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
local_tx_propagation: bool,
}

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

0 comments on commit 2ac06c3

Please sign in to comment.