From 4dc6aeefa9aa78f1218e8d545f2ef1ae9a728ed4 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 3 Feb 2024 18:33:05 +0100 Subject: [PATCH] chore: apply missing const for fn lint txpool (#6381) --- crates/transaction-pool/src/config.rs | 6 +++--- crates/transaction-pool/src/identifier.rs | 8 ++++---- crates/transaction-pool/src/lib.rs | 1 + crates/transaction-pool/src/maintain.rs | 6 +++--- crates/transaction-pool/src/noop.rs | 2 +- crates/transaction-pool/src/pool/best.rs | 2 +- crates/transaction-pool/src/pool/blob.rs | 2 +- crates/transaction-pool/src/pool/events.rs | 2 +- crates/transaction-pool/src/pool/listener.rs | 2 +- crates/transaction-pool/src/pool/mod.rs | 12 +++++------ crates/transaction-pool/src/pool/parked.rs | 4 ++-- crates/transaction-pool/src/pool/state.rs | 14 ++++++------- crates/transaction-pool/src/pool/txpool.rs | 12 +++++------ crates/transaction-pool/src/test_utils/gen.rs | 18 ++++++++--------- .../transaction-pool/src/test_utils/mock.rs | 16 +++++++-------- crates/transaction-pool/src/traits.rs | 20 +++++++++---------- crates/transaction-pool/src/validate/eth.rs | 20 +++++++++---------- crates/transaction-pool/src/validate/mod.rs | 14 ++++++------- 18 files changed, 81 insertions(+), 80 deletions(-) diff --git a/crates/transaction-pool/src/config.rs b/crates/transaction-pool/src/config.rs index c003ce862..5c3a5325e 100644 --- a/crates/transaction-pool/src/config.rs +++ b/crates/transaction-pool/src/config.rs @@ -96,7 +96,7 @@ pub struct PriceBumpConfig { impl PriceBumpConfig { /// Returns the price bump required to replace the given transaction type. #[inline] - pub(crate) fn price_bump(&self, tx_type: u8) -> u128 { + pub(crate) const fn price_bump(&self, tx_type: u8) -> u128 { if tx_type == EIP4844_TX_TYPE_ID { return self.replace_blob_tx_price_bump } @@ -143,7 +143,7 @@ impl Default for LocalTransactionConfig { impl LocalTransactionConfig { /// Returns whether local transactions are not exempt from the configured limits. #[inline] - pub fn no_local_exemptions(&self) -> bool { + pub const fn no_local_exemptions(&self) -> bool { self.no_exemptions } @@ -170,7 +170,7 @@ impl LocalTransactionConfig { /// 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 { + pub const fn set_propagate_local_transactions(mut self, propagate_local_txs: bool) -> Self { self.propagate_local_transactions = propagate_local_txs; self } diff --git a/crates/transaction-pool/src/identifier.rs b/crates/transaction-pool/src/identifier.rs index f5915ec3f..108c514ca 100644 --- a/crates/transaction-pool/src/identifier.rs +++ b/crates/transaction-pool/src/identifier.rs @@ -57,7 +57,7 @@ pub struct SenderId(u64); impl SenderId { /// Returns a `Bound` for `TransactionId` starting with nonce `0` - pub(crate) fn start_bound(self) -> std::ops::Bound { + pub(crate) const fn start_bound(self) -> std::ops::Bound { std::ops::Bound::Included(TransactionId::new(self, 0)) } } @@ -84,7 +84,7 @@ pub struct TransactionId { impl TransactionId { /// Create a new identifier pair - pub fn new(sender: SenderId, nonce: u64) -> Self { + pub const fn new(sender: SenderId, nonce: u64) -> Self { Self { sender, nonce } } @@ -110,13 +110,13 @@ impl TransactionId { } /// Returns the `TransactionId` that directly follows this transaction: `self.nonce + 1` - pub fn descendant(&self) -> TransactionId { + pub const fn descendant(&self) -> TransactionId { TransactionId::new(self.sender, self.nonce + 1) } /// Returns the nonce the follows directly after this. #[inline] - pub(crate) fn next_nonce(&self) -> u64 { + pub(crate) const fn next_nonce(&self) -> u64 { self.nonce + 1 } } diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 53f9a4432..1bc0ad1ed 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -147,6 +147,7 @@ issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![warn(clippy::missing_const_for_fn)] use crate::{identifier::TransactionId, pool::PoolInner}; use aquamarine as _; diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 055e8ce3b..7a7acc547 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -59,7 +59,7 @@ pub struct LocalTransactionBackupConfig { impl LocalTransactionBackupConfig { /// Receive path to transactions backup and return initialized config - pub fn with_local_txs_backup(transactions_path: PathBuf) -> Self { + pub const fn with_local_txs_backup(transactions_path: PathBuf) -> Self { Self { transactions_path: Some(transactions_path) } } } @@ -436,7 +436,7 @@ struct FinalizedBlockTracker { } impl FinalizedBlockTracker { - fn new(last_finalized_block: Option) -> Self { + const fn new(last_finalized_block: Option) -> Self { Self { last_finalized_block } } @@ -473,7 +473,7 @@ enum MaintainedPoolState { impl MaintainedPoolState { /// Returns `true` if the pool is assumed to be out of sync with the current state. #[inline] - fn is_drifted(&self) -> bool { + const fn is_drifted(&self) -> bool { matches!(self, MaintainedPoolState::Drifted) } } diff --git a/crates/transaction-pool/src/noop.rs b/crates/transaction-pool/src/noop.rs index c69e52d6d..c0c3b97c4 100644 --- a/crates/transaction-pool/src/noop.rs +++ b/crates/transaction-pool/src/noop.rs @@ -298,7 +298,7 @@ pub struct NoopInsertError { } impl NoopInsertError { - fn new(tx: EthPooledTransaction) -> Self { + const fn new(tx: EthPooledTransaction) -> Self { Self { tx } } diff --git a/crates/transaction-pool/src/pool/best.rs b/crates/transaction-pool/src/pool/best.rs index 8b7468c41..a140b82fd 100644 --- a/crates/transaction-pool/src/pool/best.rs +++ b/crates/transaction-pool/src/pool/best.rs @@ -204,7 +204,7 @@ pub struct BestTransactionFilter { impl BestTransactionFilter { /// Create a new [`BestTransactionFilter`] with the given predicate. - pub(crate) fn new(best: I, predicate: P) -> Self { + pub(crate) const fn new(best: I, predicate: P) -> Self { Self { best, predicate } } } diff --git a/crates/transaction-pool/src/pool/blob.rs b/crates/transaction-pool/src/pool/blob.rs index 0e8e17d7b..45371eadf 100644 --- a/crates/transaction-pool/src/pool/blob.rs +++ b/crates/transaction-pool/src/pool/blob.rs @@ -82,7 +82,7 @@ impl BlobTransactions { } /// Returns all transactions that satisfy the given basefee and blob_fee. - pub(crate) fn satisfy_attributes( + pub(crate) const fn satisfy_attributes( &self, _best_transactions_attributes: BestTransactionsAttributes, ) -> Vec>> { diff --git a/crates/transaction-pool/src/pool/events.rs b/crates/transaction-pool/src/pool/events.rs index c3a67b8bd..58578d08f 100644 --- a/crates/transaction-pool/src/pool/events.rs +++ b/crates/transaction-pool/src/pool/events.rs @@ -79,7 +79,7 @@ pub enum TransactionEvent { impl TransactionEvent { /// Returns `true` if the event is final and no more events are expected for this transaction /// hash. - pub fn is_final(&self) -> bool { + pub const fn is_final(&self) -> bool { matches!( self, TransactionEvent::Replaced(_) | diff --git a/crates/transaction-pool/src/pool/listener.rs b/crates/transaction-pool/src/pool/listener.rs index aca64c9cd..a317ce6ef 100644 --- a/crates/transaction-pool/src/pool/listener.rs +++ b/crates/transaction-pool/src/pool/listener.rs @@ -30,7 +30,7 @@ pub struct TransactionEvents { impl TransactionEvents { /// The hash for this transaction - pub fn hash(&self) -> TxHash { + pub const fn hash(&self) -> TxHash { self.hash } } diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 1f0a28117..bab3777b2 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -177,7 +177,7 @@ where } /// Returns the configured blob store. - pub(crate) fn blob_store(&self) -> &S { + pub(crate) const fn blob_store(&self) -> &S { &self.blob_store } @@ -222,12 +222,12 @@ where } /// Get the config the pool was configured with. - pub fn config(&self) -> &PoolConfig { + pub const fn config(&self) -> &PoolConfig { &self.config } /// Get the validator reference. - pub fn validator(&self) -> &V { + pub const fn validator(&self) -> &V { &self.validator } @@ -999,7 +999,7 @@ pub enum AddedTransaction { impl AddedTransaction { /// Returns whether the transaction has been added to the pending pool. - pub(crate) fn as_pending(&self) -> Option<&AddedPendingTransaction> { + pub(crate) const fn as_pending(&self) -> Option<&AddedPendingTransaction> { match self { AddedTransaction::Pending(tx) => Some(tx), _ => None, @@ -1007,7 +1007,7 @@ impl AddedTransaction { } /// Returns the replaced transaction if there was one - pub(crate) fn replaced(&self) -> Option<&Arc>> { + pub(crate) const fn replaced(&self) -> Option<&Arc>> { match self { AddedTransaction::Pending(tx) => tx.replaced.as_ref(), AddedTransaction::Parked { replaced, .. } => replaced.as_ref(), @@ -1049,7 +1049,7 @@ impl AddedTransaction { /// Returns the subpool this transaction was added to #[cfg(test)] - pub(crate) fn subpool(&self) -> SubPool { + pub(crate) const fn subpool(&self) -> SubPool { match self { AddedTransaction::Pending(_) => SubPool::Pending, AddedTransaction::Parked { subpool, .. } => *subpool, diff --git a/crates/transaction-pool/src/pool/parked.rs b/crates/transaction-pool/src/pool/parked.rs index e92632084..671248b75 100644 --- a/crates/transaction-pool/src/pool/parked.rs +++ b/crates/transaction-pool/src/pool/parked.rs @@ -325,7 +325,7 @@ impl Ord for ParkedPoolTransaction { /// Includes a [SenderId] and `submission_id`. This is used to sort senders by their last /// submission id. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub struct SubmissionSenderId { /// The sender id pub(crate) sender_id: SenderId, @@ -335,7 +335,7 @@ pub struct SubmissionSenderId { impl SubmissionSenderId { /// Creates a new [SubmissionSenderId] based on the [SenderId] and `submission_id`. - fn new(sender_id: SenderId, submission_id: u64) -> Self { + const fn new(sender_id: SenderId, submission_id: u64) -> Self { Self { sender_id, submission_id } } } diff --git a/crates/transaction-pool/src/pool/state.rs b/crates/transaction-pool/src/pool/state.rs index b7058c7ad..2e6a54123 100644 --- a/crates/transaction-pool/src/pool/state.rs +++ b/crates/transaction-pool/src/pool/state.rs @@ -48,19 +48,19 @@ impl TxState { /// - enough fee cap /// - enough blob fee cap #[inline] - pub(crate) fn is_pending(&self) -> bool { + pub(crate) const fn is_pending(&self) -> bool { self.bits() >= TxState::PENDING_POOL_BITS.bits() } /// Whether this transaction is a blob transaction. #[inline] - pub(crate) fn is_blob(&self) -> bool { + pub(crate) const fn is_blob(&self) -> bool { self.contains(TxState::BLOB_TRANSACTION) } /// Returns `true` if the transaction has a nonce gap. #[inline] - pub(crate) fn has_nonce_gap(&self) -> bool { + pub(crate) const fn has_nonce_gap(&self) -> bool { !self.intersects(TxState::NO_NONCE_GAPS) } } @@ -86,25 +86,25 @@ pub enum SubPool { impl SubPool { /// Whether this transaction is to be moved to the pending sub-pool. #[inline] - pub fn is_pending(&self) -> bool { + pub const fn is_pending(&self) -> bool { matches!(self, SubPool::Pending) } /// Whether this transaction is in the queued pool. #[inline] - pub fn is_queued(&self) -> bool { + pub const fn is_queued(&self) -> bool { matches!(self, SubPool::Queued) } /// Whether this transaction is in the base fee pool. #[inline] - pub fn is_base_fee(&self) -> bool { + pub const fn is_base_fee(&self) -> bool { matches!(self, SubPool::BaseFee) } /// Whether this transaction is in the blob pool. #[inline] - pub fn is_blob(&self) -> bool { + pub const fn is_blob(&self) -> bool { matches!(self, SubPool::Blob) } diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index 264c6172b..5644301b5 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -106,7 +106,7 @@ impl TxPool { } /// Returns access to the [`AllTransactions`] container. - pub(crate) fn all(&self) -> &AllTransactions { + pub(crate) const fn all(&self) -> &AllTransactions { &self.all_transactions } @@ -131,7 +131,7 @@ impl TxPool { } /// Returns the currently tracked block values - pub(crate) fn block_info(&self) -> BlockInfo { + pub(crate) const fn block_info(&self) -> BlockInfo { BlockInfo { last_seen_block_hash: self.all_transactions.last_seen_block_hash, last_seen_block_number: self.all_transactions.last_seen_block_number, @@ -887,15 +887,15 @@ impl Drop for TxPool { #[cfg(any(test, feature = "test-utils"))] #[allow(dead_code)] impl TxPool { - pub(crate) fn pending(&self) -> &PendingPool { + pub(crate) const fn pending(&self) -> &PendingPool { &self.pending_pool } - pub(crate) fn base_fee(&self) -> &ParkedPool> { + pub(crate) const fn base_fee(&self) -> &ParkedPool> { &self.basefee_pool } - pub(crate) fn queued(&self) -> &ParkedPool> { + pub(crate) const fn queued(&self) -> &ParkedPool> { &self.queued_pool } } @@ -2018,7 +2018,7 @@ mod tests { impl PromotionTest { /// Returns the test case for the opposite update - fn opposite(&self) -> Self { + const fn opposite(&self) -> Self { Self { basefee: self.basefee_update, blobfee: self.blobfee_update, diff --git a/crates/transaction-pool/src/test_utils/gen.rs b/crates/transaction-pool/src/test_utils/gen.rs index d94719473..63958035f 100644 --- a/crates/transaction-pool/src/test_utils/gen.rs +++ b/crates/transaction-pool/src/test_utils/gen.rs @@ -48,7 +48,7 @@ impl TransactionGenerator { } /// Sets the default gas limit for all generated transactions - pub fn with_gas_limit(mut self, gas_limit: u64) -> Self { + pub const fn with_gas_limit(mut self, gas_limit: u64) -> Self { self.gas_limit = gas_limit; self } @@ -60,7 +60,7 @@ impl TransactionGenerator { } /// Sets the base fee for the generated transactions - pub fn with_base_fee(mut self, base_fee: u64) -> Self { + pub const fn with_base_fee(mut self, base_fee: u64) -> Self { self.base_fee = base_fee as u128; self } @@ -170,19 +170,19 @@ impl TransactionBuilder { } /// Sets the signer for the transaction builder. - pub fn signer(mut self, signer: B256) -> Self { + pub const fn signer(mut self, signer: B256) -> Self { self.signer = signer; self } /// Sets the gas limit for the transaction builder. - pub fn gas_limit(mut self, gas_limit: u64) -> Self { + pub const fn gas_limit(mut self, gas_limit: u64) -> Self { self.gas_limit = gas_limit; self } /// Sets the nonce for the transaction builder. - pub fn nonce(mut self, nonce: u64) -> Self { + pub const fn nonce(mut self, nonce: u64) -> Self { self.nonce = nonce; self } @@ -200,19 +200,19 @@ impl TransactionBuilder { } /// Sets the maximum fee per gas for the transaction builder. - pub fn max_fee_per_gas(mut self, max_fee_per_gas: u128) -> Self { + pub const fn max_fee_per_gas(mut self, max_fee_per_gas: u128) -> Self { self.max_fee_per_gas = max_fee_per_gas; self } /// Sets the maximum priority fee per gas for the transaction builder. - pub fn max_priority_fee_per_gas(mut self, max_priority_fee_per_gas: u128) -> Self { + pub const fn max_priority_fee_per_gas(mut self, max_priority_fee_per_gas: u128) -> Self { self.max_priority_fee_per_gas = max_priority_fee_per_gas; self } /// Sets the recipient or contract address for the transaction builder. - pub fn to(mut self, to: Address) -> Self { + pub const fn to(mut self, to: Address) -> Self { self.to = TransactionKind::Call(to); self } @@ -236,7 +236,7 @@ impl TransactionBuilder { } /// Sets the chain ID for the transaction. - pub fn chain_id(mut self, chain_id: u64) -> Self { + pub const fn chain_id(mut self, chain_id: u64) -> Self { self.chain_id = chain_id; self } diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index eefc48f4f..abce4b774 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -397,7 +397,7 @@ impl MockTransaction { } /// Gets the priority fee for dynamic fee transactions (EIP-1559 and EIP-4844) - pub fn get_priority_fee(&self) -> Option { + pub const fn get_priority_fee(&self) -> Option { match self { MockTransaction::Eip1559 { max_priority_fee_per_gas, .. } | MockTransaction::Eip4844 { max_priority_fee_per_gas, .. } => { @@ -424,7 +424,7 @@ impl MockTransaction { } /// Gets the max fee for dynamic fee transactions (EIP-1559 and EIP-4844) - pub fn get_max_fee(&self) -> Option { + pub const fn get_max_fee(&self) -> Option { match self { MockTransaction::Eip1559 { max_fee_per_gas, .. } | MockTransaction::Eip4844 { max_fee_per_gas, .. } => Some(*max_fee_per_gas), @@ -492,7 +492,7 @@ impl MockTransaction { } /// Gets the gas price for the transaction. - pub fn get_gas_price(&self) -> u128 { + pub const fn get_gas_price(&self) -> u128 { match self { MockTransaction::Legacy { gas_price, .. } | MockTransaction::Eip2930 { gas_price, .. } => *gas_price, @@ -596,7 +596,7 @@ impl MockTransaction { } /// Returns the transaction type identifier associated with the current [MockTransaction]. - pub fn tx_type(&self) -> u8 { + pub const fn tx_type(&self) -> u8 { match self { Self::Legacy { .. } => LEGACY_TX_TYPE_ID, Self::Eip1559 { .. } => EIP1559_TX_TYPE_ID, @@ -608,22 +608,22 @@ impl MockTransaction { } /// Checks if the transaction is of the legacy type. - pub fn is_legacy(&self) -> bool { + pub const fn is_legacy(&self) -> bool { matches!(self, MockTransaction::Legacy { .. }) } /// Checks if the transaction is of the EIP-1559 type. - pub fn is_eip1559(&self) -> bool { + pub const fn is_eip1559(&self) -> bool { matches!(self, MockTransaction::Eip1559 { .. }) } /// Checks if the transaction is of the EIP-4844 type. - pub fn is_eip4844(&self) -> bool { + pub const fn is_eip4844(&self) -> bool { matches!(self, MockTransaction::Eip4844 { .. }) } /// Checks if the transaction is of the EIP-2930 type. - pub fn is_eip2930(&self) -> bool { + pub const fn is_eip2930(&self) -> bool { matches!(self, MockTransaction::Eip2930 { .. }) } } diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index dd6fef3f3..b60ac9279 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -401,7 +401,7 @@ pub enum TransactionListenerKind { impl TransactionListenerKind { /// Returns true if we're only interested in transactions that are allowed to be propagated. #[inline] - pub fn is_propagate_only(&self) -> bool { + pub const fn is_propagate_only(&self) -> bool { matches!(self, Self::PropagateOnly) } } @@ -457,7 +457,7 @@ pub enum PropagateKind { impl PropagateKind { /// Returns the peer the transaction was sent to - pub fn peer(&self) -> &PeerId { + pub const fn peer(&self) -> &PeerId { match self { PropagateKind::Full(peer) => peer, PropagateKind::Hash(peer) => peer, @@ -613,7 +613,7 @@ pub struct ChangedAccount { impl ChangedAccount { /// Creates a new `ChangedAccount` with the given address and 0 balance and nonce. - pub(crate) fn empty(address: Address) -> Self { + pub(crate) const fn empty(address: Address) -> Self { Self { address, nonce: 0, balance: U256::ZERO } } } @@ -695,17 +695,17 @@ pub struct BestTransactionsAttributes { impl BestTransactionsAttributes { /// Creates a new `BestTransactionsAttributes` with the given basefee and blob fee. - pub fn new(basefee: u64, blob_fee: Option) -> Self { + pub const fn new(basefee: u64, blob_fee: Option) -> Self { Self { basefee, blob_fee } } /// Creates a new `BestTransactionsAttributes` with the given basefee. - pub fn base_fee(basefee: u64) -> Self { + pub const fn base_fee(basefee: u64) -> Self { Self::new(basefee, None) } /// Sets the given blob fee. - pub fn with_blob_fee(mut self, blob_fee: u64) -> Self { + pub const fn with_blob_fee(mut self, blob_fee: u64) -> Self { self.blob_fee = Some(blob_fee); self } @@ -899,7 +899,7 @@ impl EthPooledTransaction { } /// Return the reference to the underlying transaction. - pub fn transaction(&self) -> &TransactionSignedEcRecovered { + pub const fn transaction(&self) -> &TransactionSignedEcRecovered { &self.transaction } } @@ -1092,7 +1092,7 @@ impl IntoRecoveredTransaction for EthPooledTransaction { } /// Represents the current status of the pool. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Copy, Default)] pub struct PoolSize { /// Number of transactions in the _pending_ sub-pool. pub pending: usize, @@ -1157,7 +1157,7 @@ pub enum GetPooledTransactionLimit { impl GetPooledTransactionLimit { /// Returns true if the given size exceeds the limit. #[inline] - pub fn exceeds(&self, size: usize) -> bool { + pub const fn exceeds(&self, size: usize) -> bool { match self { GetPooledTransactionLimit::None => false, GetPooledTransactionLimit::ResponseSizeSoftLimit(limit) => size > *limit, @@ -1177,7 +1177,7 @@ pub struct NewSubpoolTransactionStream { impl NewSubpoolTransactionStream { /// Create a new stream that yields full transactions from the subpool - pub fn new(st: Receiver>, subpool: SubPool) -> Self { + pub const fn new(st: Receiver>, subpool: SubPool) -> Self { Self { st, subpool } } diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index e19d9cc9e..f30b24c59 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -519,7 +519,7 @@ impl EthTransactionValidatorBuilder { } /// Disables the Cancun fork. - pub fn no_cancun(self) -> Self { + pub const fn no_cancun(self) -> Self { self.set_cancun(false) } @@ -533,40 +533,40 @@ impl EthTransactionValidatorBuilder { } /// Set the Cancun fork. - pub fn set_cancun(mut self, cancun: bool) -> Self { + pub const fn set_cancun(mut self, cancun: bool) -> Self { self.cancun = cancun; self } /// Disables the Shanghai fork. - pub fn no_shanghai(self) -> Self { + pub const fn no_shanghai(self) -> Self { self.set_shanghai(false) } /// Set the Shanghai fork. - pub fn set_shanghai(mut self, shanghai: bool) -> Self { + pub const fn set_shanghai(mut self, shanghai: bool) -> Self { self.shanghai = shanghai; self } /// Disables the eip2718 support. - pub fn no_eip2718(self) -> Self { + pub const fn no_eip2718(self) -> Self { self.set_eip2718(false) } /// Set eip2718 support. - pub fn set_eip2718(mut self, eip2718: bool) -> Self { + pub const fn set_eip2718(mut self, eip2718: bool) -> Self { self.eip2718 = eip2718; self } /// Disables the eip1559 support. - pub fn no_eip1559(self) -> Self { + pub const fn no_eip1559(self) -> Self { self.set_eip1559(false) } /// Set the eip1559 support. - pub fn set_eip1559(mut self, eip1559: bool) -> Self { + pub const fn set_eip1559(mut self, eip1559: bool) -> Self { self.eip1559 = eip1559; self } @@ -578,13 +578,13 @@ impl EthTransactionValidatorBuilder { } /// 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 { + pub const fn with_minimum_priority_fee(mut self, minimum_priority_fee: u128) -> Self { self.minimum_priority_fee = Some(minimum_priority_fee); self } /// Sets the number of additional tasks to spawn. - pub fn with_additional_tasks(mut self, additional_tasks: usize) -> Self { + pub const fn with_additional_tasks(mut self, additional_tasks: usize) -> Self { self.additional_tasks = additional_tasks; self } diff --git a/crates/transaction-pool/src/validate/mod.rs b/crates/transaction-pool/src/validate/mod.rs index 44ca627a5..2fb365ca5 100644 --- a/crates/transaction-pool/src/validate/mod.rs +++ b/crates/transaction-pool/src/validate/mod.rs @@ -63,17 +63,17 @@ impl TransactionValidationOutcome { } /// Returns true if the transaction is valid. - pub fn is_valid(&self) -> bool { + pub const fn is_valid(&self) -> bool { matches!(self, Self::Valid { .. }) } /// Returns true if the transaction is invalid. - pub fn is_invalid(&self) -> bool { + pub const fn is_invalid(&self) -> bool { matches!(self, Self::Invalid(_, _)) } /// Returns true if validation resulted in an error. - pub fn is_error(&self) -> bool { + pub const fn is_error(&self) -> bool { matches!(self, Self::Error(_, _)) } } @@ -116,7 +116,7 @@ impl ValidTransaction { impl ValidTransaction { #[inline] - pub(crate) fn transaction(&self) -> &T { + pub(crate) const fn transaction(&self) -> &T { match self { Self::Valid(transaction) => transaction, Self::ValidWithSidecar { transaction, .. } => transaction, @@ -249,12 +249,12 @@ impl ValidPoolTransaction { } /// Returns the internal identifier for the sender of this transaction - pub(crate) fn sender_id(&self) -> SenderId { + pub(crate) const fn sender_id(&self) -> SenderId { self.transaction_id.sender } /// Returns the internal identifier for this transaction. - pub(crate) fn id(&self) -> &TransactionId { + pub(crate) const fn id(&self) -> &TransactionId { &self.transaction_id } @@ -311,7 +311,7 @@ impl ValidPoolTransaction { } /// Whether the transaction originated locally. - pub fn is_local(&self) -> bool { + pub const fn is_local(&self) -> bool { self.origin.is_local() }