Skip to content

Commit

Permalink
chore: address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Dec 20, 2024
1 parent 35374f7 commit 8f83257
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion proto/babylon/btcstaking/v1/btcstaking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ message BTCDelegatorDelegationIndex {

// BTCDelegationStatus is the status of a delegation.
// There are two possible valid state transition paths for a BTC delegation:
// - PENDING -> ACTIVE -> UNBONDED -> EXPIRED
// - PENDING -> VERIFIED -> ACTIVE -> UNBONDED -> EXPIRED
// - PENDING -> VERIFIED -> ACTIVE -> UNBONDED/EXPIRED
// and one invalid state transition path:
// - PENDING -> VERIFIED -> UNBONDED i.e the staker unbonded before
Expand Down
2 changes: 1 addition & 1 deletion x/btcstaking/types/btcstaking.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 19 additions & 21 deletions x/finality/keeper/power_dist_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
events []*types.EventPowerDistUpdate,
) *ftypes.VotingPowerDistCache {
// a map where key is finality provider's BTC PK hex and value is a list
// of BTC delegations that newly become active under this provider
// of BTC delegations satoshis amount that newly become active under this provider
activedSatsByFpBtcPk := map[string][]uint64{}
// a map where key is finality provider's BTC PK hex and value is a list
// of BTC delegations that were unbonded or expired without previously
// of BTC delegations satoshis that were unbonded or expired without previously
// being unbonded
unbondedSatsByFpBtcPk := map[string][]uint64{}
// a map where key is slashed finality providers' BTC PK
Expand Down Expand Up @@ -284,6 +284,18 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
}

// process all new BTC delegations under this finality provider
if fpActiveBTCDels, ok := activedSatsByFpBtcPk[fpBTCPKHex]; ok {
// handle new BTC delegations for this finality provider
for _, activatedSats := range fpActiveBTCDels {
fp.AddBondedSats(activatedSats)
}
// remove the finality provider entry in activeBTCDels map, so that
// after the for loop the rest entries in activeBTCDels belongs to new
// finality providers with new BTC delegations
delete(activedSatsByFpBtcPk, fpBTCPKHex)
}

// process all new unbonding BTC delegations under this finality provider
if fpUnbondedBTCDels, ok := unbondedSatsByFpBtcPk[fpBTCPKHex]; ok {
// handle unbonded delegations for this finality provider
for _, unbodedSats := range fpUnbondedBTCDels {
Expand All @@ -296,18 +308,6 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
delete(unbondedSatsByFpBtcPk, fpBTCPKHex)
}

// process all new BTC delegations under this finality provider
if fpActiveBTCDels, ok := activedSatsByFpBtcPk[fpBTCPKHex]; ok {
// handle new BTC delegations for this finality provider
for _, activatedSats := range fpActiveBTCDels {
fp.AddBondedSats(activatedSats)
}
// remove the finality provider entry in activeBTCDels map, so that
// after the for loop the rest entries in activeBTCDels belongs to new
// finality providers with new BTC delegations
delete(activedSatsByFpBtcPk, fpBTCPKHex)
}

// add this finality provider to the new cache if it has voting power
if fp.TotalBondedSat > 0 {
newDc.AddFinalityProviderDistInfo(&fp)
Expand All @@ -333,19 +333,17 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents(
fpDistInfo := ftypes.NewFinalityProviderDistInfo(newFP)

// add each BTC delegation
fpActiveBTCDels := activedSatsByFpBtcPk[fpBTCPKHex]
for _, activatedSats := range fpActiveBTCDels {
fpActiveSats := activedSatsByFpBtcPk[fpBTCPKHex]
for _, activatedSats := range fpActiveSats {
fpDistInfo.AddBondedSats(activatedSats)
}

// edge case where we might be processing an unbonded event
// from a newly active finality provider in the same slice
// of events received.
fpUnbondedBTCDels, ok := unbondedSatsByFpBtcPk[fpBTCPKHex]
if ok {
for _, unbodedSats := range fpUnbondedBTCDels {
fpDistInfo.RemoveBondedSats(unbodedSats)
}
fpUnbondedSats := unbondedSatsByFpBtcPk[fpBTCPKHex]
for _, unbodedSats := range fpUnbondedSats {
fpDistInfo.RemoveBondedSats(unbodedSats)
}

// add this finality provider to the new cache if it has voting power
Expand Down

0 comments on commit 8f83257

Please sign in to comment.