Skip to content

Commit

Permalink
Merge pull request #5674 from multiversx/use-disabled-snapshots-manag…
Browse files Browse the repository at this point in the history
…er-for-snapshotless-nodes

use disabled snapshots manager if the snapshots are disabled
  • Loading branch information
BeniaminDrasovean authored Nov 9, 2023
2 parents e6e79c4 + 04541d2 commit cd97c0a
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 174 deletions.
5 changes: 2 additions & 3 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/multiversx/mx-chain-go/process/smartContract/hooks"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state"
disabledState "github.com/multiversx/mx-chain-go/state/disabled"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/storagePruningManager"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList"
Expand Down Expand Up @@ -904,10 +905,8 @@ func createAccountsDB(
Marshaller: marshaller,
AccountFactory: accountFactory,
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
AppStatusHandler: &statusHandlerMock.AppStatusHandlerStub{},
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
}
adb, _ := state.NewAccountsDB(args)
return adb
Expand Down
5 changes: 2 additions & 3 deletions factory/api/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/blockInfoProviders"
disabledState "github.com/multiversx/mx-chain-go/state/disabled"
factoryState "github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/storagePruningManager"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList"
Expand Down Expand Up @@ -584,10 +585,8 @@ func createNewAccountsAdapterApi(args *scQueryElementArgs, chainHandler data.Cha
Marshaller: args.coreComponents.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
ProcessingMode: args.processingMode,
ProcessStatusHandler: args.coreComponents.ProcessStatusHandler(),
AppStatusHandler: args.statusCoreComponents.AppStatusHandler(),
AddressConverter: args.coreComponents.AddressPubKeyConverter(),
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
}

provider, err := blockInfoProviders.NewCurrentBlockInfo(chainHandler)
Expand Down
6 changes: 2 additions & 4 deletions factory/processing/blockProcessorCreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
processComp "github.com/multiversx/mx-chain-go/factory/processing"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
disabledState "github.com/multiversx/mx-chain-go/state/disabled"
factoryState "github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/disabled"
"github.com/multiversx/mx-chain-go/testscommon"
componentsMock "github.com/multiversx/mx-chain-go/testscommon/components"
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
"github.com/multiversx/mx-chain-go/testscommon/statusHandler"
storageManager "github.com/multiversx/mx-chain-go/testscommon/storage"
trieMock "github.com/multiversx/mx-chain-go/testscommon/trie"
"github.com/multiversx/mx-chain-go/trie"
Expand Down Expand Up @@ -203,10 +203,8 @@ func createAccountAdapter(
Marshaller: marshaller,
AccountFactory: accountFactory,
StoragePruningManager: disabled.NewDisabledStoragePruningManager(),
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
AppStatusHandler: &statusHandler.AppStatusHandlerStub{},
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
}
adb, err := state.NewAccountsDB(args)
if err != nil {
Expand Down
97 changes: 73 additions & 24 deletions factory/state/stateComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package state

import (
"fmt"

"github.com/multiversx/mx-chain-core-go/core/check"
chainData "github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-go/common"
Expand All @@ -11,7 +10,11 @@ import (
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/disabled"
factoryState "github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/iteratorChannelsProvider"
"github.com/multiversx/mx-chain-go/state/lastSnapshotMarker"
"github.com/multiversx/mx-chain-go/state/stateMetrics"
"github.com/multiversx/mx-chain-go/state/storagePruningManager"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList"
"github.com/multiversx/mx-chain-go/state/syncer"
Expand Down Expand Up @@ -108,6 +111,30 @@ func (scf *stateComponentsFactory) Create() (*stateComponents, error) {
}, nil
}

func (scf *stateComponentsFactory) createSnapshotManager(
accountFactory state.AccountFactory,
stateMetrics state.StateMetrics,
iteratorChannelsProvider state.IteratorChannelsProvider,
) (state.SnapshotsManager, error) {
if !scf.config.StateTriesConfig.SnapshotsEnabled {
return disabled.NewDisabledSnapshotsManager(), nil
}

argsSnapshotsManager := state.ArgsNewSnapshotsManager{
ShouldSerializeSnapshots: scf.shouldSerializeSnapshots,
ProcessingMode: scf.processingMode,
Marshaller: scf.core.InternalMarshalizer(),
AddressConverter: scf.core.AddressPubKeyConverter(),
ProcessStatusHandler: scf.core.ProcessStatusHandler(),
StateMetrics: stateMetrics,
ChannelsProvider: iteratorChannelsProvider,
AccountFactory: accountFactory,
LastSnapshotMarker: lastSnapshotMarker.NewLastSnapshotMarker(),
StateStatsHandler: scf.statusCore.StateStatsHandler(),
}
return state.NewSnapshotsManager(argsSnapshotsManager)
}

func (scf *stateComponentsFactory) createAccountsAdapters(triesContainer common.TriesHolder) (state.AccountsAdapter, state.AccountsAdapter, state.AccountsRepository, error) {
argsAccCreator := factoryState.ArgsAccountCreator{
Hasher: scf.core.Hasher(),
Expand All @@ -125,17 +152,29 @@ func (scf *stateComponentsFactory) createAccountsAdapters(triesContainer common.
return nil, nil, nil, err
}

argStateMetrics := stateMetrics.ArgsStateMetrics{
SnapshotInProgressKey: common.MetricAccountsSnapshotInProgress,
LastSnapshotDurationKey: common.MetricLastAccountsSnapshotDurationSec,
SnapshotMessage: stateMetrics.UserTrieSnapshotMsg,
}
sm, err := stateMetrics.NewStateMetrics(argStateMetrics, scf.statusCore.AppStatusHandler())
if err != nil {
return nil, nil, nil, err
}

snapshotsManager, err := scf.createSnapshotManager(accountFactory, sm, iteratorChannelsProvider.NewUserStateIteratorChannelsProvider())
if err != nil {
return nil, nil, nil, err
}

argsProcessingAccountsDB := state.ArgsAccountsDB{
Trie: merkleTrie,
Hasher: scf.core.Hasher(),
Marshaller: scf.core.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
ProcessingMode: scf.processingMode,
ShouldSerializeSnapshots: scf.shouldSerializeSnapshots,
ProcessStatusHandler: scf.core.ProcessStatusHandler(),
AppStatusHandler: scf.statusCore.AppStatusHandler(),
AddressConverter: scf.core.AddressPubKeyConverter(),
Trie: merkleTrie,
Hasher: scf.core.Hasher(),
Marshaller: scf.core.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
AddressConverter: scf.core.AddressPubKeyConverter(),
SnapshotsManager: snapshotsManager,
}
accountsAdapter, err := state.NewAccountsDB(argsProcessingAccountsDB)
if err != nil {
Expand All @@ -148,10 +187,8 @@ func (scf *stateComponentsFactory) createAccountsAdapters(triesContainer common.
Marshaller: scf.core.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
ProcessingMode: scf.processingMode,
ProcessStatusHandler: scf.core.ProcessStatusHandler(),
AppStatusHandler: scf.statusCore.AppStatusHandler(),
AddressConverter: scf.core.AddressPubKeyConverter(),
SnapshotsManager: disabled.NewDisabledSnapshotsManager(),
}

accountsAdapterApiOnFinal, err := factoryState.CreateAccountsAdapterAPIOnFinal(argsAPIAccountsDB, scf.chainHandler)
Expand Down Expand Up @@ -191,17 +228,29 @@ func (scf *stateComponentsFactory) createPeerAdapter(triesContainer common.Tries
return nil, err
}

argStateMetrics := stateMetrics.ArgsStateMetrics{
SnapshotInProgressKey: common.MetricPeersSnapshotInProgress,
LastSnapshotDurationKey: common.MetricLastPeersSnapshotDurationSec,
SnapshotMessage: stateMetrics.PeerTrieSnapshotMsg,
}
sm, err := stateMetrics.NewStateMetrics(argStateMetrics, scf.statusCore.AppStatusHandler())
if err != nil {
return nil, err
}

snapshotManager, err := scf.createSnapshotManager(accountFactory, sm, iteratorChannelsProvider.NewPeerStateIteratorChannelsProvider())
if err != nil {
return nil, err
}

argsProcessingPeerAccountsDB := state.ArgsAccountsDB{
Trie: merkleTrie,
Hasher: scf.core.Hasher(),
Marshaller: scf.core.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
ProcessingMode: scf.processingMode,
ShouldSerializeSnapshots: scf.shouldSerializeSnapshots,
ProcessStatusHandler: scf.core.ProcessStatusHandler(),
AppStatusHandler: scf.statusCore.AppStatusHandler(),
AddressConverter: scf.core.AddressPubKeyConverter(),
Trie: merkleTrie,
Hasher: scf.core.Hasher(),
Marshaller: scf.core.InternalMarshalizer(),
AccountFactory: accountFactory,
StoragePruningManager: storagePruning,
AddressConverter: scf.core.AddressPubKeyConverter(),
SnapshotsManager: snapshotManager,
}
peerAdapter, err := state.NewPeerAccountsDB(argsProcessingPeerAccountsDB)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions genesis/process/memoryComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/common"
commonDisabled "github.com/multiversx/mx-chain-go/common/disabled"
"github.com/multiversx/mx-chain-go/state"
disabledState "github.com/multiversx/mx-chain-go/state/disabled"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/disabled"
"github.com/multiversx/mx-chain-go/trie"
)
Expand All @@ -32,10 +32,8 @@ func createAccountAdapter(
Marshaller: marshaller,
AccountFactory: accountFactory,
StoragePruningManager: disabled.NewDisabledStoragePruningManager(),
ProcessingMode: common.Normal,
ProcessStatusHandler: commonDisabled.NewProcessStatusHandler(),
AppStatusHandler: commonDisabled.NewAppStatusHandler(),
AddressConverter: addressConverter,
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(),
}

adb, err := state.NewAccountsDB(args)
Expand Down
37 changes: 30 additions & 7 deletions integrationTests/state/stateTrie/stateTrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/multiversx/mx-chain-core-go/hashing/sha256"
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/statistics"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/epochStart"
Expand All @@ -32,13 +33,16 @@ import (
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/iteratorChannelsProvider"
"github.com/multiversx/mx-chain-go/state/lastSnapshotMarker"
"github.com/multiversx/mx-chain-go/state/storagePruningManager"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/storage/storageunit"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/statusHandler"
"github.com/multiversx/mx-chain-go/testscommon/marshallerMock"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
testStorage "github.com/multiversx/mx-chain-go/testscommon/storage"
"github.com/multiversx/mx-chain-go/trie"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
Expand Down Expand Up @@ -1056,16 +1060,25 @@ func createAccounts(
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
}
accCreator, _ := factory.NewAccountCreator(argsAccCreator)
snapshotsManager, _ := state.NewSnapshotsManager(state.ArgsNewSnapshotsManager{
ProcessingMode: common.Normal,
Marshaller: &marshallerMock.MarshalizerMock{},
AddressConverter: &testscommon.PubkeyConverterMock{},
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
StateMetrics: &stateMock.StateMetricsStub{},
AccountFactory: accCreator,
ChannelsProvider: iteratorChannelsProvider.NewUserStateIteratorChannelsProvider(),
LastSnapshotMarker: lastSnapshotMarker.NewLastSnapshotMarker(),
StateStatsHandler: statistics.NewStateStatistics(),
})
argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: integrationTests.TestHasher,
Marshaller: integrationTests.TestMarshalizer,
AccountFactory: accCreator,
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
AppStatusHandler: &statusHandler.AppStatusHandlerStub{},
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: snapshotsManager,
}
adb, _ := state.NewAccountsDB(argsAccountsDB)

Expand Down Expand Up @@ -2502,16 +2515,26 @@ func createAccountsDBTestSetup() *state.AccountsDB {
}
accCreator, _ := factory.NewAccountCreator(argsAccCreator)

snapshotsManager, _ := state.NewSnapshotsManager(state.ArgsNewSnapshotsManager{
ProcessingMode: common.Normal,
Marshaller: &marshallerMock.MarshalizerMock{},
AddressConverter: &testscommon.PubkeyConverterMock{},
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
StateMetrics: &stateMock.StateMetricsStub{},
AccountFactory: accCreator,
ChannelsProvider: iteratorChannelsProvider.NewUserStateIteratorChannelsProvider(),
LastSnapshotMarker: lastSnapshotMarker.NewLastSnapshotMarker(),
StateStatsHandler: statistics.NewStateStatistics(),
})

argsAccountsDB := state.ArgsAccountsDB{
Trie: tr,
Hasher: integrationTests.TestHasher,
Marshaller: integrationTests.TestMarshalizer,
AccountFactory: accCreator,
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
AppStatusHandler: &statusHandler.AppStatusHandlerStub{},
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: snapshotsManager,
}
adb, _ := state.NewAccountsDB(argsAccountsDB)

Expand Down
21 changes: 17 additions & 4 deletions integrationTests/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
"github.com/multiversx/mx-chain-crypto-go/signing/secp256k1"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/statistics"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/dataRetriever/blockchain"
Expand All @@ -49,6 +50,8 @@ import (
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/iteratorChannelsProvider"
"github.com/multiversx/mx-chain-go/state/lastSnapshotMarker"
"github.com/multiversx/mx-chain-go/state/parsers"
"github.com/multiversx/mx-chain-go/state/storagePruningManager"
"github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList"
Expand All @@ -67,7 +70,6 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/marshallerMock"
"github.com/multiversx/mx-chain-go/testscommon/p2pmocks"
testStorage "github.com/multiversx/mx-chain-go/testscommon/state"
"github.com/multiversx/mx-chain-go/testscommon/statusHandler"
statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler"
testcommonStorage "github.com/multiversx/mx-chain-go/testscommon/storage"
"github.com/multiversx/mx-chain-go/testscommon/txDataBuilder"
Expand Down Expand Up @@ -454,16 +456,27 @@ func CreateAccountsDBWithEnableEpochsHandler(
ewl, _ := evictionWaitingList.NewMemoryEvictionWaitingList(ewlArgs)
accountFactory, _ := getAccountFactory(accountType, enableEpochsHandler)
spm, _ := storagePruningManager.NewStoragePruningManager(ewl, 10)

snapshotsManager, _ := state.NewSnapshotsManager(state.ArgsNewSnapshotsManager{
ProcessingMode: common.Normal,
Marshaller: TestMarshalizer,
AddressConverter: &testscommon.PubkeyConverterMock{},
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
StateMetrics: &testStorage.StateMetricsStub{},
AccountFactory: accountFactory,
ChannelsProvider: iteratorChannelsProvider.NewUserStateIteratorChannelsProvider(),
LastSnapshotMarker: lastSnapshotMarker.NewLastSnapshotMarker(),
StateStatsHandler: statistics.NewStateStatistics(),
})

args := state.ArgsAccountsDB{
Trie: tr,
Hasher: sha256.NewSha256(),
Marshaller: TestMarshalizer,
AccountFactory: accountFactory,
StoragePruningManager: spm,
ProcessingMode: common.Normal,
ProcessStatusHandler: &testscommon.ProcessStatusHandlerStub{},
AppStatusHandler: &statusHandler.AppStatusHandlerStub{},
AddressConverter: &testscommon.PubkeyConverterMock{},
SnapshotsManager: snapshotsManager,
}
adb, _ := state.NewAccountsDB(args)

Expand Down
Loading

0 comments on commit cd97c0a

Please sign in to comment.