Skip to content

Commit

Permalink
Merge pull request #4804 from multiversx/dynamic-gas-data-trie-loads
Browse files Browse the repository at this point in the history
Dynamic gas data trie loads
  • Loading branch information
gabi-vuls authored Aug 18, 2023
2 parents 44c0f9c + 12a225a commit f7045ec
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()
}
1 change: 1 addition & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,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.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
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.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=
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
Loading

0 comments on commit f7045ec

Please sign in to comment.