Skip to content

Commit

Permalink
Merge pull request #5043 from multiversx/fix-outport-data-provider-bug
Browse files Browse the repository at this point in the history
Bug-fix outport data provider
  • Loading branch information
miiu96 authored Mar 3, 2023
2 parents 3c57b72 + 3657017 commit 88a5873
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
7 changes: 5 additions & 2 deletions outport/process/transactionsfee/transactionsFeeProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField"
)

var log = logger.GetOrCreate("outport/process/transactionsfee")
const loggerName = "outport/process/transactionsfee"

// ArgTransactionsFeeProcessor holds the arguments needed for creating a new instance of transactionsFeeProcessor
type ArgTransactionsFeeProcessor struct {
Expand All @@ -30,6 +30,7 @@ type transactionsFeeProcessor struct {
txFeeCalculator FeesProcessorHandler
shardCoordinator sharding.Coordinator
dataFieldParser dataFieldParser
log logger.Logger
}

// NewTransactionsFeeProcessor will create a new instance of transactionsFeeProcessor
Expand All @@ -51,6 +52,7 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions
txFeeCalculator: arg.TxFeeCalculator,
shardCoordinator: arg.ShardCoordinator,
txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller),
log: logger.GetOrCreate(loggerName),
dataFieldParser: parser,
}, nil
}
Expand Down Expand Up @@ -178,7 +180,8 @@ func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transa

txFromStorage, err := tep.txGetter.GetTxByHash(scr.OriginalTxHash)
if err != nil {
return err
tep.log.Trace("transactionsFeeProcessor.prepareScrsNoTx: cannot find transaction in storage", "hash", scr.OriginalTxHash, "error", err.Error())
continue
}

gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value)
Expand Down
51 changes: 50 additions & 1 deletion outport/process/transactionsfee/transactionsFeeProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"github.com/multiversx/mx-chain-go/outport/mock"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/genericMocks"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/stretchr/testify/require"
)

var pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, log)
var pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, &testscommon.LoggerStub{})

func prepareMockArg() ArgTransactionsFeeProcessor {
return ArgTransactionsFeeProcessor{
Expand Down Expand Up @@ -339,3 +340,51 @@ func silentDecodeAddress(address string) []byte {
decoded, _ := pubKeyConverter.Decode(address)
return decoded
}

func TestPutFeeAndGasUsedScrWithRefundNoTx(t *testing.T) {
t.Parallel()

_ = logger.SetLogLevel("*:TRACE")

txHash := []byte("relayedTx")
scrWithRefund := []byte("scrWithRefund")

refundValueBig, _ := big.NewInt(0).SetString("226498540000000", 10)

scr := outportcore.NewTransactionHandlerWithGasAndFee(&smartContractResult.SmartContractResult{
Nonce: 3,
SndAddr: []byte("erd1qqqqqqqqqqqqqpgq3dswlnnlkfd3gqrcv3dhzgnvh8ryf27g5rfsecnn2s"),
RcvAddr: []byte("erd1k7j6ewjsla4zsgv8v6f6fe3dvrkgv3d0d9jerczw45hzedhyed8sh2u34u"),
PrevTxHash: []byte("f639cb7a0231191e04ec19dcb1359bd93a03fe8dc4a28a80d00835c5d1c988f8"),
OriginalTxHash: txHash,
Value: refundValueBig,
Data: []byte("@ok"),
}, 0, big.NewInt(0))

pool := &outportcore.Pool{
Scrs: map[string]coreData.TransactionHandlerWithGasUsedAndFee{
"wrong": outportcore.NewTransactionHandlerWithGasAndFee(&transaction.Transaction{}, 0, big.NewInt(0)),
string(scrWithRefund): scr,
},
}

arg := prepareMockArg()

wasCalled := false
txsFeeProc, err := NewTransactionsFeeProcessor(arg)
txsFeeProc.log = &testscommon.LoggerStub{
TraceCalled: func(message string, args ...interface{}) {
wasCalled = true
require.Equal(t, "transactionsFeeProcessor.prepareScrsNoTx: cannot find transaction in storage", message)
},
}

require.NotNil(t, txsFeeProc)
require.Nil(t, err)

err = txsFeeProc.PutFeeAndGasUsed(pool)
require.Nil(t, err)
require.Equal(t, big.NewInt(0), scr.GetFee())
require.Equal(t, uint64(0), scr.GetGasUsed())
require.True(t, wasCalled)
}
2 changes: 1 addition & 1 deletion process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (mp *metaProcessor) indexBlock(
PreviousHeader: lastMetaBlock,
})
if err != nil {
log.Warn("metaProcessor.indexBlock cannot prepare argSaveBlock", "error", err.Error())
log.Error("metaProcessor.indexBlock cannot prepare argSaveBlock", "error", err.Error())
return
}
mp.outportHandler.SaveBlock(argSaveBlock)
Expand Down
2 changes: 1 addition & 1 deletion process/block/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func (sp *shardProcessor) indexBlockIfNeeded(
PreviousHeader: lastBlockHeader,
})
if err != nil {
log.Warn("shardProcessor.indexBlockIfNeeded cannot prepare argSaveBlock", "error", err.Error())
log.Error("shardProcessor.indexBlockIfNeeded cannot prepare argSaveBlock", "error", err.Error())
return
}
sp.outportHandler.SaveBlock(argSaveBlock)
Expand Down

0 comments on commit 88a5873

Please sign in to comment.