mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use MIN_TRANSACTION_GAS replace magic number (#10910)
This commit is contained in:
@ -1378,7 +1378,7 @@ mod tests {
|
||||
use alloy_primitives::{keccak256, Address, B256};
|
||||
use assert_matches::assert_matches;
|
||||
use linked_hash_set::LinkedHashSet;
|
||||
use reth_chainspec::{ChainSpecBuilder, MAINNET};
|
||||
use reth_chainspec::{ChainSpecBuilder, MAINNET, MIN_TRANSACTION_GAS};
|
||||
use reth_consensus::test_utils::TestConsensus;
|
||||
use reth_db::tables;
|
||||
use reth_db_api::transaction::DbTxMut;
|
||||
@ -1558,13 +1558,13 @@ mod tests {
|
||||
provider_rw.commit().unwrap();
|
||||
}
|
||||
|
||||
let single_tx_cost = U256::from(EIP1559_INITIAL_BASE_FEE * 21_000);
|
||||
let single_tx_cost = U256::from(EIP1559_INITIAL_BASE_FEE * MIN_TRANSACTION_GAS);
|
||||
let mock_tx = |nonce: u64| -> TransactionSignedEcRecovered {
|
||||
TransactionSigned::from_transaction_and_signature(
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: chain_spec.chain.id(),
|
||||
nonce,
|
||||
gas_limit: 21_000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: Address::ZERO.into(),
|
||||
max_fee_per_gas: EIP1559_INITIAL_BASE_FEE as u128,
|
||||
..Default::default()
|
||||
@ -1587,7 +1587,7 @@ mod tests {
|
||||
Receipt {
|
||||
tx_type: tx.tx_type(),
|
||||
success: true,
|
||||
cumulative_gas_used: (idx as u64 + 1) * 21_000,
|
||||
cumulative_gas_used: (idx as u64 + 1) * MIN_TRANSACTION_GAS,
|
||||
..Default::default()
|
||||
}
|
||||
.with_bloom()
|
||||
@ -1602,7 +1602,7 @@ mod tests {
|
||||
header: Header {
|
||||
number,
|
||||
parent_hash: parent.unwrap_or_default(),
|
||||
gas_used: body.len() as u64 * 21_000,
|
||||
gas_used: body.len() as u64 * MIN_TRANSACTION_GAS,
|
||||
gas_limit: chain_spec.max_gas_limit,
|
||||
mix_hash: B256::random(),
|
||||
base_fee_per_gas: Some(EIP1559_INITIAL_BASE_FEE),
|
||||
|
||||
@ -5,7 +5,7 @@ use crate::{
|
||||
use alloy_signer::SignerSync;
|
||||
use alloy_signer_local::PrivateKeySigner;
|
||||
use rand::{thread_rng, Rng};
|
||||
use reth_chainspec::{ChainSpec, EthereumHardfork};
|
||||
use reth_chainspec::{ChainSpec, EthereumHardfork, MIN_TRANSACTION_GAS};
|
||||
use reth_execution_types::{Chain, ExecutionOutcome};
|
||||
use reth_primitives::{
|
||||
constants::{EIP1559_INITIAL_BASE_FEE, EMPTY_ROOT_HASH},
|
||||
@ -72,7 +72,7 @@ impl TestBlockBuilder {
|
||||
|
||||
/// Gas cost of a single transaction generated by the block builder.
|
||||
pub fn single_tx_cost() -> U256 {
|
||||
U256::from(EIP1559_INITIAL_BASE_FEE * 21_000)
|
||||
U256::from(EIP1559_INITIAL_BASE_FEE * MIN_TRANSACTION_GAS)
|
||||
}
|
||||
|
||||
/// Generates a random [`SealedBlockWithSenders`].
|
||||
@ -87,7 +87,7 @@ impl TestBlockBuilder {
|
||||
let tx = Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: self.chain_spec.chain.id(),
|
||||
nonce,
|
||||
gas_limit: 21_000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: Address::random().into(),
|
||||
max_fee_per_gas: EIP1559_INITIAL_BASE_FEE as u128,
|
||||
max_priority_fee_per_gas: 1,
|
||||
@ -125,7 +125,7 @@ impl TestBlockBuilder {
|
||||
Receipt {
|
||||
tx_type: tx.tx_type(),
|
||||
success: true,
|
||||
cumulative_gas_used: (idx as u64 + 1) * 21_000,
|
||||
cumulative_gas_used: (idx as u64 + 1) * MIN_TRANSACTION_GAS,
|
||||
..Default::default()
|
||||
}
|
||||
.with_bloom()
|
||||
@ -137,7 +137,7 @@ impl TestBlockBuilder {
|
||||
let header = Header {
|
||||
number,
|
||||
parent_hash,
|
||||
gas_used: transactions.len() as u64 * 21_000,
|
||||
gas_used: transactions.len() as u64 * MIN_TRANSACTION_GAS,
|
||||
gas_limit: self.chain_spec.max_gas_limit,
|
||||
mix_hash: B256::random(),
|
||||
base_fee_per_gas: Some(EIP1559_INITIAL_BASE_FEE),
|
||||
@ -261,7 +261,7 @@ impl TestBlockBuilder {
|
||||
.map(|(idx, tx)| Receipt {
|
||||
tx_type: tx.tx_type(),
|
||||
success: true,
|
||||
cumulative_gas_used: (idx as u64 + 1) * 21_000,
|
||||
cumulative_gas_used: (idx as u64 + 1) * MIN_TRANSACTION_GAS,
|
||||
..Default::default()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
use crate::spec::DepositContract;
|
||||
use alloy_primitives::{address, b256};
|
||||
|
||||
/// Gas per transaction not creating a contract.
|
||||
pub const MIN_TRANSACTION_GAS: u64 = 21_000u64;
|
||||
/// Deposit contract address: `0x00000000219ab540356cbb839cbe05303d7705fa`
|
||||
pub(crate) const MAINNET_DEPOSIT_CONTRACT: DepositContract = DepositContract::new(
|
||||
address!("00000000219ab540356cbb839cbe05303d7705fa"),
|
||||
|
||||
@ -13,6 +13,7 @@ extern crate alloc;
|
||||
|
||||
/// Chain specific constants
|
||||
pub(crate) mod constants;
|
||||
pub use constants::MIN_TRANSACTION_GAS;
|
||||
|
||||
mod api;
|
||||
/// The chain info module.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use eyre::OptionExt;
|
||||
use reth_chainspec::{ChainSpec, ChainSpecBuilder, EthereumHardfork, MAINNET};
|
||||
use reth_chainspec::{ChainSpec, ChainSpecBuilder, EthereumHardfork, MAINNET, MIN_TRANSACTION_GAS};
|
||||
use reth_evm::execute::{
|
||||
BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor,
|
||||
};
|
||||
@ -98,8 +98,8 @@ fn blocks(
|
||||
),
|
||||
difficulty: chain_spec.fork(EthereumHardfork::Paris).ttd().expect("Paris TTD"),
|
||||
number: 1,
|
||||
gas_limit: 21000,
|
||||
gas_used: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS,
|
||||
gas_used: MIN_TRANSACTION_GAS,
|
||||
..Default::default()
|
||||
},
|
||||
body: vec![sign_tx_with_key_pair(
|
||||
@ -107,7 +107,7 @@ fn blocks(
|
||||
Transaction::Eip2930(TxEip2930 {
|
||||
chain_id: chain_spec.chain.id(),
|
||||
nonce: 0,
|
||||
gas_limit: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
gas_price: 1_500_000_000,
|
||||
to: TxKind::Call(Address::ZERO),
|
||||
value: U256::from(0.1 * ETH_TO_WEI as f64),
|
||||
@ -128,8 +128,8 @@ fn blocks(
|
||||
),
|
||||
difficulty: chain_spec.fork(EthereumHardfork::Paris).ttd().expect("Paris TTD"),
|
||||
number: 2,
|
||||
gas_limit: 21000,
|
||||
gas_used: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS,
|
||||
gas_used: MIN_TRANSACTION_GAS,
|
||||
..Default::default()
|
||||
},
|
||||
body: vec![sign_tx_with_key_pair(
|
||||
@ -137,7 +137,7 @@ fn blocks(
|
||||
Transaction::Eip2930(TxEip2930 {
|
||||
chain_id: chain_spec.chain.id(),
|
||||
nonce: 1,
|
||||
gas_limit: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
gas_price: 1_500_000_000,
|
||||
to: TxKind::Call(Address::ZERO),
|
||||
value: U256::from(0.1 * ETH_TO_WEI as f64),
|
||||
|
||||
@ -77,6 +77,7 @@ impl FromIterator<PooledTransactionsElement> for PooledTransactions {
|
||||
mod tests {
|
||||
use crate::{message::RequestPair, GetPooledTransactions, PooledTransactions};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_chainspec::MIN_TRANSACTION_GAS;
|
||||
use reth_primitives::{
|
||||
hex, PooledTransactionsElement, Signature, Transaction, TransactionSigned, TxEip1559,
|
||||
TxKind, TxLegacy, U256,
|
||||
@ -283,7 +284,7 @@ mod tests {
|
||||
nonce: 26u64,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: TxKind::Call(hex!("61815774383099e24810ab832a5b2a5425c154d5").into()),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
@ -422,7 +423,7 @@ mod tests {
|
||||
nonce: 26u64,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: TxKind::Call(hex!("61815774383099e24810ab832a5b2a5425c154d5").into()),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
|
||||
@ -534,7 +534,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::OpChainSpec;
|
||||
use alloy_primitives::{b256, Address, StorageKey, StorageValue};
|
||||
use reth_chainspec::ChainSpecBuilder;
|
||||
use reth_chainspec::{ChainSpecBuilder, MIN_TRANSACTION_GAS};
|
||||
use reth_primitives::{
|
||||
Account, Block, Signature, Transaction, TransactionSigned, TxEip1559, BASE_MAINNET,
|
||||
};
|
||||
@ -608,7 +608,7 @@ mod tests {
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: chain_spec.chain.id(),
|
||||
nonce: 0,
|
||||
gas_limit: 21_000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: addr.into(),
|
||||
..Default::default()
|
||||
}),
|
||||
@ -619,7 +619,7 @@ mod tests {
|
||||
Transaction::Deposit(reth_primitives::TxDeposit {
|
||||
from: addr,
|
||||
to: addr.into(),
|
||||
gas_limit: 21_000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
..Default::default()
|
||||
}),
|
||||
Signature::default(),
|
||||
@ -692,7 +692,7 @@ mod tests {
|
||||
Transaction::Eip1559(TxEip1559 {
|
||||
chain_id: chain_spec.chain.id(),
|
||||
nonce: 0,
|
||||
gas_limit: 21_000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: addr.into(),
|
||||
..Default::default()
|
||||
}),
|
||||
@ -703,7 +703,7 @@ mod tests {
|
||||
Transaction::Deposit(reth_primitives::TxDeposit {
|
||||
from: addr,
|
||||
to: addr.into(),
|
||||
gas_limit: 21_000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
..Default::default()
|
||||
}),
|
||||
Signature::optimism_deposit_tx_signature(),
|
||||
|
||||
@ -1706,6 +1706,7 @@ mod tests {
|
||||
};
|
||||
use alloy_primitives::{address, b256, bytes};
|
||||
use alloy_rlp::{Decodable, Encodable, Error as RlpError};
|
||||
use reth_chainspec::MIN_TRANSACTION_GAS;
|
||||
use reth_codecs::Compact;
|
||||
use std::str::FromStr;
|
||||
|
||||
@ -1860,7 +1861,7 @@ mod tests {
|
||||
nonce: 26,
|
||||
max_priority_fee_per_gas: 1500000000,
|
||||
max_fee_per_gas: 1500000013,
|
||||
gas_limit: 21000,
|
||||
gas_limit: MIN_TRANSACTION_GAS as u128,
|
||||
to: Address::from_slice(&hex!("61815774383099e24810ab832a5b2a5425c154d5")[..]).into(),
|
||||
value: U256::from(3000000000000000000u64),
|
||||
input: Default::default(),
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
use crate::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};
|
||||
use alloy_primitives::{Bytes, TxKind, B256, U256};
|
||||
use futures::Future;
|
||||
use reth_chainspec::MIN_TRANSACTION_GAS;
|
||||
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
|
||||
use reth_primitives::{
|
||||
revm_primitives::{
|
||||
@ -24,9 +25,7 @@ use reth_rpc_eth_types::{
|
||||
},
|
||||
EthApiError, RevertError, RpcInvalidTransactionError, StateCacheDb,
|
||||
};
|
||||
use reth_rpc_server_types::constants::gas_oracle::{
|
||||
CALL_STIPEND_GAS, ESTIMATE_GAS_ERROR_RATIO, MIN_TRANSACTION_GAS,
|
||||
};
|
||||
use reth_rpc_server_types::constants::gas_oracle::{CALL_STIPEND_GAS, ESTIMATE_GAS_ERROR_RATIO};
|
||||
use reth_rpc_types::{
|
||||
simulate::{SimBlock, SimulatedBlock},
|
||||
state::{EvmOverrides, StateOverride},
|
||||
|
||||
@ -82,8 +82,6 @@ pub mod gas_oracle {
|
||||
/// for more complex calls.
|
||||
pub const RPC_DEFAULT_GAS_CAP: u64 = 50_000_000;
|
||||
|
||||
/// Gas per transaction not creating a contract.
|
||||
pub const MIN_TRANSACTION_GAS: u64 = 21_000u64;
|
||||
/// Allowed error ratio for gas estimation
|
||||
/// Taken from Geth's implementation in order to pass the hive tests
|
||||
/// <https://github.com/ethereum/go-ethereum/blob/a5a4fa7032bb248f5a7c40f4e8df2b131c4186a4/internal/ethapi/api.go#L56>
|
||||
|
||||
Reference in New Issue
Block a user