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
refactor(core/gas): remove WithXXGasMeter
from gas service
#20072
base: main
Are you sure you want to change the base?
Changes from all commits
b0fd8bd
178247d
fe1c34a
0479a71
8be2ca3
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 | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,22 +18,37 @@ func (g GasService) GasMeter(ctx context.Context) gas.Meter { | |||||||||||||||||||||||
return CoreGasmeter{gm: sdk.UnwrapSDKContext(ctx).GasMeter()} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (g GasService) WithGasMeter(ctx context.Context, meter gas.Meter) context.Context { | ||||||||||||||||||||||||
return sdk.UnwrapSDKContext(ctx).WithGasMeter(SDKGasMeter{gm: meter}) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (g GasService) BlockGasMeter(ctx context.Context) gas.Meter { | ||||||||||||||||||||||||
return CoreGasmeter{gm: sdk.UnwrapSDKContext(ctx).BlockGasMeter()} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (g GasService) WithBlockGasMeter(ctx context.Context, meter gas.Meter) context.Context { | ||||||||||||||||||||||||
return sdk.UnwrapSDKContext(ctx).WithGasMeter(SDKGasMeter{gm: meter}) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (g GasService) GasConfig(ctx context.Context) gas.GasConfig { | ||||||||||||||||||||||||
return gas.GasConfig(sdk.UnwrapSDKContext(ctx).KVGasConfig()) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// CoreGasmeter is a wrapper around the SDK's GasMeter that implements the GasMeter interface. | ||||||||||||||||||||||||
type CoreGasmeter struct { | ||||||||||||||||||||||||
gm storetypes.GasMeter | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) error { | ||||||||||||||||||||||||
cgm.gm.ConsumeGas(amount, descriptor) | ||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) error { | ||||||||||||||||||||||||
cgm.gm.RefundGas(amount, descriptor) | ||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+39
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. Ensure error handling in Similar to the - cgm.gm.RefundGas(amount, descriptor)
+ err := cgm.gm.RefundGas(amount, descriptor)
+ if err != nil {
+ return err
+ } Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Remaining() gas.Gas { | ||||||||||||||||||||||||
return cgm.gm.GasRemaining() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Limit() gas.Gas { | ||||||||||||||||||||||||
return cgm.gm.Limit() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// SDKGasMeter is a wrapper around the SDK's GasMeter that implements the GasMeter interface. | ||||||||||||||||||||||||
type SDKGasMeter struct { | ||||||||||||||||||||||||
gm gas.Meter | ||||||||||||||||||||||||
|
@@ -82,29 +97,6 @@ func (gm SDKGasMeter) String() string { | |||||||||||||||||||||||
return fmt.Sprintf("BasicGasMeter:\n limit: %d\n consumed: %d", gm.gm.Limit(), gm.gm.Remaining()) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// CoreGasmeter is a wrapper around the SDK's GasMeter that implements the GasMeter interface. | ||||||||||||||||||||||||
type CoreGasmeter struct { | ||||||||||||||||||||||||
gm storetypes.GasMeter | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) error { | ||||||||||||||||||||||||
cgm.gm.ConsumeGas(amount, descriptor) | ||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) error { | ||||||||||||||||||||||||
cgm.gm.RefundGas(amount, descriptor) | ||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Remaining() gas.Gas { | ||||||||||||||||||||||||
return cgm.gm.GasRemaining() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
func (cgm CoreGasmeter) Limit() gas.Gas { | ||||||||||||||||||||||||
return cgm.gm.Limit() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
type GasConfig struct { | ||||||||||||||||||||||||
gc gas.GasConfig | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
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.
Ensure error handling in
Consume
method.The
ConsumeGas
method ofstoretypes.GasMeter
might return an error which is currently ignored. Consider handling this potential error to avoid runtime panics or incorrect gas tracking.Committable suggestion