From 03102683d950a530a0faea4e0c75cf3a88363f54 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 2 Sep 2024 11:51:22 +0300 Subject: [PATCH 01/28] added state changes collector to hostDriver. --- factory/status/statusComponents.go | 8 +++-- outport/factory/hostDriverFactory.go | 15 +++++--- outport/host/driver.go | 39 ++++++++++++++------- outport/host/errors.go | 3 ++ outport/interface.go | 3 ++ outport/mock/driverStub.go | 11 ++++++ outport/notifier/eventNotifier.go | 5 +++ outport/outport.go | 26 ++++++++++++++ state/accountsDB.go | 8 +++-- state/interface.go | 4 ++- state/stateChanges/dataAnalysisCollector.go | 7 +++- state/stateChanges/writeCollector.go | 4 +++ 12 files changed, 107 insertions(+), 26 deletions(-) diff --git a/factory/status/statusComponents.go b/factory/status/statusComponents.go index b8c5cf29163..cea175fdfaf 100644 --- a/factory/status/statusComponents.go +++ b/factory/status/statusComponents.go @@ -9,6 +9,8 @@ import ( outportCore "github.com/multiversx/mx-chain-core-go/data/outport" factoryMarshalizer "github.com/multiversx/mx-chain-core-go/marshal/factory" indexerFactory "github.com/multiversx/mx-chain-es-indexer-go/process/factory" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/statistics" swVersionFactory "github.com/multiversx/mx-chain-go/common/statistics/softwareVersion/factory" @@ -23,7 +25,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" - logger "github.com/multiversx/mx-chain-logger-go" ) type statusComponents struct { @@ -286,8 +287,9 @@ func (scf *statusComponentsFactory) makeHostDriversArgs() ([]outportDriverFactor } argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, outportDriverFactory.ArgsHostDriverFactory{ - Marshaller: marshaller, - HostConfig: hostConfig, + Marshaller: marshaller, + HostConfig: hostConfig, + StateChangesCollector: scf.stateComponents.StateChangesCollector(), }) } diff --git a/outport/factory/hostDriverFactory.go b/outport/factory/hostDriverFactory.go index 42dfdeadcf7..895c5577688 100644 --- a/outport/factory/hostDriverFactory.go +++ b/outport/factory/hostDriverFactory.go @@ -4,15 +4,19 @@ import ( "github.com/multiversx/mx-chain-communication-go/websocket/data" "github.com/multiversx/mx-chain-communication-go/websocket/factory" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/outport" "github.com/multiversx/mx-chain-go/outport/host" + "github.com/multiversx/mx-chain-go/state" + logger "github.com/multiversx/mx-chain-logger-go" ) type ArgsHostDriverFactory struct { - HostConfig config.HostDriversConfig - Marshaller marshal.Marshalizer + HostConfig config.HostDriversConfig + Marshaller marshal.Marshalizer + StateChangesCollector state.StateChangesCollector } var log = logger.GetOrCreate("outport/factory/hostdriver") @@ -38,8 +42,9 @@ func CreateHostDriver(args ArgsHostDriverFactory) (outport.Driver, error) { } return host.NewHostDriver(host.ArgsHostDriver{ - Marshaller: args.Marshaller, - SenderHost: wsHost, - Log: log, + Marshaller: args.Marshaller, + SenderHost: wsHost, + Log: log, + StateChangesCollector: args.StateChangesCollector, }) } diff --git a/outport/host/driver.go b/outport/host/driver.go index d15771f28c4..e73871c2c71 100644 --- a/outport/host/driver.go +++ b/outport/host/driver.go @@ -8,21 +8,25 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/marshal" + + "github.com/multiversx/mx-chain-go/state" ) // ArgsHostDriver holds the arguments needed for creating a new hostDriver type ArgsHostDriver struct { - Marshaller marshal.Marshalizer - SenderHost SenderHost - Log core.Logger + Marshaller marshal.Marshalizer + SenderHost SenderHost + Log core.Logger + StateChangesCollector state.StateChangesCollector } type hostDriver struct { - marshaller marshal.Marshalizer - senderHost SenderHost - isClosed atomic.Flag - log core.Logger - payloadProc payloadProcessorHandler + marshaller marshal.Marshalizer + senderHost SenderHost + isClosed atomic.Flag + log core.Logger + payloadProc payloadProcessorHandler + stateChangesCollector state.StateChangesCollector } // NewHostDriver will create a new instance of hostDriver @@ -36,6 +40,9 @@ func NewHostDriver(args ArgsHostDriver) (*hostDriver, error) { if check.IfNil(args.Log) { return nil, core.ErrNilLogger } + if check.IfNil(args.StateChangesCollector) { + return nil, ErrNilStateChangesCollector + } payloadProc, err := newPayloadProcessor(args.Log) if err != nil { @@ -48,11 +55,12 @@ func NewHostDriver(args ArgsHostDriver) (*hostDriver, error) { } return &hostDriver{ - marshaller: args.Marshaller, - senderHost: args.SenderHost, - log: args.Log, - isClosed: atomic.Flag{}, - payloadProc: payloadProc, + marshaller: args.Marshaller, + senderHost: args.SenderHost, + log: args.Log, + isClosed: atomic.Flag{}, + payloadProc: payloadProc, + stateChangesCollector: args.StateChangesCollector, }, nil } @@ -124,6 +132,11 @@ func (o *hostDriver) SetCurrentSettings(config outport.OutportConfig) error { return o.handleAction(&config, outport.TopicSettings) } +func (o *hostDriver) SaveStateChanges() error { + //TODO: add this as a constant + return o.handleAction(o.stateChangesCollector.GetStateChanges(), "SaveStateChanges") +} + // Close will handle the closing of the outport driver web socket sender func (o *hostDriver) Close() error { o.isClosed.SetValue(true) diff --git a/outport/host/errors.go b/outport/host/errors.go index de45f08acef..8b092a1a102 100644 --- a/outport/host/errors.go +++ b/outport/host/errors.go @@ -7,3 +7,6 @@ var ErrHostIsClosed = errors.New("server is closed") // ErrNilHost signals that a nil host has been provided var ErrNilHost = errors.New("nil host provided") + +// ErrNilStateChangesCollector signals that a nil state change collector has been provided. +var ErrNilStateChangesCollector = errors.New("nil state changes collector provided") diff --git a/outport/interface.go b/outport/interface.go index 768920a7709..d4cd4eb205d 100644 --- a/outport/interface.go +++ b/outport/interface.go @@ -3,6 +3,7 @@ package outport import ( outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/outport/process" ) @@ -15,6 +16,7 @@ type Driver interface { SaveValidatorsPubKeys(validatorsPubKeys *outportcore.ValidatorsPubKeys) error SaveValidatorsRating(validatorsRating *outportcore.ValidatorsRating) error SaveAccounts(accounts *outportcore.Accounts) error + SaveStateChanges() error FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) error GetMarshaller() marshal.Marshalizer SetCurrentSettings(config outportcore.OutportConfig) error @@ -32,6 +34,7 @@ type OutportHandler interface { SaveValidatorsPubKeys(validatorsPubKeys *outportcore.ValidatorsPubKeys) SaveValidatorsRating(validatorsRating *outportcore.ValidatorsRating) SaveAccounts(accounts *outportcore.Accounts) + //SaveStateChanges() FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) SubscribeDriver(driver Driver) error HasDrivers() bool diff --git a/outport/mock/driverStub.go b/outport/mock/driverStub.go index e142eb9f5aa..2b7cfe35159 100644 --- a/outport/mock/driverStub.go +++ b/outport/mock/driverStub.go @@ -3,6 +3,7 @@ package mock import ( outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" ) @@ -18,6 +19,7 @@ type DriverStub struct { CloseCalled func() error RegisterHandlerCalled func(handlerFunction func() error, topic string) error SetCurrentSettingsCalled func(config outportcore.OutportConfig) error + SaveStateChangesCalled func() error } // SaveBlock - @@ -106,6 +108,15 @@ func (d *DriverStub) RegisterHandler(handlerFunction func() error, topic string) return nil } +// SaveStateChanges - +func (d *DriverStub) SaveStateChanges() error { + if d.SaveStateChangesCalled != nil { + return d.SaveStateChangesCalled() + } + + return nil +} + // Close - func (d *DriverStub) Close() error { if d.CloseCalled != nil { diff --git a/outport/notifier/eventNotifier.go b/outport/notifier/eventNotifier.go index 828b027c88e..247fd7e3d23 100644 --- a/outport/notifier/eventNotifier.go +++ b/outport/notifier/eventNotifier.go @@ -115,6 +115,11 @@ func (en *eventNotifier) SaveAccounts(_ *outport.Accounts) error { return nil } +// SaveStateChanges does nothing +func (en *eventNotifier) SaveStateChanges() error { + return nil +} + // GetMarshaller returns internal marshaller func (en *eventNotifier) GetMarshaller() marshal.Marshalizer { return en.marshalizer diff --git a/outport/outport.go b/outport/outport.go index edcecc0691a..17773f1639e 100644 --- a/outport/outport.go +++ b/outport/outport.go @@ -310,6 +310,32 @@ func (o *outport) saveAccountsBlocking(accounts *outportcore.Accounts, driver Dr } } +func (o *outport) SaveStateChanges() { + o.mutex.RLock() + defer o.mutex.RUnlock() + + for _, driver := range o.drivers { + o.saveStateChangesBlocking(driver) + } +} + +func (o *outport) saveStateChangesBlocking(driver Driver) { + ch := o.monitorCompletionOnDriver("finalizedBlockBlocking", driver) + defer close(ch) + + for { + err := driver.SaveStateChanges() + if err == nil { + return + } + + log.Error("error calling SaveStateChanges, will retry", + "driver", driverString(driver), + "retrial in", o.retrialInterval, + "error", err) + } +} + // FinalizedBlock will call all the drivers that a block is finalized func (o *outport) FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) { o.mutex.RLock() diff --git a/state/accountsDB.go b/state/accountsDB.go index 7700521ebe0..56bb820f42d 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -16,6 +16,9 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/common/holders" @@ -23,8 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/state/stateChanges" "github.com/multiversx/mx-chain-go/trie/keyBuilder" "github.com/multiversx/mx-chain-go/trie/statistics" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) const ( @@ -915,7 +916,8 @@ func (adb *AccountsDB) commit() ([]byte, error) { return nil, err } - adb.stateChangesCollector.Reset() + //TODO: discuss the workflow. If reset here, the outport driver won't be able to pick up the changes. + //adb.stateChangesCollector.Reset() oldHashes := make(common.ModifiedHashes) newHashes := make(common.ModifiedHashes) diff --git a/state/interface.go b/state/interface.go index ae2100aa7a3..80e3a6baca3 100644 --- a/state/interface.go +++ b/state/interface.go @@ -7,9 +7,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/state/stateChanges" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // AccountFactory creates an account of different types @@ -363,5 +364,6 @@ type StateChangesCollector interface { SetIndexToLastStateChange(index int) error RevertToIndex(index int) error Publish() error + GetStateChanges() []stateChanges.StateChange IsInterfaceNil() bool } diff --git a/state/stateChanges/dataAnalysisCollector.go b/state/stateChanges/dataAnalysisCollector.go index dc5d5e62a4f..85b8fd39638 100644 --- a/state/stateChanges/dataAnalysisCollector.go +++ b/state/stateChanges/dataAnalysisCollector.go @@ -8,8 +8,9 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/storage" vmcommon "github.com/multiversx/mx-chain-vm-common-go" + + "github.com/multiversx/mx-chain-go/storage" ) const ( @@ -204,6 +205,10 @@ func (scc *dataAnalysisCollector) Publish() error { return nil } +func (scc *dataAnalysisCollector) GetStateChanges() []StateChange { + return scc.stateChanges +} + // IsInterfaceNil returns true if there is no value under the interface func (scc *dataAnalysisCollector) IsInterfaceNil() bool { return scc == nil diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 188c8887160..89bfad57617 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -213,6 +213,10 @@ func printStateChanges(stateChanges []StateChangesForTx) { } } +func (scc *stateChangesCollector) GetStateChanges() []StateChange { + return scc.stateChanges +} + // IsInterfaceNil returns true if there is no value under the interface func (scc *stateChangesCollector) IsInterfaceNil() bool { return scc == nil From 682e4178be307c075f794902193610fc5bec1043 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 2 Sep 2024 12:30:02 +0300 Subject: [PATCH 02/28] some fixes. --- outport/disabled/disabledOutport.go | 6 ++++++ outport/factory/outportFactory.go | 7 +++++-- outport/interface.go | 2 +- outport/outport.go | 3 ++- process/block/metablock.go | 6 +++++- state/disabled/disabledStateChangesCollector.go | 7 ++++++- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/outport/disabled/disabledOutport.go b/outport/disabled/disabledOutport.go index 97be7894c9b..c4e861ec210 100644 --- a/outport/disabled/disabledOutport.go +++ b/outport/disabled/disabledOutport.go @@ -2,6 +2,7 @@ package disabled import ( outportcore "github.com/multiversx/mx-chain-core-go/data/outport" + "github.com/multiversx/mx-chain-go/outport" ) @@ -38,6 +39,11 @@ func (n *disabledOutport) SaveValidatorsRating(_ *outportcore.ValidatorsRating) func (n *disabledOutport) SaveAccounts(_ *outportcore.Accounts) { } +// SaveStateChanges does nothing +func (n *disabledOutport) SaveStateChanges() { + return +} + // FinalizedBlock does nothing func (n *disabledOutport) FinalizedBlock(_ *outportcore.FinalizedBlock) { } diff --git a/outport/factory/outportFactory.go b/outport/factory/outportFactory.go index e7259bfc69f..84d963131ae 100644 --- a/outport/factory/outportFactory.go +++ b/outport/factory/outportFactory.go @@ -6,6 +6,7 @@ import ( outportcore "github.com/multiversx/mx-chain-core-go/data/outport" indexerFactory "github.com/multiversx/mx-chain-es-indexer-go/process/factory" + "github.com/multiversx/mx-chain-go/outport" ) @@ -73,12 +74,14 @@ func createAndSubscribeElasticDriverIfNeeded( return nil } - elasticDriver, err := indexerFactory.NewIndexer(args) + //TODO: this needs discussed. + _, err := indexerFactory.NewIndexer(args) if err != nil { return err } - return outport.SubscribeDriver(elasticDriver) + return nil + //return outport.SubscribeDriver(elasticDriver) } func createAndSubscribeEventNotifierIfNeeded( diff --git a/outport/interface.go b/outport/interface.go index d4cd4eb205d..645721b402d 100644 --- a/outport/interface.go +++ b/outport/interface.go @@ -34,7 +34,7 @@ type OutportHandler interface { SaveValidatorsPubKeys(validatorsPubKeys *outportcore.ValidatorsPubKeys) SaveValidatorsRating(validatorsRating *outportcore.ValidatorsRating) SaveAccounts(accounts *outportcore.Accounts) - //SaveStateChanges() + SaveStateChanges() FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) SubscribeDriver(driver Driver) error HasDrivers() bool diff --git a/outport/outport.go b/outport/outport.go index 17773f1639e..b5cfdabfc83 100644 --- a/outport/outport.go +++ b/outport/outport.go @@ -279,7 +279,7 @@ func (o *outport) saveValidatorsRatingBlocking(validatorsRating *outportcore.Val } } -// SaveAccounts will save accounts for every driver +// SaveAccounts will save accounts for every driver func (o *outport) SaveAccounts(accounts *outportcore.Accounts) { o.mutex.RLock() defer o.mutex.RUnlock() @@ -310,6 +310,7 @@ func (o *outport) saveAccountsBlocking(accounts *outportcore.Accounts, driver Dr } } +// SaveStateChanges will save the state changes to every driver func (o *outport) SaveStateChanges() { o.mutex.RLock() defer o.mutex.RUnlock() diff --git a/process/block/metablock.go b/process/block/metablock.go index a341e25edc2..adbdfa72d3e 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -13,6 +13,8 @@ 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/headerVersionData" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" processOutport "github.com/multiversx/mx-chain-go/outport/process" @@ -21,7 +23,6 @@ import ( "github.com/multiversx/mx-chain-go/process/block/helpers" "github.com/multiversx/mx-chain-go/process/block/processedMb" "github.com/multiversx/mx-chain-go/state" - logger "github.com/multiversx/mx-chain-logger-go" ) const firstHeaderNonce = uint64(1) @@ -646,6 +647,9 @@ func (mp *metaProcessor) indexBlock( return } + //TODO: this can be removed. this is only to the test the integration. + mp.outportHandler.SaveStateChanges() + log.Debug("indexed block", "hash", headerHash, "nonce", metaBlock.GetNonce(), "round", metaBlock.GetRound()) indexRoundInfo(mp.outportHandler, mp.nodesCoordinator, core.MetachainShardId, metaBlock, lastMetaBlock, argSaveBlock.SignersIndexes) diff --git a/state/disabled/disabledStateChangesCollector.go b/state/disabled/disabledStateChangesCollector.go index 8405bd3821a..380c27428fa 100644 --- a/state/disabled/disabledStateChangesCollector.go +++ b/state/disabled/disabledStateChangesCollector.go @@ -2,9 +2,10 @@ package disabled import ( "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/stateChanges" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // disabledStateChangesCollector is a state changes collector that does nothing @@ -47,6 +48,10 @@ func (d *disabledStateChangesCollector) Publish() error { return nil } +func (d *disabledStateChangesCollector) GetStateChanges() []stateChanges.StateChange { + return nil +} + // IsInterfaceNil returns true if there is no value under the interface func (d *disabledStateChangesCollector) IsInterfaceNil() bool { return d == nil From f6bff485430c0d4baaf550f57957fa5aae388114 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 5 Sep 2024 15:18:54 +0300 Subject: [PATCH 03/28] migrated stateChanges to proto structure in mx-chain-core-go. --- go.mod | 2 +- go.sum | 4 +- process/block/preprocess/basePreProcess.go | 1 + process/block/preprocess/transactions.go | 5 ++- state/accountsDB.go | 32 +++++++-------- state/accountsDBApi.go | 3 +- state/accountsDBApiWithHistory.go | 3 +- state/interface.go | 5 ++- state/stateChanges/writeCollector.go | 43 ++------------------ state/trackableDataTrie/trackableDataTrie.go | 28 +++++++------ testscommon/trie/dataTrieTrackerStub.go | 11 ++--- 11 files changed, 55 insertions(+), 82 deletions(-) diff --git a/go.mod b/go.mod index 86225522dcc..33bdddeb976 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240905114358-3e9985d6cb80 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c diff --git a/go.sum b/go.sum index f12ab723392..252cb9a2c86 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 h1:WQoVgQG9YWiYM5Q3MmnbnxeoQkfHr63iFJZScFYsMxk= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240905114358-3e9985d6cb80 h1:5ogEZZrKvTAh4i2TC8udXftoSwREw9f5dvSxODDSkHY= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240905114358-3e9985d6cb80/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= diff --git a/process/block/preprocess/basePreProcess.go b/process/block/preprocess/basePreProcess.go index 58534fe4395..3519bcad6f6 100644 --- a/process/block/preprocess/basePreProcess.go +++ b/process/block/preprocess/basePreProcess.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index fd53f95aad5..c8f3a9b4eb5 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -15,6 +15,9 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -23,8 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/txcache" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var _ process.DataMarshalizer = (*transactions)(nil) diff --git a/state/accountsDB.go b/state/accountsDB.go index 56bb820f42d..9420183b7be 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" @@ -23,7 +24,6 @@ import ( "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/state/parsers" - "github.com/multiversx/mx-chain-go/state/stateChanges" "github.com/multiversx/mx-chain-go/trie/keyBuilder" "github.com/multiversx/mx-chain-go/trie/statistics" ) @@ -210,7 +210,7 @@ func (adb *AccountsDB) GetCode(codeHash []byte) []byte { return nil } - stateChange := &stateChanges.StateChangeDTO{ + stateChange := &stateChange.StateChange{ Type: "read", MainTrieKey: codeHash, MainTrieVal: val, @@ -285,7 +285,7 @@ func (adb *AccountsDB) SaveAccount(account vmcommon.AccountHandler) error { return err } - stateChange := &stateChanges.StateChangeDTO{ + stateChange := &stateChange.StateChange{ Type: "write", MainTrieKey: account.AddressBytes(), MainTrieVal: marshalledAccount, @@ -298,12 +298,12 @@ func (adb *AccountsDB) SaveAccount(account vmcommon.AccountHandler) error { return err } -func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandler) ([]stateChanges.DataTrieChange, error) { +func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandler) ([]*stateChange.DataTrieChange, error) { baseNewAcc, newAccOk := newAcc.(baseAccountHandler) baseOldAccount, _ := oldAcc.(baseAccountHandler) if !newAccOk { - return make([]stateChanges.DataTrieChange, 0), nil + return make([]*stateChange.DataTrieChange, 0), nil } newValues, err := adb.saveDataTrie(baseNewAcc) @@ -372,14 +372,14 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error return nil, nil } - stateChange := &stateChanges.StateChangeDTO{ + sc := &stateChange.StateChange{ Type: "read", MainTrieKey: oldCodeHash, MainTrieVal: nil, Operation: "getCode", DataTrieChanges: nil, } - adb.stateChangesCollector.AddStateChange(stateChange) + adb.stateChangesCollector.AddStateChange(sc) unmodifiedOldCodeEntry := &CodeEntry{ Code: oldCodeEntry.Code, @@ -392,14 +392,14 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error return nil, err } - stateChange := &stateChanges.StateChangeDTO{ + sc1 := &stateChange.StateChange{ Type: "write", MainTrieKey: oldCodeHash, MainTrieVal: nil, Operation: "writeCode", DataTrieChanges: nil, } - adb.stateChangesCollector.AddStateChange(stateChange) + adb.stateChangesCollector.AddStateChange(sc1) return unmodifiedOldCodeEntry, nil } @@ -410,14 +410,14 @@ func (adb *AccountsDB) updateOldCodeEntry(oldCodeHash []byte) (*CodeEntry, error return nil, err } - stateChange = &stateChanges.StateChangeDTO{ + sc = &stateChange.StateChange{ Type: "write", MainTrieKey: oldCodeHash, MainTrieVal: codeEntryBytes, Operation: "writeCode", DataTrieChanges: nil, } - adb.stateChangesCollector.AddStateChange(stateChange) + adb.stateChangesCollector.AddStateChange(sc) return unmodifiedOldCodeEntry, nil } @@ -444,14 +444,14 @@ func (adb *AccountsDB) updateNewCodeEntry(newCodeHash []byte, newCode []byte) er return err } - stateChange := &stateChanges.StateChangeDTO{ + sc := &stateChange.StateChange{ Type: "write", MainTrieKey: newCodeHash, MainTrieVal: codeEntryBytes, Operation: "writeCode", DataTrieChanges: nil, } - adb.stateChangesCollector.AddStateChange(stateChange) + adb.stateChangesCollector.AddStateChange(sc) return nil } @@ -517,7 +517,7 @@ func (adb *AccountsDB) loadDataTrieConcurrentSafe(accountHandler baseAccountHand // SaveDataTrie is used to save the data trie (not committing it) and to recompute the new Root value // If data is not dirtied, method will not create its JournalEntries to keep track of data modification -func (adb *AccountsDB) saveDataTrie(accountHandler baseAccountHandler) ([]stateChanges.DataTrieChange, error) { +func (adb *AccountsDB) saveDataTrie(accountHandler baseAccountHandler) ([]*stateChange.DataTrieChange, error) { newValues, oldValues, err := accountHandler.SaveDirtyData(adb.mainTrie) if err != nil { return nil, err @@ -651,13 +651,13 @@ func (adb *AccountsDB) removeDataTrie(baseAcc baseAccountHandler) error { } adb.journalize(entry) - stateChange := &stateChanges.StateChangeDTO{ + sc := &stateChange.StateChange{ Type: "write", MainTrieKey: baseAcc.AddressBytes(), Operation: "removeDataTrie", DataTrieChanges: nil, } - adb.stateChangesCollector.AddStateChange(stateChange) + adb.stateChangesCollector.AddStateChange(sc) return nil } diff --git a/state/accountsDBApi.go b/state/accountsDBApi.go index a9d42146a64..7b53e4ad85c 100644 --- a/state/accountsDBApi.go +++ b/state/accountsDBApi.go @@ -7,9 +7,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/holders" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type accountsDBApi struct { diff --git a/state/accountsDBApiWithHistory.go b/state/accountsDBApiWithHistory.go index 96d43a9cd31..c078143e3cc 100644 --- a/state/accountsDBApiWithHistory.go +++ b/state/accountsDBApiWithHistory.go @@ -7,9 +7,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/holders" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type accountsDBApiWithHistory struct { diff --git a/state/interface.go b/state/interface.go index 80e3a6baca3..f7583adc5b4 100644 --- a/state/interface.go +++ b/state/interface.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -163,7 +164,7 @@ type baseAccountHandler interface { GetRootHash() []byte SetDataTrie(trie common.Trie) DataTrie() common.DataTrieHandler - SaveDirtyData(trie common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) + SaveDirtyData(trie common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) IsInterfaceNil() bool } @@ -261,7 +262,7 @@ type DataTrieTracker interface { SaveKeyValue(key []byte, value []byte) error SetDataTrie(tr common.Trie) DataTrie() common.DataTrieHandler - SaveDirtyData(common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) + SaveDirtyData(common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) MigrateDataTrieLeaves(args vmcommon.ArgsMigrateDataTrieLeaves) error IsInterfaceNil() bool } diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 89bfad57617..7c794845832 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -14,49 +14,14 @@ import ( var log = logger.GetOrCreate("state/stateChanges") -// DataTrieChange represents a change in the data trie -type DataTrieChange struct { - Type string `json:"type"` - Key []byte `json:"key"` - Val []byte `json:"-"` -} - // ErrStateChangesIndexOutOfBounds signals that the state changes index is out of bounds var ErrStateChangesIndexOutOfBounds = errors.New("state changes index out of bounds") type StateChange interface { GetTxHash() []byte SetTxHash(txHash []byte) - GetIndex() int - SetIndex(index int) -} - -// StateChangeDTO is used to collect state changes -// TODO: change to use proto structs -type StateChangeDTO struct { - Type string `json:"type"` - Index int `json:"-"` - TxHash []byte `json:"-"` - MainTrieKey []byte `json:"mainTrieKey"` - MainTrieVal []byte `json:"-"` - Operation string `json:"operation"` - DataTrieChanges []DataTrieChange `json:"dataTrieChanges"` -} - -func (sc *StateChangeDTO) GetIndex() int { - return sc.Index -} - -func (sc *StateChangeDTO) SetIndex(index int) { - sc.Index = index -} - -func (sc *StateChangeDTO) GetTxHash() []byte { - return sc.TxHash -} - -func (sc *StateChangeDTO) SetTxHash(txHash []byte) { - sc.TxHash = txHash + GetIndex() int32 + SetIndex(index int32) } // StateChangesForTx is used to collect state changes for a transaction hash @@ -159,7 +124,7 @@ func (scc *stateChangesCollector) SetIndexToLastStateChange(index int) error { scc.stateChangesMut.Lock() defer scc.stateChangesMut.Unlock() - scc.stateChanges[len(scc.stateChanges)-1].SetIndex(index) + scc.stateChanges[len(scc.stateChanges)-1].SetIndex(int32(index)) return nil } @@ -179,7 +144,7 @@ func (scc *stateChangesCollector) RevertToIndex(index int) error { defer scc.stateChangesMut.Unlock() for i := len(scc.stateChanges) - 1; i >= 0; i-- { - if scc.stateChanges[i].GetIndex() == index { + if scc.stateChanges[i].GetIndex() == int32(index) { scc.stateChanges = scc.stateChanges[:i] break } diff --git a/state/trackableDataTrie/trackableDataTrie.go b/state/trackableDataTrie/trackableDataTrie.go index f16964c79f2..2d356ffab5d 100644 --- a/state/trackableDataTrie/trackableDataTrie.go +++ b/state/trackableDataTrie/trackableDataTrie.go @@ -8,15 +8,17 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" errorsCommon "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/dataTrieValue" - "github.com/multiversx/mx-chain-go/state/stateChanges" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var log = logger.GetOrCreate("state/trackableDataTrie") @@ -104,11 +106,11 @@ func (tdt *trackableDataTrie) RetrieveValue(key []byte) ([]byte, uint32, error) log.Trace("retrieve value from trie", "key", key, "value", val, "account", tdt.identifier) - stateChange := &stateChanges.StateChangeDTO{ + stateChange := &stateChange.StateChange{ Type: "read", MainTrieKey: tdt.identifier, MainTrieVal: nil, - DataTrieChanges: []stateChanges.DataTrieChange{ + DataTrieChanges: []*stateChange.DataTrieChange{ { Type: "read", Key: key, @@ -245,9 +247,9 @@ func (tdt *trackableDataTrie) DataTrie() common.DataTrieHandler { } // SaveDirtyData saved the dirty data to the trie -func (tdt *trackableDataTrie) SaveDirtyData(mainTrie common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { +func (tdt *trackableDataTrie) SaveDirtyData(mainTrie common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) { if len(tdt.dirtyData) == 0 { - return make([]stateChanges.DataTrieChange, 0), make([]core.TrieData, 0), nil + return make([]*stateChange.DataTrieChange, 0), make([]core.TrieData, 0), nil } if check.IfNil(tdt.tr) { @@ -267,10 +269,10 @@ func (tdt *trackableDataTrie) SaveDirtyData(mainTrie common.Trie) ([]stateChange return tdt.updateTrie(dtr) } -func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { +func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]*stateChange.DataTrieChange, []core.TrieData, error) { oldValues := make([]core.TrieData, len(tdt.dirtyData)) - newData := make([]stateChanges.DataTrieChange, len(tdt.dirtyData)) - deletedKeys := make([]stateChanges.DataTrieChange, 0) + newData := make([]*stateChange.DataTrieChange, len(tdt.dirtyData)) + deletedKeys := make([]*stateChange.DataTrieChange, 0) index := 0 for key, dataEntry := range tdt.dirtyData { @@ -287,7 +289,7 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]stateChanges.Dat if wasDeleted { deletedKeys = append(deletedKeys, - stateChanges.DataTrieChange{ + &stateChange.DataTrieChange{ Type: "write", Key: []byte(key), Val: nil, @@ -318,7 +320,7 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]stateChanges.Dat return nil, nil, fmt.Errorf("index out of range") } - newData[dataEntry.index] = stateChanges.DataTrieChange{ + newData[dataEntry.index] = &stateChange.DataTrieChange{ Type: "write", Key: dataTrieKey, Val: dataTrieVal, @@ -327,7 +329,7 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]stateChanges.Dat tdt.dirtyData = make(map[string]dirtyData) - stateChanges := make([]stateChanges.DataTrieChange, 0) + stateChanges := make([]*stateChange.DataTrieChange, 0) for i := range newData { if len(newData[i].Key) == 0 { continue diff --git a/testscommon/trie/dataTrieTrackerStub.go b/testscommon/trie/dataTrieTrackerStub.go index 9ee46a0a8e8..73c083b30c1 100644 --- a/testscommon/trie/dataTrieTrackerStub.go +++ b/testscommon/trie/dataTrieTrackerStub.go @@ -3,9 +3,10 @@ package trie import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-go/common" - "github.com/multiversx/mx-chain-go/state/stateChanges" + "github.com/multiversx/mx-chain-core-go/data/stateChange" vmcommon "github.com/multiversx/mx-chain-vm-common-go" + + "github.com/multiversx/mx-chain-go/common" ) // DataTrieTrackerStub - @@ -16,7 +17,7 @@ type DataTrieTrackerStub struct { SaveKeyValueCalled func(key []byte, value []byte) error SetDataTrieCalled func(tr common.Trie) DataTrieCalled func() common.Trie - SaveDirtyDataCalled func(trie common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) + SaveDirtyDataCalled func(trie common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) SaveTrieDataCalled func(trieData core.TrieData) error MigrateDataTrieLeavesCalled func(args vmcommon.ArgsMigrateDataTrieLeaves) error } @@ -62,12 +63,12 @@ func (dtts *DataTrieTrackerStub) DataTrie() common.DataTrieHandler { } // SaveDirtyData - -func (dtts *DataTrieTrackerStub) SaveDirtyData(mainTrie common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { +func (dtts *DataTrieTrackerStub) SaveDirtyData(mainTrie common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) { if dtts.SaveDirtyDataCalled != nil { return dtts.SaveDirtyDataCalled(mainTrie) } - return make([]stateChanges.DataTrieChange, 0), make([]core.TrieData, 0), nil + return make([]*stateChange.DataTrieChange, 0), make([]core.TrieData, 0), nil } // MigrateDataTrieLeaves - From a57053e058e0068e0ec7fdba472ae6ec4cefd4ef Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 6 Sep 2024 14:18:51 +0300 Subject: [PATCH 04/28] moved all the state changes in mx-chain-core-go. --- factory/processing/blockProcessorCreator.go | 8 +- go.mod | 2 +- go.sum | 4 +- outport/factory/hostDriverFactory.go | 7 +- outport/host/driver.go | 39 ++--- outport/interface.go | 2 - outport/outport.go | 27 ---- .../factory/outportDataProviderFactory.go | 5 +- outport/process/outportDataProvider.go | 11 +- process/block/metablock.go | 4 +- scripts/testnet/variables.sh | 10 +- .../disabled/disabledStateChangesCollector.go | 3 +- state/interface.go | 2 +- state/stateChanges/dataAnalysisCollector.go | 2 +- state/stateChanges/export_test.go | 2 +- state/stateChanges/writeCollector.go | 145 +++++++++++------- 16 files changed, 137 insertions(+), 136 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index c3618eff970..54df8094660 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -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" @@ -42,9 +46,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 { @@ -1031,6 +1032,7 @@ func (pcf *processComponentsFactory) createOutportDataProvider( MbsStorer: mbsStorer, EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), ExecutionOrderGetter: pcf.txExecutionOrderHandler, + StateChangesCollector: pcf.state.StateChangesCollector(), }) } diff --git a/go.mod b/go.mod index 33bdddeb976..68fb7ae914d 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240905114358-3e9985d6cb80 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906093529-4da59a927b44 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c diff --git a/go.sum b/go.sum index 252cb9a2c86..22d508569c2 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240905114358-3e9985d6cb80 h1:5ogEZZrKvTAh4i2TC8udXftoSwREw9f5dvSxODDSkHY= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240905114358-3e9985d6cb80/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906093529-4da59a927b44 h1:3GdhKb2Q5KeW9A8uM3a/K9Ejjm8NwRJmpWOw1TQtCk0= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906093529-4da59a927b44/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= diff --git a/outport/factory/hostDriverFactory.go b/outport/factory/hostDriverFactory.go index 895c5577688..90b5b562dac 100644 --- a/outport/factory/hostDriverFactory.go +++ b/outport/factory/hostDriverFactory.go @@ -42,9 +42,8 @@ func CreateHostDriver(args ArgsHostDriverFactory) (outport.Driver, error) { } return host.NewHostDriver(host.ArgsHostDriver{ - Marshaller: args.Marshaller, - SenderHost: wsHost, - Log: log, - StateChangesCollector: args.StateChangesCollector, + Marshaller: args.Marshaller, + SenderHost: wsHost, + Log: log, }) } diff --git a/outport/host/driver.go b/outport/host/driver.go index e73871c2c71..d15771f28c4 100644 --- a/outport/host/driver.go +++ b/outport/host/driver.go @@ -8,25 +8,21 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/marshal" - - "github.com/multiversx/mx-chain-go/state" ) // ArgsHostDriver holds the arguments needed for creating a new hostDriver type ArgsHostDriver struct { - Marshaller marshal.Marshalizer - SenderHost SenderHost - Log core.Logger - StateChangesCollector state.StateChangesCollector + Marshaller marshal.Marshalizer + SenderHost SenderHost + Log core.Logger } type hostDriver struct { - marshaller marshal.Marshalizer - senderHost SenderHost - isClosed atomic.Flag - log core.Logger - payloadProc payloadProcessorHandler - stateChangesCollector state.StateChangesCollector + marshaller marshal.Marshalizer + senderHost SenderHost + isClosed atomic.Flag + log core.Logger + payloadProc payloadProcessorHandler } // NewHostDriver will create a new instance of hostDriver @@ -40,9 +36,6 @@ func NewHostDriver(args ArgsHostDriver) (*hostDriver, error) { if check.IfNil(args.Log) { return nil, core.ErrNilLogger } - if check.IfNil(args.StateChangesCollector) { - return nil, ErrNilStateChangesCollector - } payloadProc, err := newPayloadProcessor(args.Log) if err != nil { @@ -55,12 +48,11 @@ func NewHostDriver(args ArgsHostDriver) (*hostDriver, error) { } return &hostDriver{ - marshaller: args.Marshaller, - senderHost: args.SenderHost, - log: args.Log, - isClosed: atomic.Flag{}, - payloadProc: payloadProc, - stateChangesCollector: args.StateChangesCollector, + marshaller: args.Marshaller, + senderHost: args.SenderHost, + log: args.Log, + isClosed: atomic.Flag{}, + payloadProc: payloadProc, }, nil } @@ -132,11 +124,6 @@ func (o *hostDriver) SetCurrentSettings(config outport.OutportConfig) error { return o.handleAction(&config, outport.TopicSettings) } -func (o *hostDriver) SaveStateChanges() error { - //TODO: add this as a constant - return o.handleAction(o.stateChangesCollector.GetStateChanges(), "SaveStateChanges") -} - // Close will handle the closing of the outport driver web socket sender func (o *hostDriver) Close() error { o.isClosed.SetValue(true) diff --git a/outport/interface.go b/outport/interface.go index 645721b402d..70a3673cd0c 100644 --- a/outport/interface.go +++ b/outport/interface.go @@ -16,7 +16,6 @@ type Driver interface { SaveValidatorsPubKeys(validatorsPubKeys *outportcore.ValidatorsPubKeys) error SaveValidatorsRating(validatorsRating *outportcore.ValidatorsRating) error SaveAccounts(accounts *outportcore.Accounts) error - SaveStateChanges() error FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) error GetMarshaller() marshal.Marshalizer SetCurrentSettings(config outportcore.OutportConfig) error @@ -34,7 +33,6 @@ type OutportHandler interface { SaveValidatorsPubKeys(validatorsPubKeys *outportcore.ValidatorsPubKeys) SaveValidatorsRating(validatorsRating *outportcore.ValidatorsRating) SaveAccounts(accounts *outportcore.Accounts) - SaveStateChanges() FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) SubscribeDriver(driver Driver) error HasDrivers() bool diff --git a/outport/outport.go b/outport/outport.go index b5cfdabfc83..e3210361d56 100644 --- a/outport/outport.go +++ b/outport/outport.go @@ -310,33 +310,6 @@ func (o *outport) saveAccountsBlocking(accounts *outportcore.Accounts, driver Dr } } -// SaveStateChanges will save the state changes to every driver -func (o *outport) SaveStateChanges() { - o.mutex.RLock() - defer o.mutex.RUnlock() - - for _, driver := range o.drivers { - o.saveStateChangesBlocking(driver) - } -} - -func (o *outport) saveStateChangesBlocking(driver Driver) { - ch := o.monitorCompletionOnDriver("finalizedBlockBlocking", driver) - defer close(ch) - - for { - err := driver.SaveStateChanges() - if err == nil { - return - } - - log.Error("error calling SaveStateChanges, will retry", - "driver", driverString(driver), - "retrial in", o.retrialInterval, - "error", err) - } -} - // FinalizedBlock will call all the drivers that a block is finalized func (o *outport) FinalizedBlock(finalizedBlock *outportcore.FinalizedBlock) { o.mutex.RLock() diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index 68546df1c50..f0a083f6665 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -4,6 +4,8 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/outport" "github.com/multiversx/mx-chain-go/outport/process" @@ -15,7 +17,6 @@ import ( "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // ArgOutportDataProviderFactory holds the arguments needed for creating a new instance of outport.DataProviderOutport @@ -36,6 +37,7 @@ type ArgOutportDataProviderFactory struct { MbsStorer storage.Storer EnableEpochsHandler common.EnableEpochsHandler ExecutionOrderGetter common.ExecutionOrderGetter + StateChangesCollector state.StateChangesCollector } // CreateOutportDataProvider will create a new instance of outport.DataProviderOutport @@ -82,5 +84,6 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP ExecutionOrderHandler: arg.ExecutionOrderGetter, Hasher: arg.Hasher, Marshaller: arg.Marshaller, + StateChangesCollector: arg.StateChangesCollector, }) } diff --git a/outport/process/outportDataProvider.go b/outport/process/outportDataProvider.go index a99e0bc4827..adaee8ea35f 100644 --- a/outport/process/outportDataProvider.go +++ b/outport/process/outportDataProvider.go @@ -16,12 +16,14 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/outport/process/alteredaccounts/shared" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" - logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/state" ) var log = logger.GetOrCreate("outport/process/outportDataProvider") @@ -39,6 +41,7 @@ type ArgOutportDataProvider struct { Marshaller marshal.Marshalizer Hasher hashing.Hasher ExecutionOrderHandler common.ExecutionOrderGetter + StateChangesCollector state.StateChangesCollector } // ArgPrepareOutportSaveBlockData holds the arguments needed for prepare outport save block data @@ -67,6 +70,7 @@ type outportDataProvider struct { executionOrderHandler common.ExecutionOrderGetter marshaller marshal.Marshalizer hasher hashing.Hasher + stateChangesCollector state.StateChangesCollector } // NewOutportDataProvider will create a new instance of outportDataProvider @@ -83,6 +87,7 @@ func NewOutportDataProvider(arg ArgOutportDataProvider) (*outportDataProvider, e executionOrderHandler: arg.ExecutionOrderHandler, marshaller: arg.Marshaller, hasher: arg.Hasher, + stateChangesCollector: arg.StateChangesCollector, }, nil } @@ -134,6 +139,9 @@ func (odp *outportDataProvider) PrepareOutportSaveBlockData(arg ArgPrepareOutpor return nil, err } + stateChanges := odp.stateChangesCollector.GetStateChangesForTxs() + odp.stateChangesCollector.Reset() + return &outportcore.OutportBlockWithHeaderAndBody{ OutportBlock: &outportcore.OutportBlock{ ShardID: odp.shardID, @@ -145,6 +153,7 @@ func (odp *outportDataProvider) PrepareOutportSaveBlockData(arg ArgPrepareOutpor GasPenalized: odp.gasConsumedProvider.TotalGasPenalized(), MaxGasPerBlock: odp.economicsData.MaxGasLimitPerBlock(odp.shardID), }, + StateChanges: stateChanges, AlteredAccounts: alteredAccounts, NotarizedHeadersHashes: arg.NotarizedHeadersHashes, NumberOfShards: odp.numOfShards, diff --git a/process/block/metablock.go b/process/block/metablock.go index adbdfa72d3e..073a0046282 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -635,6 +635,7 @@ func (mp *metaProcessor) indexBlock( HighestFinalBlockNonce: mp.forkDetector.GetHighestFinalBlockNonce(), HighestFinalBlockHash: mp.forkDetector.GetHighestFinalBlockHash(), }) + if err != nil { log.Error("metaProcessor.indexBlock cannot prepare argSaveBlock", "error", err.Error(), "hash", headerHash, "nonce", metaBlock.GetNonce(), "round", metaBlock.GetRound()) @@ -647,9 +648,6 @@ func (mp *metaProcessor) indexBlock( return } - //TODO: this can be removed. this is only to the test the integration. - mp.outportHandler.SaveStateChanges() - log.Debug("indexed block", "hash", headerHash, "nonce", metaBlock.GetNonce(), "round", metaBlock.GetRound()) indexRoundInfo(mp.outportHandler, mp.nodesCoordinator, core.MetachainShardId, metaBlock, lastMetaBlock, argSaveBlock.SignersIndexes) diff --git a/scripts/testnet/variables.sh b/scripts/testnet/variables.sh index f3fb44c5866..fa201f67c4c 100644 --- a/scripts/testnet/variables.sh +++ b/scripts/testnet/variables.sh @@ -12,7 +12,7 @@ export USE_PROXY=1 # Enable the MultiversX Transaction Generator. Note that this is a private # repository (mx-chain-txgen-go). -export USE_TXGEN=0 +export USE_TXGEN=1 # Path where the testnet will be instantiated. This folder is assumed to not # exist, but it doesn't matter if it already does. It will be created if not, @@ -52,13 +52,13 @@ export GENESIS_STAKE_TYPE="direct" #'delegated' or 'direct' as in direct stake export OBSERVERS_ANTIFLOOD_DISABLE=0 # Shard structure -export SHARDCOUNT=2 -export SHARD_VALIDATORCOUNT=3 +export SHARDCOUNT=1 +export SHARD_VALIDATORCOUNT=1 export SHARD_OBSERVERCOUNT=1 -export SHARD_CONSENSUS_SIZE=3 +export SHARD_CONSENSUS_SIZE=1 # Metashard structure -export META_VALIDATORCOUNT=3 +export META_VALIDATORCOUNT=1 export META_OBSERVERCOUNT=1 export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT diff --git a/state/disabled/disabledStateChangesCollector.go b/state/disabled/disabledStateChangesCollector.go index 380c27428fa..836b92776b1 100644 --- a/state/disabled/disabledStateChangesCollector.go +++ b/state/disabled/disabledStateChangesCollector.go @@ -1,6 +1,7 @@ package disabled import ( + "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -48,7 +49,7 @@ func (d *disabledStateChangesCollector) Publish() error { return nil } -func (d *disabledStateChangesCollector) GetStateChanges() []stateChanges.StateChange { +func (d *disabledStateChangesCollector) GetStateChangesForTxs() map[string]*stateChange.StateChangesForTx { return nil } diff --git a/state/interface.go b/state/interface.go index f7583adc5b4..97c264407f4 100644 --- a/state/interface.go +++ b/state/interface.go @@ -365,6 +365,6 @@ type StateChangesCollector interface { SetIndexToLastStateChange(index int) error RevertToIndex(index int) error Publish() error - GetStateChanges() []stateChanges.StateChange + GetStateChangesForTxs() map[string]*stateChange.StateChangesForTx IsInterfaceNil() bool } diff --git a/state/stateChanges/dataAnalysisCollector.go b/state/stateChanges/dataAnalysisCollector.go index 85b8fd39638..69aaf49fa2f 100644 --- a/state/stateChanges/dataAnalysisCollector.go +++ b/state/stateChanges/dataAnalysisCollector.go @@ -205,7 +205,7 @@ func (scc *dataAnalysisCollector) Publish() error { return nil } -func (scc *dataAnalysisCollector) GetStateChanges() []StateChange { +func (scc *dataAnalysisCollector) GetStateChangesForTx() []StateChange { return scc.stateChanges } diff --git a/state/stateChanges/export_test.go b/state/stateChanges/export_test.go index 86350f45a5c..3e52d0985b2 100644 --- a/state/stateChanges/export_test.go +++ b/state/stateChanges/export_test.go @@ -2,6 +2,6 @@ package stateChanges // GetStateChanges - func (scc *stateChangesCollector) GetStateChanges() []StateChangesForTx { - scs, _ := scc.getStateChangesForTxs() + scs, _ := scc.GetStateChangesForTxs() return scs } diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 7c794845832..2ed84f263ed 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -1,12 +1,10 @@ package stateChanges import ( - "bytes" - "encoding/hex" "errors" - "fmt" "sync" + data "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -18,17 +16,23 @@ var log = logger.GetOrCreate("state/stateChanges") var ErrStateChangesIndexOutOfBounds = errors.New("state changes index out of bounds") type StateChange interface { + GetType() string + GetIndex() int32 GetTxHash() []byte + GetMainTrieKey() []byte + GetMainTrieVal() []byte + GetOperation() string + GetDataTrieChanges() []*data.DataTrieChange + SetTxHash(txHash []byte) - GetIndex() int32 SetIndex(index int32) } -// StateChangesForTx is used to collect state changes for a transaction hash -type StateChangesForTx struct { - TxHash []byte `json:"txHash"` - StateChanges []StateChange `json:"stateChanges"` -} +//// StateChangesForTx is used to collect state changes for a transaction hash +//type StateChangesForTx struct { +// TxHash []byte `json:"txHash"` +// StateChanges []StateChange `json:"stateChanges"` +//} type stateChangesCollector struct { stateChanges []StateChange @@ -56,40 +60,71 @@ func (scc *stateChangesCollector) AddStateChange(stateChange StateChange) { scc.stateChangesMut.Unlock() } -func (scc *stateChangesCollector) getStateChangesForTxs() ([]StateChangesForTx, error) { +func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChangesForTx { scc.stateChangesMut.Lock() defer scc.stateChangesMut.Unlock() - stateChangesForTxs := make([]StateChangesForTx, 0) - - for i := 0; i < len(scc.stateChanges); i++ { - txHash := scc.stateChanges[i].GetTxHash() - - if len(txHash) == 0 { - log.Warn("empty tx hash, state change event not associated to a transaction") - break - } - - innerStateChangesForTx := make([]StateChange, 0) - for j := i; j < len(scc.stateChanges); j++ { - txHash2 := scc.stateChanges[j].GetTxHash() - if !bytes.Equal(txHash, txHash2) { - i = j - break + stateChangesForTxs := make(map[string]*data.StateChangesForTx) + + for _, stateChange := range scc.stateChanges { + txHash := string(stateChange.GetTxHash()) + + if sc, ok := stateChangesForTxs[txHash]; !ok { + stateChangesForTxs[txHash] = &data.StateChangesForTx{StateChanges: []*data.StateChange{ + { + Type: stateChange.GetType(), + Index: stateChange.GetIndex(), + TxHash: stateChange.GetTxHash(), + MainTrieKey: stateChange.GetMainTrieKey(), + MainTrieVal: stateChange.GetMainTrieVal(), + Operation: stateChange.GetOperation(), + DataTrieChanges: stateChange.GetDataTrieChanges(), + }, + }, } - - innerStateChangesForTx = append(innerStateChangesForTx, scc.stateChanges[j]) - i = j + } else { + stateChangesForTxs[txHash].StateChanges = append(sc.StateChanges, + &data.StateChange{ + Type: stateChange.GetType(), + Index: stateChange.GetIndex(), + TxHash: stateChange.GetTxHash(), + MainTrieKey: stateChange.GetMainTrieKey(), + MainTrieVal: stateChange.GetMainTrieVal(), + Operation: stateChange.GetOperation(), + DataTrieChanges: stateChange.GetDataTrieChanges(), + }, + ) } - - stateChangesForTx := StateChangesForTx{ - TxHash: txHash, - StateChanges: innerStateChangesForTx, - } - stateChangesForTxs = append(stateChangesForTxs, stateChangesForTx) } - return stateChangesForTxs, nil + //for i := 0; i < len(scc.stateChanges); i++ { + // txHash := scc.stateChanges[i].GetTxHash() + // + // if len(txHash) == 0 { + // log.Warn("empty tx hash, state change event not associated to a transaction") + // break + // } + // + // innerStateChangesForTx := make([]StateChange, 0) + // for j := i; j < len(scc.stateChanges); j++ { + // txHash2 := scc.stateChanges[j].GetTxHash() + // if !bytes.Equal(txHash, txHash2) { + // i = j + // break + // } + // + // innerStateChangesForTx = append(innerStateChangesForTx, scc.stateChanges[j]) + // i = j + // } + // + // stateChangesForTx := StateChangesForTx{ + // TxHash: txHash, + // StateChanges: innerStateChangesForTx, + // } + // stateChangesForTxs = append(stateChangesForTxs, stateChangesForTx) + //} + + return stateChangesForTxs } // Reset resets the state changes collector @@ -155,32 +190,28 @@ func (scc *stateChangesCollector) RevertToIndex(index int) error { // Publish will export state changes func (scc *stateChangesCollector) Publish() error { - stateChangesForTx, err := scc.getStateChangesForTxs() - if err != nil { - return err - } + //stateChangesForTx, err := scc.GetStateChangesForTxs() + //if err != nil { + // return err + //} - printStateChanges(stateChangesForTx) + //printStateChanges(stateChangesForTx) return nil } -func printStateChanges(stateChanges []StateChangesForTx) { - for _, stateChange := range stateChanges { - - if stateChange.TxHash != nil { - fmt.Println(hex.EncodeToString(stateChange.TxHash)) - } - - for _, st := range stateChange.StateChanges { - fmt.Println(st) - } - } -} - -func (scc *stateChangesCollector) GetStateChanges() []StateChange { - return scc.stateChanges -} +//func printStateChanges(stateChanges []StateChangesForTx) { +// for _, stateChange := range stateChanges { +// +// if stateChange.TxHash != nil { +// fmt.Println(hex.EncodeToString(stateChange.TxHash)) +// } +// +// for _, st := range stateChange.StateChanges { +// fmt.Println(st) +// } +// } +//} // IsInterfaceNil returns true if there is no value under the interface func (scc *stateChangesCollector) IsInterfaceNil() bool { From f8c9ba57cb647c17e8c8b6f70612518db90e56f9 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 6 Sep 2024 15:52:59 +0300 Subject: [PATCH 05/28] fixed nil pointer reference. --- state/trackableDataTrie/trackableDataTrie.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/state/trackableDataTrie/trackableDataTrie.go b/state/trackableDataTrie/trackableDataTrie.go index 2d356ffab5d..5d1d890ecdc 100644 --- a/state/trackableDataTrie/trackableDataTrie.go +++ b/state/trackableDataTrie/trackableDataTrie.go @@ -331,6 +331,9 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]*stateChange.Dat stateChanges := make([]*stateChange.DataTrieChange, 0) for i := range newData { + if newData[i] == nil { + continue + } if len(newData[i].Key) == 0 { continue } From 09802ae5e0f422bbbc6bf7aa86f45e2ee0b127d5 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 6 Sep 2024 17:48:33 +0300 Subject: [PATCH 06/28] moved collected state changes in outport block. --- go.mod | 2 +- go.sum | 4 ++-- state/disabled/disabledStateChangesCollector.go | 2 +- state/interface.go | 3 ++- state/stateChanges/writeCollector.go | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 68fb7ae914d..b32c7dfae9d 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906093529-4da59a927b44 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906142519-0afffde1cb6b github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c diff --git a/go.sum b/go.sum index 22d508569c2..2e34d2a65ab 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906093529-4da59a927b44 h1:3GdhKb2Q5KeW9A8uM3a/K9Ejjm8NwRJmpWOw1TQtCk0= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906093529-4da59a927b44/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906142519-0afffde1cb6b h1:41RtfXzxUZ34lRhtoVT3kJo/oUVDFvHToucX3fKdFs0= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906142519-0afffde1cb6b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= diff --git a/state/disabled/disabledStateChangesCollector.go b/state/disabled/disabledStateChangesCollector.go index 836b92776b1..e6e0f23990f 100644 --- a/state/disabled/disabledStateChangesCollector.go +++ b/state/disabled/disabledStateChangesCollector.go @@ -49,7 +49,7 @@ func (d *disabledStateChangesCollector) Publish() error { return nil } -func (d *disabledStateChangesCollector) GetStateChangesForTxs() map[string]*stateChange.StateChangesForTx { +func (d *disabledStateChangesCollector) GetStateChangesForTxs() map[string]*stateChange.StateChanges { return nil } diff --git a/state/interface.go b/state/interface.go index 97c264407f4..dadc450706f 100644 --- a/state/interface.go +++ b/state/interface.go @@ -7,6 +7,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/stateChange" + data "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -365,6 +366,6 @@ type StateChangesCollector interface { SetIndexToLastStateChange(index int) error RevertToIndex(index int) error Publish() error - GetStateChangesForTxs() map[string]*stateChange.StateChangesForTx + GetStateChangesForTxs() map[string]*data.StateChanges IsInterfaceNil() bool } diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 2ed84f263ed..da58f2634a0 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -60,17 +60,17 @@ func (scc *stateChangesCollector) AddStateChange(stateChange StateChange) { scc.stateChangesMut.Unlock() } -func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChangesForTx { +func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChanges { scc.stateChangesMut.Lock() defer scc.stateChangesMut.Unlock() - stateChangesForTxs := make(map[string]*data.StateChangesForTx) + stateChangesForTxs := make(map[string]*data.StateChanges) for _, stateChange := range scc.stateChanges { txHash := string(stateChange.GetTxHash()) if sc, ok := stateChangesForTxs[txHash]; !ok { - stateChangesForTxs[txHash] = &data.StateChangesForTx{StateChanges: []*data.StateChange{ + stateChangesForTxs[txHash] = &data.StateChanges{StateChanges: []*data.StateChange{ { Type: stateChange.GetType(), Index: stateChange.GetIndex(), From 28f38a8476014f5f68da71bdcbf9c1436f6f57b1 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 6 Sep 2024 17:52:47 +0300 Subject: [PATCH 07/28] update core-go. --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b32c7dfae9d..f94c99e7488 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906142519-0afffde1cb6b + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906145048-894187a86b01 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c From f492061fcec8f9fb8b716cafd96c1b871cb11edd Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 10:18:29 +0300 Subject: [PATCH 08/28] commit go.sum. --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 2e34d2a65ab..e11d135b2c0 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906142519-0afffde1cb6b h1:41RtfXzxUZ34lRhtoVT3kJo/oUVDFvHToucX3fKdFs0= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906142519-0afffde1cb6b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906145048-894187a86b01 h1:x1ZZ+4bPpz+k7xmAAAtsKo0m97c1eVCaugJI9VX6W3c= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906145048-894187a86b01/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= From b4b49d6e69328a8785ddbaac56cd145b7f30d6b2 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 11:51:09 +0300 Subject: [PATCH 09/28] update dependencies. --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index f94c99e7488..5f5b68c2c24 100644 --- a/go.mod +++ b/go.mod @@ -15,12 +15,12 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906145048-894187a86b01 + github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909083346-b1e2eff1cc9c github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a - github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c + github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 + github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909083434-9ff458d5c374 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 diff --git a/go.sum b/go.sum index e11d135b2c0..6712154f5af 100644 --- a/go.sum +++ b/go.sum @@ -387,18 +387,18 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906145048-894187a86b01 h1:x1ZZ+4bPpz+k7xmAAAtsKo0m97c1eVCaugJI9VX6W3c= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240906145048-894187a86b01/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909083346-b1e2eff1cc9c h1:ULbgO2tzBEZeu88gtjOcVWFSNmCPkYQkK8ngh9z0/p8= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909083346-b1e2eff1cc9c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= +github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= +github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909083434-9ff458d5c374 h1:Npzzj83YCZm8u2jEUWuQtZVzFiCSPAwVRXm2biB/6Xo= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909083434-9ff458d5c374/go.mod h1:ZQciW/dv/33j2pg7aFrtQG2RAsnitOyx6zgKXJ3Q3sA= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 h1:sBH1Zf5jdMqS+1LDfXBmsIdmol8CFloPzjDCtmBZGEc= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a h1:QvIC6R5sf0koeSwAs+Ye8J+CjNkAdaosTMSNTVBB8sA= From 291f6c0dd462e166f081aa37636e87edcfeea4a1 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 15:11:11 +0300 Subject: [PATCH 10/28] fix after merge. --- genesis/mock/userAccountMock.go | 5 +- go.mod | 18 ++-- go.sum | 36 ++++---- outport/outport.go | 2 +- process/transaction/shardProcess.go | 3 +- state/accountsDBApi.go | 15 ++-- state/interface.go | 6 +- state/stateChanges/writeCollector.go | 103 ++++++++++++++++------ state/stateChanges/writeCollector_test.go | 17 ++-- testscommon/p2pmocks/messengerStub.go | 1 + testscommon/state/accountWrapperMock.go | 7 +- testscommon/state/userAccountStub.go | 7 +- 12 files changed, 135 insertions(+), 85 deletions(-) diff --git a/genesis/mock/userAccountMock.go b/genesis/mock/userAccountMock.go index 6a9e31c2dd0..28ef9e7c966 100644 --- a/genesis/mock/userAccountMock.go +++ b/genesis/mock/userAccountMock.go @@ -6,8 +6,9 @@ import ( "math/big" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/stateChange" + "github.com/multiversx/mx-chain-go/common" - "github.com/multiversx/mx-chain-go/state/stateChanges" ) // ErrNegativeValue - @@ -148,7 +149,7 @@ func (uam *UserAccountMock) GetUserName() []byte { } // SaveDirtyData - -func (uam *UserAccountMock) SaveDirtyData(_ common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { +func (uam *UserAccountMock) SaveDirtyData(_ common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) { return nil, nil, nil } diff --git a/go.mod b/go.mod index 5f5b68c2c24..c95171c6435 100644 --- a/go.mod +++ b/go.mod @@ -15,17 +15,17 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909083346-b1e2eff1cc9c - github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 + github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 + github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.15 - github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909083434-9ff458d5c374 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 + github.com/multiversx/mx-chain-scenario-go v1.4.4 + github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909105906-39ad1daf2a4c + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 6712154f5af..898f63d9dfd 100644 --- a/go.sum +++ b/go.sum @@ -387,28 +387,28 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909083346-b1e2eff1cc9c h1:ULbgO2tzBEZeu88gtjOcVWFSNmCPkYQkK8ngh9z0/p8= -github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909083346-b1e2eff1cc9c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 h1:omuzhvGYFRAE0UA9UMatgSLTBlANKea0hU/jskzj6pM= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= +github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909083434-9ff458d5c374 h1:Npzzj83YCZm8u2jEUWuQtZVzFiCSPAwVRXm2biB/6Xo= -github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909083434-9ff458d5c374/go.mod h1:ZQciW/dv/33j2pg7aFrtQG2RAsnitOyx6zgKXJ3Q3sA= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 h1:sBH1Zf5jdMqS+1LDfXBmsIdmol8CFloPzjDCtmBZGEc= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a h1:QvIC6R5sf0koeSwAs+Ye8J+CjNkAdaosTMSNTVBB8sA= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a/go.mod h1:Xs0xFsPv+c1p8pwurLV7VBS7bEpIN/0jZrCwXVU26zw= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 h1:aLJhYiDBtWW4yjizhvQgTU00KfkK3oL3GnEh7pVUPRs= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34/go.mod h1:8uugq3HUeDiE6G4AS3F8/B3zA1Pabzbl7SSD6Cebwz8= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b h1:iDDarqnGFZBXxqpaPWp8ePOqhG5G3DeAoopGgRLteu0= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b/go.mod h1:4uezxguZiX42kUaYMK/x46LLbgpYqn/iQXbcGM7zdM0= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 h1:yRfY/Mj1CXPoGd21F3y84cqBIKsktSgPuxz/5a7FA3w= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35/go.mod h1:Nvanb5BZVhqnFFlWUtn7PQ/GIsl72zPVcMEw/ZvYiQA= +github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= +github.com/multiversx/mx-chain-scenario-go v1.4.4/go.mod h1:kI+TWR3oIEgUkbwkHCPo2CQ3VjIge+ezGTibiSGwMxo= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909105906-39ad1daf2a4c h1:1Wmh5iblKtE6S5NBdyPcHcKmiR3C1oF+MNRBVOrmAcc= +github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909105906-39ad1daf2a4c/go.mod h1:2VWMriwcI0s7kTnKHqJxFQnb0aMswc5KTbHp8MKw3Uk= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 h1:RlHKl5enbGrleB0Aea9TinZLLymS4WvG0/xAt/iRb6E= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e h1:BkZtPUAQ9JlATkENydCLxPZ819hjop6laZtmC7Wzqec= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69/go.mod h1:msY3zaS+K+R10ypqQs/jke6xdNAJzS38PGIaeJj2zhg= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 h1:/fYx4ClVPU48pTKh2qk4QVlve0xjjDpvzOakjFUtXJ8= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98/go.mod h1:4vqG8bSmufZx263DMrmr8OLbO6q6//VPC4W9PxZLB5Q= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= diff --git a/outport/outport.go b/outport/outport.go index e3210361d56..edcecc0691a 100644 --- a/outport/outport.go +++ b/outport/outport.go @@ -279,7 +279,7 @@ func (o *outport) saveValidatorsRatingBlocking(validatorsRating *outportcore.Val } } -// SaveAccounts will save accounts for every driver +// SaveAccounts will save accounts for every driver func (o *outport) SaveAccounts(accounts *outportcore.Accounts) { o.mutex.RLock() defer o.mutex.RUnlock() diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 415fc519c66..025418e68f1 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -15,6 +15,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -22,8 +23,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var log = logger.GetOrCreate("process/transaction") diff --git a/state/accountsDBApi.go b/state/accountsDBApi.go index 7b53e4ad85c..ef2f7e26e9f 100644 --- a/state/accountsDBApi.go +++ b/state/accountsDBApi.go @@ -65,7 +65,8 @@ func (accountsDB *accountsDBApi) doRecreateTrieWithBlockInfo(newBlockInfo common return currentBlockInfo, nil } - err := accountsDB.innerAccountsAdapter.RecreateTrie(newBlockInfo.GetRootHash()) + rootHashHolder := holders.NewDefaultRootHashesHolder(newBlockInfo.GetRootHash()) + err := accountsDB.innerAccountsAdapter.RecreateTrie(rootHashHolder) if err != nil { accountsDB.blockInfo = nil return nil, err @@ -166,14 +167,8 @@ func (accountsDB *accountsDBApi) RootHash() ([]byte, error) { return blockInfo.GetRootHash(), nil } -// RecreateTrie is used to reload the trie based on an existing rootHash -func (accountsDB *accountsDBApi) RecreateTrie(rootHash []byte) error { - _, err := accountsDB.doRecreateTrieWithBlockInfo(holders.NewBlockInfo([]byte{}, 0, rootHash)) - return err -} - -// RecreateTrieFromEpoch is a not permitted operation in this implementation and thus, will return an error -func (accountsDB *accountsDBApi) RecreateTrieFromEpoch(options common.RootHashHolder) error { +// RecreateTrie is a not permitted operation in this implementation and thus, will return an error +func (accountsDB *accountsDBApi) RecreateTrie(options common.RootHashHolder) error { accountsDB.mutRecreatedTrieBlockInfo.Lock() defer accountsDB.mutRecreatedTrieBlockInfo.Unlock() @@ -186,7 +181,7 @@ func (accountsDB *accountsDBApi) RecreateTrieFromEpoch(options common.RootHashHo return nil } - err := accountsDB.innerAccountsAdapter.RecreateTrieFromEpoch(options) + err := accountsDB.innerAccountsAdapter.RecreateTrie(options) if err != nil { accountsDB.blockInfo = nil return err diff --git a/state/interface.go b/state/interface.go index 76090b45a27..49be503dcc5 100644 --- a/state/interface.go +++ b/state/interface.go @@ -6,7 +6,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/stateChange" data "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -164,7 +163,7 @@ type baseAccountHandler interface { GetRootHash() []byte SetDataTrie(trie common.Trie) DataTrie() common.DataTrieHandler - SaveDirtyData(trie common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) + SaveDirtyData(trie common.Trie) ([]*data.DataTrieChange, []core.TrieData, error) IsInterfaceNil() bool } @@ -262,7 +261,7 @@ type DataTrieTracker interface { SaveKeyValue(key []byte, value []byte) error SetDataTrie(tr common.Trie) DataTrie() common.DataTrieHandler - SaveDirtyData(common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) + SaveDirtyData(common.Trie) ([]*data.DataTrieChange, []core.TrieData, error) MigrateDataTrieLeaves(args vmcommon.ArgsMigrateDataTrieLeaves) error IsInterfaceNil() bool } @@ -369,4 +368,5 @@ type StateChangesCollector interface { RevertToIndex(index int) error Publish() error IsInterfaceNil() bool + GetStateChangesForTxs() map[string]*data.StateChanges } diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index da58f2634a0..277b51b9e52 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -1,7 +1,10 @@ package stateChanges import ( + "bytes" + "encoding/hex" "errors" + "fmt" "sync" data "github.com/multiversx/mx-chain-core-go/data/stateChange" @@ -28,11 +31,11 @@ type StateChange interface { SetIndex(index int32) } -//// StateChangesForTx is used to collect state changes for a transaction hash -//type StateChangesForTx struct { -// TxHash []byte `json:"txHash"` -// StateChanges []StateChange `json:"stateChanges"` -//} +// StateChangesForTx is used to collect state changes for a transaction hash +type StateChangesForTx struct { + TxHash []byte `json:"txHash"` + StateChanges []StateChange `json:"stateChanges"` +} type stateChangesCollector struct { stateChanges []StateChange @@ -56,8 +59,48 @@ func (scc *stateChangesCollector) AddSaveAccountStateChange(_, _ vmcommon.Accoun // AddStateChange adds a new state change to the collector func (scc *stateChangesCollector) AddStateChange(stateChange StateChange) { scc.stateChangesMut.Lock() - scc.stateChanges = append(scc.stateChanges, stateChange) - scc.stateChangesMut.Unlock() + defer scc.stateChangesMut.Unlock() + + // TODO: add custom type for stateChange type + if stateChange.GetType() == "write" { + scc.stateChanges = append(scc.stateChanges, stateChange) + } +} + +func (scc *stateChangesCollector) getStateChangesForTxs() ([]StateChangesForTx, error) { + scc.stateChangesMut.Lock() + defer scc.stateChangesMut.Unlock() + + stateChangesForTxs := make([]StateChangesForTx, 0) + + for i := 0; i < len(scc.stateChanges); i++ { + txHash := scc.stateChanges[i].GetTxHash() + + if len(txHash) == 0 { + log.Warn("empty tx hash, state change event not associated to a transaction") + break + } + + innerStateChangesForTx := make([]StateChange, 0) + for j := i; j < len(scc.stateChanges); j++ { + txHash2 := scc.stateChanges[j].GetTxHash() + if !bytes.Equal(txHash, txHash2) { + i = j + break + } + + innerStateChangesForTx = append(innerStateChangesForTx, scc.stateChanges[j]) + i = j + } + + stateChangesForTx := StateChangesForTx{ + TxHash: txHash, + StateChanges: innerStateChangesForTx, + } + stateChangesForTxs = append(stateChangesForTxs, stateChangesForTx) + } + + return stateChangesForTxs, nil } func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChanges { @@ -132,6 +175,10 @@ func (scc *stateChangesCollector) Reset() { scc.stateChangesMut.Lock() defer scc.stateChangesMut.Unlock() + scc.resetStateChangesUnprotected() +} + +func (scc *stateChangesCollector) resetStateChangesUnprotected() { scc.stateChanges = make([]StateChange, 0) } @@ -152,12 +199,16 @@ func (scc *stateChangesCollector) AddTxHashToCollectedStateChanges(txHash []byte // SetIndexToLastStateChange will set index to the last state change func (scc *stateChangesCollector) SetIndexToLastStateChange(index int) error { + scc.stateChangesMut.Lock() + defer scc.stateChangesMut.Unlock() + if index > len(scc.stateChanges) || index < 0 { return ErrStateChangesIndexOutOfBounds } - scc.stateChangesMut.Lock() - defer scc.stateChangesMut.Unlock() + if len(scc.stateChanges) == 0 { + return nil + } scc.stateChanges[len(scc.stateChanges)-1].SetIndex(int32(index)) @@ -190,28 +241,28 @@ func (scc *stateChangesCollector) RevertToIndex(index int) error { // Publish will export state changes func (scc *stateChangesCollector) Publish() error { - //stateChangesForTx, err := scc.GetStateChangesForTxs() - //if err != nil { - // return err - //} + stateChangesForTx, err := scc.getStateChangesForTxs() + if err != nil { + return err + } - //printStateChanges(stateChangesForTx) + printStateChanges(stateChangesForTx) return nil } -//func printStateChanges(stateChanges []StateChangesForTx) { -// for _, stateChange := range stateChanges { -// -// if stateChange.TxHash != nil { -// fmt.Println(hex.EncodeToString(stateChange.TxHash)) -// } -// -// for _, st := range stateChange.StateChanges { -// fmt.Println(st) -// } -// } -//} +func printStateChanges(stateChanges []StateChangesForTx) { + for _, stateChange := range stateChanges { + + if stateChange.TxHash != nil { + fmt.Println(hex.EncodeToString(stateChange.TxHash)) + } + + for _, st := range stateChange.StateChanges { + fmt.Println(st) + } + } +} // IsInterfaceNil returns true if there is no value under the interface func (scc *stateChangesCollector) IsInterfaceNil() bool { diff --git a/state/stateChanges/writeCollector_test.go b/state/stateChanges/writeCollector_test.go index 634fcf52ce3..6341ac724b1 100644 --- a/state/stateChanges/writeCollector_test.go +++ b/state/stateChanges/writeCollector_test.go @@ -5,14 +5,15 @@ import ( "strconv" "testing" + data "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -func getDefaultStateChange() *StateChangeDTO { - return &StateChangeDTO{ +func getDefaultStateChange() *data.StateChange { + return &data.StateChange{ Type: "write", } } @@ -49,7 +50,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) { numStateChanges := 10 for i := 0; i < numStateChanges; i++ { - scc.AddStateChange(&StateChangeDTO{ + scc.AddStateChange(&data.StateChange{ Type: "write", MainTrieKey: []byte(strconv.Itoa(i)), }) @@ -66,7 +67,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) { assert.Equal(t, 1, len(stateChangesForTx)) assert.Equal(t, []byte("txHash"), stateChangesForTx[0].TxHash) for i := 0; i < len(stateChangesForTx[0].StateChanges); i++ { - sc, ok := stateChangesForTx[0].StateChanges[i].(*StateChangeDTO) + sc, ok := stateChangesForTx[0].StateChanges[i].(*data.StateChange) require.True(t, ok) assert.Equal(t, []byte(strconv.Itoa(i)), sc.MainTrieKey) @@ -82,7 +83,7 @@ func TestStateChangesCollector_GetStateChanges(t *testing.T) { numStateChanges := 10 for i := 0; i < numStateChanges; i++ { - scc.AddStateChange(&StateChangeDTO{ + scc.AddStateChange(&data.StateChange{ Type: "write", MainTrieKey: []byte(strconv.Itoa(i)), }) @@ -104,11 +105,11 @@ func TestStateChangesCollector_AddTxHashToCollectedStateChanges(t *testing.T) { scc.AddTxHashToCollectedStateChanges([]byte("txHash0"), &transaction.Transaction{}) - stateChange := &StateChangeDTO{ + stateChange := &data.StateChange{ Type: "write", MainTrieKey: []byte("mainTrieKey"), MainTrieVal: []byte("mainTrieVal"), - DataTrieChanges: []DataTrieChange{{Key: []byte("dataTrieKey"), Val: []byte("dataTrieVal")}}, + DataTrieChanges: []*data.DataTrieChange{{Key: []byte("dataTrieKey"), Val: []byte("dataTrieVal")}}, } scc.AddStateChange(stateChange) @@ -123,7 +124,7 @@ func TestStateChangesCollector_AddTxHashToCollectedStateChanges(t *testing.T) { assert.Equal(t, []byte("txHash"), stateChangesForTx[0].TxHash) assert.Equal(t, 1, len(stateChangesForTx[0].StateChanges)) - sc, ok := stateChangesForTx[0].StateChanges[0].(*StateChangeDTO) + sc, ok := stateChangesForTx[0].StateChanges[0].(*data.StateChange) require.True(t, ok) assert.Equal(t, []byte("mainTrieKey"), sc.MainTrieKey) diff --git a/testscommon/p2pmocks/messengerStub.go b/testscommon/p2pmocks/messengerStub.go index c48c95b9868..d3ab2154034 100644 --- a/testscommon/p2pmocks/messengerStub.go +++ b/testscommon/p2pmocks/messengerStub.go @@ -4,6 +4,7 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-go/p2p" ) diff --git a/testscommon/state/accountWrapperMock.go b/testscommon/state/accountWrapperMock.go index 5eecb17393f..8d67dfad6aa 100644 --- a/testscommon/state/accountWrapperMock.go +++ b/testscommon/state/accountWrapperMock.go @@ -7,15 +7,16 @@ import ( "math/big" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/stateChange" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/disabled" - "github.com/multiversx/mx-chain-go/state/stateChanges" "github.com/multiversx/mx-chain-go/state/trackableDataTrie" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var _ state.UserAccountHandler = (*AccountWrapMock)(nil) @@ -199,7 +200,7 @@ func (awm *AccountWrapMock) DataTrie() common.DataTrieHandler { } // SaveDirtyData - -func (awm *AccountWrapMock) SaveDirtyData(trie common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { +func (awm *AccountWrapMock) SaveDirtyData(trie common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) { return awm.trackableDataTrie.SaveDirtyData(trie) } diff --git a/testscommon/state/userAccountStub.go b/testscommon/state/userAccountStub.go index 10bc9fa6932..1487bb625d0 100644 --- a/testscommon/state/userAccountStub.go +++ b/testscommon/state/userAccountStub.go @@ -6,10 +6,11 @@ import ( "math/big" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/stateChange" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/state/stateChanges" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var _ state.UserAccountHandler = (*UserAccountStub)(nil) @@ -190,7 +191,7 @@ func (u *UserAccountStub) IsGuarded() bool { } // SaveDirtyData - -func (u *UserAccountStub) SaveDirtyData(_ common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { +func (u *UserAccountStub) SaveDirtyData(_ common.Trie) ([]stateChange.DataTrieChange, []core.TrieData, error) { return nil, nil, nil } From 225035446fe8de4c502554f0bea42ac06bfc27d9 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 15:45:32 +0300 Subject: [PATCH 11/28] fix version and imports. --- go.mod | 2 +- go.sum | 4 ++-- p2p/disabled/networkMessenger.go | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c95171c6435..86fd8eb1ef6 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad + github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a diff --git a/go.sum b/go.sum index 898f63d9dfd..f587754dd0a 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= +github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= +github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 h1:omuzhvGYFRAE0UA9UMatgSLTBlANKea0hU/jskzj6pM= github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= diff --git a/p2p/disabled/networkMessenger.go b/p2p/disabled/networkMessenger.go index 4f854d976bc..f76228462f9 100644 --- a/p2p/disabled/networkMessenger.go +++ b/p2p/disabled/networkMessenger.go @@ -4,6 +4,7 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-go/p2p" ) From 62d23268f23aabc8836d8a226865cbb3b1c182b7 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 16:34:04 +0300 Subject: [PATCH 12/28] fix some tests. --- outport/process/outportDataProvider_test.go | 5 ++++- process/transaction/shardProcess.go | 6 ++++++ state/accountsDB_test.go | 14 ++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index ef1422d230a..0f801968ac6 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -12,8 +12,11 @@ import ( "github.com/multiversx/mx-chain-core-go/data/rewardTx" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" + "github.com/multiversx/mx-chain-go/state/stateChanges" "github.com/multiversx/mx-chain-go/testscommon" commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" @@ -21,7 +24,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" - "github.com/stretchr/testify/require" ) func createArgOutportDataProvider() ArgOutportDataProvider { @@ -45,6 +47,7 @@ func createArgOutportDataProvider() ArgOutportDataProvider { ExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, Marshaller: &marshallerMock.MarshalizerMock{}, Hasher: &hashingMocks.HasherMock{}, + StateChangesCollector: stateChanges.NewStateChangesCollector(), } } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 025418e68f1..9014f05949b 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -148,6 +148,12 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { if check.IfNil(args.TxLogsProcessor) { return nil, process.ErrNilTxLogsProcessor } + if check.IfNil(args.RelayedTxV3Processor) { + return nil, process.ErrNilRelayedTxV3Processor + } + if check.IfNil(args.FailedTxLogsAccumulator) { + return nil, process.ErrNilFailedTxLogsAccumulator + } baseTxProcess := &baseTxProcessor{ accounts: args.Accounts, diff --git a/state/accountsDB_test.go b/state/accountsDB_test.go index f6f91242cf4..085d1bec004 100644 --- a/state/accountsDB_test.go +++ b/state/accountsDB_test.go @@ -16,7 +16,13 @@ import ( "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/core/keyValStorage" + data "github.com/multiversx/mx-chain-core-go/data/stateChange" "github.com/multiversx/mx-chain-core-go/marshal" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/dataTrieMigrator" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/common/holders" @@ -42,10 +48,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/storageManager" trieMock "github.com/multiversx/mx-chain-go/testscommon/trie" "github.com/multiversx/mx-chain-go/trie" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/dataTrieMigrator" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const trieDbOperationDelay = time.Second @@ -372,8 +374,8 @@ func TestAccountsDB_SaveAccountSavesCodeAndDataTrieForUserAccount(t *testing.T) }) dtt := &trieMock.DataTrieTrackerStub{ - SaveDirtyDataCalled: func(_ common.Trie) ([]stateChanges.DataTrieChange, []core.TrieData, error) { - var stateChanges []stateChanges.DataTrieChange + SaveDirtyDataCalled: func(_ common.Trie) ([]*data.DataTrieChange, []core.TrieData, error) { + var stateChanges []*data.DataTrieChange oldVal := []core.TrieData{ { Key: []byte("key"), From c86068433c903a6f126db14907031d2542b091e5 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 17:05:35 +0300 Subject: [PATCH 13/28] fix broken import. --- testscommon/state/userAccountStub.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testscommon/state/userAccountStub.go b/testscommon/state/userAccountStub.go index 1487bb625d0..d4af407abba 100644 --- a/testscommon/state/userAccountStub.go +++ b/testscommon/state/userAccountStub.go @@ -191,7 +191,7 @@ func (u *UserAccountStub) IsGuarded() bool { } // SaveDirtyData - -func (u *UserAccountStub) SaveDirtyData(_ common.Trie) ([]stateChange.DataTrieChange, []core.TrieData, error) { +func (u *UserAccountStub) SaveDirtyData(_ common.Trie) ([]*stateChange.DataTrieChange, []core.TrieData, error) { return nil, nil, nil } From c48252341415d9ec4ff17151fa3c4680fe5eef25 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 17:19:47 +0300 Subject: [PATCH 14/28] another round of tests fixed. --- state/stateChanges/export_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/state/stateChanges/export_test.go b/state/stateChanges/export_test.go index 3e52d0985b2..86350f45a5c 100644 --- a/state/stateChanges/export_test.go +++ b/state/stateChanges/export_test.go @@ -2,6 +2,6 @@ package stateChanges // GetStateChanges - func (scc *stateChangesCollector) GetStateChanges() []StateChangesForTx { - scs, _ := scc.GetStateChangesForTxs() + scs, _ := scc.getStateChangesForTxs() return scs } From 30d5dd97088dd1b54fedeebd8206a06a269371e7 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 9 Sep 2024 17:29:48 +0300 Subject: [PATCH 15/28] fix linter. --- outport/disabled/disabledOutport.go | 1 - 1 file changed, 1 deletion(-) diff --git a/outport/disabled/disabledOutport.go b/outport/disabled/disabledOutport.go index c4e861ec210..9000f800cce 100644 --- a/outport/disabled/disabledOutport.go +++ b/outport/disabled/disabledOutport.go @@ -41,7 +41,6 @@ func (n *disabledOutport) SaveAccounts(_ *outportcore.Accounts) { // SaveStateChanges does nothing func (n *disabledOutport) SaveStateChanges() { - return } // FinalizedBlock does nothing From 9d983f1e24839d105e908136bb4453ea4d938211 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 10 Sep 2024 15:42:15 +0300 Subject: [PATCH 16/28] fixes after review. --- outport/disabled/disabledOutport.go | 4 --- outport/factory/hostDriverFactory.go | 10 +++---- outport/factory/outportFactory.go | 6 ++-- outport/mock/driverStub.go | 10 ------- outport/notifier/eventNotifier.go | 5 ---- scripts/testnet/variables.sh | 10 +++---- .../disabled/disabledStateChangesCollector.go | 1 + state/stateChanges/dataAnalysisCollector.go | 4 --- state/stateChanges/writeCollector.go | 28 +------------------ 9 files changed, 13 insertions(+), 65 deletions(-) diff --git a/outport/disabled/disabledOutport.go b/outport/disabled/disabledOutport.go index 9000f800cce..24a53eaca18 100644 --- a/outport/disabled/disabledOutport.go +++ b/outport/disabled/disabledOutport.go @@ -39,10 +39,6 @@ func (n *disabledOutport) SaveValidatorsRating(_ *outportcore.ValidatorsRating) func (n *disabledOutport) SaveAccounts(_ *outportcore.Accounts) { } -// SaveStateChanges does nothing -func (n *disabledOutport) SaveStateChanges() { -} - // FinalizedBlock does nothing func (n *disabledOutport) FinalizedBlock(_ *outportcore.FinalizedBlock) { } diff --git a/outport/factory/hostDriverFactory.go b/outport/factory/hostDriverFactory.go index 90b5b562dac..efcf6b6c159 100644 --- a/outport/factory/hostDriverFactory.go +++ b/outport/factory/hostDriverFactory.go @@ -5,18 +5,16 @@ import ( "github.com/multiversx/mx-chain-communication-go/websocket/factory" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/outport" "github.com/multiversx/mx-chain-go/outport/host" - "github.com/multiversx/mx-chain-go/state" - - logger "github.com/multiversx/mx-chain-logger-go" ) type ArgsHostDriverFactory struct { - HostConfig config.HostDriversConfig - Marshaller marshal.Marshalizer - StateChangesCollector state.StateChangesCollector + HostConfig config.HostDriversConfig + Marshaller marshal.Marshalizer } var log = logger.GetOrCreate("outport/factory/hostdriver") diff --git a/outport/factory/outportFactory.go b/outport/factory/outportFactory.go index 84d963131ae..a137175053e 100644 --- a/outport/factory/outportFactory.go +++ b/outport/factory/outportFactory.go @@ -74,14 +74,12 @@ func createAndSubscribeElasticDriverIfNeeded( return nil } - //TODO: this needs discussed. - _, err := indexerFactory.NewIndexer(args) + elasticDriver, err := indexerFactory.NewIndexer(args) if err != nil { return err } - return nil - //return outport.SubscribeDriver(elasticDriver) + return outport.SubscribeDriver(elasticDriver) } func createAndSubscribeEventNotifierIfNeeded( diff --git a/outport/mock/driverStub.go b/outport/mock/driverStub.go index 2b7cfe35159..144e09a0ab6 100644 --- a/outport/mock/driverStub.go +++ b/outport/mock/driverStub.go @@ -19,7 +19,6 @@ type DriverStub struct { CloseCalled func() error RegisterHandlerCalled func(handlerFunction func() error, topic string) error SetCurrentSettingsCalled func(config outportcore.OutportConfig) error - SaveStateChangesCalled func() error } // SaveBlock - @@ -108,15 +107,6 @@ func (d *DriverStub) RegisterHandler(handlerFunction func() error, topic string) return nil } -// SaveStateChanges - -func (d *DriverStub) SaveStateChanges() error { - if d.SaveStateChangesCalled != nil { - return d.SaveStateChangesCalled() - } - - return nil -} - // Close - func (d *DriverStub) Close() error { if d.CloseCalled != nil { diff --git a/outport/notifier/eventNotifier.go b/outport/notifier/eventNotifier.go index 247fd7e3d23..828b027c88e 100644 --- a/outport/notifier/eventNotifier.go +++ b/outport/notifier/eventNotifier.go @@ -115,11 +115,6 @@ func (en *eventNotifier) SaveAccounts(_ *outport.Accounts) error { return nil } -// SaveStateChanges does nothing -func (en *eventNotifier) SaveStateChanges() error { - return nil -} - // GetMarshaller returns internal marshaller func (en *eventNotifier) GetMarshaller() marshal.Marshalizer { return en.marshalizer diff --git a/scripts/testnet/variables.sh b/scripts/testnet/variables.sh index 3812adbc5df..c5a5b013523 100644 --- a/scripts/testnet/variables.sh +++ b/scripts/testnet/variables.sh @@ -12,7 +12,7 @@ export USE_PROXY=1 # Enable the MultiversX Transaction Generator. Note that this is a private # repository (mx-chain-txgen-go). -export USE_TXGEN=1 +export USE_TXGEN=0 # Path where the testnet will be instantiated. This folder is assumed to not # exist, but it doesn't matter if it already does. It will be created if not, @@ -52,13 +52,13 @@ export GENESIS_STAKE_TYPE="direct" #'delegated' or 'direct' as in direct stake export OBSERVERS_ANTIFLOOD_DISABLE=0 # Shard structure -export SHARDCOUNT=1 -export SHARD_VALIDATORCOUNT=1 +export SHARDCOUNT=2 +export SHARD_VALIDATORCOUNT=3 export SHARD_OBSERVERCOUNT=1 -export SHARD_CONSENSUS_SIZE=1 +export SHARD_CONSENSUS_SIZE=3 # Metashard structure -export META_VALIDATORCOUNT=1 +export META_VALIDATORCOUNT=3 export META_OBSERVERCOUNT=1 export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT diff --git a/state/disabled/disabledStateChangesCollector.go b/state/disabled/disabledStateChangesCollector.go index e6e0f23990f..629deeb293a 100644 --- a/state/disabled/disabledStateChangesCollector.go +++ b/state/disabled/disabledStateChangesCollector.go @@ -49,6 +49,7 @@ func (d *disabledStateChangesCollector) Publish() error { return nil } +// GetStateChangesForTxs - func (d *disabledStateChangesCollector) GetStateChangesForTxs() map[string]*stateChange.StateChanges { return nil } diff --git a/state/stateChanges/dataAnalysisCollector.go b/state/stateChanges/dataAnalysisCollector.go index a58bcdd7e9e..0fe627b799f 100644 --- a/state/stateChanges/dataAnalysisCollector.go +++ b/state/stateChanges/dataAnalysisCollector.go @@ -187,10 +187,6 @@ func (scc *dataAnalysisCollector) Publish() error { return nil } -func (scc *dataAnalysisCollector) GetStateChangesForTx() []StateChange { - return scc.stateChanges -} - // IsInterfaceNil returns true if there is no value under the interface func (scc *dataAnalysisCollector) IsInterfaceNil() bool { return scc == nil diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 277b51b9e52..8cebce4dc54 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -103,6 +103,7 @@ func (scc *stateChangesCollector) getStateChangesForTxs() ([]StateChangesForTx, return stateChangesForTxs, nil } +// GetStateChangesForTxs will retrieve the state changes linked with the tx hash. func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChanges { scc.stateChangesMut.Lock() defer scc.stateChangesMut.Unlock() @@ -140,33 +141,6 @@ func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.State } } - //for i := 0; i < len(scc.stateChanges); i++ { - // txHash := scc.stateChanges[i].GetTxHash() - // - // if len(txHash) == 0 { - // log.Warn("empty tx hash, state change event not associated to a transaction") - // break - // } - // - // innerStateChangesForTx := make([]StateChange, 0) - // for j := i; j < len(scc.stateChanges); j++ { - // txHash2 := scc.stateChanges[j].GetTxHash() - // if !bytes.Equal(txHash, txHash2) { - // i = j - // break - // } - // - // innerStateChangesForTx = append(innerStateChangesForTx, scc.stateChanges[j]) - // i = j - // } - // - // stateChangesForTx := StateChangesForTx{ - // TxHash: txHash, - // StateChanges: innerStateChangesForTx, - // } - // stateChangesForTxs = append(stateChangesForTxs, stateChangesForTx) - //} - return stateChangesForTxs } From 776d2b109a9ec660c7a4ca67d96fd1a46a51b1af Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 10 Sep 2024 15:46:34 +0300 Subject: [PATCH 17/28] fix missing argument. --- factory/status/statusComponents.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/factory/status/statusComponents.go b/factory/status/statusComponents.go index cea175fdfaf..73ecb5e2777 100644 --- a/factory/status/statusComponents.go +++ b/factory/status/statusComponents.go @@ -287,9 +287,8 @@ func (scf *statusComponentsFactory) makeHostDriversArgs() ([]outportDriverFactor } argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, outportDriverFactory.ArgsHostDriverFactory{ - Marshaller: marshaller, - HostConfig: hostConfig, - StateChangesCollector: scf.stateComponents.StateChangesCollector(), + Marshaller: marshaller, + HostConfig: hostConfig, }) } From 1f90b5d740816058dd6a98ac4d87a3405680fde3 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 12 Sep 2024 13:43:45 +0300 Subject: [PATCH 18/28] fixes after review. --- go.mod | 2 +- go.sum | 4 ++-- outport/process/outportDataProvider.go | 1 - process/block/metablock.go | 1 + process/block/shardblock.go | 4 +++- scripts/testnet/variables.sh | 10 +++++----- state/accountsDB.go | 3 ++- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 86fd8eb1ef6..a0bd43bc59f 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a + github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909105906-39ad1daf2a4c diff --git a/go.sum b/go.sum index f587754dd0a..3b4364c1cbc 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 h1: github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= +github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= +github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= diff --git a/outport/process/outportDataProvider.go b/outport/process/outportDataProvider.go index cd3028c600f..0528dd6b06d 100644 --- a/outport/process/outportDataProvider.go +++ b/outport/process/outportDataProvider.go @@ -140,7 +140,6 @@ func (odp *outportDataProvider) PrepareOutportSaveBlockData(arg ArgPrepareOutpor } stateChanges := odp.stateChangesCollector.GetStateChangesForTxs() - odp.stateChangesCollector.Reset() return &outportcore.OutportBlockWithHeaderAndBody{ OutportBlock: &outportcore.OutportBlock{ diff --git a/process/block/metablock.go b/process/block/metablock.go index ebae848ae4f..2343f17e78d 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -1307,6 +1307,7 @@ func (mp *metaProcessor) CommitBlock( // TODO: Should be sent also validatorInfoTxs alongside rewardsTxs -> mp.validatorInfoCreator.GetValidatorInfoTxs(body) ? mp.indexBlock(header, headerHash, body, lastMetaBlock, notarizedHeadersHashes, rewardsTxs) + mp.stateChangesCollector.Reset() mp.recordBlockInHistory(headerHash, headerHandler, bodyHandler) highestFinalBlockNonce := mp.forkDetector.GetHighestFinalBlockNonce() diff --git a/process/block/shardblock.go b/process/block/shardblock.go index 0e562e276e4..b0683947a09 100644 --- a/process/block/shardblock.go +++ b/process/block/shardblock.go @@ -11,6 +11,8 @@ 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/headerVersionData" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -20,7 +22,6 @@ import ( "github.com/multiversx/mx-chain-go/process/block/helpers" "github.com/multiversx/mx-chain-go/process/block/processedMb" "github.com/multiversx/mx-chain-go/state" - logger "github.com/multiversx/mx-chain-logger-go" ) var _ process.BlockProcessor = (*shardProcessor)(nil) @@ -1041,6 +1042,7 @@ func (sp *shardProcessor) CommitBlock( sp.blockChain.SetCurrentBlockHeaderHash(headerHash) sp.indexBlockIfNeeded(bodyHandler, headerHash, headerHandler, lastBlockHeader) + sp.stateChangesCollector.Reset() sp.recordBlockInHistory(headerHash, headerHandler, bodyHandler) lastCrossNotarizedHeader, _, err := sp.blockTracker.GetLastCrossNotarizedHeader(core.MetachainShardId) diff --git a/scripts/testnet/variables.sh b/scripts/testnet/variables.sh index c5a5b013523..3812adbc5df 100644 --- a/scripts/testnet/variables.sh +++ b/scripts/testnet/variables.sh @@ -12,7 +12,7 @@ export USE_PROXY=1 # Enable the MultiversX Transaction Generator. Note that this is a private # repository (mx-chain-txgen-go). -export USE_TXGEN=0 +export USE_TXGEN=1 # Path where the testnet will be instantiated. This folder is assumed to not # exist, but it doesn't matter if it already does. It will be created if not, @@ -52,13 +52,13 @@ export GENESIS_STAKE_TYPE="direct" #'delegated' or 'direct' as in direct stake export OBSERVERS_ANTIFLOOD_DISABLE=0 # Shard structure -export SHARDCOUNT=2 -export SHARD_VALIDATORCOUNT=3 +export SHARDCOUNT=1 +export SHARD_VALIDATORCOUNT=1 export SHARD_OBSERVERCOUNT=1 -export SHARD_CONSENSUS_SIZE=3 +export SHARD_CONSENSUS_SIZE=1 # Metashard structure -export META_VALIDATORCOUNT=3 +export META_VALIDATORCOUNT=1 export META_OBSERVERCOUNT=1 export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT diff --git a/state/accountsDB.go b/state/accountsDB.go index 039ee9c21d0..f2641b5af58 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -303,7 +303,8 @@ func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandle baseOldAccount, _ := oldAcc.(baseAccountHandler) if !newAccOk { - return make([]*stateChange.DataTrieChange, 0), nil + //return make([]*stateChange.DataTrieChange, 0), nil + return nil, nil } newValues, err := adb.saveDataTrie(baseNewAcc) From e774eeab370416326716957361ccad4001ffdd96 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 12 Sep 2024 14:05:59 +0300 Subject: [PATCH 19/28] revert due to failing test. --- state/accountsDB.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/state/accountsDB.go b/state/accountsDB.go index f2641b5af58..039ee9c21d0 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -303,8 +303,7 @@ func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandle baseOldAccount, _ := oldAcc.(baseAccountHandler) if !newAccOk { - //return make([]*stateChange.DataTrieChange, 0), nil - return nil, nil + return make([]*stateChange.DataTrieChange, 0), nil } newValues, err := adb.saveDataTrie(baseNewAcc) From 494a7b3e4cd57d65d2bfa096fdc8dc97fef30882 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 12 Sep 2024 14:40:01 +0300 Subject: [PATCH 20/28] fix failing test. --- process/block/metablock_test.go | 8 +- state/accountsDB.go | 2 +- .../state/stateChangesCollectorStub.go | 94 +++++++++++++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 testscommon/state/stateChangesCollectorStub.go diff --git a/process/block/metablock_test.go b/process/block/metablock_test.go index c78f2c5b039..a08301b13c2 100644 --- a/process/block/metablock_test.go +++ b/process/block/metablock_test.go @@ -13,6 +13,9 @@ import ( "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dataRetriever/blockchain" @@ -36,8 +39,6 @@ import ( stateMock "github.com/multiversx/mx-chain-go/testscommon/state" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func createMockComponentHolders() ( @@ -1050,6 +1051,9 @@ func TestMetaProcessor_CommitBlockOkValsShouldWork(t *testing.T) { resetCountersForManagedBlockSignerCalled = true }, } + arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{ + ResetCalled: func() {}, + } mp, _ := blproc.NewMetaProcessor(arguments) diff --git a/state/accountsDB.go b/state/accountsDB.go index 039ee9c21d0..2ad674fbf1a 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -303,7 +303,7 @@ func (adb *AccountsDB) saveCodeAndDataTrie(oldAcc, newAcc vmcommon.AccountHandle baseOldAccount, _ := oldAcc.(baseAccountHandler) if !newAccOk { - return make([]*stateChange.DataTrieChange, 0), nil + return nil, nil } newValues, err := adb.saveDataTrie(baseNewAcc) diff --git a/testscommon/state/stateChangesCollectorStub.go b/testscommon/state/stateChangesCollectorStub.go new file mode 100644 index 00000000000..895eb2be1d3 --- /dev/null +++ b/testscommon/state/stateChangesCollectorStub.go @@ -0,0 +1,94 @@ +package state + +import ( + "github.com/multiversx/mx-chain-core-go/data/stateChange" + "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + + "github.com/multiversx/mx-chain-go/state/stateChanges" +) + +type StateChangesCollectorStub struct { + AddStateChangeCalled func(stateChange stateChanges.StateChange) + AddSaveAccountStateChangeCalled func(oldAccount, account vmcommon.AccountHandler, stateChange stateChanges.StateChange) + ResetCalled func() + AddTxHashToCollectedStateChangesCalled func(txHash []byte, tx *transaction.Transaction) + SetIndexToLastStateChangeCalled func(index int) error + RevertToIndexCalled func(index int) error + PublishCalled func() error + IsInterfaceNilCalled func() bool + GetStateChangesForTxsCalled func() map[string]*stateChange.StateChanges +} + +// AddStateChange - +func (s *StateChangesCollectorStub) AddStateChange(stateChange stateChanges.StateChange) { + if s.AddStateChangeCalled != nil { + s.AddStateChangeCalled(stateChange) + } +} + +// AddSaveAccountStateChange - +func (s *StateChangesCollectorStub) AddSaveAccountStateChange(oldAccount, account vmcommon.AccountHandler, stateChange stateChanges.StateChange) { + if s.AddSaveAccountStateChangeCalled != nil { + s.AddSaveAccountStateChangeCalled(oldAccount, account, stateChange) + } +} + +// Reset - +func (s *StateChangesCollectorStub) Reset() { + if s.ResetCalled != nil { + s.ResetCalled() + } +} + +// AddTxHashToCollectedStateChanges - +func (s *StateChangesCollectorStub) AddTxHashToCollectedStateChanges(txHash []byte, tx *transaction.Transaction) { + if s.AddTxHashToCollectedStateChangesCalled != nil { + s.AddTxHashToCollectedStateChangesCalled(txHash, tx) + } +} + +// SetIndexToLastStateChange - +func (s *StateChangesCollectorStub) SetIndexToLastStateChange(index int) error { + if s.SetIndexToLastStateChangeCalled != nil { + return s.SetIndexToLastStateChangeCalled(index) + } + + return nil +} + +// RevertToIndex - +func (s *StateChangesCollectorStub) RevertToIndex(index int) error { + if s.RevertToIndexCalled != nil { + return s.RevertToIndexCalled(index) + } + + return nil +} + +// Publish - +func (s *StateChangesCollectorStub) Publish() error { + if s.PublishCalled != nil { + return s.PublishCalled() + } + + return nil +} + +// IsInterfaceNil - +func (s *StateChangesCollectorStub) IsInterfaceNil() bool { + if s.IsInterfaceNilCalled != nil { + return s.IsInterfaceNilCalled() + } + + return false +} + +// GetStateChangesForTxs - +func (s *StateChangesCollectorStub) GetStateChangesForTxs() map[string]*stateChange.StateChanges { + if s.GetStateChangesForTxsCalled != nil { + return s.GetStateChangesForTxsCalled() + } + + return nil +} From 4b971e203d8f669d535cd7804554ea81d8f449f6 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 12 Sep 2024 17:16:16 +0300 Subject: [PATCH 21/28] fix more tests. --- process/block/metablock_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/process/block/metablock_test.go b/process/block/metablock_test.go index a08301b13c2..124320a21ee 100644 --- a/process/block/metablock_test.go +++ b/process/block/metablock_test.go @@ -920,6 +920,9 @@ func TestMetaProcessor_CommitBlockStorageFailsForHeaderShouldNotReturnError(t *t return &block.Header{}, []byte("hash"), nil } arguments.BlockTracker = blockTrackerMock + arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{ + ResetCalled: func() {}, + } mp, _ := blproc.NewMetaProcessor(arguments) processHandler := arguments.CoreComponents.ProcessStatusHandler() From 676c5a5e4c9124254adc244d3ecf5fb33e7a1160 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 13 Sep 2024 11:14:52 +0300 Subject: [PATCH 22/28] cosmetic changes. --- state/accountsDB.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/state/accountsDB.go b/state/accountsDB.go index 2ad674fbf1a..5bb0d1a13aa 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -160,9 +160,7 @@ func checkArgsAccountsDB(args ArgsAccountsDB) error { if check.IfNil(args.SnapshotsManager) { return ErrNilSnapshotsManager } - if check.IfNil(args.StateChangesCollector) { - return ErrNilStateChangesCollector - } + if check.IfNil(args.StateChangesCollector) { return ErrNilStateChangesCollector } return nil } @@ -918,9 +916,6 @@ func (adb *AccountsDB) commit() ([]byte, error) { return nil, err } - //TODO: discuss the workflow. If reset here, the outport driver won't be able to pick up the changes. - //adb.stateChangesCollector.Reset() - oldHashes := make(common.ModifiedHashes) newHashes := make(common.ModifiedHashes) // Step 1. commit all data tries From d892b5e9fdc8077af7922c8941cb01b751bf6d75 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 13 Sep 2024 12:10:48 +0300 Subject: [PATCH 23/28] added test for new method and minor fixes. --- state/stateChanges/writeCollector.go | 4 +- state/stateChanges/writeCollector_test.go | 43 +++++++++++++++++++ .../state/stateChangesCollectorStub.go | 1 + 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 8cebce4dc54..0dde2c890f4 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -44,8 +44,6 @@ type stateChangesCollector struct { // NewStateChangesCollector creates a new StateChangesCollector func NewStateChangesCollector() *stateChangesCollector { - // TODO: add outport driver - return &stateChangesCollector{ stateChanges: make([]StateChange, 0), } @@ -127,7 +125,7 @@ func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.State }, } } else { - stateChangesForTxs[txHash].StateChanges = append(sc.StateChanges, + sc.StateChanges = append(sc.StateChanges, &data.StateChange{ Type: stateChange.GetType(), Index: stateChange.GetIndex(), diff --git a/state/stateChanges/writeCollector_test.go b/state/stateChanges/writeCollector_test.go index 6341ac724b1..6aec61b7ff4 100644 --- a/state/stateChanges/writeCollector_test.go +++ b/state/stateChanges/writeCollector_test.go @@ -251,3 +251,46 @@ func TestStateChangesCollector_Reset(t *testing.T) { assert.Equal(t, 0, len(scc.GetStateChanges())) } + +func TestStateChangesCollector_GetStateChangesForTx(t *testing.T) { + t.Parallel() + + scc := NewStateChangesCollector() + assert.Equal(t, 0, len(scc.stateChanges)) + + numStateChanges := 10 + for i := 0; i < numStateChanges; i++ { + scc.AddStateChange(&data.StateChange{ + Type: "write", + // distribute evenly based on parity of the index + TxHash: []byte(fmt.Sprintf("hash%d", i%2)), + }) + } + + stateChangesForTx := scc.GetStateChangesForTxs() + + require.Len(t, stateChangesForTx, 2) + require.Len(t, stateChangesForTx["hash0"].StateChanges, 5) + require.Len(t, stateChangesForTx["hash1"].StateChanges, 5) + + require.Equal(t, stateChangesForTx, map[string]*data.StateChanges{ + "hash0" : { + []*data.StateChange{ + {Type: "write", TxHash: []byte("hash0")}, + {Type: "write", TxHash: []byte("hash0")}, + {Type: "write", TxHash: []byte("hash0")}, + {Type: "write", TxHash: []byte("hash0")}, + {Type: "write", TxHash: []byte("hash0")}, + }, + }, + "hash1" : { + []*data.StateChange{ + {Type: "write", TxHash: []byte("hash1")}, + {Type: "write", TxHash: []byte("hash1")}, + {Type: "write", TxHash: []byte("hash1")}, + {Type: "write", TxHash: []byte("hash1")}, + {Type: "write", TxHash: []byte("hash1")}, + }, + }, + }) +} diff --git a/testscommon/state/stateChangesCollectorStub.go b/testscommon/state/stateChangesCollectorStub.go index 895eb2be1d3..b748ce2b99d 100644 --- a/testscommon/state/stateChangesCollectorStub.go +++ b/testscommon/state/stateChangesCollectorStub.go @@ -8,6 +8,7 @@ import ( "github.com/multiversx/mx-chain-go/state/stateChanges" ) +// StateChangesCollectorStub represents a mock for the StateChangesCollector interface type StateChangesCollectorStub struct { AddStateChangeCalled func(stateChange stateChanges.StateChange) AddSaveAccountStateChangeCalled func(oldAccount, account vmcommon.AccountHandler, stateChange stateChanges.StateChange) From 8bd428bbdbbf6a0bbfbc8ee7b915c2ea7acc3661 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 13 Sep 2024 12:16:20 +0300 Subject: [PATCH 24/28] update mx-chain-es-indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a0bd43bc59f..9266911f467 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.4.21 + github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.17-0.20240909105906-39ad1daf2a4c diff --git a/go.sum b/go.sum index 3b4364c1cbc..74f15a2455f 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 h1: github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= -github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk= +github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 h1:VJOigTM9JbjFdy9ICVhsDfM9YQkFqMigAaQCHaM0iwY= +github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= From 6a8dc4133fac9ebc5b503813a1eed2809b33fa6c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 13 Sep 2024 12:17:32 +0300 Subject: [PATCH 25/28] revert variables.sh --- scripts/testnet/variables.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/testnet/variables.sh b/scripts/testnet/variables.sh index 3812adbc5df..c5a5b013523 100644 --- a/scripts/testnet/variables.sh +++ b/scripts/testnet/variables.sh @@ -12,7 +12,7 @@ export USE_PROXY=1 # Enable the MultiversX Transaction Generator. Note that this is a private # repository (mx-chain-txgen-go). -export USE_TXGEN=1 +export USE_TXGEN=0 # Path where the testnet will be instantiated. This folder is assumed to not # exist, but it doesn't matter if it already does. It will be created if not, @@ -52,13 +52,13 @@ export GENESIS_STAKE_TYPE="direct" #'delegated' or 'direct' as in direct stake export OBSERVERS_ANTIFLOOD_DISABLE=0 # Shard structure -export SHARDCOUNT=1 -export SHARD_VALIDATORCOUNT=1 +export SHARDCOUNT=2 +export SHARD_VALIDATORCOUNT=3 export SHARD_OBSERVERCOUNT=1 -export SHARD_CONSENSUS_SIZE=1 +export SHARD_CONSENSUS_SIZE=3 # Metashard structure -export META_VALIDATORCOUNT=1 +export META_VALIDATORCOUNT=3 export META_OBSERVERCOUNT=1 export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT From 0ffca72659f603ad05c8d2d923961f07298041ca Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 13 Sep 2024 13:46:40 +0300 Subject: [PATCH 26/28] improved readability. --- state/stateChanges/writeCollector.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/state/stateChanges/writeCollector.go b/state/stateChanges/writeCollector.go index 0dde2c890f4..87eed266252 100644 --- a/state/stateChanges/writeCollector.go +++ b/state/stateChanges/writeCollector.go @@ -103,15 +103,15 @@ func (scc *stateChangesCollector) getStateChangesForTxs() ([]StateChangesForTx, // GetStateChangesForTxs will retrieve the state changes linked with the tx hash. func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.StateChanges { - scc.stateChangesMut.Lock() - defer scc.stateChangesMut.Unlock() + scc.stateChangesMut.RLock() + defer scc.stateChangesMut.RUnlock() stateChangesForTxs := make(map[string]*data.StateChanges) for _, stateChange := range scc.stateChanges { txHash := string(stateChange.GetTxHash()) - if sc, ok := stateChangesForTxs[txHash]; !ok { + if _, ok := stateChangesForTxs[txHash]; !ok { stateChangesForTxs[txHash] = &data.StateChanges{StateChanges: []*data.StateChange{ { Type: stateChange.GetType(), @@ -125,7 +125,7 @@ func (scc *stateChangesCollector) GetStateChangesForTxs() map[string]*data.State }, } } else { - sc.StateChanges = append(sc.StateChanges, + stateChangesForTxs[txHash].StateChanges = append(stateChangesForTxs[txHash].StateChanges, &data.StateChange{ Type: stateChange.GetType(), Index: stateChange.GetIndex(), From 43e7cb86f8f99208487f3fa27469c267f7064bdc Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 17 Sep 2024 14:18:59 +0300 Subject: [PATCH 27/28] fixes after review. --- process/block/metablock_test.go | 8 ++------ state/accountsDB.go | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/process/block/metablock_test.go b/process/block/metablock_test.go index 124320a21ee..a5665e7d8cb 100644 --- a/process/block/metablock_test.go +++ b/process/block/metablock_test.go @@ -920,9 +920,7 @@ func TestMetaProcessor_CommitBlockStorageFailsForHeaderShouldNotReturnError(t *t return &block.Header{}, []byte("hash"), nil } arguments.BlockTracker = blockTrackerMock - arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{ - ResetCalled: func() {}, - } + arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{} mp, _ := blproc.NewMetaProcessor(arguments) processHandler := arguments.CoreComponents.ProcessStatusHandler() @@ -1054,9 +1052,7 @@ func TestMetaProcessor_CommitBlockOkValsShouldWork(t *testing.T) { resetCountersForManagedBlockSignerCalled = true }, } - arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{ - ResetCalled: func() {}, - } + arguments.StateChangesCollector = &stateMock.StateChangesCollectorStub{} mp, _ := blproc.NewMetaProcessor(arguments) diff --git a/state/accountsDB.go b/state/accountsDB.go index 5bb0d1a13aa..a090c4cb358 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -160,7 +160,9 @@ func checkArgsAccountsDB(args ArgsAccountsDB) error { if check.IfNil(args.SnapshotsManager) { return ErrNilSnapshotsManager } - if check.IfNil(args.StateChangesCollector) { return ErrNilStateChangesCollector } + if check.IfNil(args.StateChangesCollector) { + return ErrNilStateChangesCollector + } return nil } From 260b7b4c7a893aac654690e983d5c3a248831ebd Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 17 Sep 2024 17:18:04 +0300 Subject: [PATCH 28/28] bumped mx-chain-core-go version. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9266911f467..9782d4fea95 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 + github.com/multiversx/mx-chain-core-go v1.2.23-0.20240917141620-f95a4e7bfd42 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 github.com/multiversx/mx-chain-logger-go v1.0.15 diff --git a/go.sum b/go.sum index 74f15a2455f..6693c3c494a 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4 h1:omuzhvGYFRAE0UA9UMatgSLTBlANKea0hU/jskzj6pM= -github.com/multiversx/mx-chain-core-go v1.2.23-0.20240909105439-e1a7a06d4ac4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20240917141620-f95a4e7bfd42 h1:mxZCpz0qF0f9LzeZVAFgmuDKpKraHBOmMlfqzPmEASs= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20240917141620-f95a4e7bfd42/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 h1:VJOigTM9JbjFdy9ICVhsDfM9YQkFqMigAaQCHaM0iwY=