From d588bebb122e85b354b419ee37b6d77875dfcdbe Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Thu, 13 Nov 2025 17:06:07 +0100 Subject: [PATCH 1/6] Update execution effort weights --- fvm/environment/meter.go | 53 +++++++++++++++++++++++++++++++++------- fvm/evm/evm_test.go | 30 +++++++++++------------ 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/fvm/environment/meter.go b/fvm/environment/meter.go index 38e740d75ae..524f231563a 100644 --- a/fvm/environment/meter.go +++ b/fvm/environment/meter.go @@ -57,16 +57,51 @@ const ( ComputationKindEVMDecodeABI ) -// MainnetExecutionEffortWeights are the execution effort weights as they are -// on mainnet from crescendo spork +// MainnetExecutionEffortWeights are the execution effort weights as they are on mainnet var MainnetExecutionEffortWeights = meter.ExecutionEffortWeights{ - common.ComputationKindStatement: 314, - common.ComputationKindLoop: 314, - common.ComputationKindFunctionInvocation: 314, - ComputationKindGetValue: 162, - ComputationKindCreateAccount: 567534, - ComputationKindSetValue: 153, - ComputationKindEVMGasUsage: 13, + ComputationKindCreateAccount: 2143437, + ComputationKindBLSVerifyPOP: 1538600, + ComputationKindGetAccountBalance: 485476, + ComputationKindBLSAggregatePublicKeys: 402728, + ComputationKindGetStorageCapacity: 397087, + ComputationKindGetAccountAvailableBalance: 375235, + ComputationKindUpdateAccountContractCode: 369407, + ComputationKindBLSAggregateSignatures: 325309, + ComputationKindGenerateAccountLocalID: 75507, + ComputationKindGetAccountContractNames: 32771, + ComputationKindGetStorageUsed: 25416, + ComputationKindAccountKeysCount: 24709, + ComputationKindAllocateSlabIndex: 15372, + common.ComputationKindAtreeMapGet: 8837, + common.ComputationKindAtreeMapRemove: 7373, + common.ComputationKindCreateArrayValue: 4364, + common.ComputationKindCreateDictionaryValue: 3818, + common.ComputationKindAtreeMapSet: 3656, + common.ComputationKindAtreeArrayInsert: 3652, + common.ComputationKindAtreeMapReadIteration: 3325, + ComputationKindEncodeEvent: 2911, + common.ComputationKindTransferCompositeValue: 2358, + common.ComputationKindAtreeArrayAppend: 1907, + common.ComputationKindStatement: 1770, + common.ComputationKindAtreeArraySet: 1737, + common.ComputationKindFunctionInvocation: 1399, + common.ComputationKindAtreeMapPopIteration: 1210, + common.ComputationKindAtreeArrayPopIteration: 736, + ComputationKindRLPDecoding: 516, + common.ComputationKindGraphemesIteration: 278, + common.ComputationKindUfixParse: 257, + common.ComputationKindFixParse: 223, + common.ComputationKindLoop: 179, + common.ComputationKindAtreeArrayBatchConstruction: 177, + common.ComputationKindTransferDictionaryValue: 125, + common.ComputationKindBigIntParse: 69, + common.ComputationKindTransferArrayValue: 48, + ComputationKindSetValue: 48, + common.ComputationKindUintParse: 31, + common.ComputationKindIntParse: 28, + ComputationKindGetValue: 23, + common.ComputationKindStringToLower: 5, + ComputationKindEVMGasUsage: 3, } type Meter interface { diff --git a/fvm/evm/evm_test.go b/fvm/evm/evm_test.go index 93b12f47147..474d1296633 100644 --- a/fvm/evm/evm_test.go +++ b/fvm/evm/evm_test.go @@ -3672,7 +3672,7 @@ func TestEVMFileSystemContract(t *testing.T) { require.Equal(t, blockEventPayload.TotalGasUsed-feeTranferEventPayload.GasConsumed, txEventPayload.GasConsumed) require.Empty(t, txEventPayload.ContractAddress) - require.Greater(t, int(output.ComputationUsed), 400) + require.Greater(t, int(output.ComputationUsed), 900) }, fvm.WithExecutionEffortWeights( environment.MainnetExecutionEffortWeights, @@ -3692,7 +3692,7 @@ func TestEVMFileSystemContract(t *testing.T) { testContract *TestContract, testAccount *EOATestAccount, ) { - state, output := runFileSystemContract(ctx, vm, snapshot, testContract, testAccount, 400) + state, output := runFileSystemContract(ctx, vm, snapshot, testContract, testAccount, 500) snapshot = snapshot.Append(state) require.Len(t, output.Events, 0) @@ -3708,7 +3708,7 @@ func TestEVMFileSystemContract(t *testing.T) { require.Equal(t, uint64(0), blockEventPayload.TotalGasUsed) // only a small amount of computation was used due to the EVM transaction never being executed - require.Less(t, int(output.ComputationUsed), 20) + require.Less(t, int(output.ComputationUsed), 900) }, fvm.WithExecutionEffortWeights( environment.MainnetExecutionEffortWeights, @@ -4008,12 +4008,12 @@ func RunWithNewEnvironment( t *testing.T, chain flow.Chain, f func( - fvm.Context, - fvm.VM, - snapshot.SnapshotTree, - *TestContract, - *EOATestAccount, - ), + fvm.Context, + fvm.VM, + snapshot.SnapshotTree, + *TestContract, + *EOATestAccount, +), ) { rootAddr := evm.StorageAccountAddress(chain.ChainID()) RunWithTestBackend(t, func(backend *TestBackend) { @@ -4070,12 +4070,12 @@ func RunContractWithNewEnvironment( chain flow.Chain, tc *TestContract, f func( - fvm.Context, - fvm.VM, - snapshot.SnapshotTree, - *TestContract, - *EOATestAccount, - ), + fvm.Context, + fvm.VM, + snapshot.SnapshotTree, + *TestContract, + *EOATestAccount, +), bootstrapOpts ...fvm.BootstrapProcedureOption, ) { rootAddr := evm.StorageAccountAddress(chain.ChainID()) From 0dff75286857e009afe87844189d86ac2ccbd4fd Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Thu, 13 Nov 2025 20:31:18 +0100 Subject: [PATCH 2/6] fix EE normalization --- model/flow/constants.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/model/flow/constants.go b/model/flow/constants.go index a66bddb7b4e..61452164535 100644 --- a/model/flow/constants.go +++ b/model/flow/constants.go @@ -101,15 +101,14 @@ func paddedDomainTag(s string) [DomainTagLength]byte { } // EstimatedComputationPerMillisecond is the approximate number of computation units that can be performed in a millisecond. -// this was calibrated during the Variable Transaction Fees: Execution Effort FLIP https://github.com/onflow/flow/pull/753. -// Updated after the FLIP: -// https://github.com/onflow/flips/blob/14c5ec4/governance/20240508-computation-limit-hike.md#flip-267-increasing-the-transaction-computation-limit -const EstimatedComputationPerMillisecond = 9999.0 / 1000.0 +// this was calibrated during the FLIP 346: Variable Transaction Fees - Execution Effort II. https://github.com/onflow/flips/pull/347. +const EstimatedComputationPerMillisecond = 9999.0 / 333.4118 // NormalizedExecutionTimePerComputationUnit returns the normalized time per computation unit -// If the computation estimation is correct (as per the FLIP https://github.com/onflow/flow/pull/753) the value should be 1. +// If the computation estimation is correct (as per the FLIP https://github.com/onflow/flips/pull/347) the value should be 1. // If the value is greater than 1, the computation estimation is too low; we are underestimating transaction complexity (and thus undercharging). // If the value is less than 1, the computation estimation is too high; we are overestimating transaction complexity (and thus overcharging). +// This is only used for metrics reporting func NormalizedExecutionTimePerComputationUnit(execTime time.Duration, computationUsed uint64) float64 { if computationUsed == 0 { return 0 From 114d130e8fc953ce9bf77abee4be391b34ea7ce8 Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Thu, 13 Nov 2025 20:33:31 +0100 Subject: [PATCH 3/6] lint fix --- fvm/evm/evm_test.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/fvm/evm/evm_test.go b/fvm/evm/evm_test.go index 474d1296633..e7c9348d37a 100644 --- a/fvm/evm/evm_test.go +++ b/fvm/evm/evm_test.go @@ -4007,13 +4007,7 @@ func getEVMAccountNonce( func RunWithNewEnvironment( t *testing.T, chain flow.Chain, - f func( - fvm.Context, - fvm.VM, - snapshot.SnapshotTree, - *TestContract, - *EOATestAccount, -), + f func(fvm.Context, fvm.VM, snapshot.SnapshotTree, *TestContract, *EOATestAccount), ) { rootAddr := evm.StorageAccountAddress(chain.ChainID()) RunWithTestBackend(t, func(backend *TestBackend) { @@ -4069,13 +4063,7 @@ func RunContractWithNewEnvironment( t *testing.T, chain flow.Chain, tc *TestContract, - f func( - fvm.Context, - fvm.VM, - snapshot.SnapshotTree, - *TestContract, - *EOATestAccount, -), + f func(fvm.Context, fvm.VM, snapshot.SnapshotTree, *TestContract, *EOATestAccount), bootstrapOpts ...fvm.BootstrapProcedureOption, ) { rootAddr := evm.StorageAccountAddress(chain.ChainID()) From 1cb1be5a5c806581b27dc421a69ade748903793d Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Thu, 13 Nov 2025 21:12:27 +0100 Subject: [PATCH 4/6] fix tests --- integration/internal/emulator/tests/transaction_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/internal/emulator/tests/transaction_test.go b/integration/internal/emulator/tests/transaction_test.go index 074f3d50851..13d515cf073 100644 --- a/integration/internal/emulator/tests/transaction_test.go +++ b/integration/internal/emulator/tests/transaction_test.go @@ -1847,7 +1847,7 @@ func TestTransactionExecutionLimit(t *testing.T) { t.Parallel() - const limit = 19000 + const limit = 25000 b, adapter := setupTransactionTests( t, From 58c4e14b23c55a2e1e9055b33133e3e18b263797 Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Thu, 13 Nov 2025 21:23:33 +0100 Subject: [PATCH 5/6] more test fixes --- integration/internal/emulator/tests/script_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/internal/emulator/tests/script_test.go b/integration/internal/emulator/tests/script_test.go index ad7e4782512..e74b8bbed3a 100644 --- a/integration/internal/emulator/tests/script_test.go +++ b/integration/internal/emulator/tests/script_test.go @@ -237,7 +237,7 @@ func TestScriptExecutionLimit(t *testing.T) { t.Parallel() - const limit = 19000 + const limit = 25000 b, err := emulator.New( emulator.WithScriptGasLimit(limit), ) From 3a95cdf2a052564e9959affd74b662d370903e5a Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Fri, 14 Nov 2025 16:09:49 +0100 Subject: [PATCH 6/6] tweak metric transactionNormalizedTimePerComputation --- module/metrics/execution.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module/metrics/execution.go b/module/metrics/execution.go index f6c9b3eb361..f11543a6d5d 100644 --- a/module/metrics/execution.go +++ b/module/metrics/execution.go @@ -878,14 +878,16 @@ func (ec *ExecutionCollector) ExecutionBlockCachedPrograms(programs int) { func (ec *ExecutionCollector) ExecutionTransactionExecuted( dur time.Duration, stats module.TransactionExecutionResultStats, - info module.TransactionExecutionResultInfo, + _ module.TransactionExecutionResultInfo, ) { ec.totalExecutedTransactionsCounter.Inc() ec.transactionExecutionTime.Observe(float64(dur.Milliseconds())) ec.transactionConflictRetries.Observe(float64(stats.NumberOfTxnConflictRetries)) ec.transactionComputationUsed.Observe(float64(stats.ComputationUsed)) - ec.transactionNormalizedTimePerComputation.Observe( - flow.NormalizedExecutionTimePerComputationUnit(dur, stats.ComputationUsed)) + if stats.ComputationUsed > 0 { + ec.transactionNormalizedTimePerComputation.Observe( + flow.NormalizedExecutionTimePerComputationUnit(dur, stats.ComputationUsed)) + } ec.transactionMemoryEstimate.Observe(float64(stats.MemoryUsed)) ec.transactionEmittedEvents.Observe(float64(stats.EventCounts)) ec.transactionEventSize.Observe(float64(stats.EventSize)) @@ -900,7 +902,7 @@ func (ec *ExecutionCollector) ExecutionChunkDataPackGenerated(proofSize, numberO ec.chunkDataPackCollectionSize.Observe(float64(numberOfTransactions)) } -// ScriptExecuted reports the time spent executing a single script +// ExecutionScriptExecuted reports the time spent executing a single script func (ec *ExecutionCollector) ExecutionScriptExecuted(dur time.Duration, compUsed, memoryUsed, memoryEstimated uint64) { ec.totalExecutedScriptsCounter.Inc() ec.scriptExecutionTime.Observe(float64(dur.Milliseconds()))