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: calculate state root in background #197

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,16 @@ impl ExecutedBlock {
pub fn trie_updates(&self) -> &TrieUpdates {
&self.trie
}

/// Returns a state root of the block.
pub fn state_root(&self) -> B256 {
self.block.header.header().state_root
}

/// Sets the trie updates for the block.
pub fn set_trie_updates(&mut self, trie: TrieUpdates) {
self.trie = Arc::new(trie);
}
}

/// Non-empty chain of blocks.
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/commands/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ impl<
pruning,
enable_prefetch,
skip_state_root_validation: performance_optimization.skip_state_root_validation,
compute_state_root_in_background: performance_optimization
.compute_state_root_in_background,
enable_execution_cache: performance_optimization.enable_execution_cache,
};

Expand Down
11 changes: 9 additions & 2 deletions crates/engine/local/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ where
mode: MiningMode,
payload_attributes_builder: B,
skip_state_root_validation: bool,
compute_state_root_in_background: bool,
enable_prefetch: bool,
enable_execution_cache: bool,
) -> Self
Expand All @@ -87,8 +88,13 @@ where
let engine_kind =
if chain_spec.is_optimism() { EngineApiKind::OpStack } else { EngineApiKind::Ethereum };

let persistence_handle =
PersistenceHandle::spawn_service(provider, pruner, sync_metrics_tx, false);
let persistence_handle = PersistenceHandle::spawn_service(
provider,
blockchain_db.clone(),
pruner,
sync_metrics_tx,
false,
);
let payload_validator = ExecutionPayloadValidator::new(chain_spec);

let canonical_in_memory_state = blockchain_db.canonical_in_memory_state();
Expand All @@ -105,6 +111,7 @@ where
invalid_block_hook,
engine_kind,
skip_state_root_validation,
compute_state_root_in_background,
enable_prefetch,
enable_execution_cache,
);
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ where
invalid_block_hook: Box<dyn InvalidBlockHook>,
sync_metrics_tx: MetricEventsSender,
skip_state_root_validation: bool,
compute_state_root_in_background: bool,
enable_prefetch: bool,
enable_execution_cache: bool,
) -> Self {
Expand All @@ -90,6 +91,7 @@ where

let persistence_handle = PersistenceHandle::spawn_service(
provider,
blockchain_db.clone(),
pruner,
sync_metrics_tx,
enable_execution_cache,
Expand All @@ -110,6 +112,7 @@ where
invalid_block_hook,
engine_kind,
skip_state_root_validation,
compute_state_root_in_background,
enable_prefetch,
enable_execution_cache,
);
Expand Down Expand Up @@ -228,6 +231,7 @@ mod tests {
false,
false,
false,
false,
);
}
}
2 changes: 2 additions & 0 deletions crates/engine/tree/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ pub(crate) struct PersistenceMetrics {
pub(crate) save_blocks_duration_seconds: Histogram,
/// How long it took for blocks to be pruned
pub(crate) prune_before_duration_seconds: Histogram,
/// The height of blocks was persisted
pub(crate) persistence_height: Gauge,
}
Loading