Skip to content

Commit

Permalink
Merge pull request onflow#5915 from onflow/bastian/deploy-or-update-e…
Browse files Browse the repository at this point in the history
…vm-contract

Update or deploy EVM contract, depending on chain
  • Loading branch information
turbolent authored May 17, 2024
2 parents fc3e499 + 4a2c3e0 commit 05dad80
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
7 changes: 4 additions & 3 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,16 @@ func run(*cobra.Command, []string) {
log.Info().Msgf("state extraction plan: %s, %s", inputMsg, outputMsg)

chainID := chain.ChainID()
// TODO:
evmContractChange := migrations.EVMContractChangeNone

var burnerContractChange migrations.BurnerContractChange
burnerContractChange := migrations.BurnerContractChangeNone
evmContractChange := migrations.EVMContractChangeNone
switch chainID {
case flow.Emulator:
burnerContractChange = migrations.BurnerContractChangeDeploy
evmContractChange = migrations.EVMContractChangeDeploy
case flow.Testnet, flow.Mainnet:
burnerContractChange = migrations.BurnerContractChangeUpdate
evmContractChange = migrations.EVMContractChangeUpdate
}

stagedContracts, err := migrations.StagedContractsFromCSV(flagStagedContractsFile)
Expand Down
10 changes: 10 additions & 0 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ func NewCadence1ContractsMigrations(
)
}

if opts.EVMContractChange == EVMContractChangeDeploy {
migs = append(
migs,
NamedMigration{
Name: "evm-deployment-migration",
Migrate: NewEVMDeploymentMigration(opts.ChainID, log),
},
)
}

if opts.BurnerContractChange == BurnerContractChangeDeploy {
migs = append(
migs,
Expand Down
12 changes: 4 additions & 8 deletions cmd/util/ledger/migrations/change_contract_code_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type EVMContractChange uint8

const (
EVMContractChangeNone EVMContractChange = iota
EVMContractChangeFull
EVMContractChangeDeploy
EVMContractChangeUpdate
)

type BurnerContractChange uint8
Expand Down Expand Up @@ -213,11 +214,8 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractsMigratio
)
}

// EVM related contracts
switch options.EVM {
case EVMContractChangeNone:
// do nothing
case EVMContractChangeFull:
// EVM contract
if options.EVM == EVMContractChangeUpdate {
contractChanges = append(
contractChanges,
NewSystemContractChange(
Expand All @@ -229,8 +227,6 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractsMigratio
),
),
)
default:
panic(fmt.Errorf("unsupported EVM contract change option: %d", options.EVM))
}

// Burner contract
Expand Down
26 changes: 26 additions & 0 deletions cmd/util/ledger/migrations/deploy_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/rs/zerolog"

evm "github.com/onflow/flow-go/fvm/evm/stdlib"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/model/flow"
)

Expand Down Expand Up @@ -57,3 +59,27 @@ func NewBurnerDeploymentMigration(
logger,
)
}

func NewEVMDeploymentMigration(
chainID flow.ChainID,
logger zerolog.Logger,
) RegistersMigration {
systemContracts := systemcontracts.SystemContractsForChain(chainID)
address := systemContracts.EVMContract.Address
return NewDeploymentMigration(
chainID,
Contract{
Name: systemContracts.EVMContract.Name,
Code: evm.ContractCode(
systemContracts.NonFungibleToken.Address,
systemContracts.FungibleToken.Address,
systemContracts.FlowToken.Address,
),
},
address,
map[flow.Address]struct{}{
address: {},
},
logger,
)
}

0 comments on commit 05dad80

Please sign in to comment.