Skip to content

Commit

Permalink
sort keys for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Nov 14, 2023
1 parent e796b30 commit bac9c5a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func ExecuteBlockEphemerally(
}
}

if state.TraceLog {
fmt.Printf("XXX all transactions executed\n")
}

receiptSha := types.DeriveSha(receipts)
if !vmConfig.StatelessExec && chainConfig.IsByzantium(header.Number.Uint64()) && !vmConfig.NoReceipts && receiptSha != block.ReceiptHash() {
return nil, fmt.Errorf("mismatched receipt headers for block %d (%s != %s)", block.NumberU64(), receiptSha.Hex(), block.ReceiptHash().Hex())
Expand Down
14 changes: 13 additions & 1 deletion core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package state

import (
"fmt"
"slices"
"sort"

"github.com/holiman/uint256"
Expand Down Expand Up @@ -718,7 +719,18 @@ func (sdb *IntraBlockState) MakeWriteSet(chainRules *chain.Rules, stateWriter St
for addr := range sdb.journal.dirties {
sdb.stateObjectsDirty[addr] = struct{}{}
}
for addr, stateObject := range sdb.stateObjects {

keys := make([]string, len(sdb.stateObjects))
i := 0
for k := range sdb.stateObjects {
keys[i] = k.Hex()
i++
}
slices.Sort(keys)

for _, addrHex := range keys {
addr := libcommon.HexToAddress(addrHex)
stateObject := sdb.stateObjects[addr]
_, isDirty := sdb.stateObjectsDirty[addr]
if err := updateAccount(chainRules.IsSpuriousDragon, chainRules.IsAura, stateWriter, addr, stateObject, isDirty); err != nil {
return err
Expand Down
14 changes: 12 additions & 2 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"math/big"
"slices"

"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
Expand Down Expand Up @@ -251,8 +252,17 @@ func (so *stateObject) setState(key *libcommon.Hash, value uint256.Int) {

// updateTrie writes cached storage modifications into the object's storage trie.
func (so *stateObject) updateTrie(stateWriter StateWriter) error {
for key, value := range so.dirtyStorage {
value := value
keys := make([]string, len(so.dirtyStorage))
i := 0
for k := range so.dirtyStorage {
keys[i] = k.Hex()
i++
}
slices.Sort(keys)

for _, keyHex := range keys {
key := libcommon.HexToHash(keyHex)
value := so.dirtyStorage[key]
original := so.blockOriginStorage[key]
so.originStorage[key] = value
if err := stateWriter.WriteAccountStorage(so.address, so.data.GetIncarnation(), &key, &original, &value); err != nil {
Expand Down

0 comments on commit bac9c5a

Please sign in to comment.