Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cadence 1.0] Optionally check atree storage health before migration #5591

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,28 @@ import (
)

var (
flagExecutionStateDir string
flagOutputDir string
flagBlockHash string
flagStateCommitment string
flagDatadir string
flagChain string
flagNWorker int
flagNoMigration bool
flagNoReport bool
flagValidateMigration bool
flagAllowPartialStateFromPayloads bool
flagSortPayloads bool
flagPrune bool
flagLogVerboseValidationError bool
flagDiffMigration bool
flagLogVerboseDiff bool
flagStagedContractsFile string
flagInputPayloadFileName string
flagOutputPayloadFileName string
flagOutputPayloadByAddresses string
flagMaxAccountSize uint64
flagExecutionStateDir string
flagOutputDir string
flagBlockHash string
flagStateCommitment string
flagDatadir string
flagChain string
flagNWorker int
flagNoMigration bool
flagNoReport bool
flagValidateMigration bool
flagAllowPartialStateFromPayloads bool
flagSortPayloads bool
flagPrune bool
flagLogVerboseValidationError bool
flagDiffMigration bool
flagLogVerboseDiff bool
flagCheckStorageHealthBeforeMigration bool
flagStagedContractsFile string
flagInputPayloadFileName string
flagOutputPayloadFileName string
flagOutputPayloadByAddresses string
flagMaxAccountSize uint64
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -92,6 +93,9 @@ func init() {
Cmd.Flags().BoolVar(&flagLogVerboseDiff, "log-verbose-diff", false,
"log entire Cadence values on diff (requires --diff flag)")

Cmd.Flags().BoolVar(&flagCheckStorageHealthBeforeMigration, "check-storage-health-before", false,
"check (atree) storage health before migration")

Cmd.Flags().StringVar(&flagStagedContractsFile, "staged-contracts", "",
"Staged contracts CSV file")

Expand Down Expand Up @@ -280,6 +284,10 @@ func run(*cobra.Command, []string) {
log.Warn().Msgf("--log-verbose-diff flag is enabled which may increase size of log")
}

if flagCheckStorageHealthBeforeMigration {
log.Warn().Msgf("--check-storage-health-before flag is enabled and will increase duration of migration")
}

var inputMsg string
if len(flagInputPayloadFileName) > 0 {
// Input is payloads
Expand Down Expand Up @@ -341,6 +349,7 @@ func run(*cobra.Command, []string) {
!flagNoMigration,
flagDiffMigration,
flagLogVerboseDiff,
flagCheckStorageHealthBeforeMigration,
chainID,
evmContractChange,
burnerContractChange,
Expand All @@ -362,6 +371,7 @@ func run(*cobra.Command, []string) {
!flagNoMigration,
flagDiffMigration,
flagLogVerboseDiff,
flagCheckStorageHealthBeforeMigration,
chainID,
evmContractChange,
burnerContractChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func extractExecutionState(
runMigrations bool,
diffMigrations bool,
logVerboseDiff bool,
checkStorageHealthBeforeMigration bool,
chainID flow.ChainID,
evmContractChange migrators.EVMContractChange,
burnerContractChange migrators.BurnerContractChange,
Expand Down Expand Up @@ -114,6 +115,7 @@ func extractExecutionState(
runMigrations,
diffMigrations,
logVerboseDiff,
checkStorageHealthBeforeMigration,
chainID,
evmContractChange,
burnerContractChange,
Expand Down Expand Up @@ -229,6 +231,7 @@ func extractExecutionStateFromPayloads(
runMigrations bool,
diffMigrations bool,
logVerboseDiff bool,
checkStorageHealthBeforeMigration bool,
chainID flow.ChainID,
evmContractChange migrators.EVMContractChange,
burnerContractChange migrators.BurnerContractChange,
Expand All @@ -255,6 +258,7 @@ func extractExecutionStateFromPayloads(
runMigrations,
diffMigrations,
logVerboseDiff,
checkStorageHealthBeforeMigration,
chainID,
evmContractChange,
burnerContractChange,
Expand Down Expand Up @@ -412,6 +416,7 @@ func newMigrations(
runMigrations bool,
diffMigrations bool,
logVerboseDiff bool,
checkStorageHealthBeforeMigration bool,
chainID flow.ChainID,
evmContractChange migrators.EVMContractChange,
burnerContractChange migrators.BurnerContractChange,
Expand All @@ -434,6 +439,7 @@ func newMigrations(
chainID,
diffMigrations,
logVerboseDiff,
checkStorageHealthBeforeMigration,
evmContractChange,
burnerContractChange,
stagedContracts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestExtractExecutionState(t *testing.T) {
false,
false,
false,
false,
flow.Emulator,
migrations.EVMContractChangeNone,
migrations.BurnerContractChangeDeploy,
Expand Down
69 changes: 43 additions & 26 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func NewCadence1ValueMigrations(
chainID flow.ChainID,
diffMigrations bool,
logVerboseDiff bool,
checkStorageHealthBeforeMigration bool,
) (migrations []NamedMigration) {

// Populated by CadenceLinkValueMigrator,
Expand All @@ -246,33 +247,47 @@ func NewCadence1ValueMigrations(
},
}

for _, accountBasedMigration := range []*CadenceBaseMigrator{
NewCadence1ValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
errorMessageHandler,
contracts,
NewCadence1CompositeStaticTypeConverter(chainID),
NewCadence1InterfaceStaticTypeConverter(chainID),
),
NewCadence1LinkValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
errorMessageHandler,
contracts,
capabilityMapping,
),
NewCadence1CapabilityValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
errorMessageHandler,
contracts,
capabilityMapping,
),
for index, migrationConstructor := range []func(checkStorageHealthBeforeMigration bool) *CadenceBaseMigrator{
func(checkStorageHealthBeforeMigration bool) *CadenceBaseMigrator {
return NewCadence1ValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
checkStorageHealthBeforeMigration,
errorMessageHandler,
contracts,
NewCadence1CompositeStaticTypeConverter(chainID),
NewCadence1InterfaceStaticTypeConverter(chainID),
)
},
func(checkStorageHealthBeforeMigration bool) *CadenceBaseMigrator {
return NewCadence1LinkValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
checkStorageHealthBeforeMigration,
errorMessageHandler,
contracts,
capabilityMapping,
)
},
func(checkStorageHealthBeforeMigration bool) *CadenceBaseMigrator {
return NewCadence1CapabilityValueMigrator(
rwf,
diffMigrations,
logVerboseDiff,
checkStorageHealthBeforeMigration,
errorMessageHandler,
contracts,
capabilityMapping,
)
},
} {
accountBasedMigration := migrationConstructor(
// Only check storage health before the first migration
checkStorageHealthBeforeMigration && index == 0,
)
Comment on lines +286 to +289
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ! 👍


migrations = append(
migrations,
NamedMigration{
Expand Down Expand Up @@ -357,6 +372,7 @@ func NewCadence1Migrations(
chainID flow.ChainID,
diffMigrations bool,
logVerboseDiff bool,
checkStorageHealthBeforeMigration bool,
evmContractChange EVMContractChange,
burnerContractChange BurnerContractChange,
stagedContracts []StagedContract,
Expand Down Expand Up @@ -417,6 +433,7 @@ func NewCadence1Migrations(
nWorker,
chainID,
diffMigrations,
checkStorageHealthBeforeMigration,
logVerboseDiff,
)...,
)
Expand Down
Loading
Loading