Skip to content
Draft
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
12 changes: 1 addition & 11 deletions factory/processing/blockProcessorCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1401,36 +1401,26 @@ 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,
GasConsumedProvider: gasConsumedProvider,
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(),
})
}

Expand Down
10 changes: 4 additions & 6 deletions outport/process/factory/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
12 changes: 6 additions & 6 deletions outport/process/factory/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{},
}
}

Expand All @@ -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))
Expand Down Expand Up @@ -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))
}
12 changes: 8 additions & 4 deletions outport/process/factory/outportDataProviderFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -96,5 +99,6 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP
StateAccessesCollector: arg.StateAccessesCollector,
RoundHandler: arg.RoundHandler,
RewardsGetter: arg.RewardsGetter,
StorageService: arg.StorageService,
})
}
2 changes: 2 additions & 0 deletions outport/process/factory/outportDataProviderFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
74 changes: 62 additions & 12 deletions outport/process/outportDataProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -104,6 +107,7 @@ func NewOutportDataProvider(arg ArgOutportDataProvider) (*outportDataProvider, e
stateAccessesCollector: arg.StateAccessesCollector,
roundHandler: arg.RoundHandler,
rewardsGetter: arg.RewardsGetter,
storageService: arg.StorageService,
}, nil
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -755,25 +759,20 @@ 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)
}
}

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
}
Expand All @@ -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
}

Expand All @@ -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,
Expand Down
Loading
Loading