Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper fix for gasUsed and fee in case of relayedV3 #6440

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

sstanculeanu
Copy link
Collaborator

Reasoning behind the pull request

  • gasUsed and fee fields computed while getting transaction withResults=true are still invalid for relayed v3

Proposed changes

  • proper computation of the fields

Testing procedure

  • standard system test + scenarios on relayed v3 with verification of these fields

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

Copy link

github-actions bot commented Sep 6, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 506cd9fa48ec334775f05b3b92dc3458fa5a3d24
  • Current Branch: fix_gasused_and_fee
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 06092024-103408
  • PYTEST_EXIT_CODE: 0
    🎉 MultiversX CI/CD Workflow Complete!

tx.InitiallyPaidFee = totalFee.String()
tx.GasUsed = big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64()
}
initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the same as before right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, only removed one if

@@ -69,7 +69,17 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction

gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value)
hasRefundForSender = true
break
totalRefunds.Add(totalRefunds, scr.Value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this affect regular transactions with multiple refund scrs from other shards as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.. it means this was a bug also for that transactions.. updated to iterate through all of them

}

hasRefundForSender := false
totalRefunds := big.NewInt(0)
isRelayedV3 := len(tx.InnerTransactions) > 0
for _, scr := range tx.SmartContractResults {
if !scr.IsRefund || scr.RcvAddr != tx.Sender {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think line 67 is dead code right?
there was already the same check done on line 63 with a continue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, removed it

@@ -167,12 +169,21 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi
txWithResults.GetFeeInfo().SetGasUsed(gasUsed)
txWithResults.GetFeeInfo().SetFee(fee)
hasRefund = true
break
totalRefunds.Add(totalRefunds, scr.Value)
if !isRelayedV3 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will affect other transactions with multiple scrs in different shards as well, so I think it should iterate over all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.. it means this was a bug also for that transactions.. updated to iterate through all of them

Copy link

github-actions bot commented Sep 6, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: f3b4b1342f950aea68ccdc2dd520abbfba2ac4d2
  • Current Branch: fix_gasused_and_fee
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 06092024-122136
  • PYTEST_EXIT_CODE: 0
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

github-actions bot commented Sep 6, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 51990e706e6fda906aaf3e4cc2bd68ecbe1f6268
  • Current Branch: fix_gasused_and_fee
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 06092024-122323
  • PYTEST_EXIT_CODE: 0
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

github-actions bot commented Sep 6, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 398361a09f24c15fc039f637fb02740a298a2274
  • Current Branch: fix_gasused_and_fee
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 06092024-134122
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

@@ -682,6 +689,20 @@ func (ed *economicsData) ComputeGasLimitBasedOnBalanceInEpoch(tx data.Transactio
return totalGasLimit, nil
}

func (ed *economicsData) computeRelayedTxV3MinGasLimit(tx data.TransactionWithFeeHandler) uint64 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-trivial function, should also be unit-tested (separately from "ComputeGasUsedAndFeeBasedOnRefundValueInEpoch").

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, will add tests in a separate PR

func (ed *economicsData) computeRelayedTxV3MinGasLimit(tx data.TransactionWithFeeHandler) uint64 {
relayedTxGasLimit := ed.ComputeGasLimit(tx)
relayedTxMinGasLimit := ed.MinGasLimit()
relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the case mentioned in comment tested using "TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueRelayedV3"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed not tested here, covered by testing scenarios 100%

will add tests in a separate PR

Copy link

github-actions bot commented Sep 6, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 398361a09f24c15fc039f637fb02740a298a2274
  • Current Branch: fix_gasused_and_fee
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 06092024-135450
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

github-actions bot commented Sep 6, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 398361a09f24c15fc039f637fb02740a298a2274
  • Current Branch: fix_gasused_and_fee
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 06092024-141332
  • PYTEST_EXIT_CODE: 0
    🎉 MultiversX CI/CD Workflow Complete!

@sstanculeanu sstanculeanu merged commit 237e149 into rc/v1.7.next1 Sep 9, 2024
9 checks passed
@sstanculeanu sstanculeanu deleted the fix_gasused_and_fee branch September 9, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants