cmd, core, eth, light, trie: add trie read caching layer

This commit is contained in:
Péter Szilágyi
2018-11-12 18:47:34 +02:00
parent 9a000601c6
commit 434dd5bc00
33 changed files with 1660 additions and 127 deletions

View File

@ -119,7 +119,7 @@ func testMissingNode(t *testing.T, memonly bool) {
hash := common.HexToHash("0xe1d943cc8f061a0c0b98162830b970395ac9315654824bf21b73b891365262f9")
if memonly {
delete(triedb.nodes, hash)
delete(triedb.dirties, hash)
} else {
diskdb.Delete(hash[:])
}
@ -342,15 +342,16 @@ func TestCacheUnload(t *testing.T) {
// Commit the trie repeatedly and access key1.
// The branch containing it is loaded from DB exactly two times:
// in the 0th and 6th iteration.
db := &countingDB{Database: trie.db.diskdb, gets: make(map[string]int)}
trie, _ = New(root, NewDatabase(db))
diskdb := &countingDB{Database: trie.db.diskdb, gets: make(map[string]int)}
triedb := NewDatabase(diskdb)
trie, _ = New(root, triedb)
trie.SetCacheLimit(5)
for i := 0; i < 12; i++ {
getString(trie, key1)
trie.Commit(nil)
}
// Check that it got loaded two times.
for dbkey, count := range db.gets {
for dbkey, count := range diskdb.gets {
if count != 2 {
t.Errorf("db key %x loaded %d times, want %d times", []byte(dbkey), count, 2)
}