Skip to content
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: simplify logics in FP set rotation #188

Merged
merged 12 commits into from
Oct 16, 2024
Prev Previous commit
Next Next commit
fix
SebastianElvis committed Oct 14, 2024
commit 7fdcfc63fa3f3f76c4d68fd722e20280ad57d415
11 changes: 7 additions & 4 deletions x/btcstaking/keeper/power_dist_change.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import (
func (k Keeper) UpdatePowerDist(ctx context.Context) {
height := uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height)
btcTipHeight := k.GetCurrentBTCHeight(ctx)
maxActiveFps := k.GetParams(ctx).MaxActiveFinalityProviders

// get the power dist cache in the last height
dc := k.getVotingPowerDistCache(ctx, height-1)
@@ -35,7 +34,7 @@ func (k Keeper) UpdatePowerDist(ctx context.Context) {
if len(events) == 0 {
if dc != nil {
// map everything in prev height to this height
k.recordVotingPowerAndCache(ctx, dc, maxActiveFps)
k.recordVotingPowerAndCache(ctx, dc)
}
return
}
@@ -57,7 +56,7 @@ func (k Keeper) UpdatePowerDist(ctx context.Context) {
newDc := k.ProcessAllPowerDistUpdateEvents(ctx, dc, events)

// record voting power and cache for this height
k.recordVotingPowerAndCache(ctx, newDc, maxActiveFps)
k.recordVotingPowerAndCache(ctx, newDc)
// emit events for finality providers with state updates
k.emitFPStateUpdateEvents(ctx, dc, newDc)
// record metrics
@@ -68,11 +67,13 @@ func (k Keeper) UpdatePowerDist(ctx context.Context) {
// with the following consideration:
// 1. the fp must have timestamped pub rand
// 2. the fp must in the top x ranked by the voting power (x is given by maxActiveFps)
func (k Keeper) recordVotingPowerAndCache(ctx context.Context, newDc *types.VotingPowerDistCache, maxActiveFps uint32) {
func (k Keeper) recordVotingPowerAndCache(ctx context.Context, newDc *types.VotingPowerDistCache) {
if newDc == nil {
panic("the voting power distribution cache cannot be nil")
}

maxActiveFps := k.GetParams(ctx).MaxActiveFinalityProviders

babylonTipHeight := uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height)

// label fps with whether it has timestamped pub rand so that these fps
@@ -155,6 +156,8 @@ func (k Keeper) recordMetrics(dc *types.VotingPowerDistCache) {
// - newly active BTC delegations
// - newly unbonded BTC delegations
// - slashed finality providers
// - newly jailed finality providers
// - newly unjailed finality providers
func (k Keeper) ProcessAllPowerDistUpdateEvents(
ctx context.Context,
dc *types.VotingPowerDistCache,