-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add verify evm offchain replay util cmd
- Loading branch information
1 parent
dffadd8
commit 81578f4
Showing
5 changed files
with
344 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package verify | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
var ( | ||
flagLastK uint64 | ||
flagDatadir string | ||
flagExecutionDataDir string | ||
flagChain string | ||
flagFromTo string | ||
) | ||
|
||
// # verify the blocks from height 2000 to 3000 | ||
// ./util verify_execution_result --chain flow-testnet --datadir /var/flow/data/protocol --chunk_data_pack_dir /var/flow/data/chunk_data_pack --from_to 2000-3000 | ||
var Cmd = &cobra.Command{ | ||
Use: "verify_evm_offchain_replay", | ||
Short: "verify evm offchain replay with execution data", | ||
Run: run, | ||
} | ||
|
||
func init() { | ||
Cmd.Flags().StringVar(&flagChain, "chain", "", "Chain name") | ||
_ = Cmd.MarkFlagRequired("chain") | ||
|
||
Cmd.Flags().StringVar(&flagDatadir, "datadir", "/var/flow/data/protocol", | ||
"directory that stores the protocol state") | ||
|
||
Cmd.Flags().StringVar(&flagExecutionDataDir, "execution_data_dir", "/var/flow/data/execution_data", | ||
"directory that stores the execution state") | ||
} | ||
|
||
func run(*cobra.Command, []string) { | ||
_ = flow.ChainID(flagChain).Chain() | ||
|
||
from, to, err := parseFromTo(flagFromTo) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("could not parse from_to") | ||
} | ||
|
||
log.Info().Msgf("verifying range from %d to %d", from, to) | ||
err = Verify(from, to, flow.Testnet, flagDatadir, flagExecutionDataDir) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("could not verify last k height") | ||
} | ||
log.Info().Msgf("successfully verified range from %d to %d", from, to) | ||
|
||
} | ||
|
||
func parseFromTo(fromTo string) (from, to uint64, err error) { | ||
parts := strings.Split(fromTo, "-") | ||
if len(parts) != 2 { | ||
return 0, 0, fmt.Errorf("invalid format: expected 'from-to', got '%s'", fromTo) | ||
} | ||
|
||
from, err = strconv.ParseUint(strings.TrimSpace(parts[0]), 10, 64) | ||
if err != nil { | ||
return 0, 0, fmt.Errorf("invalid 'from' value: %w", err) | ||
} | ||
|
||
to, err = strconv.ParseUint(strings.TrimSpace(parts[1]), 10, 64) | ||
if err != nil { | ||
return 0, 0, fmt.Errorf("invalid 'to' value: %w", err) | ||
} | ||
|
||
if from > to { | ||
return 0, 0, fmt.Errorf("'from' value (%d) must be less than or equal to 'to' value (%d)", from, to) | ||
} | ||
|
||
return from, to, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package verify | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/dgraph-io/badger/v2" | ||
badgerds "github.com/ipfs/go-ds-badger2" | ||
|
||
"github.com/onflow/flow-go/cmd/util/cmd/common" | ||
"github.com/onflow/flow-go/fvm/evm/offchain/utils" | ||
"github.com/onflow/flow-go/fvm/evm/testutils" | ||
"github.com/onflow/flow-go/model/flow" | ||
"github.com/onflow/flow-go/module/blobs" | ||
"github.com/onflow/flow-go/module/executiondatasync/execution_data" | ||
"github.com/onflow/flow-go/storage" | ||
) | ||
|
||
func Verify(from uint64, to uint64, chainID flow.ChainID, dataDir string, executionDataDir string) error { | ||
db, storages, executionDataStore, dsStore, err := initStorages(chainID, dataDir, executionDataDir) | ||
if err != nil { | ||
return fmt.Errorf("could not initialize storages: %w", err) | ||
} | ||
|
||
defer db.Close() | ||
defer dsStore.Close() | ||
|
||
store := testutils.GetSimpleValueStore() | ||
|
||
return utils.OffchainReplayBackwardCompatibilityTest( | ||
chainID, | ||
from, | ||
to, | ||
storages.Headers, | ||
storages.Results, | ||
executionDataStore, | ||
store, | ||
) | ||
} | ||
|
||
func initStorages(chainID flow.ChainID, dataDir string, executionDataDir string) ( | ||
*badger.DB, | ||
*storage.All, | ||
execution_data.ExecutionDataGetter, | ||
io.Closer, | ||
error, | ||
) { | ||
db := common.InitStorage(dataDir) | ||
|
||
storages := common.InitStorages(db) | ||
|
||
datastoreDir := filepath.Join(executionDataDir, "blobstore") | ||
err := os.MkdirAll(datastoreDir, 0700) | ||
if err != nil { | ||
return nil, nil, nil, nil, err | ||
} | ||
dsOpts := &badgerds.DefaultOptions | ||
ds, err := badgerds.NewDatastore(datastoreDir, dsOpts) | ||
if err != nil { | ||
return nil, nil, nil, nil, err | ||
} | ||
|
||
executionDataBlobstore := blobs.NewBlobstore(ds) | ||
executionDataStore := execution_data.NewExecutionDataStore(executionDataBlobstore, execution_data.DefaultSerializer) | ||
|
||
return db, storages, executionDataStore, ds, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.