Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit cb869d5

Browse files
committed
perf: Use Firewood's Revision
1 parent 7c56b58 commit cb869d5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

core/txpool/legacypool/legacypool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ func (pool *LegacyPool) Close() error {
446446
if pool.journal != nil {
447447
pool.journal.close()
448448
}
449+
450+
// remove all references to state to allow GC to reclaim memory
451+
pool.pendingNonces = nil
452+
pool.currentState = nil
453+
449454
log.Info("Transaction pool stopped")
450455
return nil
451456
}

triedb/firewood/database.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,17 @@ func (db *Database) removeProposalFromMap(pCtx *ProposalContext) {
482482
// Reader retrieves a node reader belonging to the given state root.
483483
// An error will be returned if the requested state is not available.
484484
func (db *Database) Reader(root common.Hash) (database.Reader, error) {
485-
if _, err := db.fwDisk.GetFromRoot(root.Bytes(), []byte{}); err != nil {
485+
revision, err := db.fwDisk.Revision(root.Bytes())
486+
if err != nil {
486487
return nil, fmt.Errorf("firewood: unable to retrieve from root %s: %w", root.Hex(), err)
487488
}
488-
return &reader{db: db, root: root}, nil
489+
fmt.Printf("Firewood Reader created at %p\n", revision)
490+
return &reader{revision: revision}, nil
489491
}
490492

491493
// reader is a state reader of Database which implements the Reader interface.
492494
type reader struct {
493-
db *Database
494-
root common.Hash // The root of the state this reader is reading.
495+
revision *ffi.Revision
495496
}
496497

497498
// Node retrieves the trie node with the given node hash. No error will be
@@ -500,7 +501,7 @@ func (reader *reader) Node(_ common.Hash, path []byte, _ common.Hash) ([]byte, e
500501
// This function relies on Firewood's internal locking to ensure concurrent reads are safe.
501502
// This is safe even if a proposal is being committed concurrently.
502503
start := time.Now()
503-
result, err := reader.db.fwDisk.GetFromRoot(reader.root.Bytes(), path)
504+
result, err := reader.revision.Get(path)
504505
if metrics.EnabledExpensive {
505506
ffiReadCount.Inc(1)
506507
ffiReadTimer.Inc(time.Since(start).Milliseconds())

0 commit comments

Comments
 (0)