core/state, trie: fix trie flush order for proper pruning

This commit is contained in:
Péter Szilágyi
2022-08-23 21:17:12 +03:00
parent 81bd998353
commit 5758d1fb11
2 changed files with 56 additions and 3 deletions
+16 -3
View File
@@ -776,9 +776,22 @@ func (db *Database) Update(nodes *MergedNodeSet) error {
// Insert dirty nodes into the database. In the same tree, it must be
// ensured that children are inserted first, then parent so that children
// can be linked with their parent correctly. The order of writing between
// different tries(account trie, storage tries) is not required.
for owner, subset := range nodes.sets {
// can be linked with their parent correctly.
//
// Note, the storage tries must be flushed before the account trie to
// retain the invariant that children go into the dirty cache first.
var order []common.Hash
for owner := range nodes.sets {
if owner == (common.Hash{}) {
continue
}
order = append(order, owner)
}
if _, ok := nodes.sets[common.Hash{}]; ok {
order = append(order, common.Hash{})
}
for _, owner := range order {
subset := nodes.sets[owner]
for _, path := range subset.paths {
n, ok := subset.nodes[path]
if !ok {