mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: some small refactoring (#9657)
This commit is contained in:
@ -196,25 +196,24 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the requests and the requests root.
|
// Calculate the requests and the requests root.
|
||||||
let (requests, requests_root) = if chain_spec
|
let (requests, requests_root) =
|
||||||
.is_prague_active_at_timestamp(attributes.timestamp)
|
if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) {
|
||||||
{
|
// We do not calculate the EIP-6110 deposit requests because there are no
|
||||||
// We do not calculate the EIP-6110 deposit requests because there are no
|
// transactions in an empty payload.
|
||||||
// transactions in an empty payload.
|
let withdrawal_requests = post_block_withdrawal_requests_contract_call(
|
||||||
let withdrawal_requests = post_block_withdrawal_requests_contract_call::<EvmConfig, _>(
|
&self.evm_config,
|
||||||
&self.evm_config,
|
&mut db,
|
||||||
&mut db,
|
&initialized_cfg,
|
||||||
&initialized_cfg,
|
&initialized_block_env,
|
||||||
&initialized_block_env,
|
)
|
||||||
)
|
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;
|
||||||
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;
|
|
||||||
|
|
||||||
let requests = withdrawal_requests;
|
let requests = withdrawal_requests;
|
||||||
let requests_root = calculate_requests_root(&requests);
|
let requests_root = calculate_requests_root(&requests);
|
||||||
(Some(requests.into()), Some(requests_root))
|
(Some(requests.into()), Some(requests_root))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let header = Header {
|
let header = Header {
|
||||||
parent_hash: parent_block.hash(),
|
parent_hash: parent_block.hash(),
|
||||||
|
|||||||
@ -36,7 +36,7 @@ pub trait EvmEnvProvider: Send + Sync {
|
|||||||
{
|
{
|
||||||
let mut cfg = CfgEnvWithHandlerCfg::new_with_spec_id(CfgEnv::default(), SpecId::LATEST);
|
let mut cfg = CfgEnvWithHandlerCfg::new_with_spec_id(CfgEnv::default(), SpecId::LATEST);
|
||||||
let mut block_env = BlockEnv::default();
|
let mut block_env = BlockEnv::default();
|
||||||
self.fill_env_with_header::<EvmConfig>(&mut cfg, &mut block_env, header, evm_config)?;
|
self.fill_env_with_header(&mut cfg, &mut block_env, header, evm_config)?;
|
||||||
Ok((cfg, block_env))
|
Ok((cfg, block_env))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,7 @@ where
|
|||||||
// if the block number is zero (genesis block) then the parent beacon block root must
|
// if the block number is zero (genesis block) then the parent beacon block root must
|
||||||
// be 0x0 and no system transaction may occur as per EIP-4788
|
// be 0x0 and no system transaction may occur as per EIP-4788
|
||||||
if block_number == 0 {
|
if block_number == 0 {
|
||||||
if parent_beacon_block_root != B256::ZERO {
|
if !parent_beacon_block_root.is_zero() {
|
||||||
return Err(BlockValidationError::CancunGenesisParentBeaconBlockRootNotZero {
|
return Err(BlockValidationError::CancunGenesisParentBeaconBlockRootNotZero {
|
||||||
parent_beacon_block_root,
|
parent_beacon_block_root,
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ where
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// initialize a block from the env, because the post block call needs the block itself
|
// initialize a block from the env, because the post block call needs the block itself
|
||||||
apply_withdrawal_requests_contract_call::<EvmConfig, _, _>(evm_config, &mut evm_post_block)
|
apply_withdrawal_requests_contract_call(evm_config, &mut evm_post_block)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies the post-block call to the EIP-7002 withdrawal requests contract.
|
/// Applies the post-block call to the EIP-7002 withdrawal requests contract.
|
||||||
@ -256,11 +256,8 @@ where
|
|||||||
|
|
||||||
let amount = data.get_u64();
|
let amount = data.get_u64();
|
||||||
|
|
||||||
withdrawal_requests.push(Request::WithdrawalRequest(WithdrawalRequest {
|
withdrawal_requests
|
||||||
source_address,
|
.push(WithdrawalRequest { source_address, validator_pubkey, amount }.into());
|
||||||
validator_pubkey,
|
|
||||||
amount,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(withdrawal_requests)
|
Ok(withdrawal_requests)
|
||||||
@ -295,7 +292,7 @@ where
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
// initialize a block from the env, because the post block call needs the block itself
|
// initialize a block from the env, because the post block call needs the block itself
|
||||||
apply_consolidation_requests_contract_call::<EvmConfig, _, _>(evm_config, &mut evm_post_block)
|
apply_consolidation_requests_contract_call(evm_config, &mut evm_post_block)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies the post-block call to the EIP-7251 consolidation requests contract.
|
/// Applies the post-block call to the EIP-7251 consolidation requests contract.
|
||||||
|
|||||||
@ -535,7 +535,7 @@ mod tests {
|
|||||||
storage_cursor.delete_current()?;
|
storage_cursor.delete_current()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.value != U256::ZERO {
|
if !entry.value.is_zero() {
|
||||||
storage_cursor.upsert(bn_address.address(), entry)?;
|
storage_cursor.upsert(bn_address.address(), entry)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -562,7 +562,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let storage = storage_entries
|
let storage = storage_entries
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|v| v.value != U256::ZERO)
|
.filter(|v| !v.value.is_zero())
|
||||||
.map(|v| (v.key, v.value))
|
.map(|v| (v.key, v.value))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
accounts.insert(key, (account, storage));
|
accounts.insert(key, (account, storage));
|
||||||
@ -636,7 +636,7 @@ mod tests {
|
|||||||
storage_cursor.delete_current().unwrap();
|
storage_cursor.delete_current().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if value != U256::ZERO {
|
if !value.is_zero() {
|
||||||
let storage_entry = StorageEntry { key: hashed_slot, value };
|
let storage_entry = StorageEntry { key: hashed_slot, value };
|
||||||
storage_cursor.upsert(hashed_address, storage_entry).unwrap();
|
storage_cursor.upsert(hashed_address, storage_entry).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -386,7 +386,7 @@ impl TestStageDB {
|
|||||||
tx.put::<tables::HashedAccounts>(hashed_address, account)?;
|
tx.put::<tables::HashedAccounts>(hashed_address, account)?;
|
||||||
|
|
||||||
// Insert into storage tables.
|
// Insert into storage tables.
|
||||||
storage.into_iter().filter(|e| e.value != U256::ZERO).try_for_each(|entry| {
|
storage.into_iter().filter(|e| !e.value.is_zero()).try_for_each(|entry| {
|
||||||
let hashed_entry = StorageEntry { key: keccak256(entry.key), ..entry };
|
let hashed_entry = StorageEntry { key: keccak256(entry.key), ..entry };
|
||||||
|
|
||||||
let mut cursor = tx.cursor_dup_write::<tables::PlainStorageState>()?;
|
let mut cursor = tx.cursor_dup_write::<tables::PlainStorageState>()?;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use reth_db_api::{
|
|||||||
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
|
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
|
||||||
transaction::DbTxMut,
|
transaction::DbTxMut,
|
||||||
};
|
};
|
||||||
use reth_primitives::{Bytecode, StorageEntry, U256};
|
use reth_primitives::{Bytecode, StorageEntry};
|
||||||
use reth_storage_errors::db::DatabaseError;
|
use reth_storage_errors::db::DatabaseError;
|
||||||
use revm::db::states::{PlainStorageChangeset, StateChangeset};
|
use revm::db::states::{PlainStorageChangeset, StateChangeset};
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ impl StateChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.value != U256::ZERO {
|
if !entry.value.is_zero() {
|
||||||
storages_cursor.upsert(address, entry)?;
|
storages_cursor.upsert(address, entry)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1001,7 +1001,7 @@ impl<TX: DbTxMut + DbTx> DatabaseProvider<TX> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert value if needed
|
// insert value if needed
|
||||||
if *old_storage_value != U256::ZERO {
|
if !old_storage_value.is_zero() {
|
||||||
plain_storage_cursor.upsert(*address, storage_entry)?;
|
plain_storage_cursor.upsert(*address, storage_entry)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1099,7 +1099,7 @@ impl<TX: DbTxMut + DbTx> DatabaseProvider<TX> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert value if needed
|
// insert value if needed
|
||||||
if *old_storage_value != U256::ZERO {
|
if !old_storage_value.is_zero() {
|
||||||
plain_storage_cursor.upsert(*address, storage_entry)?;
|
plain_storage_cursor.upsert(*address, storage_entry)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2704,7 +2704,7 @@ impl<TX: DbTxMut + DbTx> HashingWriter for DatabaseProvider<TX> {
|
|||||||
hashed_storage.delete_current()?;
|
hashed_storage.delete_current()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if value != U256::ZERO {
|
if !value.is_zero() {
|
||||||
hashed_storage.upsert(hashed_address, StorageEntry { key, value })?;
|
hashed_storage.upsert(hashed_address, StorageEntry { key, value })?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2744,7 +2744,7 @@ impl<TX: DbTxMut + DbTx> HashingWriter for DatabaseProvider<TX> {
|
|||||||
hashed_storage_cursor.delete_current()?;
|
hashed_storage_cursor.delete_current()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if value != U256::ZERO {
|
if !value.is_zero() {
|
||||||
hashed_storage_cursor.upsert(hashed_address, StorageEntry { key, value })?;
|
hashed_storage_cursor.upsert(hashed_address, StorageEntry { key, value })?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use reth_db::{
|
|||||||
Database,
|
Database,
|
||||||
};
|
};
|
||||||
use reth_errors::{ProviderError, ProviderResult};
|
use reth_errors::{ProviderError, ProviderResult};
|
||||||
use reth_primitives::{BlockNumber, StorageEntry, U256};
|
use reth_primitives::{BlockNumber, StorageEntry};
|
||||||
use reth_storage_api::ReceiptWriter;
|
use reth_storage_api::ReceiptWriter;
|
||||||
use reth_storage_errors::writer::StorageWriterError;
|
use reth_storage_errors::writer::StorageWriterError;
|
||||||
use reth_trie::HashedPostStateSorted;
|
use reth_trie::HashedPostStateSorted;
|
||||||
@ -129,7 +129,7 @@ impl<'a, 'b, DB: Database> StorageWriter<'a, 'b, DB> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.value != U256::ZERO {
|
if !entry.value.is_zero() {
|
||||||
hashed_storage_cursor.upsert(*hashed_address, entry)?;
|
hashed_storage_cursor.upsert(*hashed_address, entry)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::create_test_provider_factory;
|
use crate::test_utils::create_test_provider_factory;
|
||||||
use reth_db_api::transaction::DbTx;
|
use reth_db_api::transaction::DbTx;
|
||||||
use reth_primitives::{keccak256, Account, Address, B256};
|
use reth_primitives::{keccak256, Account, Address, B256, U256};
|
||||||
use reth_trie::{HashedPostState, HashedStorage};
|
use reth_trie::{HashedPostState, HashedStorage};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -35,7 +35,7 @@ impl From<GenesisAccount> for TrieAccount {
|
|||||||
storage_root_unhashed(
|
storage_root_unhashed(
|
||||||
storage
|
storage
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|(_, value)| *value != B256::ZERO)
|
.filter(|(_, value)| !value.is_zero())
|
||||||
.map(|(slot, value)| (slot, U256::from_be_bytes(*value))),
|
.map(|(slot, value)| (slot, U256::from_be_bytes(*value))),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -309,7 +309,7 @@ impl HashedStorage {
|
|||||||
let mut non_zero_valued_slots = Vec::new();
|
let mut non_zero_valued_slots = Vec::new();
|
||||||
let mut zero_valued_slots = HashSet::default();
|
let mut zero_valued_slots = HashSet::default();
|
||||||
for (hashed_slot, value) in self.storage {
|
for (hashed_slot, value) in self.storage {
|
||||||
if value == U256::ZERO {
|
if value.is_zero() {
|
||||||
zero_valued_slots.insert(hashed_slot);
|
zero_valued_slots.insert(hashed_slot);
|
||||||
} else {
|
} else {
|
||||||
non_zero_valued_slots.push((hashed_slot, value));
|
non_zero_valued_slots.push((hashed_slot, value));
|
||||||
|
|||||||
@ -245,7 +245,7 @@ where
|
|||||||
let mut old_entries: Vec<_> = new_entries
|
let mut old_entries: Vec<_> = new_entries
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|entry| {
|
.filter_map(|entry| {
|
||||||
let old = if entry.value != U256::ZERO {
|
let old = if !entry.value.is_zero() {
|
||||||
storage.insert(entry.key, entry.value)
|
storage.insert(entry.key, entry.value)
|
||||||
} else {
|
} else {
|
||||||
let old = storage.remove(&entry.key);
|
let old = storage.remove(&entry.key);
|
||||||
|
|||||||
Reference in New Issue
Block a user