diff --git a/factory/consensus/consensusComponents_test.go b/factory/consensus/consensusComponents_test.go index cb4643aed7b..98eca84938b 100644 --- a/factory/consensus/consensusComponents_test.go +++ b/factory/consensus/consensusComponents_test.go @@ -9,9 +9,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" crypto "github.com/multiversx/mx-chain-crypto-go" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/consensus" retriever "github.com/multiversx/mx-chain-go/dataRetriever" @@ -118,7 +119,7 @@ func createMockConsensusComponentsFactoryArgs() consensusComp.ConsensusComponent }, }, MbProvider: &testsMocks.MiniBlocksProviderStub{}, - Store: &genericMocks.ChainStorerMock{}, + Store: genericMocks.NewChainStorerMock(0), }, ProcessComponents: &testsMocks.ProcessComponentsStub{ EpochTrigger: &testsMocks.EpochStartTriggerStub{}, diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 70ff1fb7e05..1229ad3ecdd 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -316,7 +316,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - err = cs.GenerateBlocks(1) + err = cs.GenerateBlocks(2) require.Nil(t, err) log.Info("working with the following addresses", diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index b2ba68124c5..c4121811bc3 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -21,6 +21,8 @@ import ( crypto "github.com/multiversx/mx-chain-crypto-go" "github.com/multiversx/mx-chain-crypto-go/signing" "github.com/multiversx/mx-chain-crypto-go/signing/mcl" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/node/chainSimulator/components" @@ -29,7 +31,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorErrors "github.com/multiversx/mx-chain-go/node/chainSimulator/errors" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" - logger "github.com/multiversx/mx-chain-logger-go" ) const delaySendTxs = time.Millisecond diff --git a/process/block/metablockProposal.go b/process/block/metablockProposal.go index 71deda262a7..d47b33b3559 100644 --- a/process/block/metablockProposal.go +++ b/process/block/metablockProposal.go @@ -355,8 +355,11 @@ func (mp *metaProcessor) ProcessBlockProposal( return nil, err } + var execResult data.BaseExecutionResultHandler if header.IsEpochChangeProposed() { - return mp.processEpochStartProposeBlock(header, body) + // in case of error, will be picked up by the deferred revert + execResult, err = mp.processEpochStartProposeBlock(header, body) + return execResult, err } mp.txCoordinator.RequestBlockTransactions(body) @@ -398,12 +401,20 @@ func (mp *metaProcessor) ProcessBlockProposal( return nil, err } - valStatRootHash, err := mp.updateValidatorStatistics(header) + var valStatRootHash []byte + valStatRootHash, err = mp.updateValidatorStatistics(header) if err != nil { return nil, err } - err = mp.commitState(headerHandler) + var headerHash []byte + headerHash, err = core.CalculateHash(mp.marshalizer, mp.hasher, header) + if err != nil { + return nil, err + } + + // in case of error, will be picked up by the deferred revert + execResult, err = mp.collectExecutionResults(headerHash, header, body, valStatRootHash) if err != nil { return nil, err } @@ -413,12 +424,12 @@ func (mp *metaProcessor) ProcessBlockProposal( return nil, err } - headerHash, err := core.CalculateHash(mp.marshalizer, mp.hasher, header) + err = mp.commitState(headerHandler) if err != nil { return nil, err } - return mp.collectExecutionResults(headerHash, header, body, valStatRootHash) + return execResult, nil } func (mp *metaProcessor) processEpochStartProposeBlock( @@ -447,7 +458,8 @@ func (mp *metaProcessor) processEpochStartProposeBlock( return nil, err } - computedEconomics, err := mp.getComputedEconomics(metaHeader.GetEpoch() + 1) + var computedEconomics *block.Economics + computedEconomics, err = mp.getComputedEconomics(metaHeader.GetEpoch() + 1) if err != nil { return nil, err } @@ -462,7 +474,12 @@ func (mp *metaProcessor) processEpochStartProposeBlock( return nil, err } - err = mp.commitState(metaHeader) + headerHash, err := core.CalculateHash(mp.marshalizer, mp.hasher, metaHeader) + if err != nil { + return nil, err + } + + execResult, err := mp.collectExecutionResultsEpochStartProposal(headerHash, metaHeader, constructedBody, valStatRootHash) if err != nil { return nil, err } @@ -472,12 +489,12 @@ func (mp *metaProcessor) processEpochStartProposeBlock( return nil, err } - headerHash, err := core.CalculateHash(mp.marshalizer, mp.hasher, metaHeader) + err = mp.commitState(metaHeader) if err != nil { return nil, err } - return mp.collectExecutionResultsEpochStartProposal(headerHash, metaHeader, constructedBody, valStatRootHash) + return execResult, nil } func (mp *metaProcessor) updateValidatorStatistics(header data.MetaHeaderHandler) ([]byte, error) { diff --git a/process/block/metablockProposal_test.go b/process/block/metablockProposal_test.go index 88071a0afe5..76517617353 100644 --- a/process/block/metablockProposal_test.go +++ b/process/block/metablockProposal_test.go @@ -3222,6 +3222,15 @@ func TestMetaProcessor_processIfFirstBlockAfterEpochStartBlockV3(t *testing.T) { func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { t.Parallel() + defaultMetaBlockV3 := block.MetaBlockV3{ + LastExecutionResult: &block.MetaExecutionResultInfo{ + ExecutionResult: &block.BaseMetaExecutionResult{ + AccumulatedFeesInEpoch: big.NewInt(0), + DevFeesInEpoch: big.NewInt(0), + }, + }, + } + t.Run("should return ErrNilBlockHeader because of nil metaHeader argument", func(t *testing.T) { t.Parallel() @@ -3244,7 +3253,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { mp, err := blproc.NewMetaProcessor(arguments) require.Nil(t, err) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, nil) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, nil) require.Equal(t, process.ErrNilBlockBody, err) }) @@ -3257,7 +3266,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { mp, err := blproc.NewMetaProcessor(arguments) require.Nil(t, err) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{ + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{ MiniBlocks: []*block.MiniBlock{ {}, }, @@ -3282,7 +3291,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { }) require.Nil(t, err) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -3307,7 +3316,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { require.Nil(t, err) mp.SetEpochStartData(&blproc.EpochStartDataWrapper{}) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -3342,7 +3351,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { mp.SetEpochStartData(&blproc.EpochStartDataWrapper{}) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -3381,7 +3390,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { mp.SetEpochStartData(&blproc.EpochStartDataWrapper{}) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -3416,7 +3425,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { mp.SetEpochStartData(&blproc.EpochStartDataWrapper{}) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -3452,7 +3461,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { mp.SetEpochStartData(&blproc.EpochStartDataWrapper{}) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{}, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -3486,14 +3495,7 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { }, }) - _, err = mp.ProcessEpochStartProposeBlock(&block.MetaBlockV3{ - LastExecutionResult: &block.MetaExecutionResultInfo{ - ExecutionResult: &block.BaseMetaExecutionResult{ - AccumulatedFeesInEpoch: big.NewInt(0), - DevFeesInEpoch: big.NewInt(0), - }, - }, - }, &block.Body{}) + _, err = mp.ProcessEpochStartProposeBlock(&defaultMetaBlockV3, &block.Body{}) require.Nil(t, err) }) } @@ -3501,6 +3503,15 @@ func TestMetaProcessor_processEpochStartProposeBlock(t *testing.T) { func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing.T) { t.Parallel() + defaultMetaBlockV3 := block.MetaBlockV3{ + LastExecutionResult: &block.MetaExecutionResultInfo{ + ExecutionResult: &block.BaseMetaExecutionResult{ + AccumulatedFeesInEpoch: big.NewInt(0), + DevFeesInEpoch: big.NewInt(0), + }, + }, + } + t.Run("should return ErrNilBaseExecutionResult error on nil last execution result", func(t *testing.T) { t.Parallel() @@ -3513,7 +3524,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing. }) require.Nil(t, err) - err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{}) + err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3) require.ErrorContains(t, err, process.ErrNilBaseExecutionResult.Error()) }) @@ -3529,7 +3540,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing. }) require.Nil(t, err) - err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{}) + err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3) require.Equal(t, common.ErrWrongTypeAssertion, err) }) @@ -3550,7 +3561,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing. }) require.Nil(t, err) - err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{}) + err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3) require.Equal(t, expectedErr, err) }) @@ -3578,7 +3589,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing. }) require.Nil(t, err) - err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{}) + err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3) require.Equal(t, expectedErr, err) }) @@ -3607,7 +3618,7 @@ func TestMetaProcessor_processEconomicsDataForEpochStartProposeBlock(t *testing. require.Nil(t, err) mp.SetEpochStartData(&blproc.EpochStartDataWrapper{}) - err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&block.MetaBlockV3{}) + err = mp.ProcessEconomicsDataForEpochStartProposeBlock(&defaultMetaBlockV3) require.Nil(t, err) }) } @@ -3854,6 +3865,14 @@ func TestMetaProcessor_collectExecutionResultsEpochStartProposal(t *testing.T) { func TestMetaProcessor_ProcessBlockProposal(t *testing.T) { t.Parallel() + defaultMetaBlockV3 := block.MetaBlockV3{ + LastExecutionResult: &block.MetaExecutionResultInfo{ + ExecutionResult: &block.BaseMetaExecutionResult{ + AccumulatedFeesInEpoch: big.NewInt(0), + DevFeesInEpoch: big.NewInt(0), + }, + }, + } t.Run("should return ErrNilBlockHeader because of nil argument", func(t *testing.T) { t.Parallel() @@ -4291,7 +4310,7 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) { return &block.MetaExecutionResult{} }, GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler { - return &block.MetaBlockV3{} + return &defaultMetaBlockV3 }, } @@ -4317,9 +4336,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) { mp, err := blproc.NewMetaProcessor(arguments) require.Nil(t, err) - _, err = mp.ProcessBlockProposal(&block.MetaBlockV3{ - Nonce: 1, - }, &block.Body{}) + newBlock := defaultMetaBlockV3 + newBlock.Nonce = 1 + _, err = mp.ProcessBlockProposal(&newBlock, &block.Body{}) require.Equal(t, expectedErr, err) }) @@ -4332,7 +4351,7 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) { return &block.MetaExecutionResult{} }, GetLastExecutedBlockHeaderCalled: func() data.HeaderHandler { - return &block.MetaBlockV3{} + return &defaultMetaBlockV3 }, } @@ -4345,9 +4364,9 @@ func TestMetaProcessor_ProcessBlockProposal(t *testing.T) { mp, err := blproc.NewMetaProcessor(arguments) require.Nil(t, err) - _, err = mp.ProcessBlockProposal(&block.MetaBlockV3{ - Nonce: 1, - }, &block.Body{}) + newBlock := defaultMetaBlockV3 + newBlock.Nonce = 1 + _, err = mp.ProcessBlockProposal(&newBlock, &block.Body{}) require.Equal(t, expectedErr, err) }) diff --git a/process/block/shardblockProposal.go b/process/block/shardblockProposal.go index d21c04c92b9..c71bb3bd2b1 100644 --- a/process/block/shardblockProposal.go +++ b/process/block/shardblockProposal.go @@ -369,18 +369,20 @@ func (sp *shardProcessor) ProcessBlockProposal( return nil, err } - errCutoff := sp.blockProcessingCutoffHandler.HandleProcessErrorCutoff(header) - if errCutoff != nil { - return nil, errCutoff + // TODO: should receive the header hash instead of re-computing it + var headerHash []byte + headerHash, err = core.CalculateHash(sp.marshalizer, sp.hasher, header) + if err != nil { + return nil, err } - // TODO: should receive the header hash instead of re-computing it - headerHash, err := core.CalculateHash(sp.marshalizer, sp.hasher, header) + var executionResult data.BaseExecutionResultHandler + executionResult, err = sp.collectExecutionResults(headerHash, header, body) if err != nil { return nil, err } - executionResult, err := sp.collectExecutionResults(headerHash, header, body) + err = sp.blockProcessingCutoffHandler.HandleProcessErrorCutoff(header) if err != nil { return nil, err } diff --git a/process/sync/baseSync.go b/process/sync/baseSync.go index cfe08c7bad3..65246be86ab 100644 --- a/process/sync/baseSync.go +++ b/process/sync/baseSync.go @@ -24,7 +24,6 @@ import ( logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-go/epochStart" - "github.com/multiversx/mx-chain-go/epochStart/bootstrap/disabled" "github.com/multiversx/mx-chain-go/process/asyncExecution/queue" "github.com/multiversx/mx-chain-go/update" updateSync "github.com/multiversx/mx-chain-go/update/sync" @@ -1071,6 +1070,7 @@ func (boot *baseBootstrap) syncMiniBlocksAndTxsForHeader( // sync all txs into pools + boot.txSyncer.ClearFields() ctx, cancel = context.WithTimeout(context.Background(), defaultTimeToWaitForRequestedData) err = boot.txSyncer.SyncTransactionsFor(miniBlocks, header.GetEpoch(), ctx) cancel() @@ -1113,11 +1113,6 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded( } } - err = boot.saveProposedTxsToPool(currentHeader, currentBody) - if err != nil { - return err - } - errOnProposedBlock := boot.blockProcessor.OnProposedBlock( currentBody, currentHeader, @@ -1156,11 +1151,6 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded( } } - err = boot.saveProposedTxsToPool(hdr, body) - if err != nil { - return err - } - errOnProposedBlock := boot.blockProcessor.OnProposedBlock( body, hdr, @@ -1236,80 +1226,6 @@ func (boot *baseBootstrap) getExecutionResultHeaderNonceForSyncStart( return lastExecutionResultNonce, nil } -func (boot *baseBootstrap) saveProposedTxsToPool( - header data.HeaderHandler, - body data.BodyHandler, -) error { - if !header.IsHeaderV3() { - return nil - } - - bodyPtr, ok := body.(*block.Body) - if !ok { - return process.ErrWrongTypeAssertion - } - - separatedBodies := process.SeparateBodyByType(bodyPtr) - - for blockType, blockBody := range separatedBodies { - dataPool, err := process.GetDataPoolByBlockType(blockType, boot.dataPool) - if err != nil { - return err - } - - unit, err := process.GetStorageUnitByBlockType(blockType) - if err != nil { - return err - } - - storer, err := boot.store.GetStorer(unit) - if err != nil { - return err - } - - for i := 0; i < len(blockBody.MiniBlocks); i++ { - miniBlock := blockBody.MiniBlocks[i] - err = boot.saveTxsToPool(dataPool, storer, miniBlock, blockType) - if err != nil { - return err - } - } - } - - return nil -} - -func (boot *baseBootstrap) saveTxsToPool( - dataPool dataRetriever.ShardedDataCacherNotifier, - storer storage.Storer, - miniBlock *block.MiniBlock, - blockType block.Type, -) error { - txHashes := miniBlock.TxHashes - - for _, txHash := range txHashes { - txBuff, err := storer.Get(txHash) - if err != nil { - return err - } - - tx, err := boot.unmarshalTxByBlockType(blockType, txBuff) - if err != nil { - return err - } - - cacherIdentifier := process.ShardCacherIdentifier(miniBlock.SenderShardID, miniBlock.ReceiverShardID) - dataPool.AddData( - txHash, - tx, - tx.Size(), - cacherIdentifier, - ) - } - - return nil -} - func (boot *baseBootstrap) unmarshalTxByBlockType( blockType block.Type, txBuff []byte, @@ -2266,8 +2182,13 @@ func (boot *baseBootstrap) IsInterfaceNil() bool { func (boot *baseBootstrap) createTxSyncer() error { var err error + miniBlocksStorer, err := boot.store.GetStorer(dataRetriever.MiniBlockUnit) + if err != nil { + return err + } + syncMiniBlocksArgs := updateSync.ArgsNewPendingMiniBlocksSyncer{ - Storage: disabled.CreateMemUnit(), + Storage: miniBlocksStorer, Cache: boot.dataPool.MiniBlocks(), Marshalizer: boot.marshalizer, RequestHandler: boot.requestHandler, diff --git a/process/sync/baseSync_test.go b/process/sync/baseSync_test.go index ed2de6bb1fc..1ebf5ac22f6 100644 --- a/process/sync/baseSync_test.go +++ b/process/sync/baseSync_test.go @@ -2,7 +2,6 @@ package sync import ( "context" - "errors" "sync/atomic" "testing" "time" @@ -10,20 +9,11 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "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/rewardTx" - "github.com/multiversx/mx-chain-core-go/data/smartContractResult" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "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" "github.com/multiversx/mx-chain-go/process/mock" - "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/testscommon" - dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/processMocks" - storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -450,125 +440,3 @@ func TestBaseBootstrap_PrepareForSyncAtBootstrapIfNeeded(t *testing.T) { require.Equal(t, 1, numCalls) // still 1 call }) } - -func TestBaseBootstrap_SaveProposedTxsToPool(t *testing.T) { - t.Parallel() - - marshaller := &marshal.GogoProtoMarshalizer{} - - txCalls := 0 - scCalls := 0 - rwCalls := 0 - peerCalls := 0 - - boot := &baseBootstrap{ - marshalizer: marshaller, - dataPool: &dataRetrieverMock.PoolsHolderStub{ - TransactionsCalled: func() dataRetriever.ShardedDataCacherNotifier { - return &testscommon.ShardedDataStub{ - AddDataCalled: func(key []byte, data interface{}, sizeInBytes int, cacheID string) { - txCalls++ - }, - } - }, - UnsignedTransactionsCalled: func() dataRetriever.ShardedDataCacherNotifier { - return &testscommon.ShardedDataStub{ - AddDataCalled: func(key []byte, data interface{}, sizeInBytes int, cacheID string) { - scCalls++ - }, - } - }, - RewardTransactionsCalled: func() dataRetriever.ShardedDataCacherNotifier { - return &testscommon.ShardedDataStub{ - AddDataCalled: func(key []byte, data interface{}, sizeInBytes int, cacheID string) { - rwCalls++ - }, - } - }, - ValidatorsInfoCalled: func() dataRetriever.ShardedDataCacherNotifier { - return &testscommon.ShardedDataStub{ - AddDataCalled: func(key []byte, data interface{}, sizeInBytes int, cacheID string) { - peerCalls++ - }, - } - }, - }, - store: &storageStubs.ChainStorerStub{ - GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) { - return &storageStubs.StorerStub{ - GetCalled: func(key []byte) ([]byte, error) { - switch string(key) { - case "txHash1": - tx := &transaction.Transaction{ - Nonce: 1, - } - txBytes, _ := marshaller.Marshal(tx) - return txBytes, nil - case "txHash2": - tx := &transaction.Transaction{ - Nonce: 2, - } - txBytes, _ := marshaller.Marshal(tx) - return txBytes, nil - case "txHash3": - tx := &smartContractResult.SmartContractResult{ - Nonce: 3, - CodeMetadata: []byte("codeMetadata"), - } - txBytes, _ := marshaller.Marshal(tx) - return txBytes, nil - case "txHash4": - tx := &rewardTx.RewardTx{ - Round: 1, - } - txBytes, _ := marshaller.Marshal(tx) - return txBytes, nil - case "txHash5": - tx := &state.ShardValidatorInfo{ - PublicKey: []byte("pubKey"), - } - txBytes, _ := marshaller.Marshal(tx) - return txBytes, nil - default: - return nil, errors.New("err") - } - }, - }, nil - }, - }, - } - - header := &block.HeaderV3{} - body := &block.Body{ - MiniBlocks: []*block.MiniBlock{ - &block.MiniBlock{ - TxHashes: [][]byte{[]byte("txHash1")}, - Type: block.TxBlock, - }, - &block.MiniBlock{ - TxHashes: [][]byte{[]byte("txHash2")}, - Type: block.InvalidBlock, - }, - &block.MiniBlock{ - TxHashes: [][]byte{[]byte("txHash3")}, - Type: block.SmartContractResultBlock, - }, - &block.MiniBlock{ - TxHashes: [][]byte{[]byte("txHash4")}, - Type: block.RewardsBlock, - }, - &block.MiniBlock{ - TxHashes: [][]byte{[]byte("txHash5")}, - Type: block.PeerBlock, - }, - }, - } - - err := boot.SaveProposedTxsToPool(header, body) - require.Nil(t, err) - - require.Equal(t, 2, txCalls) - require.Equal(t, 1, scCalls) - require.Equal(t, 1, rwCalls) - require.Equal(t, 1, peerCalls) -} diff --git a/process/sync/export_test.go b/process/sync/export_test.go index 427e2369864..8f468580607 100644 --- a/process/sync/export_test.go +++ b/process/sync/export_test.go @@ -357,11 +357,3 @@ func (boot *baseBootstrap) ProcessWaitTime() time.Duration { func (boot *baseBootstrap) PrepareForSyncAtBoostrapIfNeeded() error { return boot.prepareForSyncAtBoostrapIfNeeded() } - -// SaveProposedTxsToPool - -func (boot *baseBootstrap) SaveProposedTxsToPool( - header data.HeaderHandler, - body data.BodyHandler, -) error { - return boot.saveProposedTxsToPool(header, body) -}