-
Notifications
You must be signed in to change notification settings - Fork 840
refactor: Firewood Revisions #4669
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
base: alarso16/shared-firewood
Are you sure you want to change the base?
Conversation
b571ed4 to
28bc9e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the Firewood integration to use Revision objects directly for accessing state, improving concurrency safety and memory management. The change eliminates reliance on an internal one-Revision cache in favor of Firewood's native revision system with automatic memory cleanup via finalizers.
- Replaces
GetFromRootcalls withRevisionobjects that have built-in memory management - Updates the
readerstruct to hold aRevisioninstead of database reference and root hash - Adds explicit cleanup of state references in the legacy transaction pool
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| graft/coreth/triedb/firewood/database.go | Refactors Reader to use Firewood Revision objects instead of root hash lookups |
| graft/coreth/core/txpool/legacypool/legacypool.go | Adds explicit cleanup of state references during pool closure |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AminR443
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. One comment on dropping:
The Revision has a finalizer attached to release all related memory when there are no more references.
Revisions hanging around will prevent the revision manager from reaping the nodestores, and this may not be good from a memory perspective. Last I checked, finalizers were considered expensive and could run at an arbitrary time after becoming unreachable. What's preventing us from explicitly dropping the revision?
Also, if we're going with finalizers, is there any particular reason we're not using runtime.AddCleanup?
We don't know when it will no longer be used. There's very strict interfaces to adhere to, and that includes that we cannot assume there will be any behavior to indicate the
No particular reason! In our case, they should be equivalent. We know that they are properly being cleaned because closing the database doesn't hang. We could use |
|
Sounds good to me. I think we should consider using
I'll create an issue for that in firewood repo. |
28bc9e7 to
18464ef
Compare
| } | ||
|
|
||
| // remove all references to state to allow GC to reclaim memory | ||
| pool.pendingNonces = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These keep around a StateDB, which holds onto the *firewood.accountTrie, so the database closure will hang unless we remove these references. Another (worse) option is that on state.Trie.Copy(), we don't copy the Reader, and instead use GetFromRoot then. This seems too messy, so I have this small line change instead.
6b31642 to
9ab772f
Compare
18464ef to
72b24db
Compare
This comment was marked as outdated.
This comment was marked as outdated.
72b24db to
236566e
Compare
Why this should be merged
Now that using
Revisionis concurrent safe and guaranteed to not cause undefined behavior, it should be used a more canonical way of accessing state.How this works
Uses Firewood's
Revisioninstead of relying on a one-Revision cache internal to Rust. The Revision has a finalizer attached to release all related memory when there are no more references.How this was tested
CI and re-execution tests
Need to be documented in RELEASES.md?
No