From ae9c133ba43514fc51f7d0b179d71f2b5ff999bf Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Mon, 6 Mar 2023 16:09:09 +0200 Subject: [PATCH 1/2] bug-fix --- .../transactionsFeeProcessor.go | 6 +++ .../transactionsFeeProcessor_test.go | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 0f6d05429dc..1047e2ddc3a 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -1,6 +1,7 @@ package transactionsfee import ( + "bytes" "math/big" "github.com/multiversx/mx-chain-core-go/core" @@ -184,6 +185,11 @@ func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transa continue } + isForInitialTxSender := bytes.Equal(scr.RcvAddr, txFromStorage.SndAddr) + if !isForInitialTxSender { + continue + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value) scrHandler.SetGasUsed(gasUsed) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 2fcee563e7a..66a438489cd 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -150,6 +150,7 @@ func TestPutFeeAndGasUsedScrNoTx(t *testing.T) { initialTx := &transaction.Transaction{ GasLimit: 30000000, GasPrice: 1000000000, + SndAddr: []byte("erd1k7j6ewjsla4zsgv8v6f6fe3dvrkgv3d0d9jerczw45hzedhyed8sh2u34u"), } txBytes, _ := arg.Marshaller.Marshal(initialTx) @@ -388,3 +389,49 @@ func TestPutFeeAndGasUsedScrWithRefundNoTx(t *testing.T) { require.Equal(t, uint64(0), scr.GetGasUsed()) require.True(t, wasCalled) } + +func TestPutFeeAndGasUsedScrWithRefundNotForInitialSender(t *testing.T) { + t.Parallel() + + txHash := []byte("tx") + 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(""), + }, 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() + + initialTx := &transaction.Transaction{ + GasLimit: 30_000_000, + GasPrice: 1000000000, + SndAddr: []byte("erd1dglncxk6sl9a3xumj78n6z2xux4ghp5c92cstv5zsn56tjgtdwpsk46qrs"), + } + txBytes, _ := arg.Marshaller.Marshal(initialTx) + + _ = arg.TransactionsStorer.Put(txHash, txBytes) + + txsFeeProc, err := NewTransactionsFeeProcessor(arg) + 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()) +} From 7553536dcb4c0b7bce0765ff3ab68193858ae5b3 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Tue, 7 Mar 2023 11:43:41 +0200 Subject: [PATCH 2/2] small fix --- node/external/transactionAPI/gasUsedAndFeeProcessor.go | 3 +++ node/external/transactionAPI/gasUsedAndFeeProcessor_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 42290a7db19..ad01d11726c 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -36,6 +36,9 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction if !scr.IsRefund { continue } + if scr.RcvAddr != tx.Sender { + continue + } gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefund = true diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 69bfd993dc9..2c351fd8be0 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -145,11 +145,14 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. RcvAddr: silentDecodeAddress(receiver), Data: []byte("relayedTx@"), }, + Sender: sender, + Receiver: receiver, GasLimit: 10_000_000, SmartContractResults: []*transaction.ApiSmartContractResult{ { Value: big.NewInt(66350000000000), IsRefund: true, + RcvAddr: sender, }, }, Logs: &transaction.ApiLogs{