-
Notifications
You must be signed in to change notification settings - Fork 201
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-fees): use effective gas price in RefundGas #2076
Changes from 1 commit
15c6c78
a347a72
d4e2e6e
ddaaee7
3e9cbc6
b99631b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ txout.json | |
vote.json | ||
**__pycache** | ||
scratch-paper.md | ||
logs | ||
|
||
### TypeScript and Friends | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,6 +47,33 @@ lint: | |||||||||||||||||||||||||||
localnet *PASS_FLAGS: | ||||||||||||||||||||||||||||
make localnet FLAGS="{{PASS_FLAGS}}" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Clears the logs directory | ||||||||||||||||||||||||||||
log-clear: | ||||||||||||||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||||||||||||||
rm logs/* | ||||||||||||||||||||||||||||
Unique-Divine marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Runs "just localnet" with logging (logs/localnet.txt) | ||||||||||||||||||||||||||||
log-localnet: | ||||||||||||||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||||||||||||||
mkdir -p logs | ||||||||||||||||||||||||||||
just localnet 2>&1 | tee -a logs/localnet.txt | ||||||||||||||||||||||||||||
Comment on lines
+61
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance error handling in the While the recipe implements the basic functionality, it could benefit from improved error handling as suggested in the previous review. Consider updating the recipe to handle potential errors when creating the logs directory: log-localnet:
#!/usr/bin/env bash
- mkdir -p logs
+ if ! mkdir -p logs; then
+ echo "Error: Failed to create logs directory." >&2
+ exit 1
+ fi
just localnet 2>&1 | tee -a logs/localnet.txt This change will ensure that the script exits with an error message if it fails to create the 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Runs the EVM E2E test with logging (logs/e2e.txt) | ||||||||||||||||||||||||||||
log-e2e: | ||||||||||||||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||||||||||||||
just test-e2e 2>&1 | tee -a ../../logs/e2e.txt | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve consistency and error handling in the The recipe implements the basic functionality, but there are opportunities for improvement:
Consider updating the recipe as follows: log-e2e:
#!/usr/bin/env bash
- just test-e2e 2>&1 | tee -a ../../logs/e2e.txt
+ if ! mkdir -p logs; then
+ echo "Error: Failed to create logs directory." >&2
+ exit 1
+ fi
+ just test-e2e 2>&1 | tee -a logs/e2e.txt This change will:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Runs the EVM E2E tests | ||||||||||||||||||||||||||||
test-e2e: | ||||||||||||||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||||||||||||||
source contrib/bashlib.sh | ||||||||||||||||||||||||||||
log_info "Make sure the localnet is running! (just localnet)" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
cd e2e/evm | ||||||||||||||||||||||||||||
nvm use | ||||||||||||||||||||||||||||
just test | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Unique-Divine marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Test: "localnet.sh" script | ||||||||||||||||||||||||||||
test-localnet: | ||||||||||||||||||||||||||||
#!/usr/bin/env bash | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -34,36 +34,42 @@ func (k *Keeper) GetEthIntrinsicGas( | |||||
) | ||||||
} | ||||||
|
||||||
// RefundGas transfers the leftover gas to the sender of the message, caped to | ||||||
// half of the total gas consumed in the transaction. Additionally, the function | ||||||
// sets the total gas consumed to the value returned by the EVM execution, thus | ||||||
// ignoring the previous intrinsic gas consumed during in the AnteHandler. | ||||||
// RefundGas transfers the leftover gas to the sender of the message. | ||||||
func (k *Keeper) RefundGas( | ||||||
ctx sdk.Context, | ||||||
msg core.Message, | ||||||
msgFrom gethcommon.Address, | ||||||
leftoverGas uint64, | ||||||
denom string, | ||||||
weiPerGas *big.Int, | ||||||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Incomplete Updates to The
Please update all remaining calls to 🔗 Analysis chainEnsure all callers of The To automate this verification, you can run the following script: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find all calls to `RefundGas` and check for updated parameters.
# Search for calls to `RefundGas` and display the lines with context.
rg --type go 'RefundGas\(' -A 3
Length of output: 2800 |
||||||
) error { | ||||||
// Return EVM tokens for remaining gas, exchanged at the original rate. | ||||||
remaining := new(big.Int).Mul(new(big.Int).SetUint64(leftoverGas), msg.GasPrice()) | ||||||
leftoverWei := new(big.Int).Mul( | ||||||
new(big.Int).SetUint64(leftoverGas), | ||||||
weiPerGas, | ||||||
) | ||||||
leftoverMicronibi := evm.WeiToNative(leftoverWei) | ||||||
|
||||||
switch remaining.Sign() { | ||||||
switch leftoverMicronibi.Sign() { | ||||||
case -1: | ||||||
// negative refund errors | ||||||
return errors.Wrapf(evm.ErrInvalidRefund, "refunded amount value cannot be negative %d", remaining.Int64()) | ||||||
// Should be impossible since leftoverGas is a uint64. Reaching this case | ||||||
// would imply a critical error in the effective gas calculation. | ||||||
return errors.Wrapf(evm.ErrInvalidRefund, "refunded amount value cannot be negative %d", leftoverMicronibi.Int64()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use When logging Apply this diff to fix the error message: -return errors.Wrapf(evm.ErrInvalidRefund, "refunded amount value cannot be negative %d", leftoverMicronibi.Int64())
+return errors.Wrapf(evm.ErrInvalidRefund, "refunded amount value cannot be negative %s", leftoverMicronibi.String()) 📝 Committable suggestion
Suggested change
|
||||||
case 1: | ||||||
// positive amount refund | ||||||
refundedCoins := sdk.Coins{sdk.NewCoin(denom, sdkmath.NewIntFromBigInt(remaining))} | ||||||
|
||||||
// refund to sender from the fee collector module account, which is the escrow account in charge of collecting tx fees | ||||||
|
||||||
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, msg.From().Bytes(), refundedCoins) | ||||||
refundedCoins := sdk.Coins{sdk.NewCoin(evm.EVMBankDenom, sdkmath.NewIntFromBigInt(leftoverMicronibi))} | ||||||
|
||||||
// Refund to sender from the fee collector module account. This account | ||||||
// manages the collection of gas fees. | ||||||
err := k.bankKeeper.SendCoinsFromModuleToAccount( | ||||||
ctx, | ||||||
authtypes.FeeCollectorName, // sender | ||||||
msgFrom.Bytes(), // recipient | ||||||
refundedCoins, | ||||||
) | ||||||
if err != nil { | ||||||
err = errors.Wrapf(errortypes.ErrInsufficientFunds, "fee collector account failed to refund fees: %s", err.Error()) | ||||||
return errors.Wrapf(err, "failed to refund %d leftover gas (%s)", leftoverGas, refundedCoins.String()) | ||||||
} | ||||||
default: | ||||||
// no refund, consume gas and update the tx gas meter | ||||||
// no refund | ||||||
} | ||||||
|
||||||
return nil | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New gas fee refund functionality added
The addition of a fix for gas fee refunds using the effective gas price is a significant change that could impact transaction processing and user costs. This change should be thoroughly tested to ensure it behaves as expected across various transaction types and gas price scenarios.
Please provide more details on the implementation of this fix and its potential impact on users and validators. Consider adding a brief explanation of how the effective gas price is calculated and used in the refund process.