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

fix gas used and fee relayed v3 #6541

Open
wants to merge 8 commits into
base: inner_hash_on_scr_prev
Choose a base branch
from

Conversation

miiu96
Copy link
Contributor

@miiu96 miiu96 commented Oct 17, 2024

Reasoning behind the pull request

  • Fixed how is calculated gasUsed and fee fields for relayed v3 transactions

Proposed changes

Testing procedure

  • Do a system test and check if the gas used and the fee is set correctly for the API transactions and the indexed transactions

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?

@miiu96 miiu96 self-assigned this Oct 17, 2024
@AdoAdoAdo AdoAdoAdo self-requested a review October 17, 2024 09:03
@@ -580,6 +591,16 @@ func (ed *economicsData) ComputeGasUsedAndFeeBasedOnRefundValue(tx data.Transact
return ed.ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx, refundValue, currentEpoch)
}

// ComputeGasUnitsFromRefundValue will compute the gas unit based on the refund value
func (ed *economicsData) ComputeGasUnitsFromRefundValue(tx data.TransactionWithFeeHandler, refundValue *big.Int) uint64 {
currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch()
Copy link
Collaborator

Choose a reason for hiding this comment

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

epoch should be the one of tx here as well, so perhaps get it as parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

ComputeGasUnitForRelayedV3Called func(tx *transaction.ApiTransactionResult) uint64
}

func (stub *FeeComputerStub) ComputeGasUnitForRelayedV3(tx *transaction.ApiTransactionResult) uint64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -258,6 +258,22 @@ func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex str
refundsValue.Add(refundsValue, scr.Value)
}

isRelayedV3 := len(txWithResults.GetTxHandler().GetUserTransactions()) > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

should also check if it has refunds here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case no, the refunds are in the Smart Contract Results map.

@@ -52,6 +52,16 @@ type EconomicsHandlerStub struct {
ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int
}

// ComputeRelayedTxV3GasUnits -
func (e *EconomicsHandlerStub) ComputeRelayedTxV3GasUnits(_ data.TransactionWithFeeHandler, _ uint32) uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can adapt the new definitions to call user defined functions, just like the other methods in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -52,6 +52,16 @@ type EconomicsHandlerMock struct {
SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error
}

// ComputeRelayedTxV3GasUnits -
func (ehm *EconomicsHandlerMock) ComputeRelayedTxV3GasUnits(_ data.TransactionWithFeeHandler, _ uint32) uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can adapt the new definitions to call user defined functions, just like the other methods in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -258,6 +258,22 @@ func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex str
refundsValue.Add(refundsValue, scr.Value)
}

isRelayedV3 := len(txWithResults.GetTxHandler().GetUserTransactions()) > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a similar check is already done before calling the method so it is already targeted for relayed v3
maybe the ckeck can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

gasUnits := tep.txFeeCalculator.ComputeGasUnitsFromRefundValue(txFromStorage, scr.Value, epoch)

scrHandler.GetFeeInfo().SetForRelayed()
scrHandler.GetFeeInfo().SetGasUsed(gasUnits)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a new field for gasUnitsRefunded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants