snapshotter/tests: verify snapdb post-state against trie (#20812)

* core/state/snapshot: basic trie-to-hash implementation

* tests: validate snapshot after test

* core/state/snapshot: fix review concerns
This commit is contained in:
Martin Holst Swende
2020-03-31 10:25:41 +02:00
committed by GitHub
parent 84f4975520
commit 76eed9e50d
3 changed files with 137 additions and 0 deletions

View File

@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
@ -144,6 +145,19 @@ func (t *BlockTest) Run(snapshotter bool) error {
if err = t.validatePostState(newDB); err != nil {
return fmt.Errorf("post state validation failed: %v", err)
}
// Cross-check the snapshot-to-hash against the trie hash
if snapshotter {
snapTree := chain.Snapshot()
root := chain.CurrentBlock().Root()
it, err := snapTree.AccountIterator(root, common.Hash{})
if err != nil {
return fmt.Errorf("Could not create iterator for root %x: %v", root, err)
}
generatedRoot := snapshot.GenerateTrieRoot(it)
if generatedRoot != root {
return fmt.Errorf("Snapshot corruption, got %d exp %d", generatedRoot, root)
}
}
return t.validateImportedHeaders(chain, validBlocks)
}