Skip to content

Commit

Permalink
fix delegation gas cost (#1346)
Browse files Browse the repository at this point in the history
Co-authored-by: Yarom Swisa <yarom@lavanet.xyz git config --global user.name Yarom>
  • Loading branch information
Yaroms and Yarom Swisa committed Apr 3, 2024
1 parent 834df59 commit 67c24df
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions x/dualstaking/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ func (h Hooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAd
// create new delegation period record
// add description
func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
originalGas := ctx.GasMeter().GasConsumed()
originalGasMeter := ctx.GasMeter()
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
providers := 0
defer func() {
endGas := ctx.GasMeter().GasConsumed()
if endGas > originalGas && providers < PROVIDERS_NUM_GAS_REFUND {
ctx.GasMeter().RefundGas(endGas-originalGas, "refund hooks gas")
consumedGas := ctx.GasMeter().GasConsumed()
ctx = ctx.WithGasMeter(originalGasMeter)
if providers >= PROVIDERS_NUM_GAS_REFUND {
ctx.GasMeter().ConsumeGas(consumedGas, "consume hooks gas")
}
}()

Expand Down

0 comments on commit 67c24df

Please sign in to comment.