Skip to content

Commit

Permalink
Skip EVM storage account in check-storage cmd
Browse files Browse the repository at this point in the history
This commit skips EVM storage account during atree storage health
check because EVM registers require a different decoder.
Cadence-Atree decoder cannot decode EVM registers.

Support for checking EVM registers can be added later.
  • Loading branch information
fxamacker committed Aug 26, 2024
1 parent 400bcd0 commit 8604db6
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions cmd/util/cmd/check-storage/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package check_storage

import (
"context"
"slices"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand All @@ -14,7 +15,9 @@ 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 All @@ -23,6 +26,7 @@ var (
flagState string
flagStateCommitment string
flagOutputDirectory string
flagChain string
flagNWorker int
)

Expand Down Expand Up @@ -74,10 +78,22 @@ func init() {
10,
"number of workers to use",
)

Cmd.Flags().StringVar(
&flagChain,
"chain",
"",
"Chain name",
)
_ = Cmd.MarkFlagRequired("chain")
}

func run(*cobra.Command, []string) {

chainID := flow.ChainID(flagChain)
// Validate chain ID
_ = chainID.Chain()

if flagPayloads == "" && flagState == "" {
log.Fatal().Msg("Either --payloads or --state must be provided")
} else if flagPayloads != "" && flagState != "" {
Expand All @@ -87,6 +103,14 @@ func run(*cobra.Command, []string) {
log.Fatal().Msg("--state-commitment must be provided when --state is provided")
}

// For now, skip EVM storage account since a different decoder is needed for decoding EVM registers.

systemContracts := systemcontracts.SystemContractsForChain(chainID)

acctsToSkip := []string{
flow.AddressToRegisterOwner(systemContracts.EVMStorage.Address),
}

// Create report in JSONL format
rw := reporters.NewReportFileWriterFactoryWithFormat(flagOutputDirectory, log.Logger, reporters.ReportFormatJSONL).
ReportWriter(ReporterName)
Expand Down Expand Up @@ -138,7 +162,7 @@ func run(*cobra.Command, []string) {
len(payloads),
)

failedAccountAddresses, err := checkStorageHealth(registersByAccount, flagNWorker, rw)
failedAccountAddresses, err := checkStorageHealth(registersByAccount, flagNWorker, rw, acctsToSkip)
if err != nil {
log.Fatal().Err(err).Msg("failed to check storage health")
}
Expand All @@ -165,6 +189,7 @@ func checkStorageHealth(
registersByAccount *registers.ByAccount,
nWorkers int,
rw reporters.ReportWriter,
acctsToSkip []string,
) (failedAccountAddresses []string, err error) {

accountCount := registersByAccount.AccountCount()
Expand All @@ -185,6 +210,12 @@ func checkStorageHealth(
// Skip goroutine to avoid overhead
err = registersByAccount.ForEachAccount(
func(accountRegisters *registers.AccountRegisters) error {
defer logAccount(1)

if slices.Contains(acctsToSkip, accountRegisters.Owner()) {
return nil
}

accountStorageIssues := checkAccountStorageHealth(accountRegisters, nWorkers)

if len(accountStorageIssues) > 0 {
Expand All @@ -195,8 +226,6 @@ func checkStorageHealth(
}
}

logAccount(1)

return nil
})

Expand Down

0 comments on commit 8604db6

Please sign in to comment.