diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 75a1e63c4ea..0029d96f399 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -272,6 +272,9 @@ # FixDelegationChangeOwnerOnAccountEnableEpoch represents the epoch when the fix for the delegation system smart contract is enabled FixDelegationChangeOwnerOnAccountEnableEpoch = 3 + # DynamicGasCostForDataTrieStorageLoadEnableEpoch represents the epoch when dynamic gas cost for data trie storage load will be enabled + DynamicGasCostForDataTrieStorageLoadEnableEpoch = 3 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/cmd/node/config/gasSchedules/gasScheduleV1.toml b/cmd/node/config/gasSchedules/gasScheduleV1.toml index f4c8a9cf792..a0664f4a13c 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV1.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV1.toml @@ -812,3 +812,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV2.toml b/cmd/node/config/gasSchedules/gasScheduleV2.toml index ff61fde0010..b75b56cbb74 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV2.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV2.toml @@ -812,3 +812,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV3.toml b/cmd/node/config/gasSchedules/gasScheduleV3.toml index 7d04343393d..2972ea5d953 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV3.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV3.toml @@ -812,3 +812,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV4.toml b/cmd/node/config/gasSchedules/gasScheduleV4.toml index 9cd177eddbb..2e4956f47e9 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV4.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV4.toml @@ -812,3 +812,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV5.toml b/cmd/node/config/gasSchedules/gasScheduleV5.toml index ecb764fe6be..65aa269d033 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV5.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV5.toml @@ -812,3 +812,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV6.toml b/cmd/node/config/gasSchedules/gasScheduleV6.toml index afcb936f9df..1a4cac3b059 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV6.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV6.toml @@ -812,3 +812,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV7.toml b/cmd/node/config/gasSchedules/gasScheduleV7.toml index b877d64e69d..441bb321a22 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV7.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV7.toml @@ -813,3 +813,16 @@ MaxBuiltInCallsPerTx = 100 MaxNumberOfTransfersPerTx = 250 MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 11845a1f624..2ba487925f9 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -128,6 +128,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) { handler.setFlagValue(epoch >= handler.enableEpochsConfig.AutoBalanceDataTriesEnableEpoch, handler.autoBalanceDataTriesFlag, "autoBalanceDataTriesFlag", epoch, handler.enableEpochsConfig.AutoBalanceDataTriesEnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.FixDelegationChangeOwnerOnAccountEnableEpoch, handler.fixDelegationChangeOwnerOnAccountFlag, "fixDelegationChangeOwnerOnAccountFlag", epoch, handler.enableEpochsConfig.FixDelegationChangeOwnerOnAccountEnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.SCProcessorV2EnableEpoch, handler.scProcessorV2Flag, "scProcessorV2Flag", epoch, handler.enableEpochsConfig.SCProcessorV2EnableEpoch) + handler.setFlagValue(epoch >= handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch, handler.dynamicGasCostForDataTrieStorageLoadFlag, "dynamicGasCostForDataTrieStorageLoadFlag", epoch, handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch) } func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string, epoch uint32, flagEpoch uint32) { diff --git a/common/enablers/epochFlags.go b/common/enablers/epochFlags.go index 4ec5751f9b6..a7d3ec782a4 100644 --- a/common/enablers/epochFlags.go +++ b/common/enablers/epochFlags.go @@ -100,6 +100,7 @@ type epochFlagsHolder struct { consistentTokensValuesCheckFlag *atomic.Flag autoBalanceDataTriesFlag *atomic.Flag fixDelegationChangeOwnerOnAccountFlag *atomic.Flag + dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag } func newEpochFlagsHolder() *epochFlagsHolder { @@ -199,6 +200,7 @@ func newEpochFlagsHolder() *epochFlagsHolder { changeUsernameFlag: &atomic.Flag{}, autoBalanceDataTriesFlag: &atomic.Flag{}, fixDelegationChangeOwnerOnAccountFlag: &atomic.Flag{}, + dynamicGasCostForDataTrieStorageLoadFlag: &atomic.Flag{}, } } @@ -729,3 +731,8 @@ func (holder *epochFlagsHolder) IsAutoBalanceDataTriesEnabled() bool { func (holder *epochFlagsHolder) FixDelegationChangeOwnerOnAccountEnabled() bool { return holder.fixDelegationChangeOwnerOnAccountFlag.IsSet() } + +// IsDynamicGasCostForDataTrieStorageLoadEnabled returns true if dynamicGasCostForDataTrieStorageLoadFlag is enabled +func (holder *epochFlagsHolder) IsDynamicGasCostForDataTrieStorageLoadEnabled() bool { + return holder.dynamicGasCostForDataTrieStorageLoadFlag.IsSet() +} diff --git a/common/interface.go b/common/interface.go index 808b61a76ed..201083be86c 100644 --- a/common/interface.go +++ b/common/interface.go @@ -392,6 +392,7 @@ type EnableEpochsHandler interface { IsChangeUsernameEnabled() bool IsConsistentTokensValuesLengthCheckEnabled() bool IsAutoBalanceDataTriesEnabled() bool + IsDynamicGasCostForDataTrieStorageLoadEnabled() bool FixDelegationChangeOwnerOnAccountEnabled() bool IsInterfaceNil() bool diff --git a/config/epochConfig.go b/config/epochConfig.go index e0969a1a0a6..6f9a665f2b6 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -103,6 +103,7 @@ type EnableEpochs struct { AutoBalanceDataTriesEnableEpoch uint32 ConsistentTokensValuesLengthCheckEnableEpoch uint32 FixDelegationChangeOwnerOnAccountEnableEpoch uint32 + DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index b271cc8430c..968e9f19f49 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -811,6 +811,9 @@ func TestEnableEpochConfig(t *testing.T) { # DeterministicSortOnValidatorsInfoEnableEpoch represents the epoch when the deterministic sorting on validators info is enabled DeterministicSortOnValidatorsInfoEnableEpoch = 66 + # DynamicGasCostForDataTrieStorageLoadEnableEpoch represents the epoch when dynamic gas cost for data trie storage load will be enabled + DynamicGasCostForDataTrieStorageLoadEnableEpoch = 64 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -848,51 +851,53 @@ func TestEnableEpochConfig(t *testing.T) { ReturnDataToLastTransferEnableEpoch: 15, SenderInOutTransferEnableEpoch: 16, StakeEnableEpoch: 17, - StakingV2EnableEpoch: 18, - DoubleKeyProtectionEnableEpoch: 19, - ESDTEnableEpoch: 20, - GovernanceEnableEpoch: 21, - DelegationManagerEnableEpoch: 22, - DelegationSmartContractEnableEpoch: 23, - CorrectLastUnjailedEnableEpoch: 24, - RelayedTransactionsV2EnableEpoch: 25, - UnbondTokensV2EnableEpoch: 26, - SaveJailedAlwaysEnableEpoch: 27, - ReDelegateBelowMinCheckEnableEpoch: 28, - ValidatorToDelegationEnableEpoch: 29, - WaitingListFixEnableEpoch: 30, - IncrementSCRNonceInMultiTransferEnableEpoch: 31, - ESDTMultiTransferEnableEpoch: 32, - GlobalMintBurnDisableEpoch: 33, - ESDTTransferRoleEnableEpoch: 34, - BuiltInFunctionOnMetaEnableEpoch: 35, - ComputeRewardCheckpointEnableEpoch: 36, - SCRSizeInvariantCheckEnableEpoch: 37, - BackwardCompSaveKeyValueEnableEpoch: 38, - ESDTNFTCreateOnMultiShardEnableEpoch: 39, - MetaESDTSetEnableEpoch: 40, - AddTokensToDelegationEnableEpoch: 41, - MultiESDTTransferFixOnCallBackOnEnableEpoch: 42, - OptimizeGasUsedInCrossMiniBlocksEnableEpoch: 43, - CorrectFirstQueuedEpoch: 44, - DeleteDelegatorAfterClaimRewardsEnableEpoch: 45, - FixOOGReturnCodeEnableEpoch: 46, - RemoveNonUpdatedStorageEnableEpoch: 47, - OptimizeNFTStoreEnableEpoch: 48, - CreateNFTThroughExecByCallerEnableEpoch: 49, - StopDecreasingValidatorRatingWhenStuckEnableEpoch: 50, - FrontRunningProtectionEnableEpoch: 51, - IsPayableBySCEnableEpoch: 52, - CleanUpInformativeSCRsEnableEpoch: 53, - StorageAPICostOptimizationEnableEpoch: 54, - TransformToMultiShardCreateEnableEpoch: 55, + StakingV2EnableEpoch: 18, + + DoubleKeyProtectionEnableEpoch: 19, + ESDTEnableEpoch: 20, + GovernanceEnableEpoch: 21, + DelegationManagerEnableEpoch: 22, + DelegationSmartContractEnableEpoch: 23, + CorrectLastUnjailedEnableEpoch: 24, + + RelayedTransactionsV2EnableEpoch: 25, + UnbondTokensV2EnableEpoch: 26, + SaveJailedAlwaysEnableEpoch: 27, + ReDelegateBelowMinCheckEnableEpoch: 28,ValidatorToDelegationEnableEpoch: 29, + + WaitingListFixEnableEpoch: 30, + IncrementSCRNonceInMultiTransferEnableEpoch: 31, + ESDTMultiTransferEnableEpoch: 32, + GlobalMintBurnDisableEpoch: 33, + ESDTTransferRoleEnableEpoch: 34, + BuiltInFunctionOnMetaEnableEpoch: 35, + ComputeRewardCheckpointEnableEpoch: 36, + SCRSizeInvariantCheckEnableEpoch: 37, + BackwardCompSaveKeyValueEnableEpoch: 38, + ESDTNFTCreateOnMultiShardEnableEpoch: 39, + MetaESDTSetEnableEpoch: 40, + AddTokensToDelegationEnableEpoch: 41, + MultiESDTTransferFixOnCallBackOnEnableEpoch: 42, + OptimizeGasUsedInCrossMiniBlocksEnableEpoch: 43, + CorrectFirstQueuedEpoch: 44, + DeleteDelegatorAfterClaimRewardsEnableEpoch: 45, + FixOOGReturnCodeEnableEpoch: 46, + RemoveNonUpdatedStorageEnableEpoch: 47, + OptimizeNFTStoreEnableEpoch: 48, + CreateNFTThroughExecByCallerEnableEpoch: 49, + StopDecreasingValidatorRatingWhenStuckEnableEpoch: 50, + FrontRunningProtectionEnableEpoch: 51, + IsPayableBySCEnableEpoch: 52, + CleanUpInformativeSCRsEnableEpoch: 53, + StorageAPICostOptimizationEnableEpoch: 54, + TransformToMultiShardCreateEnableEpoch: 55, ESDTRegisterAndSetAllRolesEnableEpoch: 56, - ScheduledMiniBlocksEnableEpoch: 57, - CorrectJailedNotUnstakedEmptyQueueEpoch: 58, - DoNotReturnOldBlockInBlockchainHookEnableEpoch: 59, - AddFailedRelayedTxToInvalidMBsDisableEpoch: 60, - SCRSizeInvariantOnBuiltInResultEnableEpoch: 61, - CheckCorrectTokenIDForTransferRoleEnableEpoch: 62, + ScheduledMiniBlocksEnableEpoch: 57, + CorrectJailedNotUnstakedEmptyQueueEpoch: 58, + DoNotReturnOldBlockInBlockchainHookEnableEpoch: 59, + AddFailedRelayedTxToInvalidMBsDisableEpoch: 60, + SCRSizeInvariantOnBuiltInResultEnableEpoch: 61, + CheckCorrectTokenIDForTransferRoleEnableEpoch: 62, DisableExecByCallerEnableEpoch: 63, RefactorContextEnableEpoch: 64, FailExecutionOnEveryAPIErrorEnableEpoch: 65, @@ -902,8 +907,7 @@ func TestEnableEpochConfig(t *testing.T) { ESDTMetadataContinuousCleanupEnableEpoch: 69, MiniBlockPartialExecutionEnableEpoch: 70, FixAsyncCallBackArgsListEnableEpoch: 71, - FixOldTokenLiquidityEnableEpoch: 72, - RuntimeMemStoreLimitEnableEpoch: 73, + FixOldTokenLiquidityEnableEpoch: 72,RuntimeMemStoreLimitEnableEpoch: 73, SetSenderInEeiOutputTransferEnableEpoch: 74, RefactorPeersMiniBlocksEnableEpoch: 75, MaxBlockchainHookCountersEnableEpoch: 76, @@ -931,6 +935,7 @@ func TestEnableEpochConfig(t *testing.T) { }, }, DeterministicSortOnValidatorsInfoEnableEpoch: 66, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 64, BLSMultiSignerEnableEpoch: []MultiSignerConfig{ { EnableEpoch: 0, diff --git a/go.mod b/go.mod index cf61831ef02..b9bf290d87c 100644 --- a/go.mod +++ b/go.mod @@ -20,8 +20,8 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.13 github.com/multiversx/mx-chain-scenario-go v1.2.1 github.com/multiversx/mx-chain-storage-go v1.0.12 - github.com/multiversx/mx-chain-vm-common-go v1.5.2 - github.com/multiversx/mx-chain-vm-go v1.5.5 + github.com/multiversx/mx-chain-vm-common-go v1.5.3 + github.com/multiversx/mx-chain-vm-go v1.5.6 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.60 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.61 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.87 diff --git a/go.sum b/go.sum index 2c300b84a93..344259598b8 100644 --- a/go.sum +++ b/go.sum @@ -390,10 +390,10 @@ github.com/multiversx/mx-chain-scenario-go v1.2.1 h1:9eC6VcOEAKRRKZ7EbSWPLzCdNIM github.com/multiversx/mx-chain-scenario-go v1.2.1/go.mod h1:EuZY7DpNFHVNSxJR8dKE1z2I8gBYfEFFPSwNUOXptqE= github.com/multiversx/mx-chain-storage-go v1.0.12 h1:FrkgHPV38BO8cwdK0GUYHxVkUyOhyBBIhPz0P1e72NA= github.com/multiversx/mx-chain-storage-go v1.0.12/go.mod h1:/8VrMbO9CbIi0Ym3F1QPY6EENGcUq5DpEBPDt4evn9Q= -github.com/multiversx/mx-chain-vm-common-go v1.5.2 h1:iRWJNlogjkq9w+pJZIfkVkXQFmMoRxZr6pzCfg2/K68= -github.com/multiversx/mx-chain-vm-common-go v1.5.2/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c= -github.com/multiversx/mx-chain-vm-go v1.5.5 h1:/ROeFnd44/vRGtnzlfUJZMBX/g3bNwxPpLTXo52XLbY= -github.com/multiversx/mx-chain-vm-go v1.5.5/go.mod h1:5d5GC+Ibz8X27+W8TYqbsMXh8n4F/kHUbdr0bVz8o8Y= +github.com/multiversx/mx-chain-vm-common-go v1.5.3 h1:u4ttQc+1bj92SoGeRk3EYc8JvOMDPIGyrQuQGM+YYpU= +github.com/multiversx/mx-chain-vm-common-go v1.5.3/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c= +github.com/multiversx/mx-chain-vm-go v1.5.6 h1:IOwq/L4dBDBjXTIAR9hHCS/D4fn2xMkkINimHWsYiUQ= +github.com/multiversx/mx-chain-vm-go v1.5.6/go.mod h1:WCYCljlHi2UQWHQAlSw1LzDsiMlckoMzvHL2fA5VKU4= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.60 h1:YYElal1woAT3gwcVGe2JUEqBlzMXt963BSdQHuJpTMk= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.60/go.mod h1:3X3V/nj4G2ziTIijSEiucGn3r3S8v3CRIg5/szOtCLY= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.61 h1:z1LkUlVNwc6mfWqFu+VTpPorDd0/Pj7/SMNXmNDdkK4= diff --git a/integrationTests/benchmarks/loadFromTrie_test.go b/integrationTests/benchmarks/loadFromTrie_test.go index 3e2833d7067..470f722e899 100644 --- a/integrationTests/benchmarks/loadFromTrie_test.go +++ b/integrationTests/benchmarks/loadFromTrie_test.go @@ -1,10 +1,7 @@ package benchmarks import ( - "encoding/hex" "fmt" - "math/rand" - "strings" "testing" "time" @@ -12,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing/blake2b" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" "github.com/multiversx/mx-chain-go/storage/storageunit" @@ -22,12 +20,6 @@ import ( "github.com/stretchr/testify/require" ) -var charsPool = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E"} - -const ( - keyLength = 32 -) - func TestTrieLoadTime(t *testing.T) { t.Skip() @@ -133,33 +125,13 @@ func insertKeysIntoTrie(t *testing.T, tr common.Trie, numTrieLevels int, numChil } func insertInTrie(tr common.Trie, numTrieLevels int, numChildrenPerBranch int) []byte { - var key []byte - hexKeyLength := keyLength * 2 - if numTrieLevels == 1 { - hexKey := generateRandHexString(hexKeyLength) - key, _ = hex.DecodeString(hexKey) + keys := integrationTests.GenerateTrieKeysForMaxLevel(numTrieLevels, numChildrenPerBranch) + for _, key := range keys { _ = tr.Update(key, key) - return key - } - - for i := 0; i < numTrieLevels-1; i++ { - for j := 0; j < numChildrenPerBranch-1; j++ { - hexKey := generateRandHexString(hexKeyLength-numTrieLevels) + strings.Repeat(charsPool[j], numTrieLevels-i) + strings.Repeat("F", i) - key, _ = hex.DecodeString(hexKey) - _ = tr.Update(key, key) - } - } - - return key -} - -func generateRandHexString(size int) string { - buff := make([]string, size) - for i := 0; i < size; i++ { - buff[i] = charsPool[rand.Intn(len(charsPool))] } - return strings.Join(buff, "") + lastKeyIndex := len(keys) - 1 + return keys[lastKeyIndex] } func getTrieStorageManager(store storage.Storer, marshaller marshal.Marshalizer, hasher hashing.Hasher) common.StorageManager { diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index d0259c4a03c..6f386c50410 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "fmt" "math/big" + mathRand "math/rand" "strings" "sync" "sync/atomic" @@ -2694,3 +2695,39 @@ func PrepareRelayedTxDataV2(innerTx *transaction.Transaction) []byte { return txData.ToBytes() } + +var charsPool = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E"} + +// GenerateTrieKeysForMaxLevel generates a list of keys that will fill a trie until the given level is reached +func GenerateTrieKeysForMaxLevel(numTrieLevels int, numChildrenPerBranch int) [][]byte { + keys := make([][]byte, 0) + + keyLength := 32 + hexKeyLength := keyLength * 2 + if numTrieLevels == 1 { + hexKey := generateRandHexString(hexKeyLength) + key, _ := hex.DecodeString(hexKey) + keys = append(keys, key) + + return keys + } + + for i := 0; i < numTrieLevels-1; i++ { + for j := 0; j < numChildrenPerBranch-1; j++ { + hexKey := generateRandHexString(hexKeyLength-numTrieLevels) + strings.Repeat(charsPool[j], numTrieLevels-i) + strings.Repeat("F", i) + key, _ := hex.DecodeString(hexKey) + keys = append(keys, key) + } + } + + return keys +} + +func generateRandHexString(size int) string { + buff := make([]string, size) + for i := 0; i < size; i++ { + buff[i] = charsPool[mathRand.Intn(len(charsPool))] + } + + return strings.Join(buff, "") +} diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 16e5d7c6897..d2d6fc0c379 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3476,10 +3476,11 @@ func getDefaultNodesCoordinator(maxShards uint32, pksBytes map[uint32][]byte) no // GetDefaultEnableEpochsConfig returns a default EnableEpochs config func GetDefaultEnableEpochsConfig() *config.EnableEpochs { return &config.EnableEpochs{ - OptimizeGasUsedInCrossMiniBlocksEnableEpoch: UnreachableEpoch, - ScheduledMiniBlocksEnableEpoch: UnreachableEpoch, - MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, - FailExecutionOnEveryAPIErrorEnableEpoch: UnreachableEpoch, + OptimizeGasUsedInCrossMiniBlocksEnableEpoch: UnreachableEpoch, + ScheduledMiniBlocksEnableEpoch: UnreachableEpoch, + MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, + FailExecutionOnEveryAPIErrorEnableEpoch: UnreachableEpoch, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: UnreachableEpoch, } } diff --git a/integrationTests/testProcessorNodeWithMultisigner.go b/integrationTests/testProcessorNodeWithMultisigner.go index a4cac7eea1b..d76baa7a5aa 100644 --- a/integrationTests/testProcessorNodeWithMultisigner.go +++ b/integrationTests/testProcessorNodeWithMultisigner.go @@ -231,10 +231,11 @@ func CreateNodesWithNodesCoordinatorFactory( } epochsConfig := config.EnableEpochs{ - StakingV2EnableEpoch: UnreachableEpoch, - ScheduledMiniBlocksEnableEpoch: UnreachableEpoch, - MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, - RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, + StakingV2EnableEpoch: UnreachableEpoch, + ScheduledMiniBlocksEnableEpoch: UnreachableEpoch, + MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, + RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: UnreachableEpoch, } nodesMap := make(map[uint32][]*TestProcessorNode) diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index 8bde8afd023..df8851fd31f 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -30,7 +30,9 @@ func TestSCCallCostTransactionCost(t *testing.T) { t.Skip("cannot run with -race -short; requires Wasm VM fix") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() @@ -155,7 +157,9 @@ func TestAsyncESDTTransfer(t *testing.T) { t.Skip("cannot run with -race -short; requires Wasm VM fix") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/asyncCall_multi_test.go b/integrationTests/vm/txsFee/asyncCall_multi_test.go index 86c288696f5..3a3d85bf9b7 100644 --- a/integrationTests/vm/txsFee/asyncCall_multi_test.go +++ b/integrationTests/vm/txsFee/asyncCall_multi_test.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/scheduled" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" "github.com/multiversx/mx-chain-go/state" @@ -459,15 +460,21 @@ func TestAsyncCallTransferESDTAndExecute_CrossShard_Success(t *testing.T) { } func transferESDTAndExecute_CrossShard(t *testing.T, numberOfCallsFromParent int, numberOfBackTransfers int) { - vaultShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + vaultShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer vaultShard.Close() - forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer forwarderShard.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContextSender.Close() diff --git a/integrationTests/vm/txsFee/asyncCall_test.go b/integrationTests/vm/txsFee/asyncCall_test.go index a1cb2fb11a9..c24e9befd0a 100644 --- a/integrationTests/vm/txsFee/asyncCall_test.go +++ b/integrationTests/vm/txsFee/asyncCall_test.go @@ -152,8 +152,9 @@ func TestAsyncCallsOnInitFunctionOnUpgrade(t *testing.T) { gasScheduleNotifier.LatestGasSchedule()[common.BaseOperationCost]["AoTPreparePerByte"]*uint64(len(firstContractCode))/2 enableEpoch := config.EnableEpochs{ - RuntimeCodeSizeFixEnableEpoch: 100000, // fix not activated - SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, + RuntimeCodeSizeFixEnableEpoch: 100000, // fix not activated + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 100000, + SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, } testAsyncCallsOnInitFunctionOnUpgrade(t, enableEpoch, expectedGasLimit, gasScheduleNotifier, newContractCode) @@ -166,8 +167,9 @@ func TestAsyncCallsOnInitFunctionOnUpgrade(t *testing.T) { gasScheduleNotifier.LatestGasSchedule()[common.BaseOperationCost]["AoTPreparePerByte"]*uint64(len(newContractCode))/2 enableEpoch := config.EnableEpochs{ - RuntimeCodeSizeFixEnableEpoch: 0, // fix activated - SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, + RuntimeCodeSizeFixEnableEpoch: 0, // fix activated + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 100000, + SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, } testAsyncCallsOnInitFunctionOnUpgrade(t, enableEpoch, expectedGasLimit, gasScheduleNotifier, newContractCode) @@ -286,8 +288,9 @@ func TestAsyncCallsOnInitFunctionOnDeploy(t *testing.T) { gasScheduleNotifier.LatestGasSchedule()[common.BaseOperationCost]["AoTPreparePerByte"]*uint64(len(firstSCCode))/2 enableEpoch := config.EnableEpochs{ - RuntimeCodeSizeFixEnableEpoch: 100000, // fix not activated - SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, + RuntimeCodeSizeFixEnableEpoch: 100000, // fix not activated + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 100000, + SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, } testAsyncCallsOnInitFunctionOnDeploy(t, enableEpoch, expectedGasLimit, gasScheduleNotifier, pathToSecondSC) @@ -300,8 +303,9 @@ func TestAsyncCallsOnInitFunctionOnDeploy(t *testing.T) { gasScheduleNotifier.LatestGasSchedule()[common.BaseOperationCost]["AoTPreparePerByte"]*uint64(len(secondSCCode))/2 enableEpoch := config.EnableEpochs{ - RuntimeCodeSizeFixEnableEpoch: 0, // fix activated - SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, + RuntimeCodeSizeFixEnableEpoch: 0, // fix activated + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 100000, + SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, } testAsyncCallsOnInitFunctionOnDeploy(t, enableEpoch, expectedGasLimit, gasScheduleNotifier, pathToSecondSC) diff --git a/integrationTests/vm/txsFee/asyncESDT_test.go b/integrationTests/vm/txsFee/asyncESDT_test.go index 06a4d0edbf0..b5f40b32cb7 100644 --- a/integrationTests/vm/txsFee/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/asyncESDT_test.go @@ -15,6 +15,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" "github.com/multiversx/mx-chain-go/process" @@ -25,7 +26,9 @@ import ( ) func TestAsyncESDTCallShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() @@ -182,7 +185,9 @@ func TestAsyncESDTCallsOutOfGas(t *testing.T) { } func TestAsyncMultiTransferOnCallback(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index ccedea5e065..d0481efa871 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -29,7 +29,9 @@ import ( const returnOkData = "@6f6b" func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 10, + }) require.Nil(t, err) defer testContext.Close() @@ -190,11 +192,15 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameFailsCrossShardBackwardsCompat } func TestDeployDNSContract_TestGasWhenSaveUsernameAfterDNSv2IsActivated(t *testing.T) { - testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContextForDNSContract.Close() - testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContextForRelayerAndUser.Close() scAddress, _ := utils.DoDeployDNS(t, testContextForDNSContract, "../../multiShard/smartContract/dns/dns.wasm") diff --git a/integrationTests/vm/txsFee/dynamicGasCost_test.go b/integrationTests/vm/txsFee/dynamicGasCost_test.go new file mode 100644 index 00000000000..b733dec7534 --- /dev/null +++ b/integrationTests/vm/txsFee/dynamicGasCost_test.go @@ -0,0 +1,172 @@ +//go:build !race +// +build !race + +// TODO remove build condition above to allow -race -short, after Wasm VM fix + +package txsFee + +import ( + "encoding/hex" + "fmt" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/data/smartContractResult" + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests" + "github.com/multiversx/mx-chain-go/integrationTests/vm" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" + "github.com/multiversx/mx-chain-go/sharding" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestDynamicGasCostForDataTrieStorageLoad(t *testing.T) { + enableEpochs := config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 0, + } + shardCoordinator, _ := sharding.NewMultiShardCoordinator(3, 1) + gasScheduleNotifier := vm.CreateMockGasScheduleNotifier() + + testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier) + require.Nil(t, err) + defer testContext.Close() + + gasPrice := uint64(10) + + scAddress, _ := utils.DoDeployNoChecks(t, testContext, "../wasm/testdata/trieStoreAndLoad/storage.wasm") + acc := getAccount(t, testContext, scAddress) + require.Nil(t, acc.DataTrie()) + + sndNonce := uint64(0) + sndAddr := []byte("12345678901234567890123456789112") + senderBalance := big.NewInt(100000000) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, sndNonce, senderBalance) + + keys := insertInDataTrie(t, testContext, scAddress, 15) + + dataTrie := getAccountDataTrie(t, testContext, scAddress) + trieKeysDepth := getTrieDepthForKeys(t, dataTrie, keys) + + apiCallsCost := 3 + loadValCost := 32 + wasmOpsCost := 14 + + contractCode := wasm.GetSCCode("../wasm/testdata/trieStoreAndLoad/storage.wasm") + latestGasSchedule := gasScheduleNotifier.LatestGasSchedule() + aotPrepare := latestGasSchedule[common.BaseOperationCost]["AoTPreparePerByte"] * uint64(len(contractCode)) / 2 + + gasCost := int64(apiCallsCost+loadValCost+wasmOpsCost) + int64(aotPrepare) + + for i, key := range keys { + trieLoadCost := getExpectedConsumedGasForTrieLoad(testContext, int64(trieKeysDepth[i])) + + expectedGasCost := trieLoadCost + gasCost + + fmt.Println("trie level", trieKeysDepth[i]) + gasLimit := uint64(trieLoadCost) + 10000 + testGasConsumedForDataTrieLoad(t, testContext, sndNonce, key, sndAddr, scAddress, gasPrice, gasLimit, expectedGasCost) + sndNonce++ + } +} + +func insertInDataTrie( + t *testing.T, + testContext *vm.VMTestContext, + accAddr []byte, + maxTrieLevel int, +) [][]byte { + acc := getAccount(t, testContext, accAddr) + keys := integrationTests.GenerateTrieKeysForMaxLevel(maxTrieLevel, 2) + for _, key := range keys { + err := acc.SaveKeyValue(key, key) + require.Nil(t, err) + } + + err := testContext.Accounts.SaveAccount(acc) + require.Nil(t, err) + + return keys +} + +func testGasConsumedForDataTrieLoad( + t *testing.T, + testContext *vm.VMTestContext, + nonce uint64, + key []byte, + sndAddr []byte, + scAddress []byte, + gasPrice uint64, + gasLimit uint64, + expectedGasConsumed int64, +) { + testContext.CleanIntermediateTransactions(t) + + txData := []byte("trieLoad@" + hex.EncodeToString(key) + "@aa@bb@00") + scr := &smartContractResult.SmartContractResult{ + Nonce: nonce, + Value: big.NewInt(0), + RcvAddr: scAddress, + SndAddr: sndAddr, + Data: txData, + GasLimit: gasLimit, + GasPrice: gasPrice, + CallType: 1, + } + returnCode, errProcess := testContext.ScProcessor.ProcessSmartContractResult(scr) + require.Nil(t, errProcess) + require.Equal(t, vmcommon.Ok, returnCode) + + intermediate := testContext.GetIntermediateTransactions(t) + require.Equal(t, 1, len(intermediate)) + + gasConsumed := gasLimit - intermediate[0].GetGasLimit() + fmt.Println("gas consumed", gasConsumed) + fmt.Println("expected gas consumed", expectedGasConsumed) + require.Equal(t, uint64(expectedGasConsumed), gasConsumed) + +} + +func getTrieDepthForKeys(t *testing.T, tr common.Trie, keys [][]byte) []uint32 { + trieLevels := make([]uint32, len(keys)) + for i, key := range keys { + _, depth, err := tr.Get(integrationTests.TestHasher.Compute(string(key))) + require.Nil(t, err) + trieLevels[i] = depth + } + + return trieLevels +} + +type funcParams struct { + Quadratic int64 + Linear int64 + Constant int64 +} + +func getExpectedConsumedGasForTrieLoad(testContext *vm.VMTestContext, trieLevel int64) int64 { + gasSchedule := testContext.GasSchedule.LatestGasSchedule() + f := getFunc(gasSchedule) + + return trieLevel*trieLevel*f.Quadratic + trieLevel*f.Linear + f.Constant +} + +func getFunc(gasSchedule map[string]map[string]uint64) funcParams { + dynamicStorageLoad := gasSchedule["DynamicStorageLoad"] + return funcParams{ + Quadratic: getSignedCoefficient(dynamicStorageLoad["QuadraticCoefficient"], dynamicStorageLoad["SignOfQuadratic"]), + Linear: getSignedCoefficient(dynamicStorageLoad["LinearCoefficient"], dynamicStorageLoad["SignOfLinear"]), + Constant: getSignedCoefficient(dynamicStorageLoad["ConstantCoefficient"], dynamicStorageLoad["SignOfConstant"]), + } +} + +func getSignedCoefficient(coefficient uint64, sign uint64) int64 { + isNegativeNumber := uint64(1) + if sign == isNegativeNumber { + return int64(coefficient) * -1 + } + + return int64(coefficient) +} diff --git a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go index 5292d3f60a9..bc81d980a54 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go @@ -22,15 +22,19 @@ func TestAsyncCallShouldWork(t *testing.T) { t.Skip("cannot run with -race -short; requires Wasm VM fix") } - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + enableEpochs := config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + } + + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) require.Nil(t, err) defer testContextSecondContract.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) require.Nil(t, err) defer testContextSender.Close() diff --git a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go index 994eff7abc4..b9790925c06 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -18,15 +19,19 @@ import ( ) func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + enableEpochs := config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + } + + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) require.Nil(t, err) defer testContextSender.Close() - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) require.Nil(t, err) defer testContextSecondContract.Close() @@ -126,15 +131,19 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { } func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + enableEpochs := config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + } + + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) require.Nil(t, err) defer testContextSender.Close() - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) require.Nil(t, err) defer testContextSecondContract.Close() diff --git a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go index 2cd4a498ea4..ea14882730b 100644 --- a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go @@ -39,7 +39,8 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( 0, config.EnableEpochs{ - PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, + PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) require.Nil(t, err) defer testContextSource.Close() @@ -47,7 +48,8 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( 1, config.EnableEpochs{ - PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, + PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go index 8fa22d254cd..21903455982 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go @@ -28,15 +28,19 @@ import ( // 4. Execute SCR with the smart contract call on shard 1 // 5. Execute SCR with refund on relayer shard (shard 2) func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { - testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + enableEpochs := config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + } + + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) require.Nil(t, err) defer testContextRelayer.Close() - testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) require.Nil(t, err) defer testContextInnerSource.Close() - testContextInnerDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextInnerDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) require.Nil(t, err) defer testContextInnerDst.Close() diff --git a/integrationTests/vm/txsFee/multiShard/scCalls_test.go b/integrationTests/vm/txsFee/multiShard/scCalls_test.go index 19800b43f54..27beb349823 100644 --- a/integrationTests/vm/txsFee/multiShard/scCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCalls_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -17,11 +18,15 @@ import ( ) func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + enableEpochs := config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + } + + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) require.Nil(t, err) defer testContextSource.Close() - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go index 3a447d0d361..a479d8611d9 100644 --- a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go @@ -19,7 +19,9 @@ import ( ) func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index 084fe4d9469..414e165c202 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -20,7 +20,9 @@ import ( ) func TestRelayedScCallShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index 2473a8f430e..ab8cba5cad5 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -60,11 +60,12 @@ func prepareTestContextForEpoch836(tb testing.TB) (*vm.VMTestContext, []byte) { testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGasAndRoundConfig( config.EnableEpochs{ - GovernanceEnableEpoch: unreachableEpoch, - WaitingListFixEnableEpoch: unreachableEpoch, - SetSenderInEeiOutputTransferEnableEpoch: unreachableEpoch, - RefactorPeersMiniBlocksEnableEpoch: unreachableEpoch, - MaxBlockchainHookCountersEnableEpoch: unreachableEpoch, + GovernanceEnableEpoch: unreachableEpoch, + WaitingListFixEnableEpoch: unreachableEpoch, + SetSenderInEeiOutputTransferEnableEpoch: unreachableEpoch, + RefactorPeersMiniBlocksEnableEpoch: unreachableEpoch, + MaxBlockchainHookCountersEnableEpoch: unreachableEpoch, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: unreachableEpoch, }, mock.NewMultiShardsCoordinatorMock(2), db, @@ -90,7 +91,9 @@ func prepareTestContextForEpoch836(tb testing.TB) (*vm.VMTestContext, []byte) { } func TestScCallShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() @@ -261,7 +264,9 @@ func TestScCallOutOfGasShouldConsumeGas(t *testing.T) { } func TestScCallAndGasChangeShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/wasm/testdata/trieStoreAndLoad/storage.wasm b/integrationTests/vm/wasm/testdata/trieStoreAndLoad/storage.wasm new file mode 100755 index 00000000000..c72cba9fe79 Binary files /dev/null and b/integrationTests/vm/wasm/testdata/trieStoreAndLoad/storage.wasm differ diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index d4276fe0735..4d39ae3555f 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -148,7 +148,9 @@ func SetupTestContextWithGasSchedule(t *testing.T, gasSchedule map[string]map[st context.T = t context.Round = 500 context.EpochNotifier = &epochNotifier.EpochNotifierStub{} - context.EnableEpochsHandler, _ = enablers.NewEnableEpochsHandler(config.EnableEpochs{}, context.EpochNotifier) + context.EnableEpochsHandler, _ = enablers.NewEnableEpochsHandler(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + }, context.EpochNotifier) context.RoundNotifier = &epochNotifier.RoundNotifierStub{} context.EnableRoundsHandler, _ = enablers.NewEnableRoundsHandler(integrationTests.GetDefaultRoundsConfig(), context.RoundNotifier) context.WasmVMChangeLocker = &sync.RWMutex{} diff --git a/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index 45da1c8f2ec..f78ecfaac96 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -618,6 +618,11 @@ func (mock *EnableEpochsHandlerMock) IsDeterministicSortOnValidatorsInfoFixEnabl return false } +// IsDynamicGasCostForDataTrieStorageLoadEnabled - +func (mock *EnableEpochsHandlerMock) IsDynamicGasCostForDataTrieStorageLoadEnabled() bool { + return false +} + // IsInterfaceNil returns true if there is no value under the interface func (mock *EnableEpochsHandlerMock) IsInterfaceNil() bool { return mock == nil diff --git a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go index 125ad72b24b..a1d2eb1ddc7 100644 --- a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go +++ b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go @@ -127,6 +127,7 @@ type EnableEpochsHandlerStub struct { IsConsistentTokensValuesLengthCheckEnabledField bool IsAutoBalanceDataTriesEnabledField bool FixDelegationChangeOwnerOnAccountEnabledField bool + IsDynamicGasCostForDataTrieStorageLoadEnabledField bool } // ResetPenalizedTooMuchGasFlag - @@ -1016,6 +1017,14 @@ func (stub *EnableEpochsHandlerStub) IsMaxBlockchainHookCountersFlagEnabled() bo return stub.IsMaxBlockchainHookCountersFlagEnabledField } +// IsDynamicGasCostForDataTrieStorageLoadEnabled - +func (stub *EnableEpochsHandlerStub) IsDynamicGasCostForDataTrieStorageLoadEnabled() bool { + stub.RLock() + defer stub.RUnlock() + + return stub.IsMaxBlockchainHookCountersFlagEnabledField +} + // IsWipeSingleNFTLiquidityDecreaseEnabled - func (stub *EnableEpochsHandlerStub) IsWipeSingleNFTLiquidityDecreaseEnabled() bool { stub.RLock()