diff --git a/proto/babylon/btcstaking/v1/btcstaking.proto b/proto/babylon/btcstaking/v1/btcstaking.proto index 50acad4d..93333670 100644 --- a/proto/babylon/btcstaking/v1/btcstaking.proto +++ b/proto/babylon/btcstaking/v1/btcstaking.proto @@ -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 diff --git a/x/btcstaking/types/btcstaking.pb.go b/x/btcstaking/types/btcstaking.pb.go index bef35b3f..e79ca336 100644 --- a/x/btcstaking/types/btcstaking.pb.go +++ b/x/btcstaking/types/btcstaking.pb.go @@ -30,7 +30,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // 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 diff --git a/x/finality/keeper/power_dist_change.go b/x/finality/keeper/power_dist_change.go index cfed42b5..b5e48891 100644 --- a/x/finality/keeper/power_dist_change.go +++ b/x/finality/keeper/power_dist_change.go @@ -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 @@ -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 { @@ -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) @@ -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