Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ab89ffd
remove maxTrieLevelInMemory
BeniaminDrasovean Jun 23, 2025
bed6022
collapse only trie leaves
BeniaminDrasovean Jun 23, 2025
5b38d5b
Merge branch 'rc/barnard' into collapse-only-trie-leaves
BeniaminDrasovean Jun 23, 2025
2ae19ca
fix trie nodes sizeInBytes computation
BeniaminDrasovean Jun 26, 2025
df6a66f
Merge branch 'rc/barnard' into collapse-only-trie-leaves
BeniaminDrasovean Jun 26, 2025
2afc0b8
use trieMetricsCollector to retrieve maxDepth on tryGet func
BeniaminDrasovean Jun 26, 2025
a308770
compute trie size in memory for each operation
BeniaminDrasovean Jul 14, 2025
8c480b8
change how trie node sizeInBytes is computed
BeniaminDrasovean Jul 14, 2025
5aa6b54
add tests for trieMetricsCollector package
BeniaminDrasovean Jul 14, 2025
120e6be
add TODO
BeniaminDrasovean Jul 14, 2025
93e99a8
trie Get add size in memory
BeniaminDrasovean Jul 14, 2025
d8281d5
add test and fixes
BeniaminDrasovean Jul 14, 2025
2925bbb
Merge branch 'rc/barnard' into collapse-only-trie-leaves
BeniaminDrasovean Jul 15, 2025
dd48365
Merge branch 'feat/collapse-trie-based-on-size' into collapse-only-tr…
BeniaminDrasovean Aug 12, 2025
2279330
sort imports
BeniaminDrasovean Aug 12, 2025
4e58d5f
fix after review
BeniaminDrasovean Aug 12, 2025
65c8aa5
dataTriesHolder as linked list
BeniaminDrasovean Aug 14, 2025
3be4806
fixes after review
BeniaminDrasovean Sep 2, 2025
b78c176
add eviction and unit tests
BeniaminDrasovean Sep 3, 2025
621f6f9
keep totalSizeInMemory updated between commits
BeniaminDrasovean Sep 4, 2025
c55760b
add size limits to config
BeniaminDrasovean Oct 2, 2025
d4eb6a2
create dataTriesHolder with size read from config
BeniaminDrasovean Oct 8, 2025
a1a9635
use existing cacher instead of linked list
BeniaminDrasovean Oct 14, 2025
5bfd75f
fix cyclic imports
BeniaminDrasovean Oct 14, 2025
dc8dc6e
add nil check for inserted data
BeniaminDrasovean Oct 14, 2025
dc3baf5
fix after review
BeniaminDrasovean Mar 2, 2026
813d89f
fix after review
BeniaminDrasovean Mar 2, 2026
fe6d54f
remove redundant assign
BeniaminDrasovean Mar 2, 2026
b76ef46
Merge pull request #7187 from multiversx/collect-trie-size-in-mem
BeniaminDrasovean Mar 2, 2026
19947e6
Merge branch 'feat/supernova-async-exec' into feat/collapse-trie-base…
BeniaminDrasovean Mar 3, 2026
b01b375
fix after merge
BeniaminDrasovean Mar 3, 2026
b4719c0
Merge branch 'feat/supernova-async-exec' into merge-feat/supernova-as…
BeniaminDrasovean Mar 3, 2026
7750bac
Merge pull request #7784 from multiversx/merge-feat/supernova-asyn-ex…
AdoAdoAdo Mar 3, 2026
beebe58
Merge branch 'feat/collapse-trie-based-on-size' into collapse-trie-ba…
BeniaminDrasovean Mar 3, 2026
19f9527
fix after merge
BeniaminDrasovean Mar 3, 2026
ad74409
fix linter issues
BeniaminDrasovean Mar 3, 2026
17870e2
fix typo in test
BeniaminDrasovean Mar 3, 2026
96ad288
fix after review
BeniaminDrasovean Mar 12, 2026
a1758e0
Merge pull request #7191 from multiversx/collapse-trie-based-on-size
BeniaminDrasovean Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,10 @@
SnapshotsEnabled = true
AccountsStatePruningEnabled = false
PeerStatePruningEnabled = true
MaxStateTrieLevelInMemory = 5
MaxPeerTrieLevelInMemory = 5
StateStatisticsEnabled = false
MaxUserTrieSizeInMemory = 524288000 #500MB
MaxPeerTrieSizeInMemory = 104857600 #100MB
DataTriesSizeInMemory = 524288000 #500MB

[TrieLeavesRetrieverConfig]
Enabled = false
Expand Down
3 changes: 3 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
nonceIndex = 0
)

// TenMbSize defines the size of 10 megabytes in bytes, used as a constant for memory limits or buffer sizes
const TenMbSize = uint64(10485760)

type executionResultHandler interface {
GetMiniBlockHeadersHandlers() []data.MiniBlockHeaderHandler
}
Expand Down
2 changes: 1 addition & 1 deletion common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Trie interface {
VerifyProof(rootHash []byte, key []byte, proof [][]byte) (bool, error)
GetStorageManager() StorageManager
IsMigratedToLatestVersion() (bool, error)
SizeInMemory() int
Close() error
IsInterfaceNil() bool
}
Expand Down Expand Up @@ -151,7 +152,6 @@ type SnapshotDbHandler interface {
// TriesHolder is used to store multiple tries
type TriesHolder interface {
Put([]byte, Trie)
Replace(key []byte, tr Trie)
Get([]byte) Trie
GetAll() []Trie
Reset()
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,10 @@ type StateTriesConfig struct {
SnapshotsEnabled bool
AccountsStatePruningEnabled bool
PeerStatePruningEnabled bool
MaxStateTrieLevelInMemory uint
MaxPeerTrieLevelInMemory uint
StateStatisticsEnabled bool
MaxUserTrieSizeInMemory uint64
MaxPeerTrieSizeInMemory uint64
DataTriesSizeInMemory uint64
}

// StateAccessesCollectorConfig will hold information about state accesses collector
Expand Down
4 changes: 0 additions & 4 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ func TestTomlParser(t *testing.T) {
SnapshotsEnabled: true,
AccountsStatePruningEnabled: true,
PeerStatePruningEnabled: true,
MaxStateTrieLevelInMemory: 38,
MaxPeerTrieLevelInMemory: 39,
},
TxCacheBounds: TxCacheBoundsConfig{
MaxNumBytesPerSenderUpperBound: 33_554_432,
Expand Down Expand Up @@ -630,8 +628,6 @@ func TestTomlParser(t *testing.T) {
SnapshotsEnabled = true
AccountsStatePruningEnabled = true
PeerStatePruningEnabled = true
MaxStateTrieLevelInMemory = 38
MaxPeerTrieLevelInMemory = 39
`
cfg := Config{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/multiversx/mx-chain-go/dataRetriever/mock"
"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-go/process/factory"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/triesHolder"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/cache"
Expand Down Expand Up @@ -86,10 +86,10 @@ func createStoreForMeta() dataRetriever.StorageService {
}

func createTriesHolderForMeta() common.TriesHolder {
triesHolder := state.NewDataTriesHolder()
triesHolder.Put([]byte(dataRetriever.UserAccountsUnit.String()), &trieMock.TrieStub{})
triesHolder.Put([]byte(dataRetriever.PeerAccountsUnit.String()), &trieMock.TrieStub{})
return triesHolder
triesContainer := triesHolder.NewTriesHolder()
triesContainer.Put([]byte(dataRetriever.UserAccountsUnit.String()), &trieMock.TrieStub{})
triesContainer.Put([]byte(dataRetriever.PeerAccountsUnit.String()), &trieMock.TrieStub{})
return triesContainer
}

// ------- NewResolversContainerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/multiversx/mx-chain-go/dataRetriever/mock"
"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-go/process/factory"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/triesHolder"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/cache"
Expand Down Expand Up @@ -92,10 +92,10 @@ func createStoreForShard() dataRetriever.StorageService {
}

func createTriesHolderForShard() common.TriesHolder {
triesHolder := state.NewDataTriesHolder()
triesHolder.Put([]byte(dataRetriever.UserAccountsUnit.String()), &trieMock.TrieStub{})
triesHolder.Put([]byte(dataRetriever.PeerAccountsUnit.String()), &trieMock.TrieStub{})
return triesHolder
triesContainer := triesHolder.NewTriesHolder()
triesContainer.Put([]byte(dataRetriever.UserAccountsUnit.String()), &trieMock.TrieStub{})
triesContainer.Put([]byte(dataRetriever.PeerAccountsUnit.String()), &trieMock.TrieStub{})
return triesContainer
}

// ------- NewResolversContainerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ func getArgumentsMeta() storagerequesterscontainer.FactoryArgs {
StateTriesConfig: config.StateTriesConfig{
AccountsStatePruningEnabled: false,
PeerStatePruningEnabled: false,
MaxStateTrieLevelInMemory: 5,
MaxPeerTrieLevelInMemory: 5,
},
},
ShardIDForTries: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ func getArgumentsShard() storagerequesterscontainer.FactoryArgs {
StateTriesConfig: config.StateTriesConfig{
AccountsStatePruningEnabled: false,
PeerStatePruningEnabled: false,
MaxStateTrieLevelInMemory: 5,
MaxPeerTrieLevelInMemory: 5,
},
},
ShardIDForTries: 0,
Expand Down
9 changes: 3 additions & 6 deletions epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/typeConverters/uint64ByteSlice"
"github.com/multiversx/mx-chain-go/state/triesHolder"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/process/interceptors/processor"

"github.com/multiversx/mx-chain-go/common"
disabledCommon "github.com/multiversx/mx-chain-go/common/disabled"
"github.com/multiversx/mx-chain-go/common/ordering"
Expand All @@ -42,11 +41,11 @@ import (
"github.com/multiversx/mx-chain-go/process/heartbeat/validator"
"github.com/multiversx/mx-chain-go/process/interceptors"
disabledInterceptors "github.com/multiversx/mx-chain-go/process/interceptors/disabled"
"github.com/multiversx/mx-chain-go/process/interceptors/processor"
"github.com/multiversx/mx-chain-go/process/peer"
"github.com/multiversx/mx-chain-go/redundancy"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/syncer"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/storage/cache"
Expand Down Expand Up @@ -283,7 +282,7 @@ func NewEpochStartBootstrap(args ArgsEpochStartBootstrap) (*epochStartBootstrap,
return nil, err
}

epochStartProvider.trieContainer = state.NewDataTriesHolder()
epochStartProvider.trieContainer = triesHolder.NewTriesHolder()
epochStartProvider.trieStorageManagers = make(map[string]common.StorageManager)

if epochStartProvider.generalConfig.Hardfork.AfterHardFork {
Expand Down Expand Up @@ -1573,7 +1572,6 @@ func (e *epochStartBootstrap) syncUserAccountsState(rootHash []byte) error {
RequestHandler: e.requestHandler,
Timeout: common.TimeoutGettingTrieNodes,
Cacher: e.dataPool.TrieNodes(),
MaxTrieLevelInMemory: e.generalConfig.StateTriesConfig.MaxStateTrieLevelInMemory,
MaxHardCapForMissingNodes: e.maxHardCapForMissingNodes,
TrieSyncerVersion: e.trieSyncerVersion,
CheckNodesOnDisk: e.checkNodesOnDisk,
Expand Down Expand Up @@ -1647,7 +1645,6 @@ func (e *epochStartBootstrap) syncValidatorAccountsState(rootHash []byte) error
RequestHandler: e.requestHandler,
Timeout: common.TimeoutGettingTrieNodes,
Cacher: e.dataPool.TrieNodes(),
MaxTrieLevelInMemory: e.generalConfig.StateTriesConfig.MaxPeerTrieLevelInMemory,
MaxHardCapForMissingNodes: e.maxHardCapForMissingNodes,
TrieSyncerVersion: e.trieSyncerVersion,
CheckNodesOnDisk: e.checkNodesOnDisk,
Expand Down
5 changes: 3 additions & 2 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ func createMockEpochStartBootstrapArgs(
AccountsStatePruningEnabled: true,
SnapshotsEnabled: true,
PeerStatePruningEnabled: true,
MaxStateTrieLevelInMemory: 5,
MaxPeerTrieLevelInMemory: 5,
MaxUserTrieSizeInMemory: generalCfg.StateTriesConfig.MaxUserTrieSizeInMemory,
MaxPeerTrieSizeInMemory: generalCfg.StateTriesConfig.MaxPeerTrieSizeInMemory,
DataTriesSizeInMemory: generalCfg.StateTriesConfig.DataTriesSizeInMemory,
},
TrieStorageManagerConfig: config.TrieStorageManagerConfig{
PruningBufferLen: 1000,
Expand Down
5 changes: 2 additions & 3 deletions epochStart/metachain/baseRewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
"github.com/multiversx/mx-chain-go/testscommon/shardingMocks"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
"github.com/multiversx/mx-chain-go/testscommon/storage"
"github.com/multiversx/mx-chain-go/trie"
)

Expand Down Expand Up @@ -1140,11 +1139,11 @@ func getBaseRewardsArguments() BaseRewardsCreatorArgs {
hasher := sha256.NewSha256()
marshalizer := &marshal.GogoProtoMarshalizer{}

storageManagerArgs := storage.GetStorageManagerArgs()
storageManagerArgs := txExecOrderStub.GetStorageManagerArgs()
storageManagerArgs.Marshalizer = marshalizer
storageManagerArgs.Hasher = hasher

trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, storage.GetStorageManagerOptions())
trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, txExecOrderStub.GetStorageManagerOptions())
argsAccCreator := factory.ArgsAccountCreator{
Hasher: hasher,
Marshaller: marshalizer,
Expand Down
25 changes: 14 additions & 11 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
storageFactory "github.com/multiversx/mx-chain-go/storage/factory"
"github.com/multiversx/mx-chain-go/storage/storageunit"
"github.com/multiversx/mx-chain-go/testscommon"
testCommon "github.com/multiversx/mx-chain-go/testscommon/common"
"github.com/multiversx/mx-chain-go/testscommon/cryptoMocks"
dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
Expand Down Expand Up @@ -748,7 +749,8 @@ func createAccountsDB(
trieStorageManager common.StorageManager,
enableEpochsHandler common.EnableEpochsHandler,
) *state.AccountsDB {
tr, _ := trie.NewTrie(trieStorageManager, marshaller, hasher, enableEpochsHandler, 5)
tenMbSize := uint64(10485760)
tr, _ := trie.NewTrie(trieStorageManager, marshaller, hasher, enableEpochsHandler, tenMbSize)
ewlArgs := evictionWaitingList.MemoryEvictionWaitingListArgs{
RootHashesSize: 100,
HashesSize: 10000,
Expand All @@ -757,14 +759,15 @@ func createAccountsDB(
spm, _ := storagePruningManager.NewStoragePruningManager(ewl, 10)

args := state.ArgsAccountsDB{
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: accountFactory,
StoragePruningManager: spm,
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
StateAccessesCollector: disabledState.NewDisabledStateAccessesCollector(),
Trie: tr,
Hasher: hasher,
Marshaller: marshaller,
AccountFactory: accountFactory,
StoragePruningManager: spm,
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
StateAccessesCollector: disabledState.NewDisabledStateAccessesCollector(),
MaxDataTriesSizeInMemory: tenMbSize,
}
adb, _ := state.NewAccountsDB(args)
return adb
Expand All @@ -773,12 +776,12 @@ func createAccountsDB(
func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEpochs, trieStorer storage.Storer) (ArgsNewEpochStartSystemSCProcessing, vm.SystemSCContainer) {
hasher := sha256.NewSha256()
marshalizer := &marshal.GogoProtoMarshalizer{}
storageManagerArgs := storageMock.GetStorageManagerArgs()
storageManagerArgs := testCommon.GetStorageManagerArgs()
storageManagerArgs.Marshalizer = marshalizer
storageManagerArgs.Hasher = hasher
storageManagerArgs.MainStorer = trieStorer

trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, storageMock.GetStorageManagerOptions())
trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, testCommon.GetStorageManagerOptions())
argsAccCreator := factory.ArgsAccountCreator{
Hasher: hasher,
Marshaller: marshalizer,
Expand Down
20 changes: 11 additions & 9 deletions factory/api/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,27 +589,29 @@ func createNewAccountsAdapterApi(args scQueryElementArgs, chainHandler data.Chai
trieCreatorArgs := trieFactory.TrieCreateArgs{
MainStorer: trieStorer,
PruningEnabled: args.generalConfig.StateTriesConfig.AccountsStatePruningEnabled,
MaxTrieLevelInMem: args.generalConfig.StateTriesConfig.MaxStateTrieLevelInMemory,
SnapshotsEnabled: args.generalConfig.StateTriesConfig.SnapshotsEnabled,
IdleProvider: args.coreComponents.ProcessStatusHandler(),
Identifier: dataRetriever.UserAccountsUnit.String(),
EnableEpochsHandler: args.coreComponents.EnableEpochsHandler(),
StatsCollector: args.statusCoreComponents.StateStatsHandler(),
MaxSizeInMemory: args.generalConfig.StateTriesConfig.MaxUserTrieSizeInMemory,
}
trieStorageManager, merkleTrie, err := trFactory.Create(trieCreatorArgs)
if err != nil {
return nil, nil, err
}

argsAPIAccountsDB := state.ArgsAccountsDB{
Trie: merkleTrie,
Hasher: args.coreComponents.Hasher(),
Marshaller: args.coreComponents.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
AddressConverter: args.coreComponents.AddressPubKeyConverter(),
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
StateAccessesCollector: disabledState.NewDisabledStateAccessesCollector(),
Trie: merkleTrie,
Hasher: args.coreComponents.Hasher(),
Marshaller: args.coreComponents.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
AddressConverter: args.coreComponents.AddressPubKeyConverter(),
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
StateAccessesCollector: disabledState.NewDisabledStateAccessesCollector(),
// TODO check if this should be lower than in the processing adb
MaxDataTriesSizeInMemory: args.generalConfig.StateTriesConfig.DataTriesSizeInMemory,
}

provider, err := blockInfoProviders.NewCurrentBlockInfo(chainHandler)
Expand Down
9 changes: 7 additions & 2 deletions factory/api/apiResolverFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import (
"github.com/stretchr/testify/require"
)

const unreachableStep = 10000
const (
unreachableStep = 10000
tenMBSize = uint64(10485760)
)

type failingSteps struct {
marshallerStepCounter int
Expand Down Expand Up @@ -306,7 +309,9 @@ func createMockSCQueryElementArgs() api.SCQueryElementArgs {
SnapshotsGoroutineNum: 1,
},
StateTriesConfig: config.StateTriesConfig{
MaxStateTrieLevelInMemory: 5,
MaxUserTrieSizeInMemory: tenMBSize,
MaxPeerTrieSizeInMemory: tenMBSize,
DataTriesSizeInMemory: tenMBSize,
},
VirtualMachine: config.VirtualMachineServicesConfig{
Querying: config.QueryVirtualMachineConfig{
Expand Down
1 change: 0 additions & 1 deletion factory/consensus/consensusComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ func (ccf *consensusComponentsFactory) createArgsBaseAccountsSyncer(trieStorageM
RequestHandler: ccf.processComponents.RequestHandler(),
Timeout: common.TimeoutGettingTrieNodes,
Cacher: ccf.dataComponents.Datapool().TrieNodes(),
MaxTrieLevelInMemory: ccf.config.StateTriesConfig.MaxStateTrieLevelInMemory,
MaxHardCapForMissingNodes: ccf.config.TrieSync.MaxHardCapForMissingNodes,
TrieSyncerVersion: ccf.config.TrieSync.TrieSyncerVersion,
CheckNodesOnDisk: ccf.config.TrieSync.CheckNodesOnDisk,
Expand Down
Loading
Loading