Skip to content

Commit

Permalink
primitive-traits: use alloy MIN_PROTOCOL_BASE_FEE constant (paradig…
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Oct 24, 2024
1 parent 8b317f2 commit bea6e27
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 40 deletions.
3 changes: 1 addition & 2 deletions crates/node/core/src/args/txpool.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Transaction pool arguments
use crate::cli::config::RethTransactionPoolConfig;
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use alloy_eips::eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE};
use alloy_primitives::Address;
use clap::Args;
use reth_primitives::constants::MIN_PROTOCOL_BASE_FEE;
use reth_transaction_pool::{
blobstore::disk::DEFAULT_MAX_CACHED_BLOBS,
pool::{NEW_TX_LISTENER_BUFFER_SIZE, PENDING_TX_LISTENER_BUFFER_SIZE},
Expand Down
26 changes: 1 addition & 25 deletions crates/primitives-traits/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Ethereum protocol-related constants
use alloy_primitives::{address, b256, Address, B256, U256};
use alloy_primitives::{address, b256, Address, B256};

/// Gas units, for example [`GIGAGAS`].
pub mod gas_units;
Expand All @@ -9,20 +9,6 @@ pub use gas_units::{GIGAGAS, KILOGAS, MEGAGAS};
/// The client version: `reth/v{major}.{minor}.{patch}`
pub const RETH_CLIENT_VERSION: &str = concat!("reth/v", env!("CARGO_PKG_VERSION"));

/// The minimum tx fee below which the txpool will reject the transaction.
///
/// Configured to `7` WEI which is the lowest possible value of base fee under mainnet EIP-1559
/// parameters. `BASE_FEE_MAX_CHANGE_DENOMINATOR` <https://eips.ethereum.org/EIPS/eip-1559>
/// is `8`, or 12.5%. Once the base fee has dropped to `7` WEI it cannot decrease further because
/// 12.5% of 7 is less than 1.
///
/// Note that min base fee under different 1559 parameterizations may differ, but there's no
/// significant harm in leaving this setting as is.
pub const MIN_PROTOCOL_BASE_FEE: u64 = 7;

/// Same as [`MIN_PROTOCOL_BASE_FEE`] but as a U256.
pub const MIN_PROTOCOL_BASE_FEE_U256: U256 = U256::from_limbs([7u64, 0, 0, 0]);

/// Base fee max change denominator as defined in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
pub const EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 8;

Expand Down Expand Up @@ -79,13 +65,3 @@ pub const OP_SYSTEM_TX_TO_ADDR: Address = address!("4200000000000000000000000000
/// Unwind depth of `3` blocks significantly reduces the chance that the reorged block is kept in
/// the database.
pub const BEACON_CONSENSUS_REORG_UNWIND_DEPTH: u64 = 3;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn min_protocol_sanity() {
assert_eq!(MIN_PROTOCOL_BASE_FEE_U256.to::<u64>(), MIN_PROTOCOL_BASE_FEE);
}
}
3 changes: 1 addition & 2 deletions crates/transaction-pool/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate::{
PoolSize, TransactionOrigin,
};
use alloy_consensus::constants::EIP4844_TX_TYPE_ID;
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use alloy_eips::eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE};
use alloy_primitives::Address;
use reth_primitives::constants::MIN_PROTOCOL_BASE_FEE;
use std::{collections::HashSet, ops::Mul};

/// Guarantees max transactions for one sender, compatible with geth/erigon
Expand Down
4 changes: 2 additions & 2 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use alloy_consensus::constants::{
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
};
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use alloy_eips::eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE};
use alloy_primitives::{Address, TxHash, B256};
use reth_primitives::constants::{eip4844::BLOB_TX_MIN_BLOB_GASPRICE, MIN_PROTOCOL_BASE_FEE};
use reth_primitives::constants::eip4844::BLOB_TX_MIN_BLOB_GASPRICE;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use std::{
Expand Down
6 changes: 2 additions & 4 deletions crates/transaction-pool/src/test_utils/gen.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::EthPooledTransaction;
use alloy_consensus::{TxEip1559, TxEip4844, TxLegacy};
use alloy_eips::{eip2718::Encodable2718, eip2930::AccessList};
use alloy_eips::{eip1559::MIN_PROTOCOL_BASE_FEE, eip2718::Encodable2718, eip2930::AccessList};
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
use rand::Rng;
use reth_chainspec::MAINNET;
use reth_primitives::{
constants::MIN_PROTOCOL_BASE_FEE, sign_message, Transaction, TransactionSigned,
};
use reth_primitives::{sign_message, Transaction, TransactionSigned};

/// A generator for transactions for testing purposes.
#[derive(Debug)]
Expand Down
5 changes: 2 additions & 3 deletions crates/transaction-pool/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ use alloy_consensus::{
constants::{EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID},
TxEip1559, TxEip2930, TxEip4844, TxLegacy,
};
use alloy_eips::eip2930::AccessList;
use alloy_eips::{eip1559::MIN_PROTOCOL_BASE_FEE, eip2930::AccessList};
use alloy_primitives::{Address, Bytes, ChainId, TxHash, TxKind, B256, U256};
use paste::paste;
use rand::{
distributions::{Uniform, WeightedIndex},
prelude::Distribution,
};
use reth_primitives::{
constants::{eip4844::DATA_GAS_PER_BLOB, MIN_PROTOCOL_BASE_FEE},
transaction::TryFromRecoveredTransactionError,
constants::eip4844::DATA_GAS_PER_BLOB, transaction::TryFromRecoveredTransactionError,
BlobTransactionSidecar, BlobTransactionValidationError, PooledTransactionsElementEcRecovered,
Signature, Transaction, TransactionSigned, TransactionSignedEcRecovered, TxType,
};
Expand Down
3 changes: 1 addition & 2 deletions crates/transaction-pool/tests/it/evict.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Transaction pool eviction tests.
use alloy_eips::eip1559::ETHEREUM_BLOCK_GAS_LIMIT;
use alloy_eips::eip1559::{ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE};
use alloy_primitives::{Address, B256};
use rand::distributions::Uniform;
use reth_primitives::constants::MIN_PROTOCOL_BASE_FEE;
use reth_transaction_pool::{
error::PoolErrorKind,
test_utils::{
Expand Down

0 comments on commit bea6e27

Please sign in to comment.