Skip to content

Commit

Permalink
Merge 2a6908a into 7c5d69e
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniaminDrasovean committed Aug 16, 2023
2 parents 7c5d69e + 2a6908a commit 8a46f6e
Show file tree
Hide file tree
Showing 37 changed files with 504 additions and 137 deletions.
3 changes: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV5.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV6.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions cmd/node/config/gasSchedules/gasScheduleV7.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions common/enablers/epochFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type epochFlagsHolder struct {
consistentTokensValuesCheckFlag *atomic.Flag
autoBalanceDataTriesFlag *atomic.Flag
fixDelegationChangeOwnerOnAccountFlag *atomic.Flag
dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag
}

func newEpochFlagsHolder() *epochFlagsHolder {
Expand Down Expand Up @@ -199,6 +200,7 @@ func newEpochFlagsHolder() *epochFlagsHolder {
changeUsernameFlag: &atomic.Flag{},
autoBalanceDataTriesFlag: &atomic.Flag{},
fixDelegationChangeOwnerOnAccountFlag: &atomic.Flag{},
dynamicGasCostForDataTrieStorageLoadFlag: &atomic.Flag{},
}
}

Expand Down Expand Up @@ -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()

Check warning on line 737 in common/enablers/epochFlags.go

View check run for this annotation

Codecov / codecov/patch

common/enablers/epochFlags.go#L736-L737

Added lines #L736 - L737 were not covered by tests
}
1 change: 1 addition & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type EnableEpochsHandler interface {
IsChangeUsernameEnabled() bool
IsConsistentTokensValuesLengthCheckEnabled() bool
IsAutoBalanceDataTriesEnabled() bool
IsDynamicGasCostForDataTrieStorageLoadEnabled() bool
FixDelegationChangeOwnerOnAccountEnabled() bool

IsInterfaceNil() bool
Expand Down
1 change: 1 addition & 0 deletions config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type EnableEpochs struct {
AutoBalanceDataTriesEnableEpoch uint32
ConsistentTokensValuesLengthCheckEnableEpoch uint32
FixDelegationChangeOwnerOnAccountEnableEpoch uint32
DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32
BLSMultiSignerEnableEpoch []MultiSignerConfig
}

Expand Down
97 changes: 51 additions & 46 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -931,6 +935,7 @@ func TestEnableEpochConfig(t *testing.T) {
},
},
DeterministicSortOnValidatorsInfoEnableEpoch: 66,
DynamicGasCostForDataTrieStorageLoadEnableEpoch: 64,
BLSMultiSignerEnableEpoch: []MultiSignerConfig{
{
EnableEpoch: 0,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/multiversx/mx-chain-logger-go v1.0.11
github.com/multiversx/mx-chain-scenario-go v1.1.2
github.com/multiversx/mx-chain-storage-go v1.0.11
github.com/multiversx/mx-chain-vm-common-go v1.5.0
github.com/multiversx/mx-chain-vm-go v1.5.4
github.com/multiversx/mx-chain-vm-common-go v1.5.1-0.20230627123208-2baa0a0fb7a0
github.com/multiversx/mx-chain-vm-go v1.5.5-0.20230816130435-65715d4802fa
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.59
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.60
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.86
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ github.com/multiversx/mx-chain-scenario-go v1.1.2 h1:6Mok/W48r5lBlqJfriFFhDO5UiY
github.com/multiversx/mx-chain-scenario-go v1.1.2/go.mod h1:xl+aL6n3aibMtfJH3hFGxzddWmn1hEx2Fg0c6ahoQvU=
github.com/multiversx/mx-chain-storage-go v1.0.11 h1:u4ZsfIXEU3nJWRUxyAswhBn2pT6tJkKRwf9pra4CpzA=
github.com/multiversx/mx-chain-storage-go v1.0.11/go.mod h1:VP9fwyFBmbmDzahUuu0IeGX/dKG3iBWjN6FSQ6YtVaI=
github.com/multiversx/mx-chain-vm-common-go v1.5.0 h1:AG2uG/13DjULAb4PvGHynhG3xjjfCF4lwxr2LRULj9I=
github.com/multiversx/mx-chain-vm-common-go v1.5.0/go.mod h1:cnMvZN8+4oDkjloTZVExlf8ShkMGWbbDb5/D//wLT/k=
github.com/multiversx/mx-chain-vm-go v1.5.4 h1:V9Ug4grgPdVjkvRSLQm8edyFi4JqPiDqtHEdAG4JYBA=
github.com/multiversx/mx-chain-vm-go v1.5.4/go.mod h1:UJoOzoYi6fZDazRY4r/g4GZnEVGT7DTnD14Wv1WO8Wo=
github.com/multiversx/mx-chain-vm-common-go v1.5.1-0.20230627123208-2baa0a0fb7a0 h1:lAzo5pc1HyfL6RO8HTsHAjGsGzpl0BoiV7y6iKznU+c=
github.com/multiversx/mx-chain-vm-common-go v1.5.1-0.20230627123208-2baa0a0fb7a0/go.mod h1:cnMvZN8+4oDkjloTZVExlf8ShkMGWbbDb5/D//wLT/k=
github.com/multiversx/mx-chain-vm-go v1.5.5-0.20230816130435-65715d4802fa h1:YW6UXccIb3QuMe3KYTBCFk9VTlm8KtSdLCclsmGiY6E=
github.com/multiversx/mx-chain-vm-go v1.5.5-0.20230816130435-65715d4802fa/go.mod h1:6ik/9COMvRjsvS1KJuGe2e9FmfUa18I93P9vm1/ycH0=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.59 h1:vbsVspKWU0IQBo+mFBH9LCqAtkZqPQy73qdVAhpy2Bc=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.59/go.mod h1:3ABXSSfMOcdPApGoArfnVGz1BfcJgyWd8Ip2D0FZPNE=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.60 h1:1zW2c3lAt7by5fNl3T4u79z2LHyNtgsoMShTucmeNa4=
Expand Down
38 changes: 5 additions & 33 deletions integrationTests/benchmarks/loadFromTrie_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package benchmarks

import (
"encoding/hex"
"fmt"
"math/rand"
"strings"
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/hashing"
"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"
Expand All @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8a46f6e

Please sign in to comment.