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

Commit e95d98d

Browse files
committed
perf: Use Firewood's Revision
1 parent 7629fa1 commit e95d98d

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
@@ -493,16 +493,17 @@ func (db *Database) removeProposalFromMap(pCtx *ProposalContext) {
493493
// Reader retrieves a node reader belonging to the given state root.
494494
// An error will be returned if the requested state is not available.
495495
func (db *Database) Reader(root common.Hash) (database.Reader, error) {
496-
if _, err := db.fwDisk.GetFromRoot(ffi.Hash(root), []byte{}); err != nil {
496+
revision, err := db.fwDisk.Revision(ffi.Hash(root))
497+
if err != nil {
497498
return nil, fmt.Errorf("firewood: unable to retrieve from root %s: %w", root.Hex(), err)
498499
}
499-
return &reader{db: db, root: ffi.Hash(root)}, nil
500+
fmt.Printf("Firewood Reader created at %p\n", revision)
501+
return &reader{revision: revision}, nil
500502
}
501503

502504
// reader is a state reader of Database which implements the Reader interface.
503505
type reader struct {
504-
db *Database
505-
root ffi.Hash // The root of the state this reader is reading.
506+
revision *ffi.Revision
506507
}
507508

508509
// Node retrieves the trie node with the given node hash. No error will be
@@ -511,7 +512,7 @@ func (reader *reader) Node(_ common.Hash, path []byte, _ common.Hash) ([]byte, e
511512
// This function relies on Firewood's internal locking to ensure concurrent reads are safe.
512513
// This is safe even if a proposal is being committed concurrently.
513514
start := time.Now()
514-
result, err := reader.db.fwDisk.GetFromRoot(reader.root, path)
515+
result, err := reader.revision.Get(path)
515516
if metrics.EnabledExpensive {
516517
ffiReadCount.Inc(1)
517518
ffiReadTimer.Inc(time.Since(start).Milliseconds())

0 commit comments

Comments
 (0)