Skip to content

Commit 3c1c05e

Browse files
committed
Address CR comments
1 parent ebeea9c commit 3c1c05e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

core/txpool/locals/journal.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ func newTxJournal(path string) *journal {
5757
}
5858
}
5959

60+
func (journal *journal) setWriter(w io.WriteCloser) {
61+
journal.mu.Lock()
62+
defer journal.mu.Unlock()
63+
journal.writer = w
64+
}
65+
6066
// load parses a transaction journal dump from disk, loading its contents into
6167
// the specified pool.
6268
func (journal *journal) load(add func([]*types.Transaction) []error) error {
@@ -74,8 +80,8 @@ func (journal *journal) load(add func([]*types.Transaction) []error) error {
7480
defer input.Close()
7581

7682
// Temporarily discard any journal additions (don't double add on load)
77-
journal.writer = new(devNull)
78-
defer func() { journal.writer = nil }()
83+
journal.setWriter(new(devNull))
84+
defer journal.setWriter(nil)
7985

8086
// Inject all transactions from the journal into the pool
8187
stream := rlp.NewStream(input, 0)

triedb/database.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ type backend interface {
8585
// relevant with trie nodes and node preimages.
8686
type Database struct {
8787
disk ethdb.Database
88-
config *Config // Configuration for trie database
89-
preimages *preimageStore // The store for caching preimages
90-
backend backend // The backend for managing trie nodes
91-
readBackend atomic.Value // Stores backend interface, lock-free for concurrent reads
88+
config *Config // Configuration for trie database
89+
preimages *preimageStore // The store for caching preimages
90+
backend backend // The backend for managing trie nodes
91+
readBackend atomic.Pointer[backend] // Lock-free for concurrent reads, supports nil
9292
}
9393

9494
// NewDatabase initializes the trie database with default settings, note
@@ -119,14 +119,14 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
119119
}
120120

121121
func (db *Database) SetReadBackend(b backend) {
122-
db.readBackend.Store(b)
122+
db.readBackend.Store(&b)
123123
}
124124

125125
// Reader returns a reader for accessing all trie nodes with provided state root.
126126
// An error will be returned if the requested state is not available.
127127
func (db *Database) NodeReader(blockRoot common.Hash) (database.NodeReader, error) {
128-
if rb := db.readBackend.Load(); rb != nil {
129-
return rb.(backend).NodeReader(blockRoot)
128+
if rbPtr := db.readBackend.Load(); rbPtr != nil && *rbPtr != nil {
129+
return (*rbPtr).NodeReader(blockRoot)
130130
}
131131
return db.backend.NodeReader(blockRoot)
132132
}

0 commit comments

Comments
 (0)