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 Account Storage Map Migration #6761

Open
wants to merge 22 commits into
base: auto-update-onflow-cadence-v1.3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift click to select a range
5c65c32
update to Cadence with account storage map support: feature/combine-d…
turbolent Nov 26, 2024
e7d04a4
inject scheduleAccountV2Migration function into service account Accou…
turbolent Nov 26, 2024
95ca4de
update dependencies in other modules
turbolent Nov 26, 2024
8e6fbbf
export address generator constructor
turbolent Nov 27, 2024
de4b564
add AccountV2Migration contract
turbolent Nov 27, 2024
f611094
temporarily unrestrict availability scheduleAccountV2Migration function
turbolent Nov 27, 2024
c75d4fc
call account migration function from system chunk transaction
turbolent Nov 27, 2024
b31696c
add missing argument for new chain parameter
turbolent Nov 27, 2024
0906f96
update to latest commit of feature branch
turbolent Nov 27, 2024
2a04742
add function to return storage format of an account
turbolent Nov 27, 2024
5794140
fix setup for AccountV2Migration contract
turbolent Dec 3, 2024
b1c86c5
adjust expected state commitments and system chunk transaction hashes
turbolent Dec 3, 2024
06420d1
remove chain ID arguments
turbolent Dec 3, 2024
0a393ef
add new weight for string template expressions
turbolent Dec 3, 2024
2b1ecac
Merge branch 'auto-update-onflow-cadence-v1.3.0' into bastian/account…
turbolent Dec 4, 2024
a1ca332
fix address generation
turbolent Dec 5, 2024
8b597cb
test account v2 format migration of service account
turbolent Dec 5, 2024
f86dd29
remove enabled flag, use batch size
turbolent Dec 6, 2024
814c47a
verify migration event
turbolent Dec 6, 2024
e910cd0
add integration test for account storage format v2 migration using in…
turbolent Dec 6, 2024
a57912f
add a new Migration system account contract, call it in system chunk tx
turbolent Dec 12, 2024
d24f07e
adjust expected hashes
turbolent Dec 12, 2024
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
Prev Previous commit
Next Next commit
fix setup for AccountV2Migration contract
  • Loading branch information
turbolent committed Dec 3, 2024
commit 579414020c91c80b1e4b90f51afdf625d72f22d7
3 changes: 0 additions & 3 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 701,6 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
reusableRuntime.NewCustomReusableCadenceRuntimePool(
0,
runtime.Config{},
chainID,
func(_ runtime.Config) runtime.Runtime {
return emittingRuntime
},
Expand Down Expand Up @@ -817,7 816,6 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
reusableRuntime.NewCustomReusableCadenceRuntimePool(
0,
runtime.Config{},
execCtx.Chain.ChainID(),
func(_ runtime.Config) runtime.Runtime {
return rt
})),
Expand Down Expand Up @@ -933,7 931,6 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
reusableRuntime.NewCustomReusableCadenceRuntimePool(
0,
runtime.Config{},
execCtx.Chain.ChainID(),
func(_ runtime.Config) runtime.Runtime {
return rt
})),
Expand Down
1 change: 0 additions & 1 deletion engine/execution/computation/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 233,6 @@ func DefaultFVMOptions(chainID flow.ChainID, cadenceTracing bool, extensiveTraci
runtime.Config{
TracingEnabled: cadenceTracing,
},
chainID,
)),
fvm.WithEVMEnabled(true),
}
Expand Down
1 change: 0 additions & 1 deletion engine/execution/computation/manager_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 160,6 @@ func benchmarkComputeBlock(
reusableRuntime.NewReusableCadenceRuntimePool(
ReusableCadenceRuntimePoolSize,
runtime.Config{},
chainID,
)),
)
snapshotTree := testutil.RootBootstrappedLedger(
Expand Down
41 changes: 19 additions & 22 deletions fvm/accountV2Migration/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 11,7 @@ import (
"github.com/onflow/cadence/stdlib"

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

Expand Down Expand Up @@ -39,7 40,7 @@ var scheduleAccountV2MigrationType = &sema.FunctionType{

func DeclareFunctions(environment runtime.Environment, chainID flow.ChainID) {
declareScheduleAccountV2MigrationFunction(environment, chainID)
declareGetAccountStorageFormatFunction(environment)
declareGetAccountStorageFormatFunction(environment, chainID)
}

func declareScheduleAccountV2MigrationFunction(environment runtime.Environment, chainID flow.ChainID) {
Expand Down Expand Up @@ -122,19 123,17 @@ func declareScheduleAccountV2MigrationFunction(environment runtime.Environment,
),
}

// TODO: restrict, but requires to be set during bootstrapping
//sc := systemcontracts.SystemContractsForChain(chainID)
//
//accountV2MigrationLocation := common.NewAddressLocation(
// nil,
// common.Address(sc.AccountV2Migration.Address),
// ContractName,
//)
sc := systemcontracts.SystemContractsForChain(chainID)

accountV2MigrationLocation := common.NewAddressLocation(
nil,
common.Address(sc.AccountV2Migration.Address),
ContractName,
)

environment.DeclareValue(
functionValue,
// TODO: accountV2MigrationLocation,
nil,
accountV2MigrationLocation,
)
}

Expand All @@ -152,7 151,7 @@ var getAccountStorageFormatType = &sema.FunctionType{
ReturnTypeAnnotation: sema.NewTypeAnnotation(sema.UInt8Type),
}

func declareGetAccountStorageFormatFunction(environment runtime.Environment) {
func declareGetAccountStorageFormatFunction(environment runtime.Environment, chainID flow.ChainID) {

functionType := getAccountStorageFormatType

Expand Down Expand Up @@ -207,18 206,16 @@ func declareGetAccountStorageFormatFunction(environment runtime.Environment) {
),
}

// TODO: restrict, but requires to be set during bootstrapping
//sc := systemcontracts.SystemContractsForChain(chainID)
//
//accountV2MigrationLocation := common.NewAddressLocation(
// nil,
// common.Address(sc.AccountV2Migration.Address),
// ContractName,
//)
sc := systemcontracts.SystemContractsForChain(chainID)

accountV2MigrationLocation := common.NewAddressLocation(
nil,
common.Address(sc.AccountV2Migration.Address),
ContractName,
)

environment.DeclareValue(
functionValue,
// TODO: accountV2MigrationLocation,
nil,
accountV2MigrationLocation,
)
}
2 changes: 1 addition & 1 deletion fvm/environment/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 117,7 @@ func DefaultEnvironmentParams() EnvironmentParams {
return EnvironmentParams{
Chain: chainID.Chain(),
ServiceAccountEnabled: true,
RuntimeParams: DefaultRuntimeParams(chainID),
RuntimeParams: DefaultRuntimeParams(),
ProgramLoggerParams: DefaultProgramLoggerParams(),
EventEmitterParams: DefaultEventEmitterParams(),
BlockInfoParams: DefaultBlockInfoParams(),
Expand Down
4 changes: 1 addition & 3 deletions fvm/environment/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 4,17 @@ import (
cadenceRuntime "github.com/onflow/cadence/runtime"

"github.com/onflow/flow-go/fvm/runtime"
"github.com/onflow/flow-go/model/flow"
)

type RuntimeParams struct {
runtime.ReusableCadenceRuntimePool
}

func DefaultRuntimeParams(chainID flow.ChainID) RuntimeParams {
func DefaultRuntimeParams() RuntimeParams {
return RuntimeParams{
ReusableCadenceRuntimePool: runtime.NewReusableCadenceRuntimePool(
0,
cadenceRuntime.Config{},
chainID,
),
}
}
Expand Down
3 changes: 0 additions & 3 deletions fvm/executionParameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 19,6 @@ import (
"github.com/onflow/flow-go/fvm/meter"
reusableRuntime "github.com/onflow/flow-go/fvm/runtime"
"github.com/onflow/flow-go/fvm/runtime/testutil"
"github.com/onflow/flow-go/model/flow"
)

func TestGetExecutionMemoryWeights(t *testing.T) {
Expand All @@ -37,7 36,6 @@ func TestGetExecutionMemoryWeights(t *testing.T) {
ReadStoredFunc: readStored,
},
runtime.Config{},
flow.Emulator,
),
)
envMock.On("ReturnCadenceRuntime", mock.Anything).Return()
Expand Down Expand Up @@ -168,7 166,6 @@ func TestGetExecutionEffortWeights(t *testing.T) {
ReadStoredFunc: readStored,
},
runtime.Config{},
flow.Emulator,
),
)
envMock.On("ReturnCadenceRuntime", mock.Anything).Return()
Expand Down
1 change: 0 additions & 1 deletion fvm/fvm_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 165,6 @@ func NewBasicBlockExecutor(tb testing.TB, chain flow.Chain, logger zerolog.Logge
reusableRuntime.NewReusableCadenceRuntimePool(
computation.ReusableCadenceRuntimePoolSize,
runtime.Config{},
chain.ChainID(),
),
),
fvm.WithEVMEnabled(true),
Expand Down
2 changes: 0 additions & 2 deletions fvm/fvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 2451,6 @@ func TestCapabilityControllers(t *testing.T) {
reusableRuntime.NewReusableCadenceRuntimePool(
1,
runtime.Config{},
flow.Emulator,
),
),
).
Expand Down Expand Up @@ -2506,7 2505,6 @@ func TestStorageIterationWithBrokenValues(t *testing.T) {
reusableRuntime.NewReusableCadenceRuntimePool(
1,
runtime.Config{},
flow.Emulator,
),
),
fvm.WithContractDeploymentRestricted(false),
Expand Down
13 changes: 0 additions & 13 deletions fvm/runtime/reusable_cadence_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 8,7 @@ import (
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"

"github.com/onflow/flow-go/fvm/accountV2Migration"
"github.com/onflow/flow-go/fvm/errors"
"github.com/onflow/flow-go/model/flow"
)

// Note: this is a subset of environment.Environment, redeclared to handle
Expand Down Expand Up @@ -38,7 36,6 @@ type ReusableCadenceRuntime struct {
func NewReusableCadenceRuntime(
rt runtime.Runtime,
config runtime.Config,
chainID flow.ChainID,
) *ReusableCadenceRuntime {
reusable := &ReusableCadenceRuntime{
Runtime: rt,
Expand All @@ -47,7 44,6 @@ func NewReusableCadenceRuntime(
}

reusable.declareRandomSourceHistory()
accountV2Migration.DeclareFunctions(reusable.TxRuntimeEnv, chainID)

return reusable
}
Expand Down Expand Up @@ -186,8 182,6 @@ type ReusableCadenceRuntimePool struct {

config runtime.Config

chainID flow.ChainID

// When newCustomRuntime is nil, the pool will create standard cadence
// interpreter runtimes via runtime.NewInterpreterRuntime. Otherwise, the
// pool will create runtimes using this function.
Expand All @@ -199,7 193,6 @@ type ReusableCadenceRuntimePool struct {
func newReusableCadenceRuntimePool(
poolSize int,
config runtime.Config,
chainID flow.ChainID,
newCustomRuntime CadenceRuntimeConstructor,
) ReusableCadenceRuntimePool {
var pool chan *ReusableCadenceRuntime
Expand All @@ -210,34 203,29 @@ func newReusableCadenceRuntimePool(
return ReusableCadenceRuntimePool{
pool: pool,
config: config,
chainID: chainID,
newCustomRuntime: newCustomRuntime,
}
}

func NewReusableCadenceRuntimePool(
poolSize int,
config runtime.Config,
chainID flow.ChainID,
) ReusableCadenceRuntimePool {
return newReusableCadenceRuntimePool(
poolSize,
config,
chainID,
nil,
)
}

func NewCustomReusableCadenceRuntimePool(
poolSize int,
config runtime.Config,
chainID flow.ChainID,
newCustomRuntime CadenceRuntimeConstructor,
) ReusableCadenceRuntimePool {
return newReusableCadenceRuntimePool(
poolSize,
config,
chainID,
newCustomRuntime,
)
}
Expand All @@ -262,7 250,6 @@ func (pool ReusableCadenceRuntimePool) Borrow(
pool.newRuntime(),
},
pool.config,
pool.chainID,
)
}

Expand Down
11 changes: 9 additions & 2 deletions fvm/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 8,7 @@ import (
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/runtime"

"github.com/onflow/flow-go/fvm/accountV2Migration"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/errors"
"github.com/onflow/flow-go/fvm/evm"
Expand Down Expand Up @@ -201,10 202,11 @@ func (executor *scriptExecutor) executeScript() error {
rt := executor.env.BorrowCadenceRuntime()
defer executor.env.ReturnCadenceRuntime(rt)

chainID := executor.ctx.Chain.ChainID()

if executor.ctx.EVMEnabled {
chain := executor.ctx.Chain
err := evm.SetupEnvironment(
chain.ChainID(),
chainID,
executor.env,
rt.ScriptRuntimeEnv,
debug.NopTracer, // we shouldn't trace during script execution
Expand All @@ -214,6 216,11 @@ func (executor *scriptExecutor) executeScript() error {
}
}

accountV2Migration.DeclareFunctions(
rt.ScriptRuntimeEnv,
chainID,
)

value, err := rt.ExecuteScript(
runtime.Script{
Source: executor.proc.Script,
Expand Down
26 changes: 20 additions & 6 deletions fvm/transactionInvoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 10,7 @@ import (
"go.opentelemetry.io/otel/attribute"
otelTrace "go.opentelemetry.io/otel/trace"

"github.com/onflow/flow-go/fvm/accountV2Migration"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/errors"
"github.com/onflow/flow-go/fvm/evm"
Expand Down Expand Up @@ -189,11 190,12 @@ func (executor *transactionExecutor) preprocess() error {
// infrequently modified and are expensive to compute. For now this includes
// reading meter parameter overrides and parsing programs.
func (executor *transactionExecutor) preprocessTransactionBody() error {
// setup evm
chainID := executor.ctx.Chain.ChainID()

// setup EVM
if executor.ctx.EVMEnabled {
chain := executor.ctx.Chain
err := evm.SetupEnvironment(
chain.ChainID(),
chainID,
executor.env,
executor.cadenceRuntime.TxRuntimeEnv,
executor.ctx.EVMTracer,
Expand All @@ -202,6 204,12 @@ func (executor *transactionExecutor) preprocessTransactionBody() error {
return err
}
}

accountV2Migration.DeclareFunctions(
executor.cadenceRuntime.TxRuntimeEnv,
chainID,
)

// get meter parameters
executionParameters, executionStateRead, err := getExecutionParameters(
executor.env.Logger(),
Expand Down Expand Up @@ -257,11 265,12 @@ func (executor *transactionExecutor) execute() error {
}

func (executor *transactionExecutor) ExecuteTransactionBody() error {
// setup evm
chainID := executor.ctx.Chain.ChainID()

// setup EVM
if executor.ctx.EVMEnabled {
chain := executor.ctx.Chain
err := evm.SetupEnvironment(
chain.ChainID(),
chainID,
executor.env,
executor.cadenceRuntime.TxRuntimeEnv,
executor.ctx.EVMTracer,
Expand All @@ -271,6 280,11 @@ func (executor *transactionExecutor) ExecuteTransactionBody() error {
}
}

accountV2Migration.DeclareFunctions(
executor.cadenceRuntime.TxRuntimeEnv,
chainID,
)

var invalidator derived.TransactionInvalidator
if !executor.errs.CollectedError() {

Expand Down