diff --git a/crates/engine/tree/src/download.rs b/crates/engine/tree/src/download.rs index 09428a3f9d37..ec173e227a4b 100644 --- a/crates/engine/tree/src/download.rs +++ b/crates/engine/tree/src/download.rs @@ -40,10 +40,16 @@ pub enum DownloadOutcome { /// Downloaded blocks. Blocks(Vec), /// New download started. - NewDownloadStarted { remaining_blocks: u64, target: B256 }, + NewDownloadStarted { + /// How many blocks are pending in this download. + remaining_blocks: u64, + /// The hash of the highest block of this download. + target: B256, + }, } /// Basic [`BlockDownloader`]. +#[allow(missing_debug_implementations)] pub struct BasicBlockDownloader where Client: BlockClient + 'static, @@ -393,11 +399,11 @@ mod tests { assert_eq!(block_downloader.inflight_full_block_requests.len(), TOTAL_BLOCKS); // poll downloader - for i in 0..TOTAL_BLOCKS { + for _ in 0..TOTAL_BLOCKS { let sync_future = poll_fn(|cx| block_downloader.poll(cx)); let next_ready = sync_future.await; - assert_matches!(next_ready, DownloadOutcome::NewDownloadStarted { remaining_blocks, target } => { + assert_matches!(next_ready, DownloadOutcome::NewDownloadStarted { remaining_blocks, .. } => { assert_eq!(remaining_blocks, 1); }); } diff --git a/crates/engine/tree/src/engine.rs b/crates/engine/tree/src/engine.rs index 637bd5b944e2..fd1e2988a741 100644 --- a/crates/engine/tree/src/engine.rs +++ b/crates/engine/tree/src/engine.rs @@ -166,6 +166,7 @@ impl EngineApiRequestHandler where T: EngineTypes, { + /// Creates a new `EngineApiRequestHandler`. pub const fn new( to_tree: Sender>>, from_tree: UnboundedReceiver, @@ -229,6 +230,7 @@ impl From for EngineApiEvent { } } +/// Events received from the engine. #[derive(Debug)] pub enum FromEngine { /// Event from the top level orchestrator. diff --git a/crates/engine/tree/src/lib.rs b/crates/engine/tree/src/lib.rs index 4dc37f4161d9..109cf76935c1 100644 --- a/crates/engine/tree/src/lib.rs +++ b/crates/engine/tree/src/lib.rs @@ -11,7 +11,6 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] -#![allow(missing_docs, dead_code, missing_debug_implementations, unused_variables)] // TODO rm /// Re-export of the blockchain tree API. pub use reth_blockchain_tree_api::*; @@ -31,5 +30,6 @@ pub mod persistence; /// Support for interacting with the blockchain tree. pub mod tree; +/// Test utilities. #[cfg(any(test, feature = "test-utils"))] pub mod test_utils; diff --git a/crates/engine/tree/src/persistence.rs b/crates/engine/tree/src/persistence.rs index ca4d81523041..a980cf15a08c 100644 --- a/crates/engine/tree/src/persistence.rs +++ b/crates/engine/tree/src/persistence.rs @@ -95,7 +95,7 @@ where // we ignore the error because the caller may or may not care about the result let _ = sender.send(res); } - PersistenceAction::WriteTransactions(block, sender) => { + PersistenceAction::WriteTransactions(_block, _sender) => { unimplemented!() // let (block_num, td) = // self.write_transactions(block).expect("todo: handle errors"); @@ -246,7 +246,7 @@ mod tests { fn default_persistence_handle() -> PersistenceHandle { let provider = create_test_provider_factory(); - let (finished_exex_height_tx, finished_exex_height_rx) = + let (_finished_exex_height_tx, finished_exex_height_rx) = tokio::sync::watch::channel(FinishedExExHeight::NoExExs); let pruner = Pruner::<_, ProviderFactory<_>>::new( diff --git a/crates/engine/tree/src/test_utils.rs b/crates/engine/tree/src/test_utils.rs index 0a5fbd5ad560..5ace509d117b 100644 --- a/crates/engine/tree/src/test_utils.rs +++ b/crates/engine/tree/src/test_utils.rs @@ -11,7 +11,7 @@ use std::{collections::VecDeque, ops::Range, sync::Arc}; use tokio::sync::watch; /// Test pipeline builder. -#[derive(Default)] +#[derive(Default, Debug)] pub struct TestPipelineBuilder { pipeline_exec_outputs: VecDeque>, executor_results: Vec, @@ -58,7 +58,9 @@ impl TestPipelineBuilder { } } -pub(crate) fn insert_headers_into_client( +/// Starting from the given genesis header, inserts headers from the given +/// range in the given test full block client. +pub fn insert_headers_into_client( client: &TestFullBlockClient, genesis_header: SealedHeader, range: Range, diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 97390d4b3264..426428366e22 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -100,13 +100,6 @@ impl TreeState { self.blocks_by_hash.get(&hash).map(|b| b.block.clone()) } - fn block_by_number(&self, number: BlockNumber) -> Option> { - self.blocks_by_number - .get(&number) - .and_then(|blocks| blocks.last()) - .map(|executed_block| executed_block.block.clone()) - } - /// Returns all available blocks for the given hash that lead back to the canonical chain, from /// newest to oldest. And the parent hash of the oldest block that is missing from the buffer. /// @@ -194,31 +187,6 @@ impl TreeState { } } - /// Returns the maximum block number stored. - /// - /// If no blocks are currently buffered this returns the block number of the canonical head. - pub(crate) fn max_block_number(&self) -> BlockNumber { - self.blocks_by_number - .last_key_value() - .map(|e| *e.0) - .unwrap_or_else(|| self.canonical_block_number()) - } - - /// Returns the minimum block number stored. - /// - /// If no blocks are currently buffered this returns the block number of the canonical head. - pub(crate) fn min_block_number(&self) -> BlockNumber { - self.blocks_by_number - .first_key_value() - .map(|e| *e.0) - .unwrap_or_else(|| self.canonical_block_number()) - } - - /// Returns the block number of the pending block: `head + 1` - const fn pending_block_number(&self) -> BlockNumber { - self.current_canonical_head.number + 1 - } - /// Updates the canonical head to the given block. fn set_canonical_head(&mut self, new_head: BlockNumHash) { self.current_canonical_head = new_head; @@ -457,6 +425,7 @@ where E: BlockExecutorProvider, T: EngineTypes, { + /// Creates a new `EngineApiTreeHandlerImpl`. #[allow(clippy::too_many_arguments)] pub fn new( provider: P, @@ -550,7 +519,7 @@ where Ok(None) => { debug!(target: "engine", "received no engine message for some time, while waiting for persistence task to complete"); } - Err(err) => { + Err(_err) => { error!(target: "engine", "Engine channel disconnected"); return } @@ -1975,7 +1944,6 @@ mod tests { use reth_chainspec::{ChainSpec, HOLESKY, MAINNET}; use reth_ethereum_engine_primitives::EthEngineTypes; use reth_evm::test_utils::MockExecutorProvider; - use reth_payload_builder::PayloadServiceCommand; use reth_primitives::{Address, Bytes}; use reth_provider::test_utils::MockEthProvider; use reth_rpc_types_compat::engine::block_to_payload_v1; @@ -1991,8 +1959,6 @@ mod tests { from_tree_rx: UnboundedReceiver, blocks: Vec, action_rx: Receiver, - payload_command_rx: UnboundedReceiver>, - chain_spec: Arc, executor_provider: MockExecutorProvider, block_builder: TestBlockBuilder, } @@ -2016,7 +1982,7 @@ mod tests { let engine_api_tree_state = EngineApiTreeState::new(10, 10, header.num_hash()); let canonical_in_memory_state = CanonicalInMemoryState::with_head(header, None); - let (to_payload_service, payload_command_rx) = unbounded_channel(); + let (to_payload_service, _payload_command_rx) = unbounded_channel(); let payload_builder = PayloadBuilderHandle::new(to_payload_service); let tree = EngineApiTreeHandlerImpl::new( @@ -2043,8 +2009,6 @@ mod tests { from_tree_rx, blocks: vec![], action_rx, - payload_command_rx, - chain_spec, executor_provider, block_builder, } @@ -2231,12 +2195,7 @@ mod tests { #[tokio::test] async fn test_in_memory_state_trait_impl() { - let tree_config = TreeConfig::default(); - let blocks: Vec<_> = TestBlockBuilder::default().get_executed_blocks(0..10).collect(); - let head_block = blocks.last().unwrap().block(); - let first_block = blocks.first().unwrap().block(); - let test_harness = TestHarness::new(MAINNET.clone()).with_blocks(blocks.clone()); for executed_block in blocks { @@ -2312,7 +2271,6 @@ mod tests { let data = Bytes::from_str(s).unwrap(); let block = Block::decode(&mut data.as_ref()).unwrap(); let sealed = block.seal_slow(); - let hash = sealed.hash(); let mut test_harness = TestHarness::new(HOLESKY.clone()); @@ -2609,14 +2567,14 @@ mod tests { let fork_chain = test_harness.block_builder.create_fork(main_chain[2].block(), 3); // add fork blocks to the tree - for (index, block) in fork_chain.iter().enumerate() { + for block in &fork_chain { test_harness.insert_block(block.clone()).unwrap(); } test_harness.send_fcu(fork_chain.last().unwrap().hash(), ForkchoiceStatus::Valid).await; // check for ForkBlockAdded events, we expect fork_chain.len() blocks added - for index in 0..fork_chain.len() { + for _ in 0..fork_chain.len() { let event = test_harness.from_tree_rx.recv().await.unwrap(); match event { EngineApiEvent::BeaconConsensus(BeaconConsensusEngineEvent::ForkBlockAdded(