Skip to content

feat(delayed-persist): dump unpersisted nodestore #1055

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

Merged
merged 2 commits into from
Jul 15, 2025
Merged

Conversation

rkuris
Copy link
Collaborator

@rkuris rkuris commented Jul 12, 2025

dump has to work with unpersisted nodes, as there are a bunch of tests that assume an immutable proposal can be dumped. This was useful anyway while debugging some tests in the next commit, and small enough to commit separately.

dump has to work with unpersisted nodes, as there are a bunch of tests
that assume an immutable proposal can be dumped. This was useful anyway
while debugging some tests in the next commit, and small enough to
commit separately.
@rkuris rkuris requested a review from qusuyan July 12, 2025 00:40
@rkuris rkuris self-assigned this Jul 12, 2025
@rkuris rkuris requested a review from demosdemon as a code owner July 12, 2025 00:40
@rkuris rkuris added the enhancement New feature or request label Jul 12, 2025
/// Returns the root of the trie as a `MaybePersistedNode`.
/// Callers that might want to modify the root or know how it is stored
/// should use this function.
fn root_as_maybe_persisted_node(&self) -> Option<MaybePersistedNode>;
Copy link
Collaborator Author

@rkuris rkuris Jul 12, 2025

Choose a reason for hiding this comment

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

In a future diff, this will just be called root but I want it verbose during the rest of the development of this feature as it helped identify areas still to changed.

@rkuris rkuris merged commit af8d3dc into main Jul 15, 2025
34 checks passed
@rkuris rkuris deleted the rkuris/dump-unpersisted branch July 15, 2025 00:06
rkuris added a commit that referenced this pull request Jul 15, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 15, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 16, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 16, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 17, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
KushnerykPavel pushed a commit to KushnerykPavel/firewood that referenced this pull request Jul 17, 2025
dump has to work with unpersisted nodes, as there are a bunch of tests
that assume an immutable proposal can be dumped. This was useful anyway
while debugging some tests in the next commit, and small enough to
commit separately.
rkuris added a commit that referenced this pull request Jul 19, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 19, 2025
Create a new type, NodeAllocator, to handle allocations.

Currently only uses references to the original NodeStore, but this will
change in an upcoming diff.

Also:
 - Branch children iterators will soon no longer be able to return
   references to hashes, since they are behind an ArcSwap, so they
   are now cloned.
 - Added logger feature to benchmark (helped with debugging)
 - Remove use of stored_len in tests

feat(deferred-allocate): Part 3.2: Implementation

This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The commit logic is also different, with far fewer steps. See the
comments in `commit` in manager.rs.

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 19, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The implementation constisted of:
 - A new type, NodeAllocator, to consolidate all the allocation code
 - Removing the 'new' hashmap, as freshly allocatred nodes are found
   by traversing the trie and inspecting their state
 - Rewrite flush_nodes to serialize then allocate. Previously, the node
   was serialized twice, once to determine the size during proposal
   creation and once to store it
 - Branch children iterators can no longer return reference to hashes,
   since they are sometimes behind an ArcSwap
 - Changes to the commit flow by separating the node persistence logic

Some miscellaneous changes included in this diff (could be split out):
 - Propogate logger feature in fwdctl (helped with debugging)
 - Remove use of stored_len in tests
 - size_from_area_index was a method on nodestore, but didn't use
   nodestore
 - uncached_node_and_size was dead code

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 20, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The implementation constisted of:
 - A new type, NodeAllocator, to consolidate all the allocation code
 - Removing the 'new' hashmap, as freshly allocatred nodes are found
   by traversing the trie and inspecting their state
 - Use the most recently committed revision's freelist to allocate
   new nodes. This will change in a future revision when the freelist
   is tied to storage rather than the revision.
 - Rewrite flush_nodes to serialize then allocate. Previously, the node
   was serialized twice, once to determine the size during proposal
   creation (allocation time) and once to store it
 - Changes to the commit flow by separating the node persistence logic
   (see comments in commit.rs)

Some miscellaneous changes included in this diff (could be split out):
 - Branch children iterators can no longer return reference to hashes,
   since they are sometimes behind an ArcSwap
 - Propogate logger feature in fwdctl (helped with debugging)
 - Remove use of stored_len in tests
 - size_from_area_index was a method on nodestore, but didn't use
   nodestore
 - uncached_node_and_size was dead code

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 21, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The implementation constisted of:
 - A new type, NodeAllocator, to consolidate all the allocation code
 - Removing the 'new' hashmap, as freshly allocatred nodes are found
   by traversing the trie and inspecting their state
 - Use the most recently committed revision's freelist to allocate
   new nodes. This will change in a future revision when the freelist
   is tied to storage rather than the revision.
 - Rewrite flush_nodes to serialize then allocate. Previously, the node
   was serialized twice, once to determine the size during proposal
   creation (allocation time) and once to store it
 - Changes to the commit flow by separating the node persistence logic
   (see comments in commit.rs)

Some miscellaneous changes included in this diff (could be split out):
 - Branch children iterators can no longer return reference to hashes,
   since they are sometimes behind an ArcSwap
 - Propogate logger feature in fwdctl (helped with debugging)
 - Remove use of stored_len in tests
 - size_from_area_index was a method on nodestore, but didn't use
   nodestore
 - uncached_node_and_size was dead code

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 22, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The implementation constisted of:
 - A new type, NodeAllocator, to consolidate all the allocation code
 - Removing the 'new' hashmap, as freshly allocatred nodes are found
   by traversing the trie and inspecting their state
 - Use the most recently committed revision's freelist to allocate
   new nodes. This will change in a future revision when the freelist
   is tied to storage rather than the revision.
 - Rewrite flush_nodes to serialize then allocate. Previously, the node
   was serialized twice, once to determine the size during proposal
   creation (allocation time) and once to store it
 - Changes to the commit flow by separating the node persistence logic
   (see comments in commit.rs)

Some miscellaneous changes included in this diff (could be split out):
 - Branch children iterators can no longer return reference to hashes,
   since they are sometimes behind an ArcSwap
 - Propogate logger feature in fwdctl (helped with debugging)
 - Remove use of stored_len in tests
 - size_from_area_index was a method on nodestore, but didn't use
   nodestore
 - uncached_node_and_size was dead code
 - New clippy lint for hash_helper not needing &self in non-ethhash
   fixed

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 22, 2025
This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The implementation constisted of:
 - A new type, NodeAllocator, to consolidate all the allocation code
 - Removing the 'new' hashmap, as freshly allocatred nodes are found
   by traversing the trie and inspecting their state
 - Use the most recently committed revision's freelist to allocate
   new nodes. This will change in a future revision when the freelist
   is tied to storage rather than the revision.
 - Rewrite flush_nodes to serialize then allocate. Previously, the node
   was serialized twice, once to determine the size during proposal
   creation (allocation time) and once to store it
 - Changes to the commit flow by separating the node persistence logic
   (see comments in commit.rs)

Some miscellaneous changes included in this diff (could be split out):
 - Branch children iterators can no longer return reference to hashes,
   since they are sometimes behind an ArcSwap
 - Propogate logger feature in fwdctl (helped with debugging)
 - Remove use of stored_len in tests
 - size_from_area_index was a method on nodestore, but didn't use
   nodestore
 - uncached_node_and_size was dead code
 - New clippy lint for hash_helper not needing &self in non-ethhash
   fixed

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
rkuris added a commit that referenced this pull request Jul 23, 2025
feat(deferred-allocate): Part 3: Defer allocate

This implements deferred allocaion that delays allocating space for
nodes until commit time.

The nodestore refactor consisted of removing the 'new' hashmap, which
mapped newly allocated nodes to their contents in a proposal. Instead,
now we store those newly allocated nodes directly from the `Child`
struct.

The implementation constisted of:
 - A new type, NodeAllocator, to consolidate all the allocation code
 - Removing the 'new' hashmap, as freshly allocatred nodes are found
   by traversing the trie and inspecting their state
 - Use the most recently committed revision's freelist to allocate
   new nodes. This will change in a future revision when the freelist
   is tied to storage rather than the revision.
 - Rewrite flush_nodes to serialize then allocate. Previously, the node
   was serialized twice, once to determine the size during proposal
   creation (allocation time) and once to store it
 - Changes to the commit flow by separating the node persistence logic
   (see comments in commit.rs)

Some miscellaneous changes included in this diff (could be split out):
 - Branch children iterators can no longer return reference to hashes,
   since they are sometimes behind an ArcSwap
 - Propogate logger feature in fwdctl (helped with debugging)
 - Remove use of stored_len in tests
 - size_from_area_index was a method on nodestore, but didn't use
   nodestore
 - uncached_node_and_size was dead code
 - New clippy lint for hash_helper not needing &self in non-ethhash
   fixed

Task completion status:
  [x] Roots may not be persisted (Part 1: #1041)
  [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and #1047)
  [x] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s. (Part 3: #1055 and this PR)
  [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move
into the `RevisionManager`.
  [ ] Allocate new nodes from the recently-freed nodes from an expired
revision, then from the freelist. This can be done by maintaining a
local freelist from the nodes deleted in the expiring revision and
falling back to the actual freelist. Deleted nodes that are not reused
must still be pushed onto the freelist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants