mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
tests: validate snapshot after test
This commit is contained in:
parent
1236fce689
commit
239887e8b8
2 changed files with 23 additions and 0 deletions
|
|
@ -520,6 +520,15 @@ func (bc *BlockChain) CurrentBlock() *types.Block {
|
|||
return bc.currentBlock.Load().(*types.Block)
|
||||
}
|
||||
|
||||
// Snapshot returns the blockchain snapshot tree. This method is mainly used for
|
||||
// testing, to make it possible to verify the snapshot after execution.
|
||||
//
|
||||
// Warning: There are no guarantees about the safety of using the returned 'snap' if the
|
||||
// blockchain is simultaneously importing blocks, so take care.
|
||||
func (bc *BlockChain) Snapshot() *snapshot.Tree {
|
||||
return bc.snaps
|
||||
}
|
||||
|
||||
// CurrentFastBlock retrieves the current fast-sync head block of the canonical
|
||||
// chain. The block is retrieved from the blockchain's internal cache.
|
||||
func (bc *BlockChain) CurrentFastBlock() *types.Block {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue