Skip to content

Commit

Permalink
Merge pull request #6401 from onflow/fxamacker/filter-evm-storage-add…
Browse files Browse the repository at this point in the history
…ress-from-diff-states-by-values

Skip EVM storage account for value comparison in `util` program's `diff-states` command
  • Loading branch information
fxamacker authored Aug 27, 2024
2 parents 6a80b88 + 5e2b0e4 commit 2d50ebb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cmd/util/cmd/diff-states/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"

"github.com/dustin/go-humanize/english"
"github.com/onflow/cadence/runtime/common"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/onflow/flow-go/cmd/util/ledger/reporters"
"github.com/onflow/flow-go/cmd/util/ledger/util"
"github.com/onflow/flow-go/cmd/util/ledger/util/registers"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/model/flow"
moduleUtil "github.com/onflow/flow-go/module/util"
Expand Down Expand Up @@ -189,6 +191,18 @@ func run(*cobra.Command, []string) {
)
}

var acctsToSkipForCadenceValueDiff []string

// Skip EVM storage account when diffing Cadence values.
if mode == modeValues {
systemContracts := systemcontracts.SystemContractsForChain(chainID)

acctsToSkipForCadenceValueDiff = append(
acctsToSkipForCadenceValueDiff,
flow.AddressToRegisterOwner(systemContracts.EVMStorage.Address),
)
}

rw := reporters.NewReportFileWriterFactoryWithFormat(flagOutputDirectory, log.Logger, reporters.ReportFormatJSONL).
ReportWriter(ReporterName)
defer rw.Close()
Expand Down Expand Up @@ -222,7 +236,7 @@ func run(*cobra.Command, []string) {
}
}

err := diff(registers1, registers2, chainID, rw, flagNWorker, mode)
err := diff(registers1, registers2, chainID, rw, flagNWorker, mode, acctsToSkipForCadenceValueDiff)
if err != nil {
log.Warn().Err(err).Msgf("failed to diff registers")
}
Expand Down Expand Up @@ -321,6 +335,7 @@ func diffAccount(
chainID flow.ChainID,
rw reporters.ReportWriter,
mode mode,
acctsToSkip []string,
) (err error) {

if accountRegisters1.Count() != accountRegisters2.Count() {
Expand Down Expand Up @@ -375,7 +390,7 @@ func diffAccount(
}
}

if diffValues {
if diffValues && !slices.Contains(acctsToSkip, owner) {
address, err := common.BytesToAddress([]byte(owner))
if err != nil {
return err
Expand Down Expand Up @@ -404,6 +419,7 @@ func diff(
rw reporters.ReportWriter,
nWorkers int,
mode mode,
acctsToSkip []string,
) error {
log.Info().Msgf("Diffing %d accounts", registers1.AccountCount())

Expand Down Expand Up @@ -445,6 +461,7 @@ func diff(
chainID,
rw,
mode,
acctsToSkip,
)
if err != nil {
log.Warn().Err(err).Msgf("failed to diff account %x", []byte(owner))
Expand Down Expand Up @@ -499,6 +516,7 @@ func diff(
chainID,
rw,
mode,
acctsToSkip,
)

select {
Expand Down

0 comments on commit 2d50ebb

Please sign in to comment.