From 027795193f7148c7aa9174796de9297e216dd139 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Wed, 1 Mar 2023 12:24:56 +0200 Subject: [PATCH 1/3] fix outport data provider --- .../transactionsFeeProcessor.go | 7 ++- .../transactionsFeeProcessor_test.go | 49 +++++++++++++++++++ process/block/metablock.go | 2 +- process/block/shardblock.go | 2 +- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 8952ecb72e1..114c20ca654 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -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 @@ -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 } @@ -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 } @@ -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) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 73d74ec012e..ecfa64278a6 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -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" ) @@ -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) +} diff --git a/process/block/metablock.go b/process/block/metablock.go index 310072acafd..3aa15364023 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -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) diff --git a/process/block/shardblock.go b/process/block/shardblock.go index 16b88d5bf9d..0341864bfff 100644 --- a/process/block/shardblock.go +++ b/process/block/shardblock.go @@ -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) From e7ade61bbf21e242397c6266e299d8ae38169ecc Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Wed, 1 Mar 2023 12:34:17 +0200 Subject: [PATCH 2/3] fixes --- outport/process/transactionsfee/transactionsFeeProcessor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 114c20ca654..81047ab9709 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -13,6 +13,8 @@ import ( logger "github.com/multiversx/mx-chain-logger-go" ) +const loggerName = "outport/process/transactionsfee" + // ArgTransactionsFeeProcessor holds the arguments needed for creating a new instance of transactionsFeeProcessor type ArgTransactionsFeeProcessor struct { Marshaller marshal.Marshalizer @@ -40,7 +42,7 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions txFeeCalculator: arg.TxFeeCalculator, shardCoordinator: arg.ShardCoordinator, txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller), - log: logger.GetOrCreate("outport/process/transactionsfee"), + log: logger.GetOrCreate(loggerName), }, nil } From 36570172f2f191e878d6d6edb2fb787f6c84d2cf Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Thu, 2 Mar 2023 09:51:13 +0200 Subject: [PATCH 3/3] fixes after merge --- .../process/transactionsfee/transactionsFeeProcessor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 723526300bf..2fcee563e7a 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" ) -var pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, log) +var pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, &testscommon.LoggerStub{}) func prepareMockArg() ArgTransactionsFeeProcessor { return ArgTransactionsFeeProcessor{