Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bin, engine, prune): spawn pruning task from the engine #3566

Merged
merged 56 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
10a2cda
feat(bin, prune): background pruning task
shekhirin Jun 28, 2023
cd0c820
remove unused deps
shekhirin Jun 28, 2023
2799a3a
pass blockchain_db to Pruner
shekhirin Jun 28, 2023
977aadc
add todo regarding pruning task spawning
shekhirin Jun 28, 2023
427ba48
minimal -> minimum
shekhirin Jun 28, 2023
b29796a
add test
shekhirin Jun 28, 2023
6a669bf
add Future TLDR
shekhirin Jun 28, 2023
0962949
fix doc lint
shekhirin Jun 28, 2023
f9fdd4d
max_reorg_depth -> max_prune_depth
shekhirin Jun 29, 2023
4b12c1d
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jun 29, 2023
e462d98
incorporate prune config
shekhirin Jun 29, 2023
453a247
fix prune.rs doc comment
shekhirin Jul 3, 2023
ad224c3
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jul 3, 2023
7a5ab38
make pruning task runnable by engine
shekhirin Jul 3, 2023
4f10a2c
cleanup after previous impl
shekhirin Jul 3, 2023
520f6e5
fix lint
shekhirin Jul 4, 2023
23392f5
add warn messages
shekhirin Jul 4, 2023
964a6ab
prune target -> pruner
shekhirin Jul 4, 2023
6ca076b
prune only when pipeline is idle and both engine and sync are pending
shekhirin Jul 4, 2023
44f6803
pass tip block number to run fut
shekhirin Jul 4, 2023
a6b0ded
add tracing
shekhirin Jul 4, 2023
0952cee
remove trace logging
shekhirin Jul 4, 2023
d9a692a
tidy sync trace logging
shekhirin Jul 4, 2023
c929a7e
add tip block number to started event
shekhirin Jul 4, 2023
3152755
revertme: sleep in pruner
shekhirin Jul 4, 2023
6090262
Revert "revertme: sleep in pruner"
shekhirin Jul 4, 2023
faa78a5
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jul 4, 2023
f69d0d9
improve comments
shekhirin Jul 4, 2023
601ee2e
don't set syncing status
shekhirin Jul 4, 2023
7604f4a
remove unneeded if
shekhirin Jul 4, 2023
6f25a06
add comments for try_spawn_pruner
shekhirin Jul 4, 2023
54eeb50
make check_tip sync
shekhirin Jul 4, 2023
8633966
fix doc lint
shekhirin Jul 4, 2023
5eb3d35
use ctx again
shekhirin Jul 4, 2023
6f48cd9
box stream
shekhirin Jul 5, 2023
ab20796
check_tip -> is_pruning_needed
shekhirin Jul 5, 2023
ce72c22
add node/mod.rs pruner init info log
shekhirin Jul 5, 2023
55f1448
make Pruner::run sync
shekhirin Jul 5, 2023
97ed384
remove unneeded prune controller trace log
shekhirin Jul 5, 2023
2602be3
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jul 5, 2023
da3099a
improve comments
shekhirin Jul 5, 2023
64735dd
pruner canon state stream leftovers
shekhirin Jul 5, 2023
bfb2420
remove async deps from prune crate
shekhirin Jul 5, 2023
5ab728d
revert pub exports needed for canon state stream
shekhirin Jul 5, 2023
9850e72
forgot test attr
shekhirin Jul 5, 2023
d935afb
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jul 6, 2023
611f572
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jul 10, 2023
125a5ca
fixes after review
shekhirin Jul 10, 2023
41d1cce
remove loop
shekhirin Jul 10, 2023
89ab980
improve condition
shekhirin Jul 10, 2023
35e89a9
return self.poll_pruner(cx) directly
shekhirin Jul 10, 2023
3be45c7
Merge remote-tracking branch 'origin/main' into alexey/background-pru…
shekhirin Jul 11, 2023
01a111c
return Pending on NotReady
shekhirin Jul 11, 2023
c9c993b
wtf
shekhirin Jul 11, 2023
f750812
fix blockchain tree test
shekhirin Jul 11, 2023
09d25b7
fix test
shekhirin Jul 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
"crates/net/downloaders",
"crates/payload/basic",
"crates/primitives",
"crates/prune",
"crates/revm",
"crates/revm/revm-primitives",
"crates/revm/revm-inspectors",
Expand Down
1 change: 1 addition & 0 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ reth-payload-builder = { workspace = true }
reth-basic-payload-builder = { path = "../../crates/payload/basic" }
reth-discv4 = { path = "../../crates/net/discv4" }
reth-metrics = { workspace = true }
reth-prune = { path = "../../crates/prune" }
jemallocator = { version = "0.5.0", optional = true }
jemalloc-ctl = { version = "0.5.0", optional = true }

Expand Down
6 changes: 6 additions & 0 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ impl Command {
None
};

let pruner = config.prune.map(|prune_config| {
info!(target: "reth::cli", "Pruner initialized");
reth_prune::Pruner::new(prune_config.block_interval, tree_config.max_reorg_depth())
});

// Configure the consensus engine
let (beacon_consensus_engine, beacon_engine_handle) = BeaconConsensusEngine::with_channel(
client,
Expand All @@ -374,6 +379,7 @@ impl Command {
MIN_BLOCKS_FOR_PIPELINE_RUN,
consensus_engine_tx,
consensus_engine_rx,
pruner,
)?;
info!(target: "reth::cli", "Consensus engine initialized");

Expand Down
13 changes: 11 additions & 2 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,21 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
///
/// This finalizes `last_finalized_block` prior to reading the canonical hashes (using
/// [`BlockchainTree::finalize_block`]).
pub fn restore_canonical_hashes(
pub fn restore_canonical_hashes_and_finalize(
&mut self,
last_finalized_block: BlockNumber,
) -> Result<(), Error> {
self.finalize_block(last_finalized_block);

self.restore_canonical_hashes()
}

/// Reads the last `N` canonical hashes from the database and updates the block indices of the
/// tree.
///
/// `N` is the `max_reorg_depth` plus the number of block hashes needed to satisfy the
/// `BLOCKHASH` opcode in the EVM.
pub fn restore_canonical_hashes(&mut self) -> Result<(), Error> {
let num_of_canonical_hashes =
self.config.max_reorg_depth() + self.config.num_of_additional_canonical_block_hashes();

Expand Down Expand Up @@ -1578,7 +1587,7 @@ mod tests {
.assert(&tree);

// update canonical block to b2, this would make b2a be removed
assert_eq!(tree.restore_canonical_hashes(12), Ok(()));
assert_eq!(tree.restore_canonical_hashes_and_finalize(12), Ok(()));

assert_eq!(tree.is_block_known(block2.num_hash()).unwrap(), Some(BlockStatus::Valid));

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Blockchain tree configuration

/// The configuration for the blockchain tree.
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct BlockchainTreeConfig {
/// Number of blocks after the last finalized block that we are storing.
///
Expand Down
15 changes: 13 additions & 2 deletions crates/blockchain-tree/src/shareable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTreeEngine
tree.update_chains_metrics();
}

fn restore_canonical_hashes(&self, last_finalized_block: BlockNumber) -> Result<(), Error> {
fn restore_canonical_hashes_and_finalize(
&self,
last_finalized_block: BlockNumber,
) -> Result<(), Error> {
trace!(target: "blockchain_tree", ?last_finalized_block, "Restoring canonical hashes for last finalized block");
let mut tree = self.tree.write();
let res = tree.restore_canonical_hashes(last_finalized_block);
let res = tree.restore_canonical_hashes_and_finalize(last_finalized_block);
tree.update_chains_metrics();
res
}

fn restore_canonical_hashes(&self) -> Result<(), Error> {
trace!(target: "blockchain_tree", "Restoring canonical hashes");
let mut tree = self.tree.write();
let res = tree.restore_canonical_hashes();
tree.update_chains_metrics();
res
}
Expand Down
1 change: 1 addition & 0 deletions crates/consensus/beacon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ reth-rpc-types = { workspace = true }
reth-tasks = { workspace = true }
reth-payload-builder = { workspace = true }
reth-metrics = { workspace = true }
reth-prune = { path = "../../prune" }

# async
tokio = { workspace = true, features = ["sync"] }
Expand Down
7 changes: 7 additions & 0 deletions crates/consensus/beacon/src/engine/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use reth_prune::PrunerError;
use reth_rpc_types::engine::ForkchoiceUpdateError;
use reth_stages::PipelineError;

Expand All @@ -16,6 +17,12 @@ pub enum BeaconConsensusEngineError {
/// Pipeline error.
#[error(transparent)]
Pipeline(#[from] Box<PipelineError>),
/// Pruner channel closed.
#[error("Pruner channel closed")]
PrunerChannelClosed,
/// Pruner error.
#[error(transparent)]
Pruner(#[from] PrunerError),
/// Common error. Wrapper around [reth_interfaces::Error].
#[error(transparent)]
Common(#[from] reth_interfaces::Error),
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus/beacon/src/engine/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub(crate) struct EngineMetrics {
pub(crate) forkchoice_updated_messages: Counter,
/// The total count of new payload messages received.
pub(crate) new_payload_messages: Counter,
/// The number of times the pruner was run.
pub(crate) pruner_runs: Counter,
shekhirin marked this conversation as resolved.
Show resolved Hide resolved
}

/// Metrics for the `EngineSyncController`.
Expand Down
Loading