Skip to content

Commit

Permalink
chore: apply missing const for fn lint txpool (#6381)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Feb 3, 2024
1 parent 44a9975 commit 4dc6aee
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 80 deletions.
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions crates/transaction-pool/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionId> {
pub(crate) const fn start_bound(self) -> std::ops::Bound<TransactionId> {
std::ops::Bound::Included(TransactionId::new(self, 0))
}
}
Expand All @@ -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 }
}

Expand All @@ -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
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/maintain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down Expand Up @@ -436,7 +436,7 @@ struct FinalizedBlockTracker {
}

impl FinalizedBlockTracker {
fn new(last_finalized_block: Option<BlockNumber>) -> Self {
const fn new(last_finalized_block: Option<BlockNumber>) -> Self {
Self { last_finalized_block }
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub struct NoopInsertError {
}

impl NoopInsertError {
fn new(tx: EthPooledTransaction) -> Self {
const fn new(tx: EthPooledTransaction) -> Self {
Self { tx }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/best.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub struct BestTransactionFilter<I, P> {

impl<I, P> BestTransactionFilter<I, P> {
/// 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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<T: PoolTransaction> BlobTransactions<T> {
}

/// 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<Arc<ValidPoolTransaction<T>>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) |
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -999,15 +999,15 @@ pub enum AddedTransaction<T: PoolTransaction> {

impl<T: PoolTransaction> AddedTransaction<T> {
/// Returns whether the transaction has been added to the pending pool.
pub(crate) fn as_pending(&self) -> Option<&AddedPendingTransaction<T>> {
pub(crate) const fn as_pending(&self) -> Option<&AddedPendingTransaction<T>> {
match self {
AddedTransaction::Pending(tx) => Some(tx),
_ => None,
}
}

/// Returns the replaced transaction if there was one
pub(crate) fn replaced(&self) -> Option<&Arc<ValidPoolTransaction<T>>> {
pub(crate) const fn replaced(&self) -> Option<&Arc<ValidPoolTransaction<T>>> {
match self {
AddedTransaction::Pending(tx) => tx.replaced.as_ref(),
AddedTransaction::Parked { replaced, .. } => replaced.as_ref(),
Expand Down Expand Up @@ -1049,7 +1049,7 @@ impl<T: PoolTransaction> AddedTransaction<T> {

/// 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,
Expand Down
4 changes: 2 additions & 2 deletions crates/transaction-pool/src/pool/parked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<T: ParkedOrd> Ord for ParkedPoolTransaction<T> {

/// 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,
Expand All @@ -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 }
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/transaction-pool/src/pool/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<T: TransactionOrdering> TxPool<T> {
}

/// Returns access to the [`AllTransactions`] container.
pub(crate) fn all(&self) -> &AllTransactions<T::Transaction> {
pub(crate) const fn all(&self) -> &AllTransactions<T::Transaction> {
&self.all_transactions
}

Expand All @@ -131,7 +131,7 @@ impl<T: TransactionOrdering> TxPool<T> {
}

/// 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,
Expand Down Expand Up @@ -887,15 +887,15 @@ impl<T: TransactionOrdering> Drop for TxPool<T> {
#[cfg(any(test, feature = "test-utils"))]
#[allow(dead_code)]
impl<T: TransactionOrdering> TxPool<T> {
pub(crate) fn pending(&self) -> &PendingPool<T> {
pub(crate) const fn pending(&self) -> &PendingPool<T> {
&self.pending_pool
}

pub(crate) fn base_fee(&self) -> &ParkedPool<BasefeeOrd<T::Transaction>> {
pub(crate) const fn base_fee(&self) -> &ParkedPool<BasefeeOrd<T::Transaction>> {
&self.basefee_pool
}

pub(crate) fn queued(&self) -> &ParkedPool<QueuedOrd<T::Transaction>> {
pub(crate) const fn queued(&self) -> &ParkedPool<QueuedOrd<T::Transaction>> {
&self.queued_pool
}
}
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions crates/transaction-pool/src/test_utils/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<R: Rng> TransactionGenerator<R> {
}

/// 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
}
Expand All @@ -60,7 +60,7 @@ impl<R: Rng> TransactionGenerator<R> {
}

/// 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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 4dc6aee

Please sign in to comment.