-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(engine): compare invalid block witness against a healthy node #10844
Merged
shekhirin
merged 10 commits into
main
from
alexey/invalid-block-hook-healthy-node-rpc-url
Sep 16, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
55b1164
feat(engine): compare invalid block witness against a healthy node
shekhirin f2d12f7
update book
shekhirin e2fba8b
write healthy witness
shekhirin e1a7012
check chain id of a healthy node
shekhirin 21f5f28
use futures::executor::block_on
shekhirin 1a7ed2c
clarify the cli arg doc
shekhirin ab28ceb
use File::create_new
shekhirin 4fd6509
fixes after review
shekhirin b980b8c
update doc comments
shekhirin 77c3d51
Merge remote-tracking branch 'origin/main' into alexey/invalid-block-…
shekhirin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
use std::{sync::Arc, thread::available_parallelism}; | ||
|
||
use alloy_primitives::{BlockNumber, B256}; | ||
use eyre::Context; | ||
use eyre::{Context, OptionExt}; | ||
use rayon::ThreadPoolBuilder; | ||
use reth_auto_seal_consensus::MiningMode; | ||
use reth_beacon_consensus::EthBeaconConsensus; | ||
|
@@ -23,6 +23,7 @@ use reth_invalid_block_hooks::InvalidBlockWitnessHook; | |
use reth_network_p2p::headers::client::HeadersClient; | ||
use reth_node_api::{FullNodeTypes, NodeTypes, NodeTypesWithDB}; | ||
use reth_node_core::{ | ||
args::InvalidBlockHookType, | ||
dirs::{ChainPath, DataDirPath}, | ||
node_config::NodeConfig, | ||
version::{ | ||
|
@@ -44,6 +45,7 @@ use reth_provider::{ | |
TreeViewer, | ||
}; | ||
use reth_prune::{PruneModes, PrunerBuilder}; | ||
use reth_rpc_api::clients::EthApiClient; | ||
use reth_rpc_builder::config::RethRpcServerConfig; | ||
use reth_rpc_layer::JwtSecret; | ||
use reth_stages::{sets::DefaultStages, MetricEvent, Pipeline, PipelineTarget, StageId}; | ||
|
@@ -855,35 +857,62 @@ where | |
{ | ||
/// Returns the [`InvalidBlockHook`] to use for the node. | ||
pub fn invalid_block_hook(&self) -> eyre::Result<Box<dyn InvalidBlockHook>> { | ||
Ok(if let Some(ref hook) = self.node_config().debug.invalid_block_hook { | ||
let output_directory = self.data_dir().invalid_block_hooks(); | ||
let hooks = hook | ||
.iter() | ||
.copied() | ||
.map(|hook| { | ||
let output_directory = output_directory.join(hook.to_string()); | ||
fs::create_dir_all(&output_directory)?; | ||
|
||
Ok(match hook { | ||
reth_node_core::args::InvalidBlockHook::Witness => { | ||
Box::new(InvalidBlockWitnessHook::new( | ||
output_directory, | ||
self.blockchain_db().clone(), | ||
self.components().evm_config().clone(), | ||
)) as Box<dyn InvalidBlockHook> | ||
} | ||
reth_node_core::args::InvalidBlockHook::PreState | | ||
reth_node_core::args::InvalidBlockHook::Opcode => { | ||
eyre::bail!("invalid block hook {hook:?} is not implemented yet") | ||
} | ||
}) | ||
}) | ||
.collect::<Result<_, _>>()?; | ||
|
||
Box::new(InvalidBlockHooks(hooks)) | ||
} else { | ||
Box::new(NoopInvalidBlockHook::default()) | ||
}) | ||
let Some(ref hook) = self.node_config().debug.invalid_block_hook else { | ||
return Ok(Box::new(NoopInvalidBlockHook::default())) | ||
}; | ||
let healthy_node_rpc_client = self.get_healthy_node_client()?; | ||
|
||
let output_directory = self.data_dir().invalid_block_hooks(); | ||
let hooks = hook | ||
.iter() | ||
.copied() | ||
.map(|hook| { | ||
let output_directory = output_directory.join(hook.to_string()); | ||
fs::create_dir_all(&output_directory)?; | ||
|
||
Ok(match hook { | ||
InvalidBlockHookType::Witness => Box::new(InvalidBlockWitnessHook::new( | ||
self.blockchain_db().clone(), | ||
self.components().evm_config().clone(), | ||
output_directory, | ||
healthy_node_rpc_client.clone(), | ||
)), | ||
InvalidBlockHookType::PreState | InvalidBlockHookType::Opcode => { | ||
eyre::bail!("invalid block hook {hook:?} is not implemented yet") | ||
} | ||
} as Box<dyn InvalidBlockHook>) | ||
}) | ||
.collect::<Result<_, _>>()?; | ||
|
||
Ok(Box::new(InvalidBlockHooks(hooks))) | ||
} | ||
|
||
/// Returns an RPC client for the healthy node, if configured in the node config. | ||
fn get_healthy_node_client(&self) -> eyre::Result<Option<jsonrpsee::http_client::HttpClient>> { | ||
self.node_config() | ||
.debug | ||
.healthy_node_rpc_url | ||
.as_ref() | ||
.map(|url| { | ||
let client = jsonrpsee::http_client::HttpClientBuilder::default().build(url)?; | ||
|
||
// Verify that the healthy node is running the same chain as the current node. | ||
let chain_id = futures::executor::block_on(async { | ||
EthApiClient::< | ||
reth_rpc_types::Transaction, | ||
reth_rpc_types::Block, | ||
reth_rpc_types::Receipt, | ||
>::chain_id(&client) | ||
Comment on lines
+900
to
+905
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes me wonder if we should just provide a blocking api in |
||
.await | ||
})? | ||
.ok_or_eyre("healthy node rpc client didn't return a chain id")?; | ||
if chain_id.to::<u64>() != self.chain_id().id() { | ||
eyre::bail!("invalid chain id for healthy node: {chain_id}") | ||
} | ||
|
||
Ok(client) | ||
}) | ||
.transpose() | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we even need this check?
I mean this is a debug feature, so do we need to explicitly check this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd prefer to have it so we don't end up in a situation when generated witness diff is incorrect and we spend time figuring out why