Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Nov 21, 2024
1 parent 016d009 commit d36671d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/util/cmd/verify-evm-offchain-replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func run(*cobra.Command, []string) {
}

log.Info().Msgf("verifying range from %d to %d", from, to)
err = Verify(from, to, flow.Testnet, flagDatadir, flagExecutionDataDir, flagEVMStateGobDir)
err = Verify(log.Logger, from, to, flow.Testnet, flagDatadir, flagExecutionDataDir, flagEVMStateGobDir)
if err != nil {
log.Fatal().Err(err).Msg("could not verify last k height")
}
Expand Down
23 changes: 20 additions & 3 deletions cmd/util/cmd/verify-evm-offchain-replay/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/dgraph-io/badger/v2"
badgerds "github.com/ipfs/go-ds-badger2"
"github.com/rs/zerolog"

"github.com/onflow/flow-go/cmd/util/cmd/common"
"github.com/onflow/flow-go/fvm/environment"
Expand All @@ -20,7 +21,16 @@ import (
"github.com/onflow/flow-go/storage"
)

func Verify(from uint64, to uint64, chainID flow.ChainID, dataDir string, executionDataDir string, evmStateGobDir string) error {
// Verify verifies the offchain replay of EVM blocks from the given height range
// and updates the EVM state gob files with the latest state
func Verify(log zerolog.Logger, from uint64, to uint64, chainID flow.ChainID, dataDir string, executionDataDir string, evmStateGobDir string) error {
log.Info().
Str("chain", chainID.String()).
Str("dataDir", dataDir).
Str("executionDataDir", executionDataDir).
Str("evmStateGobDir", evmStateGobDir).
Msgf("verifying range from %d to %d", from, to)

db, storages, executionDataStore, dsStore, err := initStorages(chainID, dataDir, executionDataDir)
if err != nil {
return fmt.Errorf("could not initialize storages: %w", err)
Expand All @@ -32,6 +42,8 @@ func Verify(from uint64, to uint64, chainID flow.ChainID, dataDir string, execut
var store *testutils.TestValueStore
isRoot := isEVMRootHeight(chainID, from)
if isRoot {
log.Info().Msgf("initializing EVM state for root height %d", from)

store = testutils.GetSimpleValueStore()
as := environment.NewAccountStatus()
rootAddr := evm.StorageAccountAddress(chainID)
Expand All @@ -41,20 +53,23 @@ func Verify(from uint64, to uint64, chainID flow.ChainID, dataDir string, execut
}
} else {
prev := from - 1
log.Info().Msgf("loading EVM state from previous height %d", prev)

valueFileName, allocatorFileName := evmStateGobFileNamesByEndHeight(evmStateGobDir, prev)
values, err := testutils.DeserializeState(valueFileName)
if err != nil {
return err
return fmt.Errorf("could not deserialize state %v: %w", valueFileName, err)
}

allocators, err := testutils.DeserializeAllocator(allocatorFileName)
if err != nil {
return err
return fmt.Errorf("could not deserialize allocator %v: %w", allocatorFileName, err)
}
store = testutils.GetSimpleValueStorePopulated(values, allocators)
}

err = utils.OffchainReplayBackwardCompatibilityTest(
log,
chainID,
from,
to,
Expand All @@ -79,6 +94,8 @@ func Verify(from uint64, to uint64, chainID flow.ChainID, dataDir string, execut
return err
}

log.Info().Msgf("saved EVM state to %s and %s", valueFileName, allocatorFileName)

return nil
}

Expand Down
8 changes: 5 additions & 3 deletions fvm/evm/offchain/utils/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"errors"
"strings"

"github.com/rs/zerolog/log"

"github.com/onflow/cadence"
"github.com/onflow/cadence/encoding/ccf"
"github.com/rs/zerolog"

"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/evm"
Expand All @@ -25,6 +24,7 @@ import (
)

func OffchainReplayBackwardCompatibilityTest(
log zerolog.Logger,
chainID flow.ChainID,
flowStartHeight uint64,
flowEndHeight uint64,
Expand Down Expand Up @@ -97,7 +97,7 @@ func OffchainReplayBackwardCompatibilityTest(
}

sp := testutils.NewTestStorageProvider(store, evmBlockEvent.Height)
cr := sync.NewReplayer(chainID, rootAddr, sp, bp, log.Logger, nil, true)
cr := sync.NewReplayer(chainID, rootAddr, sp, bp, log, nil, true)
res, err := cr.ReplayBlock(evmTxEvents, evmBlockEvent)
if err != nil {
return err
Expand Down Expand Up @@ -125,6 +125,8 @@ func OffchainReplayBackwardCompatibilityTest(
return err
}
}

log.Info().Msgf("verified block %d", height)
}

return nil
Expand Down

0 comments on commit d36671d

Please sign in to comment.