Skip to content

Conversation

kevaundray
Copy link
Contributor

@kevaundray kevaundray commented Apr 17, 2025

This PR makes the SparseTrie and SparseStateTrie no_std compatible similar to revm

@@ -769,15 +778,15 @@ impl<P> RevealedSparseTrie<P> {
prefix_set: &mut PrefixSet,
buffers: &mut RlpNodeBuffers,
) -> RlpNode {
let starting_path = buffers.path_stack.last().map(|item| item.path.clone());
let _starting_path = buffers.path_stack.last().map(|item| item.path.clone());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

underscore because starting_path is only used in the trace! macro and in no_std this is a noop, so clippy warns of an unused variable

@kevaundray kevaundray marked this pull request as ready for review April 17, 2025 12:44
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

some comments

supportive in general

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Apr 17, 2025
@kevaundray kevaundray requested a review from fgimenez as a code owner April 17, 2025 14:32
@kevaundray kevaundray force-pushed the kw/reth-trie-sparse-no-std branch 2 times, most recently from d91c417 to 5a02c05 Compare April 17, 2025 15:14
@@ -7,6 +7,7 @@ crates_to_check=(
reth-primitives-traits
reth-network-peers
reth-trie-common
reth-trie-sparse
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reth already guarantees that certain crates should compile under no-std riscv, so just adding this line here

@@ -769,15 +778,15 @@ impl<P> RevealedSparseTrie<P> {
prefix_set: &mut PrefixSet,
buffers: &mut RlpNodeBuffers,
) -> RlpNode {
let starting_path = buffers.path_stack.last().map(|item| item.path.clone());
let _starting_path = buffers.path_stack.last().map(|item| item.path.clone());
Copy link
Member

Choose a reason for hiding this comment

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

this will still perform a clone if tracing is disabled, let's inline this in the trace macro itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it give the same behaviour? Since this takes the last item and its called in a method that mutates the path_stack:

        'main: while let Some(RlpNodePathStackItem { level, path, mut is_in_prefix_set }) =
            buffers.path_stack.pop()
        {
            let node = self.nodes.get_mut(&path).unwrap();
            trace!(
                target: "trie::sparse",
                ?_starting_path,
                ?level,
                ?path,
                ?is_in_prefix_set,
                ?node,
                "Popped node from path stack"
            );

@kevaundray
Copy link
Contributor Author

tracing supports no_std (see https://github.com/tokio-rs/tracing/blob/dfc2c8b81889f1bc65f053e574de32ec79b72ce1/tracing/Cargo.toml#L64), why is this needed?

Swapped out reth-tracing for tracing -- since that was the main issue. I can look into making reth-tracing no-std in a different PR (I think some features will need to be disabled)

@kevaundray
Copy link
Contributor Author

Was exploring making reth-tracing no_std and it boiled down to everything being feature gated except for tracing and tracing_subscriber (under "alloc" feature) so it was not very useful

@kevaundray kevaundray requested review from rkrasiuk and mattsse April 21, 2025 15:16
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

the way metrics are recorded can be improved, I'll open a new issue for this but not a blocker for this

@@ -16,24 +17,28 @@ pub(crate) struct SparseStateTrieMetrics {
/// Number of total storage nodes, including those that were skipped.
pub(crate) multiproof_total_storage_nodes: u64,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the way this is structured feels a bit strange, ideally this entire file is feature gated but this would require rewriting how metrics are recorded and we can do that separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that was my initial thought too

@@ -31,7 +31,7 @@ reth-stages-api.workspace = true
reth-tasks.workspace = true
reth-trie-db.workspace = true
reth-trie-parallel.workspace = true
reth-trie-sparse.workspace = true
reth-trie-sparse = { workspace = true, features = ["std", "metrics"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

@shekhirin I enabled the metrics feature here so that we still record them.

I also forward activated them in trie-parallel but I noticed we never activate the metrics feature for trie-parallel?

@mattsse mattsse enabled auto-merge April 23, 2025 11:46
@mattsse mattsse added this pull request to the merge queue Apr 23, 2025
Merged via the queue into paradigmxyz:main with commit 40f0edf Apr 23, 2025
44 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Apr 23, 2025
07Vaishnavi-Singh pushed a commit to 07Vaishnavi-Singh/reth that referenced this pull request May 3, 2025
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants