-
Notifications
You must be signed in to change notification settings - Fork 36
flag to determine if calculating state root #241
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
Changes from 2 commits
94e00e0
1860635
0c70cff
8ef2ef9
24b1534
9eee120
6777a35
2469ade
f54d25b
b0d44b7
d6cf5c7
1ec6310
a8dd72a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ use reth_provider::{ | |
| use reth_revm::{ | ||
| database::StateProviderDatabase, db::states::bundle_state::BundleRetention, State, | ||
| }; | ||
| use reth_trie::{updates::TrieUpdates, HashedPostState}; | ||
| use revm::Database; | ||
| use rollup_boost::{ | ||
| ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, FlashblocksPayloadV1, | ||
|
|
@@ -46,7 +47,7 @@ use std::{ | |
| atomic::{AtomicU64, Ordering}, | ||
| Arc, | ||
| }, | ||
| time::Instant, | ||
| time::{Instant, SystemTime, UNIX_EPOCH}, | ||
| }; | ||
| use tokio::sync::{ | ||
| mpsc, | ||
|
|
@@ -192,6 +193,10 @@ where | |
| best_payload: BlockCell<OpBuiltPayload>, | ||
| ) -> Result<(), PayloadBuilderError> { | ||
| let block_build_start_time = Instant::now(); | ||
| let current_timestamp = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .unwrap() | ||
| .as_secs(); | ||
| let BuildArguments { | ||
| mut cached_reads, | ||
| config, | ||
|
|
@@ -214,6 +219,12 @@ where | |
|
|
||
| let chain_spec = self.client.chain_spec(); | ||
| let timestamp = config.attributes.timestamp(); | ||
| let is_doing_historical_sync = timestamp < current_timestamp; | ||
| let calculate_state_root = if is_doing_historical_sync { | ||
| true | ||
| } else { | ||
| self.config.specific.calculate_state_root | ||
| }; | ||
| let block_env_attributes = OpNextBlockEnvAttributes { | ||
| timestamp, | ||
| suggested_fee_recipient: config.attributes.suggested_fee_recipient(), | ||
|
|
@@ -288,16 +299,18 @@ where | |
| ctx.add_builder_tx(&mut info, &mut state, builder_tx_gas, message.clone()); | ||
| } | ||
|
|
||
| let (payload, fb_payload) = build_block(&mut state, &ctx, &mut info)?; | ||
| let (payload, fb_payload) = build_block(&mut state, &ctx, &mut info, calculate_state_root)?; | ||
|
|
||
| best_payload.set(payload.clone()); | ||
| let flashblock_byte_size = self | ||
| .ws_pub | ||
| .publish(&fb_payload) | ||
| .map_err(PayloadBuilderError::other)?; | ||
| ctx.metrics | ||
| .flashblock_byte_size_histogram | ||
| .record(flashblock_byte_size as f64); | ||
| if !is_doing_historical_sync { | ||
|
||
| let flashblock_byte_size = self | ||
| .ws_pub | ||
| .publish(&fb_payload) | ||
| .map_err(PayloadBuilderError::other)?; | ||
| ctx.metrics | ||
| .flashblock_byte_size_histogram | ||
| .record(flashblock_byte_size as f64); | ||
| } | ||
|
|
||
| info!( | ||
| target: "payload_builder", | ||
|
|
@@ -484,7 +497,8 @@ where | |
| }; | ||
|
|
||
| let total_block_built_duration = Instant::now(); | ||
| let build_result = build_block(&mut state, &ctx, &mut info); | ||
| let build_result = | ||
| build_block(&mut state, &ctx, &mut info, calculate_state_root); | ||
| let total_block_built_duration = total_block_built_duration.elapsed(); | ||
| ctx.metrics | ||
| .total_block_built_duration | ||
|
|
@@ -770,6 +784,7 @@ fn build_block<DB, P, ExtraCtx>( | |
| state: &mut State<DB>, | ||
| ctx: &OpPayloadBuilderCtx<ExtraCtx>, | ||
| info: &mut ExecutionInfo<ExtraExecutionInfo>, | ||
| calculate_state_root: bool, | ||
| ) -> Result<(OpBuiltPayload, FlashblocksPayloadV1), PayloadBuilderError> | ||
| where | ||
| DB: Database<Error = ProviderError> + AsRef<P>, | ||
|
|
@@ -814,28 +829,37 @@ where | |
| // TODO: maybe recreate state with bundle in here | ||
| // // calculate the state root | ||
| let state_root_start_time = Instant::now(); | ||
| let state_provider = state.database.as_ref(); | ||
| let hashed_state = state_provider.hashed_post_state(execution_outcome.state()); | ||
| let (state_root, trie_output) = { | ||
| state | ||
| .database | ||
| .as_ref() | ||
| .state_root_with_updates(hashed_state.clone()) | ||
| .inspect_err(|err| { | ||
| warn!(target: "payload_builder", | ||
| parent_header=%ctx.parent().hash(), | ||
| %err, | ||
| "failed to calculate state root for payload" | ||
| ); | ||
| })? | ||
| }; | ||
| let state_root_calculation_time = state_root_start_time.elapsed(); | ||
| ctx.metrics | ||
| .state_root_calculation_duration | ||
| .record(state_root_calculation_time); | ||
| ctx.metrics | ||
| .state_root_calculation_gauge | ||
| .set(state_root_calculation_time); | ||
| let mut state_root = B256::ZERO; | ||
| let mut trie_output = TrieUpdates::default(); | ||
| let mut hashed_state = HashedPostState::default(); | ||
|
|
||
| if calculate_state_root { | ||
| let state_provider = state.database.as_ref(); | ||
| let _hashed_state = state_provider.hashed_post_state(execution_outcome.state()); | ||
| let (_state_root, _trie_output) = { | ||
cody-wang-cb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| state | ||
| .database | ||
| .as_ref() | ||
| .state_root_with_updates(hashed_state.clone()) | ||
| .inspect_err(|err| { | ||
| warn!(target: "payload_builder", | ||
| parent_header=%ctx.parent().hash(), | ||
| %err, | ||
| "failed to calculate state root for payload" | ||
| ); | ||
| })? | ||
| }; | ||
| let state_root_calculation_time = state_root_start_time.elapsed(); | ||
| ctx.metrics | ||
| .state_root_calculation_duration | ||
| .record(state_root_calculation_time); | ||
| ctx.metrics | ||
| .state_root_calculation_gauge | ||
| .set(state_root_calculation_time); | ||
| state_root = _state_root; | ||
| trie_output = _trie_output; | ||
| hashed_state = _hashed_state; | ||
cody-wang-cb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| let mut requests_hash = None; | ||
| let withdrawals_root = if ctx | ||
|
|
||
cody-wang-cb marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
why do we need to build blocks and calculate the state root during historical sync?
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.
answered here
#241 (comment)