refactor(core/gas): remove WithXXGasMeter from gas service#20072
Conversation
WalkthroughWalkthroughThe recent updates streamline the gas management functionalities in the codebase by removing the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
fefa773 to
b0fd8bd
Compare
|
After this PR I'll be bringing the tx validators to main |
There was a problem hiding this comment.
Actionable comments posted: 2
Outside diff range and nitpick comments (2)
runtime/gas.go (2)
29-32: Define the purpose ofCoreGasmetermore clearly in the comment.The comment for
CoreGasmetercould be enhanced to explain why this wrapper is necessary and how it interacts with other parts of the system.
44-46: Review the necessity of separateRemainingandLimitmethods.Both methods
RemainingandLimitdirectly call corresponding methods onstoretypes.GasMeter. If these methods do not add additional logic or processing, consider whether these wrapper methods are necessary, or if direct calls tostoretypes.GasMetercould be used instead.Also applies to: 48-50
Review Details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- core/gas/service.go (1 hunks)
- runtime/gas.go (2 hunks)
Files skipped from review due to trivial changes (1)
- core/gas/service.go
Additional Context Used
Path-based Instructions (1)
runtime/gas.go (1)
Pattern
**/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
| func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) error { | ||
| cgm.gm.ConsumeGas(amount, descriptor) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Ensure error handling in Consume method.
The ConsumeGas method of storetypes.GasMeter might return an error which is currently ignored. Consider handling this potential error to avoid runtime panics or incorrect gas tracking.
- cgm.gm.ConsumeGas(amount, descriptor)
+ err := cgm.gm.ConsumeGas(amount, descriptor)
+ if err != nil {
+ return err
+ }Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
| func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) error { | |
| cgm.gm.ConsumeGas(amount, descriptor) | |
| return nil | |
| } | |
| func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) error { | |
| err := cgm.gm.ConsumeGas(amount, descriptor) | |
| if err != nil { | |
| return err | |
| } | |
| return nil | |
| } |
| func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) error { | ||
| cgm.gm.RefundGas(amount, descriptor) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Ensure error handling in Refund method.
Similar to the Consume method, the RefundGas method might return an error that is not currently handled. This could lead to incorrect gas calculations if ignored.
- cgm.gm.RefundGas(amount, descriptor)
+ err := cgm.gm.RefundGas(amount, descriptor)
+ if err != nil {
+ return err
+ }Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
| func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) error { | |
| cgm.gm.RefundGas(amount, descriptor) | |
| return nil | |
| } | |
| func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) error { | |
| err := cgm.gm.RefundGas(amount, descriptor) | |
| if err != nil { | |
| return err | |
| } | |
| return nil | |
| } |
Description
Follow-up of #20071.
Needed by #19949
The inconsistency in api supported by the services requires having two different implementations for the ante handler in tx validator in #19949.
This is because WithGasMeter and WithBlockMeter isn't implemented in server/v2/stf.
Additionally, having getter and setter separated makes the api weird.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!in the type prefix if API or client breaking changeCHANGELOG.mdReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
Summary by CodeRabbit
New Features
Refactor