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

Separate fee handling for inner tx of type move balance #5627

Merged
merged 7 commits into from
Nov 27, 2023

Conversation

sstanculeanu
Copy link
Collaborator

@sstanculeanu sstanculeanu commented Oct 4, 2023

Reasoning behind the pull request

  • relayed move balance uses fee for processing

Proposed changes

  • use real move balance fee

Testing procedure

  • with feat branch

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?

@sstanculeanu sstanculeanu self-assigned this Oct 4, 2023
Base automatically changed from relayedV3 to feat/relayedv3 October 11, 2023 07:05
@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (fe4c31c) 80.05% compared to head (c64461a) 80.05%.
Report is 1 commits behind head on feat/relayedv3.

❗ Current head c64461a differs from pull request most recent head 21fd96a. Consider uploading reports for the commit 21fd96a to get more accurate results

Additional details and impacted files
@@                Coverage Diff                 @@
##           feat/relayedv3    #5627      +/-   ##
==================================================
- Coverage           80.05%   80.05%   -0.01%     
==================================================
  Files                 706      706              
  Lines               93789    93809      +20     
==================================================
+ Hits                75081    75096      +15     
- Misses              13369    13372       +3     
- Partials             5339     5341       +2     
Files Coverage Δ
common/enablers/enableEpochsHandler.go 100.00% <100.00%> (ø)
common/enablers/epochFlags.go 98.73% <100.00%> (+0.01%) ⬆️
genesis/process/shardGenesisBlockCreator.go 77.09% <100.00%> (+0.03%) ⬆️
node/metrics/metrics.go 100.00% <100.00%> (ø)
process/transaction/baseProcess.go 83.66% <100.00%> (+0.32%) ⬆️
process/transaction/shardProcess.go 73.90% <76.92%> (-0.03%) ⬇️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -286,3 +290,15 @@ func GetUserAccount(
}
return nil
}
func subFeesFromRelayer(tx, userTx *transaction.Transaction, economicsFee process.FeeHandler, relayer *integrationTests.TestWalletAccount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add empty line before

shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance &&
txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled()
if shouldConsiderMoveBalanceFee {
totalCost = txProc.economicsFee.ComputeMoveBalanceFee(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 not correct. Rewriting the totalCost to moveBalance - will only add the move balance part, and it will not use the gasLimit of the transaction. So it is only 50K + 1.5K*len(txData). You need to use ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int function. This handles correctly. Do this on all this implementation

Copy link
Collaborator Author

@sstanculeanu sstanculeanu Oct 26, 2023

Choose a reason for hiding this comment

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

pushed, but as seen after tests it does not reach the desired behavior.. looking for another solution

@@ -962,15 +962,15 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) {
alice,
david,
gasPrice,
transferGas+guardianSigVerificationGas,
1+guardianSigVerificationGas,
Copy link
Contributor

Choose a reason for hiding this comment

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

what is that magic 1?
maybe have a variable instead?

@@ -151,3 +149,16 @@ func checkPlayerBalancesWithPenalization(
assert.Equal(t, userAcc.GetNonce(), players[i].Nonce)
}
}

func appendFeeToTotalFees(relayerTx, userTx *transaction.Transaction, economicsData process.EconomicsDataHandler, totalFees *big.Int) {
if len(userTx.Data) == 0 { // move balance
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 remove the else and do a return on the if instead?

integrationTests/vm/txsFee/relayedMoveBalance_test.go Outdated Show resolved Hide resolved
@@ -145,7 +146,13 @@ func (txProc *baseTxProcessor) checkTxValues(
if tx.GasLimit < txProc.economicsFee.ComputeGasLimit(tx) {
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 extract what is inside if isUserTxOfRelayed into a method computeRelayedUserTxFee
you can then use this in the shard process as well.

process/transaction/baseProcess.go Outdated Show resolved Hide resolved
require.Equal(t, vmcommon.Ok, retCode)
require.Nil(t, err)
rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx)
rTxGasLimit := 1 + gasLimit + uint64(len(rtxData))
Copy link
Contributor

Choose a reason for hiding this comment

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

there are still some magic 1's here and in other places.
Could you replace with some constant/variable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, replaced everywhere

rTxGasLimit := 1 + gasLimit + uint64(len(rtxData))
rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData)
rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx)
rTxGasLimit := 1 + gasLimit + uint64(len(rtxData))
Copy link
Contributor

Choose a reason for hiding this comment

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

here as well there is a magic 1

@@ -1124,13 +1125,13 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) {
alice,
david,
gasPrice,
transferGas+guardianSigVerificationGas,
1,
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 replace with some variable?

require.Equal(t, vmcommon.Ok, retCode)
require.Nil(t, err)
rtxData := integrationTests.PrepareRelayedTxDataV1(userTx)
rTxGasLimit := 1 + gasLimit + uint64(len(rtxData))
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 replace the 1 with a variable instead?

also valid in other places in this file

@sstanculeanu sstanculeanu merged commit 564dc15 into feat/relayedv3 Nov 27, 2023
5 checks passed
@sstanculeanu sstanculeanu deleted the relayed_move_balance branch November 27, 2023 12:22
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.

3 participants