Skip to content

Commit

Permalink
Merge branch 'main' into onbjerg/deterministic-rng
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg authored Jun 21, 2023
2 parents 5d467b3 + 938b979 commit 76f0a78
Show file tree
Hide file tree
Showing 41 changed files with 301 additions and 135 deletions.
117 changes: 54 additions & 63 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ ethers-signers = { version = "2.0.7", default-features = false }
ethers-middleware = { version = "2.0.7", default-features = false }

## misc
tracing = "^0.1.0"
bytes = "1.4"
tracing = "0.1.0"
thiserror = "1.0.37"
serde_json = "1.0.94"
serde = { version = "1.0", default-features = false }
Expand Down
8 changes: 8 additions & 0 deletions bin/reth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
))]

//! Rust Ethereum (reth) binary executable.
//!
//! ## Feature Flags
//!
//! - `jemalloc`: Uses [jemallocator](https://github.com/tikv/jemallocator) as the global allocator.
//! This is **not recommended on Windows**. See [here](https://rust-lang.github.io/rfcs/1974-global-allocators.html#jemalloc)
//! for more info.
//! - `only-info-logs`: Disables all logs below `info` level. This can speed up the node, since
//! fewer calls to the logging component is made.
pub mod args;
pub mod chain;
Expand Down
1 change: 1 addition & 0 deletions crates/blockchain-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ normal = [
reth-primitives = { workspace = true }
reth-interfaces = { workspace = true }
reth-db = { path = "../storage/db" }
reth-metrics = { workspace = true, features = ["common"] }
reth-provider = { workspace = true }

# common
Expand Down
8 changes: 8 additions & 0 deletions crates/blockchain-tree/src/block_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet},
num::NonZeroUsize,
};

use crate::metrics::BlockBufferMetrics;
/// Type that contains blocks by number and hash.
pub type BufferedBlocks = BTreeMap<BlockNumber, HashMap<BlockHash, SealedBlockWithSenders>>;

Expand Down Expand Up @@ -35,6 +37,8 @@ pub struct BlockBuffer {
///
/// Used as counter of amount of blocks inside buffer.
pub(crate) lru: LruCache<BlockNumHash, ()>,
/// Various metrics for the block buffer.
pub(crate) metrics: BlockBufferMetrics,
}

impl BlockBuffer {
Expand All @@ -45,6 +49,7 @@ impl BlockBuffer {
parent_to_child: Default::default(),
hash_to_num: Default::default(),
lru: LruCache::new(NonZeroUsize::new(limit).unwrap()),
metrics: Default::default(),
}
}

Expand All @@ -65,6 +70,7 @@ impl BlockBuffer {
self.remove_from_parent(evicted_block.parent_hash, &evicted_num_hash);
}
}
self.metrics.blocks.set(self.len() as f64);
}

/// Removes the given block from the buffer and also all the children of the block.
Expand All @@ -81,6 +87,7 @@ impl BlockBuffer {
}

taken.extend(self.remove_children(vec![parent]).into_iter());
self.metrics.blocks.set(self.len() as f64);
taken
}

Expand All @@ -105,6 +112,7 @@ impl BlockBuffer {
}

self.remove_children(remove_parent_children);
self.metrics.blocks.set(self.len() as f64);
}

/// Return reference to buffered blocks
Expand Down
10 changes: 10 additions & 0 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::{
canonical_chain::CanonicalChain,
chain::{BlockChainId, BlockKind},
metrics::TreeMetrics,
AppendableChain, BlockBuffer, BlockIndices, BlockchainTreeConfig, PostStateData, TreeExternals,
};
use reth_db::{cursor::DbCursorRO, database::Database, tables, transaction::DbTx};
Expand Down Expand Up @@ -87,6 +88,8 @@ pub struct BlockchainTree<DB: Database, C: Consensus, EF: ExecutorFactory> {
config: BlockchainTreeConfig,
/// Broadcast channel for canon state changes notifications.
canon_state_notification_sender: CanonStateNotificationSender,
/// Metrics for the blockchain tree.
metrics: TreeMetrics,
}

/// A container that wraps chains and block indices to allow searching for block hashes across all
Expand Down Expand Up @@ -137,6 +140,7 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
),
config,
canon_state_notification_sender,
metrics: Default::default(),
})
}

Expand Down Expand Up @@ -1058,6 +1062,12 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
Ok(Some(Chain::new(blocks_and_execution)))
}
}

/// Update blockchain tree metrics
pub(crate) fn update_tree_metrics(&self) {
self.metrics.sidechains.set(self.chains.len() as f64);
self.metrics.canonical_chain_height.set(self.canonical_chain().tip().number as f64);
}
}

#[cfg(test)]
Expand Down
15 changes: 14 additions & 1 deletion crates/blockchain-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Implementation of the [BlockchainTree]
//! Implementation of a tree-like structure for blockchains.
//!
//! The [BlockchainTree] can validate, execute, and revert blocks in multiple competing sidechains.
//! This structure is used for Reth's sync mode at the tip instead of the pipeline, and is the
//! primary executor and validator of payloads sent from the consensus layer.
//!
//! Blocks and their resulting state transitions are kept in-memory until they are persisted.
//!
//! ## Feature Flags
//!
//! - `test-utils`: Export utilities for testing
/// Execution result types.
pub use reth_provider::post_state;
Expand Down Expand Up @@ -34,4 +44,7 @@ pub use post_state_data::{PostStateData, PostStateDataRef};
pub mod block_buffer;
mod canonical_chain;

/// Common blockchain tree metrics.
pub mod metrics;

pub use block_buffer::BlockBuffer;
Loading

0 comments on commit 76f0a78

Please sign in to comment.