forked from cerc-io/plugeth
cmd, core/state, eth, tests, trie: improve state reader (#27428)
The state availability is checked during the creation of a state reader.
- In hash-based database, if the specified root node does not exist on disk disk, then
the state reader won't be created and an error will be returned.
- In path-based database, if the specified state layer is not available, then the
state reader won't be created and an error will be returned.
This change also contains a stricter semantics regarding the `Commit` operation: once it has been performed, the trie is no longer usable, and certain operations will return an error.
This commit is contained in:
@@ -221,7 +221,7 @@ func (f *fuzzer) fuzz() int {
|
||||
panic(fmt.Sprintf("roots differ: (trie) %x != %x (stacktrie)", rootA, rootC))
|
||||
}
|
||||
trieA, _ = trie.New(trie.TrieID(rootA), dbA)
|
||||
iterA := trieA.NodeIterator(nil)
|
||||
iterA := trieA.MustNodeIterator(nil)
|
||||
for iterA.Next(true) {
|
||||
if iterA.Hash() == (common.Hash{}) {
|
||||
if _, present := nodeset[string(iterA.Path())]; present {
|
||||
|
||||
@@ -179,7 +179,7 @@ func runRandTest(rt randTest) error {
|
||||
origin = hash
|
||||
case opItercheckhash:
|
||||
checktr := trie.NewEmpty(triedb)
|
||||
it := trie.NewIterator(tr.NodeIterator(nil))
|
||||
it := trie.NewIterator(tr.MustNodeIterator(nil))
|
||||
for it.Next() {
|
||||
checktr.MustUpdate(it.Key, it.Value)
|
||||
}
|
||||
|
||||
@@ -204,6 +204,11 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bo
|
||||
if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
|
||||
return snaps, statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
|
||||
}
|
||||
// Re-init the post-state instance for further operation
|
||||
statedb, err = state.New(root, statedb.Database(), snaps)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return snaps, statedb, nil
|
||||
}
|
||||
|
||||
@@ -275,9 +280,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
||||
// the coinbase gets no txfee, so isn't created, and thus needs to be touched
|
||||
statedb.AddBalance(block.Coinbase(), new(big.Int))
|
||||
// Commit block
|
||||
statedb.Commit(config.IsEIP158(block.Number()))
|
||||
// And _now_ get the state root
|
||||
root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
|
||||
root, _ := statedb.Commit(config.IsEIP158(block.Number()))
|
||||
return snaps, statedb, root, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user