Skip to content

Commit

Permalink
fix outport data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed Mar 1, 2023
1 parent 3f5fffe commit 0277951
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
7 changes: 6 additions & 1 deletion outport/process/transactionsfee/transactionsFeeProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/storage"
logger "github.com/multiversx/mx-chain-logger-go"
)

// ArgTransactionsFeeProcessor holds the arguments needed for creating a new instance of transactionsFeeProcessor
Expand All @@ -24,11 +25,13 @@ type transactionsFeeProcessor struct {
txGetter transactionGetter
txFeeCalculator FeesProcessorHandler
shardCoordinator sharding.Coordinator
log logger.Logger
}

// NewTransactionsFeeProcessor will create a new instance of transactionsFeeProcessor
func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactionsFeeProcessor, error) {
err := checkArg(arg)

if err != nil {
return nil, err
}
Expand All @@ -37,6 +40,7 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions
txFeeCalculator: arg.TxFeeCalculator,
shardCoordinator: arg.ShardCoordinator,
txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller),
log: logger.GetOrCreate("outport/process/transactionsfee"),
}, nil
}

Expand Down Expand Up @@ -160,7 +164,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
49 changes: 49 additions & 0 deletions outport/process/transactionsfee/transactionsFeeProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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"
)

Expand Down Expand Up @@ -298,3 +299,51 @@ func TestPutFeeAndGasUsedWrongRelayedTx(t *testing.T) {
require.Equal(t, uint64(550000000), initialTx.GetGasUsed())
require.Equal(t, "6103405000000000", initialTx.GetInitialPaidFee().String())
}

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 0277951

Please sign in to comment.