diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 8cd3a50046d..39ace02da78 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -1401,22 +1401,12 @@ func (pcf *processComponentsFactory) createOutportDataProvider( gasConsumedProvider processOutport.GasConsumedProvider, epochRewards processOutport.EpochRewardsGetter, ) (outport.DataProviderOutport, error) { - txsStorer, err := pcf.data.StorageService().GetStorer(dataRetriever.TransactionUnit) - if err != nil { - return nil, err - } - mbsStorer, err := pcf.data.StorageService().GetStorer(dataRetriever.MiniBlockUnit) - if err != nil { - return nil, err - } - return factoryOutportProvider.CreateOutportDataProvider(factoryOutportProvider.ArgOutportDataProviderFactory{ HasDrivers: pcf.statusComponents.OutportHandler().HasDrivers(), AddressConverter: pcf.coreData.AddressPubKeyConverter(), AccountsDB: pcf.state.AccountsAdapterAPI(), Marshaller: pcf.coreData.InternalMarshalizer(), EsdtDataStorageHandler: pcf.esdtNftStorage, - TransactionsStorer: txsStorer, ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), TxCoordinator: txCoordinator, NodesCoordinator: pcf.nodesCoordinator, @@ -1424,13 +1414,13 @@ func (pcf *processComponentsFactory) createOutportDataProvider( EconomicsData: pcf.coreData.EconomicsData(), IsImportDBMode: pcf.importDBConfig.IsImportDBMode, Hasher: pcf.coreData.Hasher(), - MbsStorer: mbsStorer, EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), ExecutionOrderGetter: pcf.txExecutionOrderHandler, DataPool: pcf.data.Datapool(), StateAccessesCollector: pcf.state.StateAccessesCollector(), RoundHandler: pcf.coreData.RoundHandler(), RewardsGetter: epochRewards, + StorageService: pcf.data.StorageService(), }) } diff --git a/outport/process/factory/check.go b/outport/process/factory/check.go index 68010b4ae44..ef1b1655409 100644 --- a/outport/process/factory/check.go +++ b/outport/process/factory/check.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/process" "github.com/multiversx/mx-chain-go/outport/process/alteredaccounts" "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" + processS "github.com/multiversx/mx-chain-go/process" ) func checkArgOutportDataProviderFactory(arg ArgOutportDataProviderFactory) error { @@ -21,9 +22,6 @@ func checkArgOutportDataProviderFactory(arg ArgOutportDataProviderFactory) error if check.IfNil(arg.EsdtDataStorageHandler) { return alteredaccounts.ErrNilESDTDataStorageHandler } - if check.IfNil(arg.TransactionsStorer) { - return transactionsfee.ErrNilStorage - } if check.IfNil(arg.EconomicsData) { return transactionsfee.ErrNilTransactionFeeCalculator } @@ -42,9 +40,6 @@ func checkArgOutportDataProviderFactory(arg ArgOutportDataProviderFactory) error if check.IfNil(arg.Hasher) { return process.ErrNilHasher } - if check.IfNil(arg.MbsStorer) { - return process.ErrNilStorer - } if check.IfNil(arg.EnableEpochsHandler) { return process.ErrNilEnableEpochsHandler } @@ -60,6 +55,9 @@ func checkArgOutportDataProviderFactory(arg ArgOutportDataProviderFactory) error if check.IfNil(arg.RewardsGetter) { return process.ErrNilRewardsGetter } + if check.IfNil(arg.StorageService) { + return processS.ErrNilStorageService + } return nil } diff --git a/outport/process/factory/check_test.go b/outport/process/factory/check_test.go index 7655585becd..31e7c88562a 100644 --- a/outport/process/factory/check_test.go +++ b/outport/process/factory/check_test.go @@ -7,6 +7,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/process" "github.com/multiversx/mx-chain-go/outport/process/alteredaccounts" "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" + proc "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" @@ -26,19 +27,18 @@ func createArgOutportDataProviderFactory() ArgOutportDataProviderFactory { AccountsDB: &state.AccountsStub{}, Marshaller: &marshallerMock.MarshalizerMock{}, EsdtDataStorageHandler: &testscommon.EsdtStorageHandlerStub{}, - TransactionsStorer: &genericMocks.StorerMock{}, ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, TxCoordinator: &testscommon.TransactionCoordinatorMock{}, NodesCoordinator: &shardingMocks.NodesCoordinatorMock{}, GasConsumedProvider: &testscommon.GasHandlerStub{}, EconomicsData: &economicsmocks.EconomicsHandlerMock{}, Hasher: &testscommon.KeccakMock{}, - MbsStorer: &genericMocks.StorerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ExecutionOrderGetter: &commonMocks.TxExecutionOrderHandlerStub{}, DataPool: &dataRetriever.PoolsHolderMock{}, RoundHandler: &testscommon.RoundHandlerMock{}, RewardsGetter: &testscommon.RewardsCreatorStub{}, + StorageService: &genericMocks.ChainStorerMock{}, } } @@ -61,10 +61,6 @@ func TestCheckArgCreateOutportDataProvider(t *testing.T) { arg.EsdtDataStorageHandler = nil require.Equal(t, alteredaccounts.ErrNilESDTDataStorageHandler, checkArgOutportDataProviderFactory(arg)) - arg = createArgOutportDataProviderFactory() - arg.TransactionsStorer = nil - require.Equal(t, transactionsfee.ErrNilStorage, checkArgOutportDataProviderFactory(arg)) - arg = createArgOutportDataProviderFactory() arg.ShardCoordinator = nil require.Equal(t, transactionsfee.ErrNilShardCoordinator, checkArgOutportDataProviderFactory(arg)) @@ -101,6 +97,10 @@ func TestCheckArgCreateOutportDataProvider(t *testing.T) { arg.RewardsGetter = nil require.Equal(t, process.ErrNilRewardsGetter, checkArgOutportDataProviderFactory(arg)) + arg = createArgOutportDataProviderFactory() + arg.StorageService = nil + require.Equal(t, proc.ErrNilStorageService, checkArgOutportDataProviderFactory(arg)) + arg = createArgOutportDataProviderFactory() require.Nil(t, checkArgOutportDataProviderFactory(arg)) } diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index 4ed982b92a3..5680c0c28a7 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -18,7 +18,6 @@ import ( "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/storage" ) // ArgOutportDataProviderFactory holds the arguments needed for creating a new instance of outport.DataProviderOutport @@ -29,20 +28,19 @@ type ArgOutportDataProviderFactory struct { AccountsDB state.AccountsAdapter Marshaller marshal.Marshalizer EsdtDataStorageHandler vmcommon.ESDTNFTStorageHandler - TransactionsStorer storage.Storer ShardCoordinator sharding.Coordinator TxCoordinator processTxs.TransactionCoordinator NodesCoordinator nodesCoordinator.NodesCoordinator GasConsumedProvider process.GasConsumedProvider EconomicsData process.EconomicsDataHandler Hasher hashing.Hasher - MbsStorer storage.Storer EnableEpochsHandler common.EnableEpochsHandler ExecutionOrderGetter common.ExecutionOrderGetter DataPool dataRetriever.PoolsHolder StateAccessesCollector state.StateAccessesCollector RoundHandler process.RoundHandler RewardsGetter process.EpochRewardsGetter + StorageService dataRetriever.StorageService } // CreateOutportDataProvider will create a new instance of outport.DataProviderOutport @@ -66,9 +64,14 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP return nil, err } + transactionsStorer, err := arg.StorageService.GetStorer(dataRetriever.TransactionUnit) + if err != nil { + return nil, err + } + transactionsFeeProc, err := transactionsfee.NewTransactionsFeeProcessor(transactionsfee.ArgTransactionsFeeProcessor{ Marshaller: arg.Marshaller, - TransactionsStorer: arg.TransactionsStorer, + TransactionsStorer: transactionsStorer, ShardCoordinator: arg.ShardCoordinator, TxFeeCalculator: arg.EconomicsData, PubKeyConverter: arg.AddressConverter, @@ -96,5 +99,6 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP StateAccessesCollector: arg.StateAccessesCollector, RoundHandler: arg.RoundHandler, RewardsGetter: arg.RewardsGetter, + StorageService: arg.StorageService, }) } diff --git a/outport/process/factory/outportDataProviderFactory_test.go b/outport/process/factory/outportDataProviderFactory_test.go index 644cc8917df..97f811d8292 100644 --- a/outport/process/factory/outportDataProviderFactory_test.go +++ b/outport/process/factory/outportDataProviderFactory_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/multiversx/mx-chain-go/outport/process/alteredaccounts" + "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/stretchr/testify/require" ) @@ -36,6 +37,7 @@ func TestCreateOutportDataProvider(t *testing.T) { t.Parallel() arg := createArgOutportDataProviderFactory() + arg.StorageService = genericMocks.NewChainStorerMock(0) arg.HasDrivers = true provider, err := CreateOutportDataProvider(arg) diff --git a/outport/process/outportDataProvider.go b/outport/process/outportDataProvider.go index 0b42d3f15dd..4fcdb336092 100644 --- a/outport/process/outportDataProvider.go +++ b/outport/process/outportDataProvider.go @@ -18,6 +18,7 @@ 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" + "github.com/multiversx/mx-chain-go/storage" logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-go/common" @@ -49,6 +50,7 @@ type ArgOutportDataProvider struct { StateAccessesCollector state.StateAccessesCollector RoundHandler RoundHandler RewardsGetter EpochRewardsGetter + StorageService dataRetriever.StorageService } // ArgPrepareOutportSaveBlockData holds the arguments needed for prepare outport save block data @@ -83,6 +85,7 @@ type outportDataProvider struct { stateAccessesCollector state.StateAccessesCollector roundHandler RoundHandler rewardsGetter EpochRewardsGetter + storageService dataRetriever.StorageService } // NewOutportDataProvider will create a new instance of outportDataProvider @@ -104,6 +107,7 @@ func NewOutportDataProvider(arg ArgOutportDataProvider) (*outportDataProvider, e stateAccessesCollector: arg.StateAccessesCollector, roundHandler: arg.RoundHandler, rewardsGetter: arg.RewardsGetter, + storageService: arg.StorageService, }, nil } @@ -270,7 +274,7 @@ func (odp *outportDataProvider) prepareExecutionResultsData(args ArgPrepareOutpo return nil, err } - putInMapTxsFromBody(odp.dataPool, body, odp.shardID, cachedTxs) + odp.putInMapTxsFromBody(body, cachedTxs) if isMeta && hasRewardsOnBody(body) { cachedTxs[block.RewardsBlock] = odp.rewardsGetter.GetRewardsTxs(body) @@ -755,12 +759,7 @@ func (odp *outportDataProvider) filterOutDuplicatedMiniBlocks(miniBlocksFromBody return filteredMiniBlocks, nil } -func putInMapTxsFromBody( - dataPool dataRetriever.PoolsHolder, - body *block.Body, - selfShardID uint32, - txs map[block.Type]map[string]data.TransactionHandler, -) { +func (odp *outportDataProvider) putInMapTxsFromBody(body *block.Body, txs map[block.Type]map[string]data.TransactionHandler) { for _, t := range []block.Type{block.TxBlock, block.SmartContractResultBlock, block.RewardsBlock} { if txs[t] == nil { txs[t] = make(map[string]data.TransactionHandler) @@ -768,12 +767,12 @@ func putInMapTxsFromBody( } for _, mb := range body.MiniBlocks { - isCrossSCRBlockFromMe := mb.Type == block.SmartContractResultBlock && mb.SenderShardID == selfShardID + isCrossSCRBlockFromMe := mb.Type == block.SmartContractResultBlock && mb.SenderShardID == odp.shardID if isCrossSCRBlockFromMe { continue } - storeByType, found := getDataStoreForType(dataPool, mb.Type) + storeByType, found := getDataStoreForType(odp.dataPool, mb.Type) if !found { continue } @@ -785,9 +784,10 @@ func putInMapTxsFromBody( continue } - for _, txHash := range mb.TxHashes { - txI, found := cache.Get(txHash) - if !found { + for idx, txHash := range mb.TxHashes { + txI, err := odp.getTxFromCacheOrStorage(cache, txHash, mb.Type) + if err != nil { + log.Warn("putInMapTxsFromBody cannot find tx", "txHash", txHash, "idx", idx, "err", err) continue } @@ -796,6 +796,56 @@ func putInMapTxsFromBody( } } +func (odp *outportDataProvider) getTxFromCacheOrStorage( + cacher storage.Cacher, + txHash []byte, + mbType block.Type, +) (interface{}, error) { + if tx, found := cacher.Get(txHash); found { + return tx, nil + } + + unit, err := process.GetStorageUnitByBlockType(mbType) + if err != nil { + return nil, err + } + + storer, err := odp.storageService.GetStorer(unit) + if err != nil { + return nil, err + } + + txBytes, err := storer.Get(txHash) + if err != nil { + return nil, err + } + + txObj, err := odp.createTxObject(mbType) + if err != nil { + return nil, err + } + + err = odp.marshaller.Unmarshal(txObj, txBytes) + if err != nil { + return nil, err + } + + return txObj, nil +} + +func (odp *outportDataProvider) createTxObject(mbType block.Type) (interface{}, error) { + switch mbType { + case block.SmartContractResultBlock: + return &smartContractResult.SmartContractResult{}, nil + case block.RewardsBlock: + return &rewardTx.RewardTx{}, nil + case block.TxBlock: + return &transaction.Transaction{}, nil + default: + return nil, common.ErrWrongTypeAssertion + } +} + func getDataStoreForType( dataPool dataRetriever.PoolsHolder, mbType block.Type, diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index 10ec51cc774..3b28f145186 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -16,6 +16,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" + dr "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/outport/process/alteredaccounts/shared" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/storage" @@ -33,6 +34,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/state" + storageMocks "github.com/multiversx/mx-chain-go/testscommon/storage" ) func createArgOutportDataProvider() ArgOutportDataProvider { @@ -270,6 +272,185 @@ func Test_extractExecutedTxsFromMb(t *testing.T) { }) } +func TestOutportDataProvider_getTxFromCacheOrStorage(t *testing.T) { + t.Parallel() + + t.Run("cache hit returns tx without storage", func(t *testing.T) { + txHash := []byte("tx-hash") + expectedTx := &transaction.Transaction{Nonce: 7} + cacher := cache.NewCacherMock() + cacher.Put(txHash, expectedTx, 0) + + arg := createArgOutportDataProvider() + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + t.Fatalf("unexpected GetStorer call for unit %v", unitType) + return nil, errors.New("unexpected") + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + res, err := outportDataP.getTxFromCacheOrStorage(cacher, txHash, block.TxBlock) + require.NoError(t, err) + require.Same(t, expectedTx, res) + }) + + t.Run("cache miss uses storage and unmarshals", func(t *testing.T) { + txHash := []byte("tx-hash") + expectedTx := &transaction.Transaction{Nonce: 42} + marshaller := &marshallerMock.MarshalizerMock{} + txBytes, err := marshaller.Marshal(expectedTx) + require.NoError(t, err) + + storer := &storageMocks.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + require.Equal(t, txHash, key) + return txBytes, nil + }, + } + arg := createArgOutportDataProvider() + arg.Marshaller = marshaller + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + require.Equal(t, dr.TransactionUnit, unitType) + return storer, nil + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + res, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), txHash, block.TxBlock) + require.NoError(t, err) + require.IsType(t, &transaction.Transaction{}, res) + require.Equal(t, expectedTx.Nonce, res.(*transaction.Transaction).Nonce) + }) + + t.Run("cache miss SCR uses storage and unmarshals", func(t *testing.T) { + txHash := []byte("scr-hash") + expectedTx := &smartContractResult.SmartContractResult{Nonce: 11} + marshaller := &marshallerMock.MarshalizerMock{} + txBytes, err := marshaller.Marshal(expectedTx) + require.NoError(t, err) + + storer := &storageMocks.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + require.Equal(t, txHash, key) + return txBytes, nil + }, + } + arg := createArgOutportDataProvider() + arg.Marshaller = marshaller + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + require.Equal(t, dr.UnsignedTransactionUnit, unitType) + return storer, nil + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + res, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), txHash, block.SmartContractResultBlock) + require.NoError(t, err) + require.IsType(t, &smartContractResult.SmartContractResult{}, res) + require.Equal(t, expectedTx.Nonce, res.(*smartContractResult.SmartContractResult).Nonce) + }) + + t.Run("cache miss rewards uses storage and unmarshals", func(t *testing.T) { + txHash := []byte("reward-hash") + expectedTx := &rewardTx.RewardTx{Round: 7} + marshaller := &marshallerMock.MarshalizerMock{} + txBytes, err := marshaller.Marshal(expectedTx) + require.NoError(t, err) + + storer := &storageMocks.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + require.Equal(t, txHash, key) + return txBytes, nil + }, + } + arg := createArgOutportDataProvider() + arg.Marshaller = marshaller + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + require.Equal(t, dr.RewardTransactionUnit, unitType) + return storer, nil + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + res, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), txHash, block.RewardsBlock) + require.NoError(t, err) + require.IsType(t, &rewardTx.RewardTx{}, res) + require.Equal(t, expectedTx.Round, res.(*rewardTx.RewardTx).Round) + }) + + t.Run("get storer error", func(t *testing.T) { + arg := createArgOutportDataProvider() + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + return nil, errors.New("get storer error") + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + _, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), []byte("tx-hash"), block.TxBlock) + require.Error(t, err) + }) + + t.Run("storer get error", func(t *testing.T) { + storer := &storageMocks.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + return nil, errors.New("get error") + }, + } + arg := createArgOutportDataProvider() + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + return storer, nil + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + _, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), []byte("tx-hash"), block.TxBlock) + require.Error(t, err) + }) + + t.Run("create tx object error for unsupported block type", func(t *testing.T) { + storer := &storageMocks.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + return []byte(`{"Nonce":1}`), nil + }, + } + arg := createArgOutportDataProvider() + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + return storer, nil + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + _, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), []byte("tx-hash"), block.PeerBlock) + require.Error(t, err) + }) + + t.Run("unmarshal error", func(t *testing.T) { + storer := &storageMocks.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + return []byte(`{"Nonce":1}`), nil + }, + } + arg := createArgOutportDataProvider() + arg.Marshaller = &marshallerMock.MarshalizerMock{Fail: true} + arg.StorageService = &storageMocks.ChainStorerStub{ + GetStorerCalled: func(unitType dr.UnitType) (storage.Storer, error) { + return storer, nil + }, + } + outportDataP, _ := NewOutportDataProvider(arg) + + _, err := outportDataP.getTxFromCacheOrStorage(cache.NewCacherMock(), []byte("tx-hash"), block.TxBlock) + require.Error(t, err) + }) +} + func Test_setExecutionOrderInTransactionPool(t *testing.T) { t.Parallel() @@ -960,6 +1141,8 @@ func TestPrepareExecutionResultsData(t *testing.T) { func TestPutInMapTxsFromBody(t *testing.T) { t.Parallel() + arg := createArgOutportDataProvider() + dataPool := dataRetriever.NewPoolsHolderMock() txsMap := make(map[block.Type]map[string]data.TransactionHandler) shardID := uint32(0) @@ -978,6 +1161,10 @@ func TestPutInMapTxsFromBody(t *testing.T) { cacheID = process.ShardCacherIdentifier(2, 0) dataPool.UnsignedTransactions().AddData(tx3H, tx3, 1, cacheID) + arg.DataPool = dataPool + outportDataP, err := NewOutportDataProvider(arg) + require.Nil(t, err) + body := &block.Body{ MiniBlocks: []*block.MiniBlock{ { @@ -1007,7 +1194,7 @@ func TestPutInMapTxsFromBody(t *testing.T) { }, } - putInMapTxsFromBody(dataPool, body, shardID, txsMap) + outportDataP.putInMapTxsFromBody(body, txsMap) txPool, scrPool, rewardPool := txsMap[block.TxBlock], txsMap[block.SmartContractResultBlock], txsMap[block.RewardsBlock] txFromPool := txPool[string(tx1H)].(*transaction.Transaction) diff --git a/process/block/metablock.go b/process/block/metablock.go index 666685dce79..55b22f59eca 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -1373,11 +1373,6 @@ func (mp *metaProcessor) CommitBlock( return err } - err = mp.OnExecutedBlock(lastExecutionResultHeader, rootHash) - if err != nil { - return err - } - if !check.IfNil(finalMetaBlock) && finalMetaBlock.IsStartOfEpochBlock() { mp.blockTracker.CleanupInvalidCrossHeaders(header.GetEpoch(), header.GetRound()) } @@ -1391,6 +1386,11 @@ func (mp *metaProcessor) CommitBlock( mp.indexBlock(header, headerHash, body, finalMetaBlock, notarizedHeadersHashes, rewardsTxs) mp.recordBlockInHistory(headerHash, headerHandler, bodyHandler) + err = mp.OnExecutedBlock(lastExecutionResultHeader, rootHash) + if err != nil { + return err + } + highestFinalBlockNonce := mp.forkDetector.GetHighestFinalBlockNonce() saveMetricsForCommitMetachainBlock(mp.appStatusHandler, header, headerHash, mp.nodesCoordinator, highestFinalBlockNonce, mp.managedPeersHolder) diff --git a/process/block/shardblock.go b/process/block/shardblock.go index b55c936f732..95ab872561c 100644 --- a/process/block/shardblock.go +++ b/process/block/shardblock.go @@ -1104,14 +1104,14 @@ func (sp *shardProcessor) CommitBlock( return err } + sp.indexBlockIfNeeded(bodyHandler, headerHash, headerHandler, lastBlockHeader) + sp.recordBlockInHistory(headerHash, headerHandler, bodyHandler) + err = sp.OnExecutedBlock(lastExecutionResultHeader, rootHash) if err != nil { return err } - sp.indexBlockIfNeeded(bodyHandler, headerHash, headerHandler, lastBlockHeader) - sp.recordBlockInHistory(headerHash, headerHandler, bodyHandler) - lastCrossNotarizedHeader, _, err := sp.blockTracker.GetLastCrossNotarizedHeader(core.MetachainShardId) if err != nil { return err