Skip to content

feat(delayed-persist): Part 1: Roots may be in mem #1041

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 11 commits into from
Jul 8, 2025
Merged

Conversation

rkuris
Copy link
Collaborator

@rkuris rkuris commented Jul 7, 2025

Introduces a new type, MaybePersistedNode, which is a node which is either a SharedNode or a LinearAddress. This new type will allow writes to occur while readers are still reading this revision using an ArcSwap.

Note that this does not actually put any additional nodes in memory, it just sets things up so they could be in memory.

Additional changes needed for this feature to be complete are:

  • BranchNode children can now be Node, LinearAddress or a MaybePersistedNode
  • When converting a MutableProposal to an ImmutableProposal, don't actually allocate space, just create SharedNodes from the Nodes.
  • 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.

Introduces a new type, `MemDiskNode`, which is a node which is either a
SharedNode or a LinearAddress. This new type will allow writes to occur
while readers are still reading this revision using an `ArcSwap`.

Note that this does not actually put any additional nodes in memory, it
just sets things up so they could be in memory.

Additional changes needed for this feature to be complete are:

 - [ ] BranchNode children can now be Node, LinearAddress or MemDiskNode
 - [ ] When converting a `MutableProposal` to an `ImmutableProposal`,
   don't actually allocate space, just create `SharedNode`s from the
   `Node`s.
 - [ ] 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 rkuris requested review from qusuyan and alarso16 July 7, 2025 23:14
@rkuris rkuris removed the request for review from aaronbuchwald July 7, 2025 23:17
@rkuris
Copy link
Collaborator Author

rkuris commented Jul 8, 2025

The goal of this set of diffs is to separate persistence from both proposals and committed revisions. When proposing, we currently allocate space and modify the freelist. When committing, we currently flush all the modified nodes to disk.

This diff is step 1. The only thing this diff does is allow for the root node (and only the root node) of proposals and revisions to be kept in memory and, using a lockless type, allow them to be persisted even while being read by other threads. It doesn't do that, since they are currently always created as an allocated node, but that will change on future diffs.

In other words, it still always marks the node as persisted by assigning the address at propose time and using the persisted variant of the new MemDiskNode type when created, doesn't allow for branches to have their changes in memory, and doesn't defer the allocation to commit time. So this means this diff doesn't actually make any improvements. It might have a performance impact and it might be good to measure it at this point though.

This is a better name.
/// # Arguments
///
/// * `addr` - The `LinearAddress` where the node has been persisted on disk
pub fn persist_at(&self, addr: LinearAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like this function is really called when the node is evicted from cache instead of when it gets persisted. Maybe rename?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's called after the. node is written to disk.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh because after you persist it you can read it from the cache of linear storage using its address right? Then I think MaybeAllocated may be a better name than MemDiskNode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not just allocated, it's persisted. The states here are:

  • Node in memory (SharedNode)
  • Node on disk (LinearAddress)

Allocation is the verb that describes part of persisting a node. First you allocate space, then you write (persist) it. If it has a LinearAddress, and I'm done with all my changes, the only thing that will have LinearAddresses are persisted. Right now we get a LinearAddress at allocation time, which is at propose time, but that's all moving.

@rkuris rkuris requested a review from qusuyan July 8, 2025 16:24
@rkuris rkuris force-pushed the rkuris/memory-root branch from c51a807 to c31a9ce Compare July 8, 2025 16:32
rkuris added 3 commits July 8, 2025 09:43
Upcoming changes make supporting this harder, and it's not necessary, as
the size of a LinearAddress and the size of a pointer are the same, so
it's more efficient to return the actual value rather than a pointer to
the value.
Members renamed from Mem to Unpersisted and Disk to Persisted, just to
keep the naming a bit more consistent.
@rkuris rkuris force-pushed the rkuris/memory-root branch from c31a9ce to 7575745 Compare July 8, 2025 16:43
/// - `Unpersisted(SharedNode)`: The node is currently in memory
/// - `Persisted(LinearAddress)`: The node is currently on disk at the specified address
#[derive(Debug)]
pub enum MaybePersisted {

This comment was marked as resolved.

rkuris added 2 commits July 8, 2025 11:28
Most important test is that the node is no longer referenced after it
becomes persisted, and it's shared across clones.
Create a table explaining the type more clearly.

Lower visibility of MaybePersisted.
@rkuris rkuris enabled auto-merge (squash) July 8, 2025 19:26
@rkuris rkuris merged commit d9e93c9 into main Jul 8, 2025
34 checks passed
@rkuris rkuris deleted the rkuris/memory-root branch July 8, 2025 19:40
rkuris added a commit that referenced this pull request Jul 9, 2025
Branch children might also not be persisted.

This also splits up hash_helper which got too long for clippy.

- [x] Roots may not be persisted (Part 1: #1041)
- [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: #1045 and this PR #1047)
- [ ] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s.
- [ ] 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 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
Branch children might also not be persisted.

This also splits up hash_helper which got too long for clippy.

- [x] Roots may not be persisted (Part 1: ava-labs#1041)
- [x] BranchNode children can now be Node, LinearAddress or a
MaybePersistedNode (Part 2: ava-labs#1045 and this PR ava-labs#1047)
- [ ] When converting a `MutableProposal` to an `ImmutableProposal`,
don't actually allocate space, just create `SharedNode`s from the
`Node`s.
- [ ] 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 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants