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 migration] Add EVM storage account creation migration #6422

Merged
merged 1 commit into from
Aug 30, 2024
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
62 changes: 62 additions & 0 deletions cmd/util/ledger/migrations/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package migrations

import (
"fmt"

"github.com/rs/zerolog"

"github.com/onflow/flow-go/cmd/util/ledger/util/registers"
"github.com/onflow/flow-go/model/flow"
)

func NewAccountCreationMigration(
address flow.Address,
logger zerolog.Logger,
) RegistersMigration {

return func(registersByAccount *registers.ByAccount) error {

migrationRuntime := NewBasicMigrationRuntime(registersByAccount)

// Check if the account already exists
exists, err := migrationRuntime.Accounts.Exists(address)
if err != nil {
return fmt.Errorf(
"failed to check if account %s exists: %w",
address,
err,
)
}

// If the account already exists, do nothing
if exists {
logger.Info().Msgf("account %s already exists", address)
return nil
}

// Create the account
err = migrationRuntime.Accounts.Create(nil, address)
if err != nil {
return fmt.Errorf(
"failed to create account %s: %w",
address,
err,
)
}

logger.Info().Msgf("created account %s", address)

// Commit the changes to the migrated registers
err = migrationRuntime.Commit(
map[flow.Address]struct{}{
address: {},
},
logger,
)
if err != nil {
return fmt.Errorf("failed to commit account creation: %w", err)
}

return nil
}
}
15 changes: 15 additions & 0 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,21 @@ func NewCadence1Migrations(
Migrate: NewEVMSetupMigration(opts.ChainID, log),
},
)
if opts.ChainID == flow.Emulator {

// In the Emulator the EVM storage account needs to be created

systemContracts := systemcontracts.SystemContractsForChain(opts.ChainID)
evmStorageAddress := systemContracts.EVMStorage.Address

migs = append(
migs,
NamedMigration{
Name: "evm-storage-account-creation-migration",
Migrate: NewAccountCreationMigration(evmStorageAddress, log),
},
)
}
}

return migs
Expand Down
Loading