From c5bc960d31acc65d852fd3a2bbf3672fd1897573 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Thu, 23 May 2024 13:16:13 +0200 Subject: [PATCH 01/10] fix(storage): use u8 for NippiJar's DataReader::offset_size (#8360) --- crates/storage/nippy-jar/src/error.rs | 2 +- crates/storage/nippy-jar/src/lib.rs | 9 +++++---- crates/storage/nippy-jar/src/writer.rs | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/storage/nippy-jar/src/error.rs b/crates/storage/nippy-jar/src/error.rs index 2f7bcf804cf83..d59500842c7a6 100644 --- a/crates/storage/nippy-jar/src/error.rs +++ b/crates/storage/nippy-jar/src/error.rs @@ -40,7 +40,7 @@ pub enum NippyJarError { #[error("the size of an offset must be at most 8 bytes, got {offset_size}")] OffsetSizeTooBig { /// The read offset size in number of bytes. - offset_size: u64, + offset_size: u8, }, #[error("attempted to read an out of bounds offset: {index}")] OffsetOutOfBounds { diff --git a/crates/storage/nippy-jar/src/lib.rs b/crates/storage/nippy-jar/src/lib.rs index ac9e771b1e76a..2eafe68c409e8 100644 --- a/crates/storage/nippy-jar/src/lib.rs +++ b/crates/storage/nippy-jar/src/lib.rs @@ -476,7 +476,7 @@ pub struct DataReader { /// Mmap handle for offsets. offset_mmap: Mmap, /// Number of bytes that represent one offset. - offset_size: u64, + offset_size: u8, } impl DataReader { @@ -491,7 +491,7 @@ impl DataReader { let offset_mmap = unsafe { Mmap::map(&offset_file)? }; // First byte is the size of one offset in bytes - let offset_size = offset_mmap[0] as u64; + let offset_size = offset_mmap[0]; // Ensure that the size of an offset is at most 8 bytes. if offset_size > 8 { @@ -525,7 +525,8 @@ impl DataReader { /// Returns total number of offsets in the file. /// The size of one offset is determined by the file itself. pub fn offsets_count(&self) -> Result { - Ok((self.offset_file.metadata()?.len().saturating_sub(1) / self.offset_size) as usize) + Ok((self.offset_file.metadata()?.len().saturating_sub(1) / self.offset_size as u64) + as usize) } /// Reads one offset-sized (determined by the offset file) u64 at the provided index. @@ -542,7 +543,7 @@ impl DataReader { } /// Returns number of bytes that represent one offset. - pub fn offset_size(&self) -> u64 { + pub fn offset_size(&self) -> u8 { self.offset_size } diff --git a/crates/storage/nippy-jar/src/writer.rs b/crates/storage/nippy-jar/src/writer.rs index 6417e60076cf1..bd56b4a6b386b 100644 --- a/crates/storage/nippy-jar/src/writer.rs +++ b/crates/storage/nippy-jar/src/writer.rs @@ -7,7 +7,7 @@ use std::{ }; /// Size of one offset in bytes. -const OFFSET_SIZE_BYTES: u64 = 8; +const OFFSET_SIZE_BYTES: u8 = 8; /// Writer of [`NippyJar`]. Handles table data and offsets only. /// @@ -112,7 +112,7 @@ impl NippyJarWriter { let mut offsets_file = OpenOptions::new().read(true).write(true).open(offsets)?; // First byte of the offset file is the size of one offset in bytes - offsets_file.write_all(&[OFFSET_SIZE_BYTES as u8])?; + offsets_file.write_all(&[OFFSET_SIZE_BYTES])?; offsets_file.seek(SeekFrom::End(0))?; Ok((data_file, offsets_file, is_created)) @@ -133,9 +133,9 @@ impl NippyJarWriter { return Err(NippyJarError::FrozenJar) } - let expected_offsets_file_size = 1 + // first byte is the size of one offset - OFFSET_SIZE_BYTES * self.jar.rows as u64 * self.jar.columns as u64 + // `offset size * num rows * num columns` - OFFSET_SIZE_BYTES; // expected size of the data file + let expected_offsets_file_size: u64 = (1 + // first byte is the size of one offset + OFFSET_SIZE_BYTES as usize* self.jar.rows * self.jar.columns + // `offset size * num rows * num columns` + OFFSET_SIZE_BYTES as usize) as u64; // expected size of the data file let actual_offsets_file_size = self.offsets_file.get_ref().metadata()?.len(); // Offsets configuration wasn't properly committed @@ -151,9 +151,9 @@ impl NippyJarWriter { // `num rows = (file size - 1 - size of one offset) / num columns` self.jar.rows = ((actual_offsets_file_size. saturating_sub(1). // first byte is the size of one offset - saturating_sub(OFFSET_SIZE_BYTES) / // expected size of the data file + saturating_sub(OFFSET_SIZE_BYTES as u64) / // expected size of the data file (self.jar.columns as u64)) / - OFFSET_SIZE_BYTES) as usize; + OFFSET_SIZE_BYTES as u64) as usize; // Freeze row count changed self.jar.freeze_config()?; @@ -183,7 +183,7 @@ impl NippyJarWriter { .get_ref() .metadata()? .len() - .saturating_sub(OFFSET_SIZE_BYTES * (index as u64 + 1)); + .saturating_sub(OFFSET_SIZE_BYTES as u64 * (index as u64 + 1)); self.offsets_file.get_mut().set_len(new_len)?; drop(reader); @@ -318,7 +318,7 @@ impl NippyJarWriter { // Handle non-empty offset file if length > 1 { // first byte is reserved for `bytes_per_offset`, which is 8 initially. - let num_offsets = (length - 1) / OFFSET_SIZE_BYTES; + let num_offsets = (length - 1) / OFFSET_SIZE_BYTES as u64; if remaining_to_prune as u64 > num_offsets { return Err(NippyJarError::InvalidPruning( @@ -336,10 +336,10 @@ impl NippyJarWriter { self.data_file.get_mut().set_len(0)?; } else { // Calculate the new length for the on-disk offset list - let new_len = 1 + new_num_offsets * OFFSET_SIZE_BYTES; + let new_len = 1 + new_num_offsets * OFFSET_SIZE_BYTES as u64; // Seek to the position of the last offset self.offsets_file - .seek(SeekFrom::Start(new_len.saturating_sub(OFFSET_SIZE_BYTES)))?; + .seek(SeekFrom::Start(new_len.saturating_sub(OFFSET_SIZE_BYTES as u64)))?; // Read the last offset value let mut last_offset = [0u8; OFFSET_SIZE_BYTES as usize]; self.offsets_file.get_ref().read_exact(&mut last_offset)?; From 155876d28c91e172d692155b658e15514d733469 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 23 May 2024 07:17:48 -0400 Subject: [PATCH 02/10] chore: improve HaveNotReceivedUpdatesForAWhile warning (#8356) --- crates/node/events/src/node.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/node/events/src/node.rs b/crates/node/events/src/node.rs index 383da986b4a14..8c01c0a737a76 100644 --- a/crates/node/events/src/node.rs +++ b/crates/node/events/src/node.rs @@ -315,7 +315,7 @@ impl NodeState { warn!("Beacon client online, but never received consensus updates. Please ensure your beacon client is operational to follow the chain!") } ConsensusLayerHealthEvent::HaveNotReceivedUpdatesForAWhile(period) => { - warn!(?period, "Beacon client online, but no consensus updates received for a while. Please fix your beacon client to follow the chain!") + warn!(?period, "Beacon client online, but no consensus updates received for a while. This may be because of a reth error, or an error in the beacon client! Please investigate reth and beacon client logs!") } } } From 4250c33da1db2b0c1925ca6d8a4e10b4c7bb754a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 23 May 2024 13:24:20 +0200 Subject: [PATCH 03/10] chore: clippy happy (#8362) Co-authored-by: Alexey Shekhirin --- Cargo.toml | 2 +- Makefile | 6 +++--- bin/reth/src/commands/db/stats.rs | 2 +- crates/blockchain-tree/src/blockchain_tree.rs | 2 +- .../consensus/beacon/src/engine/hooks/prune.rs | 8 ++++---- .../beacon/src/engine/hooks/static_file.rs | 14 +++++++------- crates/consensus/beacon/src/engine/mod.rs | 10 +++++----- crates/exex/src/manager.rs | 2 +- crates/interfaces/src/blockchain_tree/mod.rs | 1 + crates/net/ecies/src/algorithm.rs | 4 ++-- crates/net/eth-wire-types/src/message.rs | 2 +- crates/node-core/src/args/utils.rs | 2 +- crates/node-core/src/dirs.rs | 1 + crates/payload/validator/src/lib.rs | 4 ++-- crates/primitives/src/prune/target.rs | 4 ++-- crates/primitives/src/revm/env.rs | 4 ++-- crates/primitives/src/transaction/mod.rs | 2 +- crates/stages/src/stages/execution.rs | 3 +-- crates/stages/src/stages/hashing_account.rs | 9 ++++----- crates/stages/src/stages/sender_recovery.rs | 5 ++--- crates/stages/src/stages/tx_lookup.rs | 5 ++--- .../db/src/implementation/mdbx/cursor.rs | 3 +-- .../src/providers/database/provider.rs | 18 +++++++++--------- crates/tokio-util/src/event_stream.rs | 2 +- crates/transaction-pool/src/pool/mod.rs | 16 ++++++++-------- crates/transaction-pool/src/pool/pending.rs | 6 +++--- crates/transaction-pool/src/pool/txpool.rs | 1 + examples/node-event-hooks/src/main.rs | 8 ++------ 28 files changed, 70 insertions(+), 76 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bf7ea50bde171..a44a474e092c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ rust.missing_debug_implementations = "warn" rust.missing_docs = "warn" rust.unreachable_pub = "warn" rust.unused_must_use = "deny" -rust.rust_2018_idioms = "deny" +rust.rust_2018_idioms = { level = "deny", priority = -1 } rustdoc.all = "warn" [workspace.lints.clippy] diff --git a/Makefile b/Makefile index bfa56011c1a0c..f62ef19f33463 100644 --- a/Makefile +++ b/Makefile @@ -413,9 +413,9 @@ fix-lint-other-targets: -- -D warnings fix-lint: - make lint-reth && \ - make lint-op-reth && \ - make lint-other-targets && \ + make fix-lint-reth && \ + make fix-lint-op-reth && \ + make fix-lint-other-targets && \ make fmt .PHONY: rustdocs diff --git a/bin/reth/src/commands/db/stats.rs b/bin/reth/src/commands/db/stats.rs index a59a904eb7424..03c384b2ffc4d 100644 --- a/bin/reth/src/commands/db/stats.rs +++ b/bin/reth/src/commands/db/stats.rs @@ -377,7 +377,7 @@ impl Command { let max_widths = table.column_max_content_widths(); let mut separator = Row::new(); for width in max_widths { - separator.add_cell(Cell::new(&"-".repeat(width as usize))); + separator.add_cell(Cell::new("-".repeat(width as usize))); } table.add_row(separator); diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index ef8fe65e72a97..e6694447bbca9 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -307,7 +307,7 @@ where *key_value.0 } else { debug!(target: "blockchain_tree", ?chain_id, "No blockhashes stored"); - return None; + return None }; let canonical_chain = canonical_chain .iter() diff --git a/crates/consensus/beacon/src/engine/hooks/prune.rs b/crates/consensus/beacon/src/engine/hooks/prune.rs index a9bb4f05bd427..d2c2e2d33a1e9 100644 --- a/crates/consensus/beacon/src/engine/hooks/prune.rs +++ b/crates/consensus/beacon/src/engine/hooks/prune.rs @@ -78,10 +78,10 @@ impl PruneHook { /// This will try to spawn the pruner if it is idle: /// 1. Check if pruning is needed through [Pruner::is_pruning_needed]. - /// 2. - /// 1. If pruning is needed, pass tip block number to the [Pruner::run] and spawn it in a - /// separate task. Set pruner state to [PrunerState::Running]. - /// 2. If pruning is not needed, set pruner state back to [PrunerState::Idle]. + /// + /// 2.1. If pruning is needed, pass tip block number to the [Pruner::run] and spawn it in a + /// separate task. Set pruner state to [PrunerState::Running]. + /// 2.2. If pruning is not needed, set pruner state back to [PrunerState::Idle]. /// /// If pruner is already running, do nothing. fn try_spawn_pruner(&mut self, tip_block_number: BlockNumber) -> Option { diff --git a/crates/consensus/beacon/src/engine/hooks/static_file.rs b/crates/consensus/beacon/src/engine/hooks/static_file.rs index 01b7056c37f02..3786e29f87f33 100644 --- a/crates/consensus/beacon/src/engine/hooks/static_file.rs +++ b/crates/consensus/beacon/src/engine/hooks/static_file.rs @@ -71,13 +71,13 @@ impl StaticFileHook { /// 1. Check if producing static files is needed through /// [StaticFileProducer::get_static_file_targets](reth_static_file::StaticFileProducerInner::get_static_file_targets) /// and then [StaticFileTargets::any](reth_static_file::StaticFileTargets::any). - /// 2. - /// 1. If producing static files is needed, pass static file request to the - /// [StaticFileProducer::run](reth_static_file::StaticFileProducerInner::run) and spawn - /// it in a separate task. Set static file producer state to - /// [StaticFileProducerState::Running]. - /// 2. If producing static files is not needed, set static file producer state back to - /// [StaticFileProducerState::Idle]. + /// + /// 2.1. If producing static files is needed, pass static file request to the + /// [StaticFileProducer::run](reth_static_file::StaticFileProducerInner::run) and + /// spawn it in a separate task. Set static file producer state to + /// [StaticFileProducerState::Running]. + /// 2.2. If producing static files is not needed, set static file producer state back to + /// [StaticFileProducerState::Idle]. /// /// If static_file_producer is already running, do nothing. fn try_spawn_static_file_producer( diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 8139a0c577314..5f7f583902dd0 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -703,13 +703,13 @@ where /// If validation fails, the response MUST contain the latest valid hash: /// /// - The block hash of the ancestor of the invalid payload satisfying the following two - /// conditions: + /// conditions: /// - It is fully validated and deemed VALID /// - Any other ancestor of the invalid payload with a higher blockNumber is INVALID /// - 0x0000000000000000000000000000000000000000000000000000000000000000 if the above - /// conditions are satisfied by a PoW block. + /// conditions are satisfied by a PoW block. /// - null if client software cannot determine the ancestor of the invalid payload satisfying - /// the above conditions. + /// the above conditions. fn latest_valid_hash_for_invalid_payload( &mut self, parent_hash: B256, @@ -1103,8 +1103,8 @@ where /// - invalid extra data /// - invalid transactions /// - incorrect hash - /// - the versioned hashes passed with the payload do not exactly match transaction - /// versioned hashes + /// - the versioned hashes passed with the payload do not exactly match transaction versioned + /// hashes /// - the block does not contain blob transactions if it is pre-cancun /// /// This validates the following engine API rule: diff --git a/crates/exex/src/manager.rs b/crates/exex/src/manager.rs index 1de8c102e3be8..088328c860556 100644 --- a/crates/exex/src/manager.rs +++ b/crates/exex/src/manager.rs @@ -160,7 +160,7 @@ pub struct ExExManagerMetrics { /// The manager is responsible for: /// /// - Receiving relevant events from the rest of the node, and sending these to the execution -/// extensions +/// extensions /// - Backpressure /// - Error handling /// - Monitoring diff --git a/crates/interfaces/src/blockchain_tree/mod.rs b/crates/interfaces/src/blockchain_tree/mod.rs index 7d2b50e418e1c..0c1a9553dc30b 100644 --- a/crates/interfaces/src/blockchain_tree/mod.rs +++ b/crates/interfaces/src/blockchain_tree/mod.rs @@ -210,6 +210,7 @@ pub enum BlockStatus { /// This is required to: /// - differentiate whether trie state updates should be cached. /// - inform other +/// /// This is required because the state root check can only be performed if the targeted block can be /// traced back to the canonical __head__. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/net/ecies/src/algorithm.rs b/crates/net/ecies/src/algorithm.rs index 52398de4fe42e..65d74627e27f9 100644 --- a/crates/net/ecies/src/algorithm.rs +++ b/crates/net/ecies/src/algorithm.rs @@ -45,8 +45,8 @@ fn ecdh_x(public_key: &PublicKey, secret_key: &SecretKey) -> B256 { /// # Panics /// * If the `dest` is empty /// * If the `dest` len is greater than or equal to the hash output len * the max counter value. In -/// this case, the hash output len is 32 bytes, and the max counter value is 2^32 - 1. So the dest -/// cannot have a len greater than 32 * 2^32 - 1. +/// this case, the hash output len is 32 bytes, and the max counter value is 2^32 - 1. So the dest +/// cannot have a len greater than 32 * 2^32 - 1. fn kdf(secret: B256, s1: &[u8], dest: &mut [u8]) { concat_kdf::derive_key_into::(secret.as_slice(), s1, dest).unwrap(); } diff --git a/crates/net/eth-wire-types/src/message.rs b/crates/net/eth-wire-types/src/message.rs index dc8011879ba1f..c4101e852d2cb 100644 --- a/crates/net/eth-wire-types/src/message.rs +++ b/crates/net/eth-wire-types/src/message.rs @@ -169,7 +169,7 @@ impl From for ProtocolBroadcastMessage { /// The ethereum wire protocol is a set of messages that are broadcast to the network in two /// styles: /// * A request message sent by a peer (such as [`GetPooledTransactions`]), and an associated -/// response message (such as [`PooledTransactions`]). +/// response message (such as [`PooledTransactions`]). /// * A message that is broadcast to the network, without a corresponding request. /// /// The newer `eth/66` is an efficiency upgrade on top of `eth/65`, introducing a request id to diff --git a/crates/node-core/src/args/utils.rs b/crates/node-core/src/args/utils.rs index 72b84914f5ba0..4f49bf1349e75 100644 --- a/crates/node-core/src/args/utils.rs +++ b/crates/node-core/src/args/utils.rs @@ -141,7 +141,7 @@ pub enum SocketAddressParsingError { /// The following formats are checked: /// /// - If the value can be parsed as a `u16` or starts with `:` it is considered a port, and the -/// hostname is set to `localhost`. +/// hostname is set to `localhost`. /// - If the value contains `:` it is assumed to be the format `:` /// - Otherwise it is assumed to be a hostname /// diff --git a/crates/node-core/src/dirs.rs b/crates/node-core/src/dirs.rs index 75919f6f0fcae..b33df18f26f34 100644 --- a/crates/node-core/src/dirs.rs +++ b/crates/node-core/src/dirs.rs @@ -257,6 +257,7 @@ impl From for MaybePlatformPath { /// * mainnet: `/mainnet` /// * goerli: `/goerli` /// * sepolia: `/sepolia` +/// /// Otherwise, the path will be dependent on the chain ID: /// * `/` #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/crates/payload/validator/src/lib.rs b/crates/payload/validator/src/lib.rs index 7f85a0177ae6a..13c20541f03ab 100644 --- a/crates/payload/validator/src/lib.rs +++ b/crates/payload/validator/src/lib.rs @@ -84,8 +84,8 @@ impl ExecutionPayloadValidator { /// - invalid extra data /// - invalid transactions /// - incorrect hash - /// - the versioned hashes passed with the payload do not exactly match transaction - /// versioned hashes + /// - the versioned hashes passed with the payload do not exactly match transaction versioned + /// hashes /// - the block does not contain blob transactions if it is pre-cancun /// /// The checks are done in the order that conforms with the engine-API specification. diff --git a/crates/primitives/src/prune/target.rs b/crates/primitives/src/prune/target.rs index 1300b9b0b9694..7f39c8d74ce3f 100644 --- a/crates/primitives/src/prune/target.rs +++ b/crates/primitives/src/prune/target.rs @@ -70,8 +70,8 @@ impl PruneModes { /// /// 1. For [PruneMode::Full], it fails if `MIN_BLOCKS > 0`. /// 2. For [PruneMode::Distance(distance)], it fails if `distance < MIN_BLOCKS + 1`. `+ 1` is needed -/// because `PruneMode::Distance(0)` means that we leave zero blocks from the latest, meaning we -/// have one block in the database. +/// because `PruneMode::Distance(0)` means that we leave zero blocks from the latest, meaning we +/// have one block in the database. fn deserialize_opt_prune_mode_with_min_blocks<'de, const MIN_BLOCKS: u64, D: Deserializer<'de>>( deserializer: D, ) -> Result, D::Error> { diff --git a/crates/primitives/src/revm/env.rs b/crates/primitives/src/revm/env.rs index 0c16f5482f8d1..49b9f609c2b20 100644 --- a/crates/primitives/src/revm/env.rs +++ b/crates/primitives/src/revm/env.rs @@ -138,8 +138,8 @@ pub fn tx_env_with_recovered(transaction: &TransactionSignedEcRecovered) -> TxEn /// and therefore: /// * the call must execute to completion /// * the call does not count against the block’s gas limit -/// * the call does not follow the EIP-1559 burn semantics - no value should be transferred as -/// part of the call +/// * the call does not follow the EIP-1559 burn semantics - no value should be transferred as part +/// of the call /// * if no code exists at `BEACON_ROOTS_ADDRESS`, the call must fail silently pub fn fill_tx_env_with_beacon_root_contract_call(env: &mut Env, parent_beacon_block_root: B256) { env.tx = TxEnv { diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index c823a21577873..d481bed166f2a 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1346,7 +1346,7 @@ impl TransactionSigned { }; if !input_data.is_empty() { - return Err(RlpError::UnexpectedLength); + return Err(RlpError::UnexpectedLength) } Ok(output_data) diff --git a/crates/stages/src/stages/execution.rs b/crates/stages/src/stages/execution.rs index e16b9e8b6d0c6..d3bcfba171191 100644 --- a/crates/stages/src/stages/execution.rs +++ b/crates/stages/src/stages/execution.rs @@ -59,8 +59,7 @@ use tracing::*; /// - [tables::BlockBodyIndices] get tx index to know what needs to be unwinded /// - [tables::AccountsHistory] to remove change set and apply old values to /// - [tables::PlainAccountState] [tables::StoragesHistory] to remove change set and apply old -/// values -/// to [tables::PlainStorageState] +/// values to [tables::PlainStorageState] // false positive, we cannot derive it if !DB: Debug. #[allow(missing_debug_implementations)] pub struct ExecutionStage { diff --git a/crates/stages/src/stages/hashing_account.rs b/crates/stages/src/stages/hashing_account.rs index 1a63f6d893c65..db0e3ca625828 100644 --- a/crates/stages/src/stages/hashing_account.rs +++ b/crates/stages/src/stages/hashing_account.rs @@ -70,11 +70,10 @@ impl Default for AccountHashingStage { /// /// In order to check the "full hashing" mode of the stage you want to generate more /// transitions than `AccountHashingStage.clean_threshold`. This requires: -/// 1. Creating enough blocks so there's enough transactions to generate -/// the required transition keys in the `BlockTransitionIndex` (which depends on the -/// `TxTransitionIndex` internally) -/// 2. Setting `blocks.len() > clean_threshold` so that there's enough diffs to actually -/// take the 2nd codepath +/// 1. Creating enough blocks so there's enough transactions to generate the required transition +/// keys in the `BlockTransitionIndex` (which depends on the `TxTransitionIndex` internally) +/// 2. Setting `blocks.len() > clean_threshold` so that there's enough diffs to actually take the +/// 2nd codepath #[derive(Clone, Debug)] pub struct SeedOpts { /// The range of blocks to be generated diff --git a/crates/stages/src/stages/sender_recovery.rs b/crates/stages/src/stages/sender_recovery.rs index 0bb05e0c40e02..2695fb074c27e 100644 --- a/crates/stages/src/stages/sender_recovery.rs +++ b/crates/stages/src/stages/sender_recovery.rs @@ -507,10 +507,9 @@ mod tests { /// # Panics /// /// 1. If there are any entries in the [tables::TransactionSenders] table above a given - /// block number. - /// + /// block number. /// 2. If the is no requested block entry in the bodies table, but - /// [tables::TransactionSenders] is not empty. + /// [tables::TransactionSenders] is not empty. fn ensure_no_senders_by_block(&self, block: BlockNumber) -> Result<(), TestRunnerError> { let body_result = self .db diff --git a/crates/stages/src/stages/tx_lookup.rs b/crates/stages/src/stages/tx_lookup.rs index fae08e854dc02..332bcf8e70008 100644 --- a/crates/stages/src/stages/tx_lookup.rs +++ b/crates/stages/src/stages/tx_lookup.rs @@ -428,10 +428,9 @@ mod tests { /// # Panics /// /// 1. If there are any entries in the [tables::TransactionHashNumbers] table above a given - /// block number. - /// + /// block number. /// 2. If the is no requested block entry in the bodies table, but - /// [tables::TransactionHashNumbers] is not empty. + /// [tables::TransactionHashNumbers] is not empty. fn ensure_no_hash_by_block(&self, number: BlockNumber) -> Result<(), TestRunnerError> { let body_result = self .db diff --git a/crates/storage/db/src/implementation/mdbx/cursor.rs b/crates/storage/db/src/implementation/mdbx/cursor.rs index 43adc249272f8..3d1a8815291ba 100644 --- a/crates/storage/db/src/implementation/mdbx/cursor.rs +++ b/crates/storage/db/src/implementation/mdbx/cursor.rs @@ -191,8 +191,7 @@ impl DbDupCursorRO for Cursor { /// - Some(key), Some(subkey): a `key` item whose data is >= than `subkey` /// - Some(key), None: first item of a specified `key` /// - None, Some(subkey): like first case, but in the first key - /// - None, None: first item in the table - /// of a DUPSORT table. + /// - None, None: first item in the table of a DUPSORT table. fn walk_dup( &mut self, key: Option, diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 6e07b7c46a1b7..643bc23e65e4e 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -375,20 +375,20 @@ impl DatabaseProvider { /// /// If UNWIND is false we will just read the state/blocks and return them. /// - /// 1. Iterate over the [BlockBodyIndices][tables::BlockBodyIndices] table to get all - /// the transaction ids. - /// 2. Iterate over the [StorageChangeSets][tables::StorageChangeSets] table - /// and the [AccountChangeSets][tables::AccountChangeSets] tables in reverse order to - /// reconstruct the changesets. - /// - In order to have both the old and new values in the changesets, we also access the - /// plain state tables. + /// 1. Iterate over the [BlockBodyIndices][tables::BlockBodyIndices] table to get all the + /// transaction ids. + /// 2. Iterate over the [StorageChangeSets][tables::StorageChangeSets] table and the + /// [AccountChangeSets][tables::AccountChangeSets] tables in reverse order to reconstruct + /// the changesets. + /// - In order to have both the old and new values in the changesets, we also access the + /// plain state tables. /// 3. While iterating over the changeset tables, if we encounter a new account or storage slot, - /// we: + /// we: /// 1. Take the old value from the changeset /// 2. Take the new value from the plain state /// 3. Save the old value to the local state /// 4. While iterating over the changeset tables, if we encounter an account/storage slot we - /// have seen before we: + /// have seen before we: /// 1. Take the old value from the changeset /// 2. Take the new value from the local state /// 3. Set the local state to the value in the changeset diff --git a/crates/tokio-util/src/event_stream.rs b/crates/tokio-util/src/event_stream.rs index fc7e56a13bbe5..67bc72a97d07d 100644 --- a/crates/tokio-util/src/event_stream.rs +++ b/crates/tokio-util/src/event_stream.rs @@ -36,7 +36,7 @@ where Poll::Ready(Some(Ok(item))) => return Poll::Ready(Some(item)), Poll::Ready(Some(Err(e))) => { warn!("BroadcastStream lagged: {e:?}"); - continue; + continue } Poll::Ready(None) => return Poll::Ready(None), Poll::Pending => return Poll::Pending, diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index a27b9d02167bb..163f30ea6b498 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -34,16 +34,16 @@ //! //! In essence the transaction pool is made of three separate sub-pools: //! -//! - Pending Pool: Contains all transactions that are valid on the current state and satisfy -//! (3. a)(1): _No_ nonce gaps. A _pending_ transaction is considered _ready_ when it has the lowest -//! nonce of all transactions from the same sender. Once a _ready_ transaction with nonce `n` has -//! been executed, the next highest transaction from the same sender `n + 1` becomes ready. +//! - Pending Pool: Contains all transactions that are valid on the current state and satisfy (3. +//! a)(1): _No_ nonce gaps. A _pending_ transaction is considered _ready_ when it has the lowest +//! nonce of all transactions from the same sender. Once a _ready_ transaction with nonce `n` has +//! been executed, the next highest transaction from the same sender `n + 1` becomes ready. //! -//! - Queued Pool: Contains all transactions that are currently blocked by missing -//! transactions: (3. a)(2): _With_ nonce gaps or due to lack of funds. +//! - Queued Pool: Contains all transactions that are currently blocked by missing transactions: +//! (3. a)(2): _With_ nonce gaps or due to lack of funds. //! -//! - Basefee Pool: To account for the dynamic base fee requirement (3. b) which could render -//! an EIP-1559 and all subsequent transactions of the sender currently invalid. +//! - Basefee Pool: To account for the dynamic base fee requirement (3. b) which could render an +//! EIP-1559 and all subsequent transactions of the sender currently invalid. //! //! The classification of transactions is always dependent on the current state that is changed as //! soon as a new block is mined. Once a new block is mined, the account changeset must be applied diff --git a/crates/transaction-pool/src/pool/pending.rs b/crates/transaction-pool/src/pool/pending.rs index 7e733a6593c9a..d78af79085b9d 100644 --- a/crates/transaction-pool/src/pool/pending.rs +++ b/crates/transaction-pool/src/pool/pending.rs @@ -90,9 +90,9 @@ impl PendingPool { /// Returns an iterator over all transactions that are _currently_ ready. /// /// 1. The iterator _always_ returns transaction in order: It never returns a transaction with - /// an unsatisfied dependency and only returns them if dependency transaction were yielded - /// previously. In other words: The nonces of transactions with the same sender will _always_ - /// increase by exactly 1. + /// an unsatisfied dependency and only returns them if dependency transaction were yielded + /// previously. In other words: The nonces of transactions with the same sender will _always_ + /// increase by exactly 1. /// /// The order of transactions which satisfy (1.) is determent by their computed priority: A /// transaction with a higher priority is returned before a transaction with a lower priority. diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index bcad71edbd4a0..4e35733d4bc63 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1002,6 +1002,7 @@ impl AllTransactions { /// For all transactions: /// - decreased basefee: promotes from `basefee` to `pending` sub-pool. /// - increased basefee: demotes from `pending` to `basefee` sub-pool. + /// /// Individually: /// - decreased sender allowance: demote from (`basefee`|`pending`) to `queued`. /// - increased sender allowance: promote from `queued` to diff --git a/examples/node-event-hooks/src/main.rs b/examples/node-event-hooks/src/main.rs index b9cd53298b4b8..e8a751840e0da 100644 --- a/examples/node-event-hooks/src/main.rs +++ b/examples/node-event-hooks/src/main.rs @@ -8,12 +8,8 @@ //! ``` //! //! This launch the regular reth node and also print: -//! -//! > "All components initialized" -//! once all components have been initialized and -//! -//! > "Node started" -//! once the node has been started. +//! > "All components initialized" – once all components have been initialized +//! > "Node started" – once the node has been started. use reth::cli::Cli; use reth_node_ethereum::EthereumNode; From f447db1eee20c04f76d30e32e027179e4f59a416 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 23 May 2024 13:39:11 +0200 Subject: [PATCH 04/10] feat: add static-file-types (#8361) --- Cargo.lock | 14 +++++++++-- Cargo.toml | 2 ++ crates/primitives/Cargo.toml | 5 ++-- crates/primitives/src/lib.rs | 2 +- crates/static-file-types/Cargo.toml | 23 +++++++++++++++++++ .../src}/compression.rs | 0 .../src}/filters.rs | 0 .../mod.rs => static-file-types/src/lib.rs} | 10 +++++++- .../src}/segment.rs | 12 ++++------ 9 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 crates/static-file-types/Cargo.toml rename crates/{primitives/src/static_file => static-file-types/src}/compression.rs (100%) rename crates/{primitives/src/static_file => static-file-types/src}/filters.rs (100%) rename crates/{primitives/src/static_file/mod.rs => static-file-types/src/lib.rs} (84%) rename crates/{primitives/src/static_file => static-file-types/src}/segment.rs (97%) diff --git a/Cargo.lock b/Cargo.lock index ce125ced72b09..413d83fc9f20c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7548,7 +7548,6 @@ dependencies = [ "byteorder", "bytes", "c-kzg", - "clap", "criterion", "derive_more", "hash-db", @@ -7565,13 +7564,13 @@ dependencies = [ "reth-codecs", "reth-ethereum-forks", "reth-network-types", + "reth-static-file-types", "revm", "revm-primitives", "roaring", "secp256k1 0.28.2", "serde", "serde_json", - "strum", "sucds", "tempfile", "test-fuzz", @@ -7932,6 +7931,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "reth-static-file-types" +version = "0.2.0-beta.7" +dependencies = [ + "alloy-primitives", + "clap", + "derive_more", + "serde", + "strum", +] + [[package]] name = "reth-tasks" version = "0.2.0-beta.7" diff --git a/Cargo.toml b/Cargo.toml index a44a474e092c9..a779905e6978e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ members = [ "crates/stages/", "crates/stages-api", "crates/static-file/", + "crates/static-file-types/", "crates/storage/codecs/", "crates/storage/codecs/derive/", "crates/storage/db/", @@ -271,6 +272,7 @@ reth-rpc-layer = { path = "crates/rpc/rpc-layer" } reth-stages = { path = "crates/stages" } reth-stages-api = { path = "crates/stages-api" } reth-static-file = { path = "crates/static-file" } +reth-static-file-types = { path = "crates/static-file-types" } reth-tasks = { path = "crates/tasks" } reth-tokio-util = { path = "crates/tokio-util" } reth-tracing = { path = "crates/tracing" } diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 34100b24b70e1..f44db3cae1e2e 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -16,6 +16,7 @@ workspace = true reth-codecs.workspace = true reth-ethereum-forks.workspace = true reth-network-types.workspace = true +reth-static-file-types.workspace = true revm.workspace = true revm-primitives = { workspace = true, features = ["serde"] } @@ -41,7 +42,6 @@ c-kzg = { workspace = true, features = ["serde"], optional = true } # misc bytes.workspace = true byteorder = "1" -clap = { workspace = true, features = ["derive"], optional = true } derive_more.workspace = true itertools.workspace = true modular-bitfield.workspace = true @@ -62,7 +62,6 @@ plain_hasher = { version = "0.2", optional = true } arbitrary = { workspace = true, features = ["derive"], optional = true } proptest = { workspace = true, optional = true } proptest-derive = { workspace = true, optional = true } -strum = { workspace = true, features = ["derive"] } [dev-dependencies] # eth @@ -116,7 +115,7 @@ c-kzg = [ "alloy-eips/kzg", ] zstd-codec = ["dep:zstd"] -clap = ["dep:clap"] +clap = ["reth-static-file-types/clap"] optimism = [ "reth-codecs/optimism", "reth-ethereum-forks/optimism", diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 35dfc14915a23..b10582cf9e522 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -42,7 +42,7 @@ mod receipt; /// Helpers for working with revm pub mod revm; pub mod stage; -pub mod static_file; +pub use reth_static_file_types as static_file; mod storage; /// Helpers for working with transactions pub mod transaction; diff --git a/crates/static-file-types/Cargo.toml b/crates/static-file-types/Cargo.toml new file mode 100644 index 0000000000000..63ba40c8f5256 --- /dev/null +++ b/crates/static-file-types/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "reth-static-file-types" +version.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +description = "Commonly used types for static file usage in reth." + +[lints] +workspace = true + +[dependencies] +alloy-primitives.workspace = true + +clap = { workspace = true, features = ["derive"], optional = true } +derive_more.workspace = true +serde = { workspace = true, features = ["derive"] } +strum = { workspace = true, features = ["derive"] } + +[features] +clap = ["dep:clap"] \ No newline at end of file diff --git a/crates/primitives/src/static_file/compression.rs b/crates/static-file-types/src/compression.rs similarity index 100% rename from crates/primitives/src/static_file/compression.rs rename to crates/static-file-types/src/compression.rs diff --git a/crates/primitives/src/static_file/filters.rs b/crates/static-file-types/src/filters.rs similarity index 100% rename from crates/primitives/src/static_file/filters.rs rename to crates/static-file-types/src/filters.rs diff --git a/crates/primitives/src/static_file/mod.rs b/crates/static-file-types/src/lib.rs similarity index 84% rename from crates/primitives/src/static_file/mod.rs rename to crates/static-file-types/src/lib.rs index e7e9e47fd2588..26d2496948b97 100644 --- a/crates/primitives/src/static_file/mod.rs +++ b/crates/static-file-types/src/lib.rs @@ -1,4 +1,12 @@ -//! StaticFile primitives. +//! Commonly used types for static file usage. + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] mod compression; mod filters; diff --git a/crates/primitives/src/static_file/segment.rs b/crates/static-file-types/src/segment.rs similarity index 97% rename from crates/primitives/src/static_file/segment.rs rename to crates/static-file-types/src/segment.rs index a9ad2a075f988..82b937f29442c 100644 --- a/crates/primitives/src/static_file/segment.rs +++ b/crates/static-file-types/src/segment.rs @@ -1,7 +1,5 @@ -use crate::{ - static_file::{Compression, Filters, InclusionFilter}, - BlockNumber, TxNumber, -}; +use crate::{BlockNumber, Compression, Filters, InclusionFilter}; +use alloy_primitives::TxNumber; use derive_more::Display; use serde::{Deserialize, Serialize}; use std::{ops::RangeInclusive, str::FromStr}; @@ -385,7 +383,7 @@ mod tests { Compression::Lz4, Filters::WithFilters( InclusionFilter::Cuckoo, - crate::static_file::PerfectHashingFunction::Fmph, + crate::PerfectHashingFunction::Fmph, ), )), ), @@ -397,7 +395,7 @@ mod tests { Compression::Zstd, Filters::WithFilters( InclusionFilter::Cuckoo, - crate::static_file::PerfectHashingFunction::Fmph, + crate::PerfectHashingFunction::Fmph, ), )), ), @@ -409,7 +407,7 @@ mod tests { Compression::ZstdWithDictionary, Filters::WithFilters( InclusionFilter::Cuckoo, - crate::static_file::PerfectHashingFunction::Fmph, + crate::PerfectHashingFunction::Fmph, ), )), ), From 3312dc26cbb881b9b8a78dcb6b17c6e204ec6ac4 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 23 May 2024 08:27:21 -0400 Subject: [PATCH 05/10] chore: make unknown block error lowercase (#8355) --- crates/rpc/rpc/src/eth/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rpc/rpc/src/eth/error.rs b/crates/rpc/rpc/src/eth/error.rs index 77bffee400b78..90ed87facc0c1 100644 --- a/crates/rpc/rpc/src/eth/error.rs +++ b/crates/rpc/rpc/src/eth/error.rs @@ -40,11 +40,11 @@ pub enum EthApiError { /// Thrown when querying for `finalized` or `safe` block before the merge transition is /// finalized, /// - /// op-node uses case sensitive string comparison to parse this error: - /// + /// op-node now checks for either `Unknown block` OR `unknown block`: + /// /// /// TODO(#8045): Temporary, until a version of is pushed through that doesn't require this to figure out the EL sync status. - #[error("Unknown block")] + #[error("unknown block")] UnknownSafeOrFinalizedBlock, /// Thrown when an unknown block or transaction index is encountered #[error("unknown block or tx index")] From b8eebbd3d42a1bcfc1f05cce91b4fc9dc5c4d4e5 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 23 May 2024 08:27:34 -0400 Subject: [PATCH 06/10] chore: add docs for using personal tag in kurtosis (#8354) --- book/run/private-testnet.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/book/run/private-testnet.md b/book/run/private-testnet.md index 958d769e348d3..c85ff7d547862 100644 --- a/book/run/private-testnet.md +++ b/book/run/private-testnet.md @@ -35,6 +35,10 @@ First, in your home directory, create a file with the name `network_params.json` "launch_additional_services": false } ``` + +> [!TIP] +> If you would like to use a modified reth node, you can build an image locally with a custom tag. The tag can then be used in the `el_image` field in the `network_params.json` file. + ### Step 2: Spin up your network Next, run the following command from your command line: From bc4dd37872e4aad257831d10aa3fe59f0ac41701 Mon Sep 17 00:00:00 2001 From: Delweng Date: Thu, 23 May 2024 20:51:25 +0800 Subject: [PATCH 07/10] chore(editor): set indent size=2 for the yaml files (#8366) Signed-off-by: jsvisa --- .editorconfig | 3 +++ .github/ISSUE_TEMPLATE/config.yml | 2 +- .github/ISSUE_TEMPLATE/feature.yml | 2 +- .github/workflows/assertoor.yml | 9 ++++----- .github/workflows/label-pr.yml | 1 - 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.editorconfig b/.editorconfig index d53c0e8dded96..19fe6f5ad6eae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,9 @@ indent_size = 4 [*.rs] max_line_length = 100 +[*.{yml,yaml}] +indent_size = 2 + [*.md] # double whitespace at end of line # denotes a line break in Markdown diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c096920040757..ee2646490db50 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -5,4 +5,4 @@ contact_links: about: Please ask and answer questions here to keep the issue tracker clean. - name: Security url: mailto:georgios@paradigm.xyz - about: Please report security vulnerabilities here. \ No newline at end of file + about: Please report security vulnerabilities here. diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml index 2e33e3bc6ee3d..005c33ae3faa8 100644 --- a/.github/ISSUE_TEMPLATE/feature.yml +++ b/.github/ISSUE_TEMPLATE/feature.yml @@ -11,7 +11,7 @@ body: label: Describe the feature description: | Please describe the feature and what it is aiming to solve, if relevant. - + If the feature is for a crate, please include a proposed API surface. validations: required: true diff --git a/.github/workflows/assertoor.yml b/.github/workflows/assertoor.yml index 3d1ee58c48000..becbf4a3a59bb 100644 --- a/.github/workflows/assertoor.yml +++ b/.github/workflows/assertoor.yml @@ -29,7 +29,7 @@ jobs: id: services run: | export github_sha=${{ github.sha }} - export github_repository=${{ github.repository }} + export github_repository=${{ github.repository }} cat etc/assertoor/assertoor-template.yaml | envsubst > etc/assertoor/assertoor.yaml @@ -92,7 +92,7 @@ jobs: elif [ "$task_result" == "failure" ]; then task_result="${RED}failure${NC}" fi - + echo -e " $(printf '%-4s' "$task_id")\t$task_status\t$task_result\t$(printf '%-50s' "$task_graph$task_name") \t$task_title" done <<< $(echo "$tasks") } @@ -153,7 +153,7 @@ jobs: echo "$task_lines" fi - if [ $failed_tests -gt 0 ]; then + if [ $failed_tests -gt 0 ]; then final_test_result="failure" break fi @@ -197,7 +197,7 @@ jobs: with: name: "kurtosis-enclave-dump-${{ github.run_id }}" path: ./temp/dump - + - name: Return test result shell: bash run: | @@ -227,4 +227,3 @@ jobs: exit 1 # fail action fi - diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml index e52721b9cc832..857d354a8fb8c 100644 --- a/.github/workflows/label-pr.yml +++ b/.github/workflows/label-pr.yml @@ -21,4 +21,3 @@ jobs: script: | const label_pr = require('./.github/scripts/label_pr.js') await label_pr({github, context}) - From c73af6298ecfc869e04c33f269c8a5109d42deaf Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 23 May 2024 14:59:06 +0200 Subject: [PATCH 08/10] chore: remove network setup from config (#8364) Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> --- Cargo.lock | 3 --- bin/reth/src/commands/p2p/mod.rs | 6 ++++-- crates/config/Cargo.toml | 5 ----- crates/config/src/config.rs | 28 +++++++++------------------- crates/config/src/lib.rs | 1 + crates/net/network/src/config.rs | 15 ++++++++++++++- crates/node-core/src/args/network.rs | 7 +++++-- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 413d83fc9f20c..ec86a945a966e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6591,11 +6591,8 @@ version = "0.2.0-beta.7" dependencies = [ "confy", "humantime-serde", - "reth-discv4", - "reth-net-nat", "reth-network", "reth-primitives", - "secp256k1 0.28.2", "serde", "tempfile", "toml", diff --git a/bin/reth/src/commands/p2p/mod.rs b/bin/reth/src/commands/p2p/mod.rs index 8ad8fadf1d34f..b6710a363a991 100644 --- a/bin/reth/src/commands/p2p/mod.rs +++ b/bin/reth/src/commands/p2p/mod.rs @@ -15,6 +15,7 @@ use discv5::ListenConfig; use reth_config::Config; use reth_db::create_db; use reth_interfaces::p2p::bodies::client::BodiesClient; +use reth_network::NetworkConfigBuilder; use reth_primitives::{BlockHashOrNumber, ChainSpec}; use reth_provider::ProviderFactory; use std::{ @@ -112,8 +113,9 @@ impl Command { let rlpx_socket = (self.network.addr, self.network.port).into(); let boot_nodes = self.chain.bootnodes().unwrap_or_default(); - let mut network_config_builder = config - .network_config(self.network.nat, None, p2p_secret_key) + let mut network_config_builder = NetworkConfigBuilder::new(p2p_secret_key) + .peer_config(config.peers_config_with_basic_nodes_from_file(None)) + .external_ip_resolver(self.network.nat) .chain_spec(self.chain.clone()) .disable_discv4_discovery_if(self.chain.chain.is_optimism()) .boot_nodes(boot_nodes.clone()); diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index d9147d7b7a7cb..9e9aa48064c81 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -13,17 +13,12 @@ workspace = true [dependencies] # reth reth-network.workspace = true -reth-net-nat.workspace = true -reth-discv4.workspace = true reth-primitives.workspace = true # serde serde.workspace = true humantime-serde.workspace = true -# crypto -secp256k1 = { workspace = true, features = ["global-context", "rand-std", "recovery"] } - # toml confy.workspace = true diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 4215f89a438c7..7847ae202e3c3 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -1,9 +1,7 @@ //! Configuration files. -use reth_discv4::Discv4Config; -use reth_network::{NetworkConfigBuilder, PeersConfig, SessionsConfig}; +use reth_network::{PeersConfig, SessionsConfig}; use reth_primitives::PruneModes; -use secp256k1::SecretKey; use serde::{Deserialize, Deserializer, Serialize}; use std::{ ffi::OsStr, @@ -30,25 +28,17 @@ pub struct Config { } impl Config { - /// Initializes network config from read data - pub fn network_config( + /// Returns the [PeersConfig] for the node. + /// + /// If a peers file is provided, the basic nodes from the file are added to the configuration. + pub fn peers_config_with_basic_nodes_from_file( &self, - nat_resolution_method: reth_net_nat::NatResolver, - peers_file: Option, - secret_key: SecretKey, - ) -> NetworkConfigBuilder { - let peer_config = self - .peers + peers_file: Option<&Path>, + ) -> PeersConfig { + self.peers .clone() .with_basic_nodes_from_file(peers_file) - .unwrap_or_else(|_| self.peers.clone()); - - let discv4 = - Discv4Config::builder().external_ip_resolver(Some(nat_resolution_method)).clone(); - NetworkConfigBuilder::new(secret_key) - .sessions_config(self.sessions.clone()) - .peer_config(peer_config) - .discovery(discv4) + .unwrap_or_else(|_| self.peers.clone()) } /// Save the configuration to toml file. diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 362e814632e3a..1e81e18ec4291 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -5,6 +5,7 @@ html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" )] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] pub mod config; diff --git a/crates/net/network/src/config.rs b/crates/net/network/src/config.rs index 4bd1dab8835e2..368f958b2a309 100644 --- a/crates/net/network/src/config.rs +++ b/crates/net/network/src/config.rs @@ -8,7 +8,7 @@ use crate::{ transactions::TransactionsManagerConfig, NetworkHandle, NetworkManager, }; -use reth_discv4::{Discv4Config, Discv4ConfigBuilder, DEFAULT_DISCOVERY_ADDRESS}; +use reth_discv4::{Discv4Config, Discv4ConfigBuilder, NatResolver, DEFAULT_DISCOVERY_ADDRESS}; use reth_discv5::NetworkStackId; use reth_dns_discovery::DnsDiscoveryConfig; use reth_eth_wire::{HelloMessage, HelloMessageWithProtocols, Status}; @@ -314,6 +314,19 @@ impl NetworkConfigBuilder { self } + /// Sets the external ip resolver to use for discovery v4. + /// + /// If no [Discv4ConfigBuilder] is set via [Self::discovery], this will create a new one. + /// + /// This is a convenience function for setting the external ip resolver on the default + /// [Discv4Config] config. + pub fn external_ip_resolver(mut self, resolver: NatResolver) -> Self { + self.discovery_v4_builder + .get_or_insert_with(Discv4Config::builder) + .external_ip_resolver(Some(resolver)); + self + } + /// Sets the discv4 config to use. pub fn discovery(mut self, builder: Discv4ConfigBuilder) -> Self { self.discovery_v4_builder = Some(builder); diff --git a/crates/node-core/src/args/network.rs b/crates/node-core/src/args/network.rs index 350e7c4a1b1a4..115ec8517ab40 100644 --- a/crates/node-core/src/args/network.rs +++ b/crates/node-core/src/args/network.rs @@ -145,8 +145,11 @@ impl NetworkArgs { ), }; // Configure basic network stack - let mut network_config_builder = config - .network_config(self.nat, self.persistent_peers_file(peers_file), secret_key) + let mut network_config_builder = NetworkConfigBuilder::new(secret_key) + .peer_config(config.peers_config_with_basic_nodes_from_file( + self.persistent_peers_file(peers_file).as_deref(), + )) + .external_ip_resolver(self.nat) .sessions_config( SessionsConfig::default().with_upscaled_event_buffer(peers_config.max_peers()), ) From a4933e72a3d55b085e7771d10ada43c1efd85afc Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 23 May 2024 16:02:28 +0200 Subject: [PATCH 09/10] chore: remove peer types dep (#8368) --- Cargo.lock | 2 +- crates/net/common/Cargo.toml | 4 ++-- crates/net/common/src/ban_list.rs | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec86a945a966e..1f8160c450f54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7128,8 +7128,8 @@ dependencies = [ name = "reth-net-common" version = "0.2.0-beta.7" dependencies = [ + "alloy-primitives", "pin-project", - "reth-network-types", "tokio", ] diff --git a/crates/net/common/Cargo.toml b/crates/net/common/Cargo.toml index 0c3b253a50ad0..3d73f480f5704 100644 --- a/crates/net/common/Cargo.toml +++ b/crates/net/common/Cargo.toml @@ -12,8 +12,8 @@ description = "Types shared across network code" workspace = true [dependencies] -# reth -reth-network-types.workspace = true +# ethereum +alloy-primitives.workspace = true # async pin-project.workspace = true diff --git a/crates/net/common/src/ban_list.rs b/crates/net/common/src/ban_list.rs index 11d4c6049b40f..1cde15ef2b98f 100644 --- a/crates/net/common/src/ban_list.rs +++ b/crates/net/common/src/ban_list.rs @@ -1,6 +1,7 @@ //! Support for banning peers. -use reth_network_types::PeerId; +type PeerId = alloy_primitives::B512; + use std::{collections::HashMap, net::IpAddr, time::Instant}; /// Determines whether or not the IP is globally routable. From 39d24b495f7799eed6d4d184516deaa3e75165e8 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 23 May 2024 10:37:39 -0400 Subject: [PATCH 10/10] feat: return parent beacon block root in payload conversion (#8349) --- .../ethereum/engine-primitives/src/payload.rs | 2 +- crates/optimism/payload/src/payload.rs | 2 +- crates/rpc/rpc-engine-api/tests/it/payload.rs | 1 + .../rpc-types-compat/src/engine/payload.rs | 25 +++++++++++-------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/ethereum/engine-primitives/src/payload.rs b/crates/ethereum/engine-primitives/src/payload.rs index ed3f484b8d0c0..6e753dac9626a 100644 --- a/crates/ethereum/engine-primitives/src/payload.rs +++ b/crates/ethereum/engine-primitives/src/payload.rs @@ -112,7 +112,7 @@ impl From for ExecutionPayloadEnvelopeV3 { let EthBuiltPayload { block, fees, sidecars, .. } = value; ExecutionPayloadEnvelopeV3 { - execution_payload: block_to_payload_v3(block), + execution_payload: block_to_payload_v3(block).0, block_value: fees, // From the engine API spec: // diff --git a/crates/optimism/payload/src/payload.rs b/crates/optimism/payload/src/payload.rs index 182dadfed9b2e..41a3eec9be102 100644 --- a/crates/optimism/payload/src/payload.rs +++ b/crates/optimism/payload/src/payload.rs @@ -256,7 +256,7 @@ impl From for OptimismExecutionPayloadEnvelopeV3 { B256::ZERO }; OptimismExecutionPayloadEnvelopeV3 { - execution_payload: block_to_payload_v3(block), + execution_payload: block_to_payload_v3(block).0, block_value: fees, // From the engine API spec: // diff --git a/crates/rpc/rpc-engine-api/tests/it/payload.rs b/crates/rpc/rpc-engine-api/tests/it/payload.rs index 22219584c7e14..e2b39691afea3 100644 --- a/crates/rpc/rpc-engine-api/tests/it/payload.rs +++ b/crates/rpc/rpc-engine-api/tests/it/payload.rs @@ -29,6 +29,7 @@ fn transform_block Block>(src: SealedBlock, f: F) -> Executi ommers: transformed.ommers, withdrawals: transformed.withdrawals, }) + .0 } #[test] diff --git a/crates/rpc/rpc-types-compat/src/engine/payload.rs b/crates/rpc/rpc-types-compat/src/engine/payload.rs index f3478d189ab33..9f968a1a4ebd6 100644 --- a/crates/rpc/rpc-types-compat/src/engine/payload.rs +++ b/crates/rpc/rpc-types-compat/src/engine/payload.rs @@ -97,18 +97,20 @@ pub fn try_payload_v4_to_block(payload: ExecutionPayloadV4) -> Result ExecutionPayload { +/// Converts [SealedBlock] to [ExecutionPayload], returning additional data (the parent beacon block +/// root) if the block is a V3 payload +pub fn block_to_payload(value: SealedBlock) -> (ExecutionPayload, Option) { // todo(onbjerg): check for requests_root here and return payload v4 if value.header.parent_beacon_block_root.is_some() { // block with parent beacon block root: V3 - ExecutionPayload::V3(block_to_payload_v3(value)) + let (payload, beacon_block_root) = block_to_payload_v3(value); + (ExecutionPayload::V3(payload), beacon_block_root) } else if value.withdrawals.is_some() { // block with withdrawals: V2 - ExecutionPayload::V2(block_to_payload_v2(value)) + (ExecutionPayload::V2(block_to_payload_v2(value)), None) } else { // otherwise V1 - ExecutionPayload::V1(block_to_payload_v1(value)) + (ExecutionPayload::V1(block_to_payload_v1(value)), None) } } @@ -158,11 +160,12 @@ pub fn block_to_payload_v2(value: SealedBlock) -> ExecutionPayloadV2 { } } -/// Converts [SealedBlock] to [ExecutionPayloadV3] -pub fn block_to_payload_v3(value: SealedBlock) -> ExecutionPayloadV3 { +/// Converts [SealedBlock] to [ExecutionPayloadV3], and returns the parent beacon block root. +pub fn block_to_payload_v3(value: SealedBlock) -> (ExecutionPayloadV3, Option) { let transactions = value.raw_transactions(); - ExecutionPayloadV3 { + let parent_beacon_block_root = value.header.parent_beacon_block_root; + let payload = ExecutionPayloadV3 { blob_gas_used: value.blob_gas_used.unwrap_or_default(), excess_blob_gas: value.excess_blob_gas.unwrap_or_default(), payload_inner: ExecutionPayloadV2 { @@ -184,7 +187,9 @@ pub fn block_to_payload_v3(value: SealedBlock) -> ExecutionPayloadV3 { }, withdrawals: value.withdrawals.unwrap_or_default().into_inner(), }, - } + }; + + (payload, parent_beacon_block_root) } /// Converts [SealedBlock] to [ExecutionPayloadFieldV2] @@ -374,7 +379,7 @@ mod tests { let converted_payload = block_to_payload_v3(block.seal_slow()); // ensure the payloads are the same - assert_eq!(new_payload, converted_payload); + assert_eq!((new_payload, Some(parent_beacon_block_root.into())), converted_payload); } #[test]