diff --git a/trie/secure_trie.go b/trie/secure_trie.go index 901e5c09cf..9d391d8ec6 100644 --- a/trie/secure_trie.go +++ b/trie/secure_trie.go @@ -33,6 +33,9 @@ type preimageStore interface { // InsertPreimage commits a set of preimages along with their hashes. InsertPreimage(preimages map[common.Hash][]byte) + + // PreimageEnabled returns true if the preimage store is enabled. + PreimageEnabled() bool } // SecureTrie is the old name of StateTrie. @@ -84,8 +87,7 @@ func NewStateTrie(id *ID, db database.NodeDatabase) (*StateTrie, error) { tr := &StateTrie{trie: *trie, db: db} // link the preimage store if it's supported - preimages, ok := db.(preimageStore) - if ok { + if preimages, ok := db.(preimageStore); ok && preimages.PreimageEnabled() { tr.preimages = preimages } return tr, nil diff --git a/triedb/database.go b/triedb/database.go index 18e24cd176..1c9d49b245 100644 --- a/triedb/database.go +++ b/triedb/database.go @@ -213,6 +213,11 @@ func (db *Database) InsertPreimage(preimages map[common.Hash][]byte) { db.preimages.insertPreimage(preimages) } +// PreimageEnabled returns the indicator if the pre-image store is enabled. +func (db *Database) PreimageEnabled() bool { + return db.preimages != nil +} + // Cap iteratively flushes old but still referenced trie nodes until the total // memory usage goes below the given threshold. The held pre-images accumulated // up to this point will be flushed in case the size exceeds the threshold.