primitives: use alloy Header struct (#10691)

This commit is contained in:
Thomas Coratger
2024-09-23 14:53:43 +02:00
committed by GitHub
parent 7529d36515
commit ed1de8996d
85 changed files with 826 additions and 991 deletions

View File

@ -106,11 +106,14 @@ struct InvalidHeaderCacheMetrics {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::Sealable;
#[test]
fn test_hit_eviction() {
let mut cache = InvalidHeaderCache::new(10);
let header = Header::default().seal_slow();
let sealed = Header::default().seal_slow();
let (header, seal) = sealed.into_parts();
let header = SealedHeader::new(header, seal);
cache.insert(header.clone());
assert_eq!(cache.headers.get(&header.hash()).unwrap().hit_count, 0);

View File

@ -946,7 +946,7 @@ where
.blockchain
.find_block_by_hash(safe_block_hash, BlockSource::Any)?
.ok_or_else(|| ProviderError::UnknownBlockHash(safe_block_hash))?;
self.blockchain.set_safe(safe.header.seal(safe_block_hash));
self.blockchain.set_safe(SealedHeader::new(safe.header, safe_block_hash));
}
Ok(())
}
@ -967,7 +967,8 @@ where
.find_block_by_hash(finalized_block_hash, BlockSource::Any)?
.ok_or_else(|| ProviderError::UnknownBlockHash(finalized_block_hash))?;
self.blockchain.finalize_block(finalized.number)?;
self.blockchain.set_finalized(finalized.header.seal(finalized_block_hash));
self.blockchain
.set_finalized(SealedHeader::new(finalized.header, finalized_block_hash));
}
Ok(())
}

View File

@ -410,6 +410,7 @@ impl<N: ProviderNodeTypes> PipelineState<N> {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::Sealable;
use assert_matches::assert_matches;
use futures::poll;
use reth_chainspec::{ChainSpec, ChainSpecBuilder, MAINNET};
@ -598,7 +599,9 @@ mod tests {
header.parent_hash = hash;
header.number += 1;
header.timestamp += 1;
sealed_header = header.seal_slow();
let sealed = header.seal_slow();
let (header, seal) = sealed.into_parts();
sealed_header = SealedHeader::new(header, seal);
client.insert(sealed_header.clone(), body.clone());
}
}
@ -614,12 +617,14 @@ mod tests {
);
let client = TestFullBlockClient::default();
let header = Header {
let sealed = Header {
base_fee_per_gas: Some(7),
gas_limit: chain_spec.max_gas_limit,
gas_limit: chain_spec.max_gas_limit.into(),
..Default::default()
}
.seal_slow();
let (header, seal) = sealed.into_parts();
let header = SealedHeader::new(header, seal);
insert_headers_into_client(&client, header, 0..10);
// set up a pipeline

View File

@ -1,6 +1,10 @@
#![allow(missing_docs)]
use alloy_primitives::{BlockNumber, B256};
use crate::{
engine::hooks::PruneHook, hooks::EngineHooks, BeaconConsensusEngine,
BeaconConsensusEngineError, BeaconConsensusEngineHandle, BeaconForkChoiceUpdateError,
BeaconOnNewPayloadError, EthBeaconConsensus, MIN_BLOCKS_FOR_PIPELINE_RUN,
};
use alloy_primitives::{BlockNumber, Sealable, B256};
use reth_blockchain_tree::{
config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree,
};
@ -18,6 +22,7 @@ use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_exex_types::FinishedExExHeight;
use reth_network_p2p::{sync::NoopSyncStateUpdater, test_utils::NoopFullBlockClient, BlockClient};
use reth_payload_builder::test_utils::spawn_test_payload_service;
use reth_primitives::SealedHeader;
use reth_provider::{
providers::BlockchainProvider,
test_utils::{create_test_provider_factory_with_chain_spec, MockNodeTypesWithDB},
@ -34,12 +39,6 @@ use reth_tasks::TokioTaskExecutor;
use std::{collections::VecDeque, sync::Arc};
use tokio::sync::{oneshot, watch};
use crate::{
engine::hooks::PruneHook, hooks::EngineHooks, BeaconConsensusEngine,
BeaconConsensusEngineError, BeaconConsensusEngineHandle, BeaconForkChoiceUpdateError,
BeaconOnNewPayloadError, EthBeaconConsensus, MIN_BLOCKS_FOR_PIPELINE_RUN,
};
type DatabaseEnv = TempDatabase<DE>;
type TestBeaconConsensusEngine<Client> = BeaconConsensusEngine<
@ -395,7 +394,9 @@ where
BlockchainTree::new(externals, BlockchainTreeConfig::new(1, 2, 3, 2))
.expect("failed to create tree"),
));
let genesis_block = self.base_config.chain_spec.genesis_header().clone().seal_slow();
let sealed = self.base_config.chain_spec.genesis_header().clone().seal_slow();
let (header, seal) = sealed.into_parts();
let genesis_block = SealedHeader::new(header, seal);
let blockchain_provider =
BlockchainProvider::with_blocks(provider_factory.clone(), tree, genesis_block, None);