Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 7 additions & 86 deletions process/sync/baseSync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1113,11 +1113,6 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(
}
}

err = boot.saveProposedTxsToPool(currentHeader, currentBody)
if err != nil {
return err
}

errOnProposedBlock := boot.blockProcessor.OnProposedBlock(
currentBody,
currentHeader,
Expand Down Expand Up @@ -1156,11 +1151,6 @@ func (boot *baseBootstrap) prepareForSyncIfNeeded(
}
}

err = boot.saveProposedTxsToPool(hdr, body)
if err != nil {
return err
}

errOnProposedBlock := boot.blockProcessor.OnProposedBlock(
body,
hdr,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
132 changes: 0 additions & 132 deletions process/sync/baseSync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,18 @@ package sync

import (
"context"
"errors"
"sync/atomic"
"testing"
"time"

"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"
)
Expand Down Expand Up @@ -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)
}
8 changes: 0 additions & 8 deletions process/sync/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading