diff --git a/trie/trie_reader.go b/trie/trie_reader.go index ff2db1d674..4b8ba808df 100644 --- a/trie/trie_reader.go +++ b/trie/trie_reader.go @@ -55,6 +55,9 @@ func newEmptyReader() *trieReader { // node retrieves the rlp-encoded trie node with the provided trie node // information. An MissingNodeError will be returned in case the node is // not found or any error is encountered. +// +// Don't modify the returned byte slice since it's not deep-copied and +// still be referenced by database. func (r *trieReader) node(path []byte, hash common.Hash) ([]byte, error) { // Perform the logics in tests for preventing trie node access. if r.banned != nil { diff --git a/triedb/pathdb/buffer.go b/triedb/pathdb/buffer.go index bb591a594f..3f1d0e90ee 100644 --- a/triedb/pathdb/buffer.go +++ b/triedb/pathdb/buffer.go @@ -104,11 +104,6 @@ func (b *buffer) size() uint64 { return b.nodes.size } -// allocBatch returns a database batch with pre-allocated buffer. -func (b *buffer) allocBatch(db ethdb.KeyValueStore) ethdb.Batch { - return db.NewBatchWithSize(b.nodes.dbsize() * 11 / 10) // extra 10% for potential pebble internal stuff -} - // flush persists the in-memory dirty trie node into the disk if the configured // memory threshold is reached. Note, all data must be written atomically. func (b *buffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWriter, nodesCache *fastcache.Cache, id uint64) error { @@ -120,7 +115,7 @@ func (b *buffer) flush(db ethdb.KeyValueStore, freezer ethdb.AncientWriter, node // Terminate the state snapshot generation if it's active var ( start = time.Now() - batch = b.allocBatch(db) + batch = db.NewBatchWithSize(b.nodes.dbsize() * 11 / 10) // extra 10% for potential pebble internal stuff ) // Explicitly sync the state freezer, ensuring that all written // data is transferred to disk before updating the key-value store. diff --git a/triedb/pathdb/flush.go b/triedb/pathdb/flush.go index 8728f47e56..baa0bfb292 100644 --- a/triedb/pathdb/flush.go +++ b/triedb/pathdb/flush.go @@ -24,7 +24,8 @@ import ( "github.com/ethereum/go-ethereum/trie/trienode" ) -// nodeCacheKey constructs the unique key of clean cache. +// nodeCacheKey constructs the unique key of clean cache. The assumption is held +// that zero address does not have any associated storage slots. func nodeCacheKey(owner common.Hash, path []byte) []byte { if owner == (common.Hash{}) { return path