Skip to content

Commit 92d5d24

Browse files
Merge pull request #6903 from onflow/janez/execution-parameters-from-different-account
Move execution parameter to separate account
2 parents bcb042d + e657d89 commit 92d5d24

File tree

4 files changed

+67
-17
lines changed

4 files changed

+67
-17
lines changed

fvm/environment/derived_data_invalidator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func TestMeterParamOverridesUpdated(t *testing.T) {
244244

245245
snapshotTree := snapshot.NewSnapshotTree(nil)
246246

247-
ctx := fvm.NewContext(fvm.WithChain(flow.Testnet.Chain()))
247+
ctx := fvm.NewContext(fvm.WithChain(flow.Emulator.Chain()))
248248

249249
vm := fvm.NewVirtualMachine()
250250
executionSnapshot, _, err := vm.Run(

fvm/executionParameters.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/onflow/flow-go/fvm/storage"
2020
"github.com/onflow/flow-go/fvm/storage/derived"
2121
"github.com/onflow/flow-go/fvm/storage/state"
22+
"github.com/onflow/flow-go/fvm/systemcontracts"
2223
)
2324

2425
func ProcedureStateParameters(
@@ -143,10 +144,14 @@ func (computer ExecutionParametersComputer) getExecutionParameters() (
143144
derived.StateExecutionParameters,
144145
error,
145146
) {
146-
// Check that the service account exists because all the settings are
147-
// stored in it
148-
serviceAddress := computer.ctx.Chain.ServiceAddress()
149-
service := common.Address(serviceAddress)
147+
sc := systemcontracts.SystemContractsForChain(computer.ctx.Chain.ChainID())
148+
149+
// The execution parameters are stored in the ExecutionParametersAccount. This is
150+
// just the service account for all networks except mainnet and testnet.
151+
// For mainnet and testnet, the execution parameters are stored in a separate
152+
// account, so that they are separated from the frequently changing data on the
153+
// service account.
154+
service := common.Address(sc.ExecutionParametersAccount.Address)
150155

151156
env := environment.NewScriptEnv(
152157
context.Background(),

fvm/fvm_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,11 @@ func TestTransactionFeeDeduction(t *testing.T) {
10831083

10841084
func TestSettingExecutionWeights(t *testing.T) {
10851085

1086+
// change the chain so that the metering settings are read from the service account
1087+
chain := flow.Emulator.Chain()
1088+
10861089
t.Run("transaction should fail with high weights", newVMTest().withBootstrapProcedureOptions(
1090+
10871091
fvm.WithMinimumStorageReservation(fvm.DefaultMinimumStorageReservation),
10881092
fvm.WithAccountCreationFee(fvm.DefaultAccountCreationFee),
10891093
fvm.WithStorageMBPerFLOW(fvm.DefaultStorageMBPerFLOW),
@@ -1092,6 +1096,8 @@ func TestSettingExecutionWeights(t *testing.T) {
10921096
common.ComputationKindLoop: 100_000 << meter.MeterExecutionInternalPrecisionBytes,
10931097
},
10941098
),
1099+
).withContextOptions(
1100+
fvm.WithChain(chain),
10951101
).run(
10961102
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
10971103

@@ -1140,6 +1146,7 @@ func TestSettingExecutionWeights(t *testing.T) {
11401146
),
11411147
).withContextOptions(
11421148
fvm.WithMemoryLimit(10_000_000_000),
1149+
fvm.WithChain(chain),
11431150
).run(
11441151
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
11451152
// Create an account private key.
@@ -1190,6 +1197,7 @@ func TestSettingExecutionWeights(t *testing.T) {
11901197
),
11911198
).withContextOptions(
11921199
fvm.WithMemoryLimit(10_000_000_000),
1200+
fvm.WithChain(chain),
11931201
).run(
11941202
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
11951203

@@ -1234,6 +1242,8 @@ func TestSettingExecutionWeights(t *testing.T) {
12341242
fvm.WithExecutionMemoryWeights(
12351243
memoryWeights,
12361244
),
1245+
).withContextOptions(
1246+
fvm.WithChain(chain),
12371247
).run(
12381248
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
12391249
privateKeys, err := testutil.GenerateAccountPrivateKeys(1)
@@ -1301,6 +1311,8 @@ func TestSettingExecutionWeights(t *testing.T) {
13011311
environment.ComputationKindCreateAccount: (fvm.DefaultComputationLimit + 1) << meter.MeterExecutionInternalPrecisionBytes,
13021312
},
13031313
),
1314+
).withContextOptions(
1315+
fvm.WithChain(chain),
13041316
).run(
13051317
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
13061318
txBody := flow.NewTransactionBody().
@@ -1337,6 +1349,8 @@ func TestSettingExecutionWeights(t *testing.T) {
13371349
environment.ComputationKindCreateAccount: 100_000_000 << meter.MeterExecutionInternalPrecisionBytes,
13381350
},
13391351
),
1352+
).withContextOptions(
1353+
fvm.WithChain(chain),
13401354
).run(
13411355
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
13421356

@@ -1374,6 +1388,8 @@ func TestSettingExecutionWeights(t *testing.T) {
13741388
environment.ComputationKindCreateAccount: 100_000_000 << meter.MeterExecutionInternalPrecisionBytes,
13751389
},
13761390
),
1391+
).withContextOptions(
1392+
fvm.WithChain(chain),
13771393
).run(
13781394
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
13791395
txBody := flow.NewTransactionBody().
@@ -1417,6 +1433,7 @@ func TestSettingExecutionWeights(t *testing.T) {
14171433
fvm.WithAccountStorageLimit(true),
14181434
fvm.WithTransactionFeesEnabled(true),
14191435
fvm.WithMemoryLimit(math.MaxUint64),
1436+
fvm.WithChain(chain),
14201437
).run(
14211438
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
14221439
// Use the maximum amount of computation so that the transaction still passes.
@@ -1510,6 +1527,7 @@ func TestSettingExecutionWeights(t *testing.T) {
15101527
fvm.WithAccountStorageLimit(true),
15111528
fvm.WithTransactionFeesEnabled(true),
15121529
fvm.WithMemoryLimit(math.MaxUint64),
1530+
fvm.WithChain(chain),
15131531
).run(
15141532
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
15151533
// Create an account private key.
@@ -2165,6 +2183,8 @@ func TestScriptExecutionLimit(t *testing.T) {
21652183

21662184
t.Parallel()
21672185

2186+
chain := flow.Emulator.Chain()
2187+
21682188
script := fvm.Script([]byte(`
21692189
access(all) fun main() {
21702190
var s: Int256 = 1024102410241024
@@ -2206,6 +2226,7 @@ func TestScriptExecutionLimit(t *testing.T) {
22062226
fvm.WithTransactionFeesEnabled(true),
22072227
fvm.WithAccountStorageLimit(true),
22082228
fvm.WithComputationLimit(10000),
2229+
fvm.WithChain(chain),
22092230
).run(
22102231
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
22112232
scriptCtx := fvm.NewContextFromParent(ctx)
@@ -2228,6 +2249,7 @@ func TestScriptExecutionLimit(t *testing.T) {
22282249
fvm.WithTransactionFeesEnabled(true),
22292250
fvm.WithAccountStorageLimit(true),
22302251
fvm.WithComputationLimit(20000),
2252+
fvm.WithChain(chain),
22312253
).run(
22322254
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
22332255
scriptCtx := fvm.NewContextFromParent(ctx)

fvm/systemcontracts/system_contracts.go

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const (
4747

4848
// AccountNameEVMStorage is not a contract, but a special account that is used to store EVM state
4949
AccountNameEVMStorage = "EVMStorageAccount"
50+
// AccountNameExecutionParametersAccount is not a contract, but a special account that is used to store execution parameters
51+
// This is generally just the service account. For mainnet and testnet, it is a separate account,
52+
// in order to separate it away from the frequently changing data on the service account.
53+
AccountNameExecutionParametersAccount = "ExecutionParametersAccount"
5054

5155
// Unqualified names of service events (not including address prefix or contract name)
5256

@@ -100,6 +104,11 @@ var (
100104
evmStorageAddressTestnet = flow.HexToAddress("1a54ed2be7552821")
101105
// evmStorageAddressMainnet is the address of the EVM state storage contract on Mainnet
102106
evmStorageAddressMainnet = flow.HexToAddress("d421a63faae318f9")
107+
108+
// executionParametersAddressTestnet is the address of the Execution Parameters contract on Testnet
109+
executionParametersAddressTestnet = flow.HexToAddress("6997a2f2cf57b73a")
110+
// executionParametersAddressMainnet is the address of the Execution Parameters contract on Mainnet
111+
executionParametersAddressMainnet = flow.HexToAddress("f426ff57ee8f6110")
103112
)
104113

105114
// SystemContract represents a system contract on a particular chain.
@@ -149,10 +158,11 @@ type SystemContracts struct {
149158
DKG SystemContract
150159

151160
// service account related contracts
152-
FlowServiceAccount SystemContract
153-
NodeVersionBeacon SystemContract
154-
RandomBeaconHistory SystemContract
155-
FlowStorageFees SystemContract
161+
FlowServiceAccount SystemContract
162+
NodeVersionBeacon SystemContract
163+
RandomBeaconHistory SystemContract
164+
FlowStorageFees SystemContract
165+
ExecutionParametersAccount SystemContract
156166

157167
// token related contracts
158168
FlowFees SystemContract
@@ -344,16 +354,28 @@ func init() {
344354
}
345355
}
346356

357+
executionParametersAccountFunc := func(chain flow.ChainID) flow.Address {
358+
switch chain {
359+
case flow.Mainnet:
360+
return executionParametersAddressMainnet
361+
case flow.Testnet:
362+
return executionParametersAddressTestnet
363+
default:
364+
return serviceAddressFunc(chain)
365+
}
366+
}
367+
347368
contractAddressFunc = map[string]func(id flow.ChainID) flow.Address{
348369
ContractNameIDTableStaking: epochAddressFunc,
349370
ContractNameEpoch: epochAddressFunc,
350371
ContractNameClusterQC: epochAddressFunc,
351372
ContractNameDKG: epochAddressFunc,
352373

353-
ContractNameNodeVersionBeacon: serviceAddressFunc,
354-
ContractNameRandomBeaconHistory: serviceAddressFunc,
355-
ContractNameServiceAccount: serviceAddressFunc,
356-
ContractNameStorageFees: serviceAddressFunc,
374+
ContractNameNodeVersionBeacon: serviceAddressFunc,
375+
ContractNameRandomBeaconHistory: serviceAddressFunc,
376+
ContractNameServiceAccount: serviceAddressFunc,
377+
ContractNameStorageFees: serviceAddressFunc,
378+
AccountNameExecutionParametersAccount: executionParametersAccountFunc,
357379

358380
ContractNameFlowFees: nthAddressFunc(FlowFeesAccountIndex),
359381
ContractNameFungibleToken: nthAddressFunc(FungibleTokenAccountIndex),
@@ -406,10 +428,11 @@ func init() {
406428
ClusterQC: addressOfContract(ContractNameClusterQC),
407429
DKG: addressOfContract(ContractNameDKG),
408430

409-
FlowServiceAccount: addressOfContract(ContractNameServiceAccount),
410-
NodeVersionBeacon: addressOfContract(ContractNameNodeVersionBeacon),
411-
RandomBeaconHistory: addressOfContract(ContractNameRandomBeaconHistory),
412-
FlowStorageFees: addressOfContract(ContractNameStorageFees),
431+
FlowServiceAccount: addressOfContract(ContractNameServiceAccount),
432+
NodeVersionBeacon: addressOfContract(ContractNameNodeVersionBeacon),
433+
RandomBeaconHistory: addressOfContract(ContractNameRandomBeaconHistory),
434+
FlowStorageFees: addressOfContract(ContractNameStorageFees),
435+
ExecutionParametersAccount: addressOfContract(AccountNameExecutionParametersAccount),
413436

414437
FlowFees: addressOfContract(ContractNameFlowFees),
415438
FlowToken: addressOfContract(ContractNameFlowToken),

0 commit comments

Comments
 (0)