From 1933cbad61ddff56335053aba24cb2c077e51bef Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Dec 2025 13:09:09 +0200 Subject: [PATCH 1/2] remove search into storage on sync for txs --- process/sync/baseSync.go | 93 +++------------------------------------- 1 file changed, 7 insertions(+), 86 deletions(-) diff --git a/process/sync/baseSync.go b/process/sync/baseSync.go index cfe08c7bad..65246be86a 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, From 442ec61daed12b574b3b065b0f395c9bc476ecd9 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Dec 2025 13:14:16 +0200 Subject: [PATCH 2/2] remove unit tests --- process/sync/baseSync_test.go | 132 ---------------------------------- process/sync/export_test.go | 8 --- 2 files changed, 140 deletions(-) diff --git a/process/sync/baseSync_test.go b/process/sync/baseSync_test.go index ed2de6bb1f..1ebf5ac22f 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 427e236986..8f46858060 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) -}