Skip to content

Commit

Permalink
move funcs to keeper namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Apr 14, 2024
1 parent 38af681 commit ef9ddf2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
33 changes: 33 additions & 0 deletions keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,36 @@ func (k Keeper) UpdateBondedPoolPower(ctx context.Context) error {

return nil
}

// ResetCachedTotalPower resets the block power index to the current total power.
func (k Keeper) ResetCachedTotalPower(ctx context.Context) error {
currValPower, err := k.GetStakingKeeper().GetLastTotalPower(ctx)
if err != nil {
return err
}

prev, err := k.GetCachedBlockPower(ctx)
if err != nil {
return err
}

if currValPower.Uint64() != prev {
return k.SetCachedBlockPower(ctx, currValPower.Uint64())
}

return nil
}

// resetAbsoluteBlockPower resets the absolute block power to 0 since updates per block have been executed upon.
func (k Keeper) ResetAbsoluteBlockPower(ctx context.Context) error {
var err error

val, err := k.GetAbsoluteChangedInBlockPower(ctx)
if err != nil {
return err
} else if val != 0 {
return k.SetAbsoluteChangedInBlockPower(ctx, 0)
}

return err
}
37 changes: 2 additions & 35 deletions module/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,14 @@ func (am AppModule) BeginBlocker(ctx context.Context) error {

if sdkCtx.BlockHeight() > 1 {
// non gentx messages reset the cached block powers for IBC validations.
if err := am.resetCachedTotalPower(ctx); err != nil {
if err := am.keeper.ResetCachedTotalPower(ctx); err != nil {
return err
}

if err := am.resetAbsoluteBlockPower(ctx); err != nil {
if err := am.keeper.ResetAbsoluteBlockPower(ctx); err != nil {
return err
}
}

return nil
}

// resetCachedTotalPower resets the block power index to the current total power.
func (am AppModule) resetCachedTotalPower(ctx context.Context) error {
currValPower, err := am.keeper.GetStakingKeeper().GetLastTotalPower(ctx)
if err != nil {
return err
}

prev, err := am.keeper.GetCachedBlockPower(ctx)
if err != nil {
return err
}

if currValPower.Uint64() != prev {
return am.keeper.SetCachedBlockPower(ctx, currValPower.Uint64())
}

return nil
}

// resetAbsoluteBlockPower resets the absolute block power to 0 since updates per block have been executed upon.
func (am AppModule) resetAbsoluteBlockPower(ctx context.Context) error {
var err error

val, err := am.keeper.GetAbsoluteChangedInBlockPower(ctx)
if err != nil {
return err
} else if val != 0 {
return am.keeper.SetAbsoluteChangedInBlockPower(ctx, 0)
}

return err
}

0 comments on commit ef9ddf2

Please sign in to comment.