Skip to content

Commit

Permalink
Add sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
0x00101010 committed Oct 8, 2024
1 parent 93214fb commit 9d71866
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"maps"
"slices"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -348,6 +349,9 @@ func (s *stateObject) updateTrie() (Trie, error) {
// Cache the items for preloading
used = append(used, common.CopyBytes(key[:])) // Copy needed for closure
}
// Perform deletes in sorted order to make the touched trie nodes deterministic
slices.SortFunc(deletions, func(a, b common.Hash) int { return bytes.Compare(a[:], b[:]) })

for _, key := range deletions {
if err := tr.DeleteStorage(s.address, key[:]); err != nil {
s.db.setError(err)
Expand Down
4 changes: 4 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package state

import (
"bytes"
"errors"
"fmt"
"maps"
Expand Down Expand Up @@ -935,6 +936,9 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
}
usedAddrs = append(usedAddrs, common.CopyBytes(addr[:])) // Copy needed for closure
}
// Perform deletes in sorted order to make the touched trie nodes deterministic
slices.SortFunc(deletedAddrs, func(a, b common.Address) int { return bytes.Compare(a[:], b[:]) })

for _, deletedAddr := range deletedAddrs {
s.deleteStateObject(deletedAddr)
s.AccountDeleted += 1
Expand Down

0 comments on commit 9d71866

Please sign in to comment.