diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 43599a73..d2d85ba8 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -776,10 +776,6 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques fetched: false, } - //if isRelayedTxV3(getTxResponse.Data.Transaction) { - // return tp.mergeSCRLogsFromInnerReceivers(&getTxResponse.Data.Transaction, withResults), nil - //} - isIntraShard := sndShardID == rcvShardID observerIsInDestShard := rcvShardID == observerShardID @@ -836,65 +832,6 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques return nil, errors.ErrTransactionNotFound } -func isRelayedTxV3(tx transaction.ApiTransactionResult) bool { - return tx.ProcessingTypeOnSource == relayedV3TransactionDescriptor && tx.ProcessingTypeOnDestination == relayedV3TransactionDescriptor -} - -func (tp *TransactionProcessor) mergeSCRLogsFromInnerReceivers(tx *transaction.ApiTransactionResult, withResults bool) *transaction.ApiTransactionResult { - logsOnDestMap := make(map[string]*transaction.ApiLogs, len(tx.SmartContractResults)) - - txsByReceiverShardMap := tp.groupTxsByReceiverShard(tx) - for shardID, scrHashes := range txsByReceiverShardMap { - for _, scrHash := range scrHashes { - observers, err := tp.getNodesInShard(shardID, requestTypeObservers) - if err != nil { - break - } - - if withResults { - for _, observer := range observers { - getTxResponse, ok, _ := tp.getTxFromObserver(observer, scrHash, withResults) - if !ok { - continue - } - - logsOnDestMap[scrHash] = getTxResponse.Data.Transaction.Logs - break - } - } - } - } - - finalTx := *tx - // if withResults, override the scr logs with the one from the receiver shard - if withResults { - for _, scr := range finalTx.SmartContractResults { - logsOnDest, found := logsOnDestMap[scr.Hash] - if !found { - continue - } - - scr.Logs = logsOnDest - } - } - - return &finalTx -} - -func (tp *TransactionProcessor) groupTxsByReceiverShard(tx *transaction.ApiTransactionResult) map[uint32][]string { - txsByReceiverShardMap := make(map[uint32][]string) - for _, scr := range tx.SmartContractResults { - shardID, err := tp.getShardByAddress(scr.RcvAddr) - if err != nil { - continue - } - - txsByReceiverShardMap[shardID] = append(txsByReceiverShardMap[shardID], scr.Hash) - } - - return txsByReceiverShardMap -} - func (tp *TransactionProcessor) fetchSCRSBasedOnShardMap(tx *transaction.ApiTransactionResult, shardIDWasFetch map[uint32]*tupleHashWasFetched) error { for shardID, info := range shardIDWasFetch { scrs, err := tp.fetchSCRs(tx.Hash, info.hash, shardID) diff --git a/process/transactionProcessor_test.go b/process/transactionProcessor_test.go index b37765a2..4e551aff 100644 --- a/process/transactionProcessor_test.go +++ b/process/transactionProcessor_test.go @@ -1322,131 +1322,6 @@ func TestTransactionProcessor_GetTransactionWithEventsFirstFromDstShardAndAfterS assert.Equal(t, 3, len(tx.SmartContractResults)) } -func TestTransactionProcessor_GetTransactionRelayedV3ShouldMergeEvents(t *testing.T) { - t.Parallel() - - relayer := hex.EncodeToString([]byte("relayer")) - sender1 := hex.EncodeToString([]byte("sender1")) - sender2 := hex.EncodeToString([]byte("sender2")) - receiver1 := hex.EncodeToString([]byte("receiver1")) - receiver2 := hex.EncodeToString([]byte("receiver2")) - - addrObs0 := "observer0" - addrObsFailing := "observerFailing" - addrObs1 := "observer1" - - hashRelayed := "hashRelayed" - - scrHash1 := "scrHash1" - providedLogsInnerTx1 := &transaction.ApiLogs{ - Events: []*transaction.Events{ - { - Address: receiver1, - Identifier: "events innertx 1", - }, - }, - } - - scrHash2 := "scrHash2" - providedLogsInnerTx2 := &transaction.ApiLogs{ - Events: []*transaction.Events{ - { - Address: receiver2, - Identifier: "events innertx 2", - }, - }, - } - - tp, _ := process.NewTransactionProcessor( - &mock.ProcessorStub{ - ComputeShardIdCalled: func(addressBuff []byte) (uint32, error) { - switch string(addressBuff) { - case "relayer", "sender1", "sender2", "receiver1": - return 0, nil - case "receiver2": - return 1, nil - } - - return 0, nil - }, - GetShardIDsCalled: func() []uint32 { - return []uint32{0, 1} - }, - GetObserversCalled: func(shardId uint32, dataAvailability data.ObserverDataAvailabilityType) ([]*data.NodeData, error) { - if shardId == 0 { - return []*data.NodeData{ - {Address: addrObs0, ShardId: 0}, - }, nil - } - if shardId == 1 { - return []*data.NodeData{ - {Address: addrObsFailing, ShardId: 1}, - {Address: addrObs1, ShardId: 1}, - }, nil - } - - return nil, nil - }, - CallGetRestEndPointCalled: func(address string, path string, value interface{}) (i int, err error) { - if address == addrObsFailing { - return http.StatusBadRequest, errors.New("error for coverage only") - } - - responseGetTx := value.(*data.GetTransactionResponse) - if strings.Contains(path, hashRelayed) { - responseGetTx.Data.Transaction.Hash = hashRelayed - responseGetTx.Data.Transaction.ProcessingTypeOnSource = "RelayedTxV3" - responseGetTx.Data.Transaction.ProcessingTypeOnDestination = "RelayedTxV3" - responseGetTx.Data.Transaction.SmartContractResults = []*transaction.ApiSmartContractResult{ - { - Hash: scrHash1, - RcvAddr: receiver1, - SndAddr: sender1, - RelayerAddr: relayer, - IsRelayed: true, - }, - { - Hash: scrHash2, - RcvAddr: receiver2, - SndAddr: sender2, - RelayerAddr: relayer, - IsRelayed: true, - }, - } - - return http.StatusOK, nil - } - if strings.Contains(path, scrHash1) { - responseGetTx.Data.Transaction.Hash = scrHash1 - responseGetTx.Data.Transaction.Logs = providedLogsInnerTx1 - - return http.StatusOK, nil - } - if strings.Contains(path, scrHash2) { - responseGetTx.Data.Transaction.Hash = scrHash2 - responseGetTx.Data.Transaction.Logs = providedLogsInnerTx2 - - return http.StatusOK, nil - } - - return http.StatusBadRequest, nil - }, - }, - &mock.PubKeyConverterMock{}, - hasher, - marshalizer, - funcNewTxCostHandler, - logsMerger, - true, - ) - - tx, err := tp.GetTransaction(hashRelayed, true) - require.NoError(t, err) - require.Equal(t, 2, len(tx.SmartContractResults)) - require.Equal(t, providedLogsInnerTx1, tx.SmartContractResults[0].Logs) - require.Equal(t, providedLogsInnerTx2, tx.SmartContractResults[1].Logs) -} - func TestTransactionProcessor_GetTransactionPool(t *testing.T) { t.Parallel()