mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: Add reth rustfmt
This commit is contained in:
@ -61,12 +61,7 @@ where
|
||||
execution_ctx: ctx,
|
||||
parent,
|
||||
transactions,
|
||||
output:
|
||||
BlockExecutionResult {
|
||||
receipts,
|
||||
requests,
|
||||
gas_used,
|
||||
},
|
||||
output: BlockExecutionResult { receipts, requests, gas_used },
|
||||
state_root,
|
||||
..
|
||||
} = input;
|
||||
@ -74,16 +69,10 @@ where
|
||||
let timestamp = evm_env.block_env.timestamp;
|
||||
|
||||
// Filter out system tx receipts
|
||||
let transactions_for_root: Vec<TransactionSigned> = transactions
|
||||
.iter()
|
||||
.filter(|t| !is_system_transaction(t))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let receipts_for_root: Vec<Receipt> = receipts
|
||||
.iter()
|
||||
.filter(|r| r.cumulative_gas_used() != 0)
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let transactions_for_root: Vec<TransactionSigned> =
|
||||
transactions.iter().filter(|t| !is_system_transaction(t)).cloned().collect::<Vec<_>>();
|
||||
let receipts_for_root: Vec<Receipt> =
|
||||
receipts.iter().filter(|r| r.cumulative_gas_used() != 0).cloned().collect::<Vec<_>>();
|
||||
|
||||
let transactions_root = proofs::calculate_transaction_root(&transactions_for_root);
|
||||
let receipts_root = Receipt::calculate_receipt_root_no_memo(&receipts_for_root);
|
||||
@ -92,16 +81,10 @@ where
|
||||
let withdrawals = inner
|
||||
.chain_spec
|
||||
.is_shanghai_active_at_timestamp(timestamp)
|
||||
.then(|| {
|
||||
ctx.ctx
|
||||
.withdrawals
|
||||
.map(|w| w.into_owned())
|
||||
.unwrap_or_default()
|
||||
});
|
||||
.then(|| ctx.ctx.withdrawals.map(|w| w.into_owned()).unwrap_or_default());
|
||||
|
||||
let withdrawals_root = withdrawals
|
||||
.as_deref()
|
||||
.map(|w| proofs::calculate_withdrawals_root(w));
|
||||
let withdrawals_root =
|
||||
withdrawals.as_deref().map(|w| proofs::calculate_withdrawals_root(w));
|
||||
let requests_hash = inner
|
||||
.chain_spec
|
||||
.is_prague_active_at_timestamp(timestamp)
|
||||
@ -112,16 +95,9 @@ where
|
||||
|
||||
// only determine cancun fields when active
|
||||
if inner.chain_spec.is_cancun_active_at_timestamp(timestamp) {
|
||||
blob_gas_used = Some(
|
||||
transactions
|
||||
.iter()
|
||||
.map(|tx| tx.blob_gas_used().unwrap_or_default())
|
||||
.sum(),
|
||||
);
|
||||
excess_blob_gas = if inner
|
||||
.chain_spec
|
||||
.is_cancun_active_at_timestamp(parent.timestamp)
|
||||
{
|
||||
blob_gas_used =
|
||||
Some(transactions.iter().map(|tx| tx.blob_gas_used().unwrap_or_default()).sum());
|
||||
excess_blob_gas = if inner.chain_spec.is_cancun_active_at_timestamp(parent.timestamp) {
|
||||
parent.maybe_next_block_excess_blob_gas(
|
||||
inner.chain_spec.blob_params_at_timestamp(timestamp),
|
||||
)
|
||||
@ -160,11 +136,7 @@ where
|
||||
Ok(Self::Block {
|
||||
header,
|
||||
body: HlBlockBody {
|
||||
inner: BlockBody {
|
||||
transactions,
|
||||
ommers: Default::default(),
|
||||
withdrawals,
|
||||
},
|
||||
inner: BlockBody { transactions, ommers: Default::default(), withdrawals },
|
||||
sidecars: None,
|
||||
read_precompile_calls: Some(read_precompile_calls),
|
||||
},
|
||||
@ -174,9 +146,7 @@ where
|
||||
|
||||
impl HlBlockAssembler {
|
||||
pub fn new(chain_spec: Arc<HlChainSpec>) -> Self {
|
||||
Self {
|
||||
inner: EthBlockAssembler::new(chain_spec),
|
||||
}
|
||||
Self { inner: EthBlockAssembler::new(chain_spec) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,11 +210,7 @@ impl<R, Spec, EvmFactory> HlBlockExecutorFactory<R, Spec, EvmFactory> {
|
||||
/// Creates a new [`HlBlockExecutorFactory`] with the given spec, [`EvmFactory`], and
|
||||
/// [`ReceiptBuilder`].
|
||||
pub const fn new(receipt_builder: R, spec: Spec, evm_factory: EvmFactory) -> Self {
|
||||
Self {
|
||||
receipt_builder,
|
||||
spec,
|
||||
evm_factory,
|
||||
}
|
||||
Self { receipt_builder, spec, evm_factory }
|
||||
}
|
||||
|
||||
/// Exposes the receipt builder.
|
||||
@ -327,9 +293,8 @@ where
|
||||
);
|
||||
|
||||
// configure evm env based on parent block
|
||||
let mut cfg_env = CfgEnv::new()
|
||||
.with_chain_id(self.chain_spec().chain().id())
|
||||
.with_spec(spec);
|
||||
let mut cfg_env =
|
||||
CfgEnv::new().with_chain_id(self.chain_spec().chain().id()).with_spec(spec);
|
||||
|
||||
if let Some(blob_params) = &blob_params {
|
||||
cfg_env.set_blob_max_count(blob_params.max_blob_count);
|
||||
@ -342,16 +307,10 @@ where
|
||||
// derive the EIP-4844 blob fees from the header's `excess_blob_gas` and the current
|
||||
// blobparams
|
||||
let blob_excess_gas_and_price =
|
||||
header
|
||||
.excess_blob_gas
|
||||
.zip(blob_params)
|
||||
.map(|(excess_blob_gas, params)| {
|
||||
let blob_gasprice = params.calc_blob_fee(excess_blob_gas);
|
||||
BlobExcessGasAndPrice {
|
||||
excess_blob_gas,
|
||||
blob_gasprice,
|
||||
}
|
||||
});
|
||||
header.excess_blob_gas.zip(blob_params).map(|(excess_blob_gas, params)| {
|
||||
let blob_gasprice = params.calc_blob_fee(excess_blob_gas);
|
||||
BlobExcessGasAndPrice { excess_blob_gas, blob_gasprice }
|
||||
});
|
||||
|
||||
let eth_spec = spec.into_eth_spec();
|
||||
|
||||
@ -359,16 +318,8 @@ where
|
||||
number: header.number(),
|
||||
beneficiary: header.beneficiary(),
|
||||
timestamp: header.timestamp(),
|
||||
difficulty: if eth_spec >= SpecId::MERGE {
|
||||
U256::ZERO
|
||||
} else {
|
||||
header.difficulty()
|
||||
},
|
||||
prevrandao: if eth_spec >= SpecId::MERGE {
|
||||
header.mix_hash()
|
||||
} else {
|
||||
None
|
||||
},
|
||||
difficulty: if eth_spec >= SpecId::MERGE { U256::ZERO } else { header.difficulty() },
|
||||
prevrandao: if eth_spec >= SpecId::MERGE { header.mix_hash() } else { None },
|
||||
gas_limit: header.gas_limit(),
|
||||
basefee: header.base_fee_per_gas().unwrap_or_default(),
|
||||
blob_excess_gas_and_price,
|
||||
@ -390,23 +341,20 @@ where
|
||||
);
|
||||
|
||||
// configure evm env based on parent block
|
||||
let cfg_env = CfgEnv::new()
|
||||
.with_chain_id(self.chain_spec().chain().id())
|
||||
.with_spec(spec_id);
|
||||
let cfg_env =
|
||||
CfgEnv::new().with_chain_id(self.chain_spec().chain().id()).with_spec(spec_id);
|
||||
|
||||
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
|
||||
// cancun now, we need to set the excess blob gas to the default value(0)
|
||||
let blob_excess_gas_and_price = parent
|
||||
.maybe_next_block_excess_blob_gas(
|
||||
self.chain_spec()
|
||||
.blob_params_at_timestamp(attributes.timestamp),
|
||||
self.chain_spec().blob_params_at_timestamp(attributes.timestamp),
|
||||
)
|
||||
.or_else(|| (spec_id.into_eth_spec().is_enabled_in(SpecId::CANCUN)).then_some(0))
|
||||
.map(|gas| BlobExcessGasAndPrice::new(gas, false));
|
||||
|
||||
let mut basefee = parent.next_block_base_fee(
|
||||
self.chain_spec()
|
||||
.base_fee_params_at_timestamp(attributes.timestamp),
|
||||
self.chain_spec().base_fee_params_at_timestamp(attributes.timestamp),
|
||||
);
|
||||
|
||||
let mut gas_limit = U256::from(parent.gas_limit);
|
||||
@ -486,9 +434,9 @@ where
|
||||
|
||||
/// Map the latest active hardfork at the given timestamp or block number to a [`HlSpecId`].
|
||||
pub fn revm_spec_by_timestamp_and_block_number(
|
||||
chain_spec: impl HlHardforks,
|
||||
timestamp: u64,
|
||||
block_number: u64,
|
||||
_chain_spec: impl HlHardforks,
|
||||
_timestamp: u64,
|
||||
_block_number: u64,
|
||||
) -> HlSpecId {
|
||||
HlSpecId::V1
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use super::config::HlBlockExecutionCtx;
|
||||
use super::patch::patch_mainnet_after_tx;
|
||||
use super::{config::HlBlockExecutionCtx, patch::patch_mainnet_after_tx};
|
||||
use crate::{
|
||||
evm::transaction::HlTxEnv,
|
||||
hardforks::HlHardforks,
|
||||
@ -24,7 +23,10 @@ use revm::{
|
||||
context::{
|
||||
result::{ExecutionResult, ResultAndState},
|
||||
TxEnv,
|
||||
}, precompile::{PrecompileError, PrecompileOutput, PrecompileResult}, primitives::HashMap, DatabaseCommit
|
||||
},
|
||||
precompile::{PrecompileError, PrecompileOutput, PrecompileResult},
|
||||
primitives::HashMap,
|
||||
DatabaseCommit,
|
||||
};
|
||||
|
||||
pub fn is_system_transaction(tx: &TransactionSigned) -> bool {
|
||||
@ -59,31 +61,20 @@ fn run_precompile(
|
||||
data: &[u8],
|
||||
gas_limit: u64,
|
||||
) -> PrecompileResult {
|
||||
let input = ReadPrecompileInput {
|
||||
input: Bytes::copy_from_slice(data),
|
||||
gas_limit,
|
||||
};
|
||||
let input = ReadPrecompileInput { input: Bytes::copy_from_slice(data), gas_limit };
|
||||
let Some(get) = precompile_calls.get(&input) else {
|
||||
return Err(PrecompileError::OutOfGas);
|
||||
};
|
||||
|
||||
match *get {
|
||||
ReadPrecompileResult::Ok {
|
||||
gas_used,
|
||||
ref bytes,
|
||||
} => {
|
||||
Ok(PrecompileOutput {
|
||||
gas_used,
|
||||
bytes: bytes.clone(),
|
||||
})
|
||||
ReadPrecompileResult::Ok { gas_used, ref bytes } => {
|
||||
Ok(PrecompileOutput { gas_used, bytes: bytes.clone() })
|
||||
}
|
||||
ReadPrecompileResult::OutOfGas => {
|
||||
// Use all the gas passed to this precompile
|
||||
Err(PrecompileError::OutOfGas)
|
||||
}
|
||||
ReadPrecompileResult::Error => {
|
||||
Err(PrecompileError::OutOfGas)
|
||||
}
|
||||
ReadPrecompileResult::Error => Err(PrecompileError::OutOfGas),
|
||||
ReadPrecompileResult::UnexpectedError => panic!("unexpected precompile error"),
|
||||
}
|
||||
}
|
||||
@ -124,14 +115,7 @@ where
|
||||
}))
|
||||
});
|
||||
}
|
||||
Self {
|
||||
spec,
|
||||
evm,
|
||||
gas_used: 0,
|
||||
receipts: vec![],
|
||||
receipt_builder,
|
||||
ctx,
|
||||
}
|
||||
Self { spec, evm, gas_used: 0, receipts: vec![], receipt_builder, ctx }
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,13 +164,11 @@ where
|
||||
|
||||
let block_available_gas = self.evm.block().gas_limit - self.gas_used;
|
||||
if tx.tx().gas_limit() > block_available_gas {
|
||||
return Err(
|
||||
BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
||||
transaction_gas_limit: tx.tx().gas_limit(),
|
||||
block_available_gas,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
||||
transaction_gas_limit: tx.tx().gas_limit(),
|
||||
block_available_gas,
|
||||
}
|
||||
.into());
|
||||
}
|
||||
let result_and_state = self
|
||||
.evm
|
||||
@ -207,14 +189,13 @@ where
|
||||
&mut state,
|
||||
)?;
|
||||
|
||||
self.receipts
|
||||
.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
|
||||
tx: tx.tx(),
|
||||
evm: &self.evm,
|
||||
result,
|
||||
state: &state,
|
||||
cumulative_gas_used: self.gas_used,
|
||||
}));
|
||||
self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx {
|
||||
tx: tx.tx(),
|
||||
evm: &self.evm,
|
||||
result,
|
||||
state: &state,
|
||||
cumulative_gas_used: self.gas_used,
|
||||
}));
|
||||
|
||||
self.evm.db_mut().commit(state);
|
||||
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
use super::HlEvm;
|
||||
use crate::{
|
||||
evm::{
|
||||
api::{
|
||||
builder::HlBuilder,
|
||||
ctx::{DefaultHl, HlContext},
|
||||
},
|
||||
spec::HlSpecId,
|
||||
transaction::HlTxEnv,
|
||||
use crate::evm::{
|
||||
api::{
|
||||
builder::HlBuilder,
|
||||
ctx::{DefaultHl, HlContext},
|
||||
},
|
||||
spec::HlSpecId,
|
||||
transaction::HlTxEnv,
|
||||
};
|
||||
use reth_evm::{precompiles::PrecompilesMap, EvmEnv, EvmFactory};
|
||||
use reth_revm::{Context, Database};
|
||||
|
||||
@ -117,12 +117,7 @@ where
|
||||
}
|
||||
|
||||
fn finish(self) -> (Self::DB, EvmEnv<Self::Spec>) {
|
||||
let Context {
|
||||
block: block_env,
|
||||
cfg: cfg_env,
|
||||
journaled_state,
|
||||
..
|
||||
} = self.inner.0.ctx;
|
||||
let Context { block: block_env, cfg: cfg_env, journaled_state, .. } = self.inner.0.ctx;
|
||||
|
||||
(journaled_state.database, EvmEnv { block_env, cfg_env })
|
||||
}
|
||||
|
||||
@ -5,114 +5,24 @@ use revm::{primitives::HashMap, state::Account};
|
||||
/// Applies storage patches to the state after a transaction is executed.
|
||||
/// See https://github.com/hyperliquid-dex/hyper-evm-sync/commit/39047242b6260f7764527a2f5057dd9c3a75aa89 for more details.
|
||||
static MAINNET_PATCHES_AFTER_TX: &[(u64, u64, bool, Address)] = &[
|
||||
(
|
||||
1_467_569,
|
||||
0,
|
||||
false,
|
||||
address!("0x33f6fe38c55cb100ce27b3138e5d2d041648364f"),
|
||||
),
|
||||
(
|
||||
1_467_631,
|
||||
0,
|
||||
false,
|
||||
address!("0x33f6fe38c55cb100ce27b3138e5d2d041648364f"),
|
||||
),
|
||||
(
|
||||
1_499_313,
|
||||
2,
|
||||
false,
|
||||
address!("0xe27bfc0a812b38927ff646f24af9149f45deb550"),
|
||||
),
|
||||
(
|
||||
1_499_406,
|
||||
0,
|
||||
false,
|
||||
address!("0xe27bfc0a812b38927ff646f24af9149f45deb550"),
|
||||
),
|
||||
(
|
||||
1_499_685,
|
||||
0,
|
||||
false,
|
||||
address!("0xfee3932b75a87e86930668a6ab3ed43b404c8a30"),
|
||||
),
|
||||
(
|
||||
1_514_843,
|
||||
0,
|
||||
false,
|
||||
address!("0x723e5fbbeed025772a91240fd0956a866a41a603"),
|
||||
),
|
||||
(
|
||||
1_514_936,
|
||||
0,
|
||||
false,
|
||||
address!("0x723e5fbbeed025772a91240fd0956a866a41a603"),
|
||||
),
|
||||
(
|
||||
1_530_529,
|
||||
2,
|
||||
false,
|
||||
address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a"),
|
||||
),
|
||||
(
|
||||
1_530_622,
|
||||
2,
|
||||
false,
|
||||
address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a"),
|
||||
),
|
||||
(
|
||||
1_530_684,
|
||||
3,
|
||||
false,
|
||||
address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a"),
|
||||
),
|
||||
(
|
||||
1_530_777,
|
||||
3,
|
||||
false,
|
||||
address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a"),
|
||||
),
|
||||
(
|
||||
1_530_839,
|
||||
2,
|
||||
false,
|
||||
address!("0x692a343fc401a7755f8fc2facf61af426adaf061"),
|
||||
),
|
||||
(
|
||||
1_530_901,
|
||||
0,
|
||||
false,
|
||||
address!("0xfd9716f16596715ce765dabaee11787870e04b8a"),
|
||||
),
|
||||
(
|
||||
1_530_994,
|
||||
3,
|
||||
false,
|
||||
address!("0xfd9716f16596715ce765dabaee11787870e04b8a"),
|
||||
),
|
||||
(
|
||||
1_531_056,
|
||||
4,
|
||||
false,
|
||||
address!("0xdc67c2b8349ca20f58760e08371fc9271e82b5a4"),
|
||||
),
|
||||
(
|
||||
1_531_149,
|
||||
0,
|
||||
false,
|
||||
address!("0xdc67c2b8349ca20f58760e08371fc9271e82b5a4"),
|
||||
),
|
||||
(
|
||||
1_531_211,
|
||||
3,
|
||||
false,
|
||||
address!("0xdc67c2b8349ca20f58760e08371fc9271e82b5a4"),
|
||||
),
|
||||
(
|
||||
1_531_366,
|
||||
1,
|
||||
false,
|
||||
address!("0x9a90a517d27a9e60e454c96fefbbe94ff244ed6f"),
|
||||
),
|
||||
(1_467_569, 0, false, address!("0x33f6fe38c55cb100ce27b3138e5d2d041648364f")),
|
||||
(1_467_631, 0, false, address!("0x33f6fe38c55cb100ce27b3138e5d2d041648364f")),
|
||||
(1_499_313, 2, false, address!("0xe27bfc0a812b38927ff646f24af9149f45deb550")),
|
||||
(1_499_406, 0, false, address!("0xe27bfc0a812b38927ff646f24af9149f45deb550")),
|
||||
(1_499_685, 0, false, address!("0xfee3932b75a87e86930668a6ab3ed43b404c8a30")),
|
||||
(1_514_843, 0, false, address!("0x723e5fbbeed025772a91240fd0956a866a41a603")),
|
||||
(1_514_936, 0, false, address!("0x723e5fbbeed025772a91240fd0956a866a41a603")),
|
||||
(1_530_529, 2, false, address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a")),
|
||||
(1_530_622, 2, false, address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a")),
|
||||
(1_530_684, 3, false, address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a")),
|
||||
(1_530_777, 3, false, address!("0xa694e8fd8f4a177dd23636d838e9f1fb2138d87a")),
|
||||
(1_530_839, 2, false, address!("0x692a343fc401a7755f8fc2facf61af426adaf061")),
|
||||
(1_530_901, 0, false, address!("0xfd9716f16596715ce765dabaee11787870e04b8a")),
|
||||
(1_530_994, 3, false, address!("0xfd9716f16596715ce765dabaee11787870e04b8a")),
|
||||
(1_531_056, 4, false, address!("0xdc67c2b8349ca20f58760e08371fc9271e82b5a4")),
|
||||
(1_531_149, 0, false, address!("0xdc67c2b8349ca20f58760e08371fc9271e82b5a4")),
|
||||
(1_531_211, 3, false, address!("0xdc67c2b8349ca20f58760e08371fc9271e82b5a4")),
|
||||
(1_531_366, 1, false, address!("0x9a90a517d27a9e60e454c96fefbbe94ff244ed6f")),
|
||||
];
|
||||
|
||||
pub(crate) fn patch_mainnet_after_tx(
|
||||
|
||||
Reference in New Issue
Block a user