Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 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
151d3d4
implement collapse manager
BeniaminDrasovean Oct 27, 2025
04762c5
add unit tests and comments for the collapse manager implementations
BeniaminDrasovean Oct 27, 2025
8569c67
fix failing tests
BeniaminDrasovean Oct 27, 2025
1987ca5
add unit tests and use ctx for collapsing
BeniaminDrasovean Oct 28, 2025
1bb6309
serialize collapsing
BeniaminDrasovean Oct 29, 2025
040f204
comments update
BeniaminDrasovean Dec 15, 2025
afae922
cache data tries between blocks
BeniaminDrasovean Dec 16, 2025
e1466b2
remove commented code
BeniaminDrasovean Dec 16, 2025
0460add
remove tests logging
BeniaminDrasovean Dec 16, 2025
26113fb
add logging for data tries holder
BeniaminDrasovean Dec 18, 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
a971823
Merge branch 'collapse-trie-based-on-size' into collapse-main-trie-le…
BeniaminDrasovean Mar 4, 2026
1b82639
fix after merge
BeniaminDrasovean Mar 4, 2026
ba75b3f
remove unused variable
BeniaminDrasovean Mar 5, 2026
2fd4f2d
Merge remote-tracking branch 'origin/collapse-main-trie-leaves' into …
BeniaminDrasovean Mar 9, 2026
0d50a61
fix after merge
BeniaminDrasovean Mar 9, 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
f48d88f
Merge remote-tracking branch 'origin/feat/collapse-trie-based-on-size…
BeniaminDrasovean Mar 17, 2026
3d38337
fix after review
BeniaminDrasovean Mar 23, 2026
4054754
fix after review
BeniaminDrasovean Mar 30, 2026
bc1f7f4
pass the dataTriesCache to the accountsCreator and load data tries on…
BeniaminDrasovean Apr 2, 2026
3231397
fix after review
BeniaminDrasovean Apr 6, 2026
780c325
fix failing test
BeniaminDrasovean Apr 6, 2026
05f59ea
Merge pull request #7373 from multiversx/collapse-main-trie-leaves
BeniaminDrasovean Apr 6, 2026
b14e9c2
Merge remote-tracking branch 'origin/rc/supernova' into merge-feat/su…
BeniaminDrasovean Apr 6, 2026
ecaf3dc
fix failing test
BeniaminDrasovean Apr 6, 2026
1b97162
Merge pull request #7824 from multiversx/merge-feat/supernova-in-feat…
BeniaminDrasovean Apr 6, 2026
25a5939
Merge remote-tracking branch 'origin/feat/collapse-trie-based-on-size…
BeniaminDrasovean Apr 6, 2026
4b050aa
small fixes
BeniaminDrasovean Apr 6, 2026
8209e1a
remove not needed data
BeniaminDrasovean Apr 6, 2026
9b27a02
fix removeAccount edgecase
BeniaminDrasovean Apr 6, 2026
52666b0
Merge branch 'data-tries-caching-between-blocks' into load-data-tries…
BeniaminDrasovean Apr 7, 2026
ab2f667
fix after merge
BeniaminDrasovean Apr 7, 2026
0a430b9
Merge pull request #7554 from multiversx/data-tries-caching-between-b…
BeniaminDrasovean Apr 7, 2026
15ced70
Merge branch 'feat/collapse-trie-based-on-size' into load-data-tries-…
BeniaminDrasovean Apr 7, 2026
df495fe
fix linter issue
BeniaminDrasovean Apr 7, 2026
c4540ff
fix after review
BeniaminDrasovean Apr 9, 2026
fb337f3
small refactor
BeniaminDrasovean Apr 9, 2026
e338e81
Merge pull request #7823 from multiversx/load-data-tries-only-when-ne…
BeniaminDrasovean Apr 27, 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
6 changes: 4 additions & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,11 @@
SnapshotsEnabled = true
AccountsStatePruningEnabled = false
PeerStatePruningEnabled = true
MaxStateTrieLevelInMemory = 5
MaxPeerTrieLevelInMemory = 5
StateStatisticsEnabled = false
MaxUserTrieSizeInMemory = 524288000 #500MB
MaxPeerTrieSizeInMemory = 104857600 #100MB
DataTriesSizeInMemory = 524288000 #500MB
NumLeavesToCollapseSingleRun = 100

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

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

// NumLeavesToCollapseSingleRun defines the number of leaves to collapse in a single run, used in trie collapsing operations to manage performance and resource usage
NumLeavesToCollapseSingleRun = 100
)

type executionResultHandler interface {
GetMiniBlockHeadersHandlers() []data.MiniBlockHeaderHandler
}
Expand Down
22 changes: 21 additions & 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,13 +152,20 @@ 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
Remove([]byte)
MarkAsDirty([]byte)
Reset()
IsInterfaceNil() bool
}

// DataTrieCreator is an adapter for the Trie interface used only for recreating tries
type DataTrieCreator interface {
Recreate(options RootHashHolder) (Trie, error)
IsInterfaceNil() bool
}

// Locker defines the operations used to lock different critical areas. Implemented by the RWMutex.
type Locker interface {
Lock()
Expand Down Expand Up @@ -527,3 +535,15 @@ type AOTSelectionPreempter interface {
CancelOngoingSelection()
IsInterfaceNil() bool
}

// TrieCollapseManager defines the behavior of a trie collapse manager
type TrieCollapseManager interface {
MarkKeyAsAccessed(key []byte, sizeLoadedInMemory int)
RemoveKey(key []byte, sizeLoadedInMemory int)
ShouldCollapseTrie() bool
GetCollapsibleLeaves() ([][]byte, error)
AddSizeInMemory(size int)
GetSizeInMemory() int
CloneWithoutState() TrieCollapseManager
IsInterfaceNil() bool
}
14 changes: 8 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,14 @@ type FacadeConfig struct {

// StateTriesConfig will hold information about state tries
type StateTriesConfig struct {
SnapshotsEnabled bool
AccountsStatePruningEnabled bool
PeerStatePruningEnabled bool
MaxStateTrieLevelInMemory uint
MaxPeerTrieLevelInMemory uint
StateStatisticsEnabled bool
SnapshotsEnabled bool
AccountsStatePruningEnabled bool
PeerStatePruningEnabled bool
StateStatisticsEnabled bool
MaxUserTrieSizeInMemory uint64
MaxPeerTrieSizeInMemory uint64
DataTriesSizeInMemory uint64
NumLeavesToCollapseSingleRun uint32
}

// StateAccessesCollectorConfig will hold information about state accesses collector
Expand Down
12 changes: 5 additions & 7 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ func TestTomlParser(t *testing.T) {
},
},
StateTriesConfig: StateTriesConfig{
SnapshotsEnabled: true,
AccountsStatePruningEnabled: true,
PeerStatePruningEnabled: true,
MaxStateTrieLevelInMemory: 38,
MaxPeerTrieLevelInMemory: 39,
SnapshotsEnabled: true,
AccountsStatePruningEnabled: true,
PeerStatePruningEnabled: true,
NumLeavesToCollapseSingleRun: 100,
},
TxCacheBounds: TxCacheBoundsConfig{
MaxNumBytesPerSenderUpperBound: 33_554_432,
Expand Down Expand Up @@ -632,8 +631,7 @@ func TestTomlParser(t *testing.T) {
SnapshotsEnabled = true
AccountsStatePruningEnabled = true
PeerStatePruningEnabled = true
MaxStateTrieLevelInMemory = 38
MaxPeerTrieLevelInMemory = 39
NumLeavesToCollapseSingleRun = 100
`
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
17 changes: 5 additions & 12 deletions epochStart/metachain/baseRewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ import (
"github.com/multiversx/mx-chain-core-go/data/rewardTx"
"github.com/multiversx/mx-chain-core-go/hashing/sha256"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/state"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/testscommon"
txExecOrderStub "github.com/multiversx/mx-chain-go/testscommon/common"
dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"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,20 +1139,14 @@ 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())
argsAccCreator := factory.ArgsAccountCreator{
Hasher: hasher,
Marshaller: marshalizer,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
StateAccessesCollector: &stateMock.StateAccessesCollectorStub{},
}
accCreator, _ := factory.NewAccountCreator(argsAccCreator)
trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, txExecOrderStub.GetStorageManagerOptions())
enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{}
userAccountsDB := createAccountsDB(hasher, marshalizer, accCreator, trieFactoryManager, enableEpochsHandler)
userAccountsDBArgs := createAccountsDBArgs(hasher, marshalizer, trieFactoryManager, enableEpochsHandler)
userAccountsDB, _ := state.NewAccountsDB(userAccountsDBArgs)
shardCoordinator := mock.NewMultiShardsCoordinatorMock(2)
shardCoordinator.CurrentShard = core.MetachainShardId
shardCoordinator.ComputeIdCalled = func(address []byte) uint32 {
Expand Down
Loading
Loading