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(engine): wire StateRootTask in EngineApiTreeHandler #12639

Merged
merged 33 commits into from
Jan 7, 2025

Conversation

fgimenez
Copy link
Member

@fgimenez fgimenez commented Nov 18, 2024

Towards #12053

@fgimenez fgimenez added C-perf A change motivated by improving speed, memory usage or disk footprint A-engine Related to the engine implementation A-trie Related to Merkle Patricia Trie implementation labels Nov 18, 2024
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 5eba0ab to e3149b0 Compare November 19, 2024 12:02
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from 70e9ba3 to 8f89fff Compare November 19, 2024 12:02
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from e3149b0 to ffd4c4a Compare November 19, 2024 12:45
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from 8f89fff to 20ec32e Compare November 19, 2024 12:46
Comment on lines 2197 to 2240
let consistent_view = ConsistentDbView::new_with_latest_tip(self.provider.clone())?;

let input = self
.compute_trie_input(consistent_view.clone(), block.parent_hash)
.map_err(|e| InsertBlockErrorKindTwo::Other(Box::new(e)))?;
let state_root_config =
StateRootConfig { consistent_view: consistent_view.clone(), input: Arc::new(input) };
let receiver_stream = StdReceiverStream::new(state_root_rx);
let state_root_task = StateRootTask::new(state_root_config, receiver_stream);
let state_root_handle = state_root_task.spawn();
let state_hook = move |result_and_state: &ResultAndState| {
let _ = state_root_tx.send(result_and_state.state.clone());
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected to instantiate a state root task each time, or is it expected that we spawn it once?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it is designed to instantiate one task per block. maybe we could get rid of the overhead of creating the task with a background service, similar to what we have for persistence, once everything is working correctly we can measure to compare both approaches

@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from ffd4c4a to fde920f Compare November 20, 2024 14:21
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from 4e45271 to 60a90c7 Compare November 20, 2024 15:35
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 52e1366 to 2ffe7c8 Compare November 21, 2024 09:43
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch 2 times, most recently from c373aa2 to 256cd4d Compare November 22, 2024 09:18
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 8e7f598 to e734d3f Compare November 22, 2024 17:54
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch 2 times, most recently from fa4e2d1 to b5f64dc Compare November 24, 2024 16:47
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from f982fa2 to 1665120 Compare November 24, 2024 16:49
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from b5f64dc to a265490 Compare November 25, 2024 12:14
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 7939f11 to d8dea1f Compare November 25, 2024 15:12
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from a265490 to 885b439 Compare November 25, 2024 16:27
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from 4730fcb to fbc22f5 Compare November 26, 2024 16:09
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from 885b439 to 598aa99 Compare November 26, 2024 16:12
@fgimenez fgimenez force-pushed the fgimenez/srt-proof-fetching branch from fbc22f5 to 344a9b8 Compare November 27, 2024 10:01
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from 598aa99 to c43f9fa Compare November 27, 2024 14:15
Base automatically changed from fgimenez/srt-proof-fetching to main November 27, 2024 14:30
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch 4 times, most recently from 465e211 to c04977e Compare November 29, 2024 12:30
@fgimenez fgimenez force-pushed the fgimenez/srt-wiring branch from 2ca2c39 to e900abf Compare December 27, 2024 11:52
bin/reth/src/main.rs Outdated Show resolved Hide resolved
Comment on lines +2278 to +2280
// it is ok to leak here because we are in a scoped thread, the
// memory will be freed when the thread completes
let context = Box::leak(Box::new(context));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without it there are issues with the lifecycle of the variables used inside the std::thread::scope, even when they are created outside it, bc of the state hook being moved outside the scoped thread. the errors look like this:

error[E0597]: `provider_ro` does not live long enough
    --> crates/engine/tree/src/tree/mod.rs:2264:56
     |
2255 |         let provider_ro = consistent_view.provider_ro()?;
     |             ----------- binding `provider_ro` declared here
...
2260 |         let state_root_result = match std::thread::scope(|scope| {
     |                                                          ------- value captured here
...
2264 |                         DatabaseTrieCursorFactory::new(provider_ro.tx_ref()),
     |                                                        ^^^^^^^^^^^ borrowed value does not live long enough
...
2277 |                 (Some(state_root_task.spawn(scope)), Box::new(state_hook) as Box<dyn OnStateHook>)
     |                                                      -------------------------------------------- cast requires that `provider_ro` is borrowed for `'static`
...
2419 |     }
     |     - `provider_ro` dropped here while still borrowed

@fgimenez fgimenez added this pull request to the merge queue Jan 7, 2025
Merged via the queue into main with commit 107dfae Jan 7, 2025
43 checks passed
@fgimenez fgimenez deleted the fgimenez/srt-wiring branch January 7, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-engine Related to the engine implementation A-trie Related to Merkle Patricia Trie implementation C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants