Skip to content

Commit

Permalink
Merge pull request #6296 from multiversx/state-changes-read-operations
Browse files Browse the repository at this point in the history
State changes read operations
  • Loading branch information
ssd04 authored Oct 25, 2024
2 parents ccffe6d + d6383f5 commit d892499
Show file tree
Hide file tree
Showing 83 changed files with 1,810 additions and 537 deletions.
15 changes: 8 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,14 @@ type FacadeConfig struct {

// StateTriesConfig will hold information about state tries
type StateTriesConfig struct {
SnapshotsEnabled bool
AccountsStatePruningEnabled bool
PeerStatePruningEnabled bool
CollectStateChangesEnabled bool
MaxStateTrieLevelInMemory uint
MaxPeerTrieLevelInMemory uint
StateStatisticsEnabled bool
SnapshotsEnabled bool
AccountsStatePruningEnabled bool
PeerStatePruningEnabled bool
CollectStateChangesEnabled bool
CollectStateChangesWithReadEnabled bool
MaxStateTrieLevelInMemory uint
MaxPeerTrieLevelInMemory uint
StateStatisticsEnabled bool
}

// TrieStorageManagerConfig will hold config information about trie storage manager
Expand Down
8 changes: 2 additions & 6 deletions epochStart/bootstrap/disabled/disabledAccountsAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package disabled
import (
"context"

"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/state"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
Expand Down Expand Up @@ -129,12 +130,7 @@ func (a *accountsAdapter) GetStackDebugFirstEntry() []byte {
}

// SetTxHashForLatestStateChanges -
func (a *accountsAdapter) SetTxHashForLatestStateChanges(_ []byte) {
}

// ResetStateChangesCollector -
func (a *accountsAdapter) ResetStateChangesCollector() []state.StateChangesForTx {
return nil
func (a *accountsAdapter) SetTxHashForLatestStateChanges(_ []byte, _ *transaction.Transaction) {
}

// Close -
Expand Down
8 changes: 5 additions & 3 deletions epochStart/metachain/baseRewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/state/stateChanges"
"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"
Expand Down Expand Up @@ -1177,9 +1178,10 @@ func getBaseRewardsArguments() BaseRewardsCreatorArgs {

trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, storage.GetStorageManagerOptions())
argsAccCreator := factory.ArgsAccountCreator{
Hasher: hasher,
Marshaller: marshalizer,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
Hasher: hasher,
Marshaller: marshalizer,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
StateChangesCollector: stateChanges.NewStateChangesCollector(),
}
accCreator, _ := factory.NewAccountCreator(argsAccCreator)
enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{}
Expand Down
7 changes: 4 additions & 3 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,10 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp

trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, storageMock.GetStorageManagerOptions())
argsAccCreator := factory.ArgsAccountCreator{
Hasher: hasher,
Marshaller: marshalizer,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
Hasher: hasher,
Marshaller: marshalizer,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
StateChangesCollector: disabledState.NewDisabledStateChangesCollector(),
}
accCreator, _ := factory.NewAccountCreator(argsAccCreator)
peerAccCreator := factory.NewPeerAccountCreator()
Expand Down
7 changes: 4 additions & 3 deletions factory/api/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,10 @@ func createShardVmContainerFactory(args scQueryElementArgs, argsHook hooks.ArgBl

func createNewAccountsAdapterApi(args scQueryElementArgs, chainHandler data.ChainHandler) (state.AccountsAdapterAPI, common.StorageManager, error) {
argsAccCreator := factoryState.ArgsAccountCreator{
Hasher: args.coreComponents.Hasher(),
Marshaller: args.coreComponents.InternalMarshalizer(),
EnableEpochsHandler: args.coreComponents.EnableEpochsHandler(),
Hasher: args.coreComponents.Hasher(),
Marshaller: args.coreComponents.InternalMarshalizer(),
EnableEpochsHandler: args.coreComponents.EnableEpochsHandler(),
StateChangesCollector: args.stateComponents.StateChangesCollector(),
}
accountFactory, err := factoryState.NewAccountCreator(argsAccCreator)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions factory/api/apiResolverFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/sync/disabled"
"github.com/multiversx/mx-chain-go/state"
stateDisabled "github.com/multiversx/mx-chain-go/state/disabled"
"github.com/multiversx/mx-chain-go/testscommon"
componentsMock "github.com/multiversx/mx-chain-go/testscommon/components"
"github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
Expand Down Expand Up @@ -344,6 +345,9 @@ func createMockSCQueryElementArgs() api.SCQueryElementArgs {
PeerAccountsCalled: func() state.AccountsAdapter {
return &stateMocks.AccountsStub{}
},
StateChangesCollectorCalled: func() state.StateChangesCollector {
return stateDisabled.NewDisabledStateChangesCollector()
},
},
StatusCoreComponents: &factory.StatusCoreComponentsStub{
AppStatusHandlerCalled: func() core.AppStatusHandler {
Expand Down
1 change: 1 addition & 0 deletions factory/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ type StateComponentsHolder interface {
TriesContainer() common.TriesHolder
TrieStorageManagers() map[string]common.StorageManager
MissingTrieNodesNotifier() common.MissingTrieNodesNotifier
StateChangesCollector() state.StateChangesCollector
Close() error
IsInterfaceNil() bool
}
Expand Down
10 changes: 10 additions & 0 deletions factory/mock/stateComponentsHolderStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type StateComponentsHolderStub struct {
TriesContainerCalled func() common.TriesHolder
TrieStorageManagersCalled func() map[string]common.StorageManager
MissingTrieNodesNotifierCalled func() common.MissingTrieNodesNotifier
StateChangesCollectorCalled func() state.StateChangesCollector
}

// PeerAccounts -
Expand Down Expand Up @@ -79,6 +80,15 @@ func (s *StateComponentsHolderStub) MissingTrieNodesNotifier() common.MissingTri
return nil
}

// StateChangesCollector -
func (s *StateComponentsHolderStub) StateChangesCollector() state.StateChangesCollector {
if s.StateChangesCollectorCalled != nil {
return s.StateChangesCollectorCalled()
}

return nil
}

// Close -
func (s *StateComponentsHolderStub) Close() error {
return nil
Expand Down
10 changes: 7 additions & 3 deletions factory/processing/blockProcessorCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
dataBlock "github.com/multiversx/mx-chain-core-go/data/block"
logger "github.com/multiversx/mx-chain-logger-go"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-common-go/parsers"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand Down Expand Up @@ -43,9 +47,6 @@ import (
"github.com/multiversx/mx-chain-go/state/syncer"
"github.com/multiversx/mx-chain-go/storage/txcache"
"github.com/multiversx/mx-chain-go/vm"
logger "github.com/multiversx/mx-chain-logger-go"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-common-go/parsers"
)

type blockProcessorAndVmFactories struct {
Expand Down Expand Up @@ -454,6 +455,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor(
BlockProcessingCutoffHandler: blockProcessingCutoffHandler,
ManagedPeersHolder: pcf.crypto.ManagedPeersHolder(),
SentSignaturesTracker: sentSignaturesTracker,
StateChangesCollector: pcf.state.StateChangesCollector(),
}
arguments := block.ArgShardProcessor{
ArgBaseProcessor: argumentsBaseProcessor,
Expand Down Expand Up @@ -898,6 +900,7 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor(
BlockProcessingCutoffHandler: blockProcessingCutoffhandler,
ManagedPeersHolder: pcf.crypto.ManagedPeersHolder(),
SentSignaturesTracker: sentSignaturesTracker,
StateChangesCollector: pcf.state.StateChangesCollector(),
}

esdtOwnerAddress, err := pcf.coreData.AddressPubKeyConverter().Decode(pcf.systemSCConfig.ESDTSystemSCConfig.OwnerAddress)
Expand Down Expand Up @@ -1057,6 +1060,7 @@ func (pcf *processComponentsFactory) createOutportDataProvider(
MbsStorer: mbsStorer,
EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(),
ExecutionOrderGetter: pcf.txExecutionOrderHandler,
StateChangesCollector: pcf.state.StateChangesCollector(),
})
}

Expand Down
8 changes: 5 additions & 3 deletions factory/processing/blockProcessorCreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"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/stateChanges"
"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"
Expand Down Expand Up @@ -103,9 +104,10 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) {
trieStorageManagers[dataRetriever.PeerAccountsUnit.String()] = storageManagerPeer

argsAccCreator := factoryState.ArgsAccountCreator{
Hasher: coreComponents.Hasher(),
Marshaller: coreComponents.InternalMarshalizer(),
EnableEpochsHandler: coreComponents.EnableEpochsHandler(),
Hasher: coreComponents.Hasher(),
Marshaller: coreComponents.InternalMarshalizer(),
EnableEpochsHandler: coreComponents.EnableEpochsHandler(),
StateChangesCollector: stateChanges.NewStateChangesCollector(),
}
accCreator, _ := factoryState.NewAccountCreator(argsAccCreator)

Expand Down
4 changes: 2 additions & 2 deletions factory/processing/processComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ func (pcf *processComponentsFactory) newShardInterceptorContainerFactory(
shardInterceptorsContainerFactoryArgs := interceptorscontainer.CommonInterceptorsContainerFactoryArgs{
CoreComponents: pcf.coreData,
CryptoComponents: pcf.crypto,
Accounts: pcf.state.AccountsAdapter(),
Accounts: pcf.state.AccountsAdapterAPI(),
ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(),
NodesCoordinator: pcf.nodesCoordinator,
MainMessenger: pcf.network.NetworkMessenger(),
Expand Down Expand Up @@ -1748,7 +1748,7 @@ func (pcf *processComponentsFactory) newMetaInterceptorContainerFactory(
FullArchiveMessenger: pcf.network.FullArchiveNetworkMessenger(),
Store: pcf.data.StorageService(),
DataPool: pcf.data.Datapool(),
Accounts: pcf.state.AccountsAdapter(),
Accounts: pcf.state.AccountsAdapterAPI(),
MaxTxNonceDeltaAllowed: common.MaxTxNonceDeltaAllowed,
TxFeeHandler: pcf.coreData.EconomicsData(),
BlockBlackList: headerBlackList,
Expand Down
Loading

0 comments on commit d892499

Please sign in to comment.