diff --git a/proto/babylon/btcstaking/v1/events.proto b/proto/babylon/btcstaking/v1/events.proto index fdc58b094..848a81f23 100644 --- a/proto/babylon/btcstaking/v1/events.proto +++ b/proto/babylon/btcstaking/v1/events.proto @@ -46,13 +46,21 @@ message EventPowerDistUpdate { bytes pk = 1 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ]; } + // EventUnjailedFinalityProvider defines an event that a jailed finality provider + // is unjailed after the jailing period is passed + message EventUnjailedFinalityProvider { + bytes pk = 1 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ]; + } + // ev is the event that affects voting power distribution oneof ev { // slashed_fp means a finality provider is slashed EventSlashedFinalityProvider slashed_fp = 1; // jailed_fp means a finality provider is jailed EventJailedFinalityProvider jailed_fp = 2; + // unjailed_fp means a jailed finality provider is unjailed + EventUnjailedFinalityProvider unjailed_fp = 3; // btc_del_state_update means a BTC delegation's state is updated - EventBTCDelegationStateUpdate btc_del_state_update = 3; + EventBTCDelegationStateUpdate btc_del_state_update = 4; } } diff --git a/x/btcstaking/keeper/finality_providers.go b/x/btcstaking/keeper/finality_providers.go index a31643092..93ef46d81 100644 --- a/x/btcstaking/keeper/finality_providers.go +++ b/x/btcstaking/keeper/finality_providers.go @@ -139,6 +139,35 @@ func (k Keeper) JailFinalityProvider(ctx context.Context, fpBTCPK []byte) error return nil } +// UnjailFinalityProvider reverts the Jailed flag of a finality provider +func (k Keeper) UnjailFinalityProvider(ctx context.Context, fpBTCPK []byte) error { + // ensure finality provider exists + fp, err := k.GetFinalityProvider(ctx, fpBTCPK) + if err != nil { + return err + } + + // ensure finality provider is not jailed yet + if fp.IsJailed() { + return types.ErrFpAlreadyJailed + } + + fp.Jailed = false + k.setFinalityProvider(ctx, fp) + + btcTip := k.btclcKeeper.GetTipInfo(ctx) + if btcTip == nil { + return fmt.Errorf("failed to get current BTC tip") + } + + // record unjailed event. The next `BeginBlock` will consume this + // event for updating the finality provider set + powerUpdateEvent := types.NewEventPowerDistUpdateWithUnjailedFP(fp.BtcPk) + k.addPowerDistUpdateEvent(ctx, btcTip.Height, powerUpdateEvent) + + return nil +} + // finalityProviderStore returns the KVStore of the finality provider set // prefix: FinalityProviderKey // key: Bitcoin secp256k1 PK diff --git a/x/btcstaking/keeper/power_dist_change.go b/x/btcstaking/keeper/power_dist_change.go index 7d1a5d61a..7f7cd166d 100644 --- a/x/btcstaking/keeper/power_dist_change.go +++ b/x/btcstaking/keeper/power_dist_change.go @@ -160,6 +160,8 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( slashedFPs := map[string]struct{}{} // a map where key is jailed finality providers' BTC PK jailedFPs := map[string]struct{}{} + // a map where key is unjailed finality providers' BTC PK + unjailedFPs := map[string]struct{}{} /* filter and classify all events into new/expired BTC delegations and jailed/slashed FPs @@ -189,6 +191,9 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( case *types.EventPowerDistUpdate_JailedFp: // record jailed fps jailedFPs[typedEvent.JailedFp.Pk.MarshalHex()] = struct{}{} + case *types.EventPowerDistUpdate_UnjailedFp: + // record unjailed fps + unjailedFPs[typedEvent.UnjailedFp.Pk.MarshalHex()] = struct{}{} } } @@ -225,6 +230,11 @@ func (k Keeper) ProcessAllPowerDistUpdateEvents( fp.IsJailed = true } + // set IsJailed to be false if the fp is unjailed + if _, ok := unjailedFPs[fpBTCPKHex]; ok { + fp.IsJailed = false + } + // add all BTC delegations that are not unbonded to the new finality provider for j := range dc.FinalityProviders[i].BtcDels { btcDel := *dc.FinalityProviders[i].BtcDels[j] diff --git a/x/btcstaking/types/events.go b/x/btcstaking/types/events.go index e3c92c493..1c9022466 100644 --- a/x/btcstaking/types/events.go +++ b/x/btcstaking/types/events.go @@ -31,3 +31,13 @@ func NewEventPowerDistUpdateWithJailedFP(fpBTCPK *bbn.BIP340PubKey) *EventPowerD }, } } + +func NewEventPowerDistUpdateWithUnjailedFP(fpBTCPK *bbn.BIP340PubKey) *EventPowerDistUpdate { + return &EventPowerDistUpdate{ + Ev: &EventPowerDistUpdate_UnjailedFp{ + UnjailedFp: &EventPowerDistUpdate_EventUnjailedFinalityProvider{ + Pk: fpBTCPK, + }, + }, + } +} diff --git a/x/btcstaking/types/events.pb.go b/x/btcstaking/types/events.pb.go index cb198ace7..bcd198fe0 100644 --- a/x/btcstaking/types/events.pb.go +++ b/x/btcstaking/types/events.pb.go @@ -185,6 +185,7 @@ type EventPowerDistUpdate struct { // Types that are valid to be assigned to Ev: // *EventPowerDistUpdate_SlashedFp // *EventPowerDistUpdate_JailedFp + // *EventPowerDistUpdate_UnjailedFp // *EventPowerDistUpdate_BtcDelStateUpdate Ev isEventPowerDistUpdate_Ev `protobuf_oneof:"ev"` } @@ -234,12 +235,16 @@ type EventPowerDistUpdate_SlashedFp struct { type EventPowerDistUpdate_JailedFp struct { JailedFp *EventPowerDistUpdate_EventJailedFinalityProvider `protobuf:"bytes,2,opt,name=jailed_fp,json=jailedFp,proto3,oneof" json:"jailed_fp,omitempty"` } +type EventPowerDistUpdate_UnjailedFp struct { + UnjailedFp *EventPowerDistUpdate_EventUnjailedFinalityProvider `protobuf:"bytes,3,opt,name=unjailed_fp,json=unjailedFp,proto3,oneof" json:"unjailed_fp,omitempty"` +} type EventPowerDistUpdate_BtcDelStateUpdate struct { - BtcDelStateUpdate *EventBTCDelegationStateUpdate `protobuf:"bytes,3,opt,name=btc_del_state_update,json=btcDelStateUpdate,proto3,oneof" json:"btc_del_state_update,omitempty"` + BtcDelStateUpdate *EventBTCDelegationStateUpdate `protobuf:"bytes,4,opt,name=btc_del_state_update,json=btcDelStateUpdate,proto3,oneof" json:"btc_del_state_update,omitempty"` } func (*EventPowerDistUpdate_SlashedFp) isEventPowerDistUpdate_Ev() {} func (*EventPowerDistUpdate_JailedFp) isEventPowerDistUpdate_Ev() {} +func (*EventPowerDistUpdate_UnjailedFp) isEventPowerDistUpdate_Ev() {} func (*EventPowerDistUpdate_BtcDelStateUpdate) isEventPowerDistUpdate_Ev() {} func (m *EventPowerDistUpdate) GetEv() isEventPowerDistUpdate_Ev { @@ -263,6 +268,13 @@ func (m *EventPowerDistUpdate) GetJailedFp() *EventPowerDistUpdate_EventJailedFi return nil } +func (m *EventPowerDistUpdate) GetUnjailedFp() *EventPowerDistUpdate_EventUnjailedFinalityProvider { + if x, ok := m.GetEv().(*EventPowerDistUpdate_UnjailedFp); ok { + return x.UnjailedFp + } + return nil +} + func (m *EventPowerDistUpdate) GetBtcDelStateUpdate() *EventBTCDelegationStateUpdate { if x, ok := m.GetEv().(*EventPowerDistUpdate_BtcDelStateUpdate); ok { return x.BtcDelStateUpdate @@ -275,6 +287,7 @@ func (*EventPowerDistUpdate) XXX_OneofWrappers() []interface{} { return []interface{}{ (*EventPowerDistUpdate_SlashedFp)(nil), (*EventPowerDistUpdate_JailedFp)(nil), + (*EventPowerDistUpdate_UnjailedFp)(nil), (*EventPowerDistUpdate_BtcDelStateUpdate)(nil), } } @@ -366,6 +379,49 @@ func (m *EventPowerDistUpdate_EventJailedFinalityProvider) XXX_DiscardUnknown() var xxx_messageInfo_EventPowerDistUpdate_EventJailedFinalityProvider proto.InternalMessageInfo +// EventUnjailedFinalityProvider defines an event that a jailed finality provider +// is unjailed after the jailing period is passed +type EventPowerDistUpdate_EventUnjailedFinalityProvider struct { + Pk *github_com_babylonlabs_io_babylon_types.BIP340PubKey `protobuf:"bytes,1,opt,name=pk,proto3,customtype=github.com/babylonlabs-io/babylon/types.BIP340PubKey" json:"pk,omitempty"` +} + +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) Reset() { + *m = EventPowerDistUpdate_EventUnjailedFinalityProvider{} +} +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) String() string { + return proto.CompactTextString(m) +} +func (*EventPowerDistUpdate_EventUnjailedFinalityProvider) ProtoMessage() {} +func (*EventPowerDistUpdate_EventUnjailedFinalityProvider) Descriptor() ([]byte, []int) { + return fileDescriptor_74118427820fff75, []int{3, 2} +} +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventPowerDistUpdate_EventUnjailedFinalityProvider.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventPowerDistUpdate_EventUnjailedFinalityProvider.Merge(m, src) +} +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) XXX_Size() int { + return m.Size() +} +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) XXX_DiscardUnknown() { + xxx_messageInfo_EventPowerDistUpdate_EventUnjailedFinalityProvider.DiscardUnknown(m) +} + +var xxx_messageInfo_EventPowerDistUpdate_EventUnjailedFinalityProvider proto.InternalMessageInfo + func init() { proto.RegisterType((*EventNewFinalityProvider)(nil), "babylon.btcstaking.v1.EventNewFinalityProvider") proto.RegisterType((*EventBTCDelegationStateUpdate)(nil), "babylon.btcstaking.v1.EventBTCDelegationStateUpdate") @@ -373,6 +429,7 @@ func init() { proto.RegisterType((*EventPowerDistUpdate)(nil), "babylon.btcstaking.v1.EventPowerDistUpdate") proto.RegisterType((*EventPowerDistUpdate_EventSlashedFinalityProvider)(nil), "babylon.btcstaking.v1.EventPowerDistUpdate.EventSlashedFinalityProvider") proto.RegisterType((*EventPowerDistUpdate_EventJailedFinalityProvider)(nil), "babylon.btcstaking.v1.EventPowerDistUpdate.EventJailedFinalityProvider") + proto.RegisterType((*EventPowerDistUpdate_EventUnjailedFinalityProvider)(nil), "babylon.btcstaking.v1.EventPowerDistUpdate.EventUnjailedFinalityProvider") } func init() { @@ -380,39 +437,41 @@ func init() { } var fileDescriptor_74118427820fff75 = []byte{ - // 500 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0xcb, 0x6e, 0xd3, 0x40, - 0x14, 0x86, 0x6d, 0x53, 0xa1, 0x64, 0xb8, 0x09, 0x2b, 0xa0, 0x28, 0x80, 0xa9, 0xbc, 0x28, 0x15, - 0x12, 0x76, 0x2f, 0x91, 0x60, 0x6d, 0xd2, 0xd4, 0x5c, 0x54, 0x45, 0x76, 0xd9, 0xb0, 0xb1, 0xc6, - 0xce, 0x89, 0x3d, 0xc4, 0x78, 0x46, 0x99, 0x89, 0x93, 0xbc, 0x45, 0xdf, 0x83, 0x17, 0x61, 0xd9, - 0x25, 0x62, 0x81, 0x50, 0xf2, 0x22, 0xc8, 0x63, 0x53, 0xa2, 0xe6, 0x22, 0x90, 0xd8, 0xd9, 0xa3, - 0xf3, 0x7f, 0xdf, 0x39, 0xc7, 0x1e, 0x64, 0x86, 0x38, 0x9c, 0xa5, 0x34, 0xb3, 0x43, 0x11, 0x71, - 0x81, 0x87, 0x24, 0x8b, 0xed, 0xfc, 0xd0, 0x86, 0x1c, 0x32, 0xc1, 0x2d, 0x36, 0xa2, 0x82, 0xea, - 0x0f, 0xaa, 0x1a, 0xeb, 0x4f, 0x8d, 0x95, 0x1f, 0xb6, 0x1a, 0x31, 0x8d, 0xa9, 0xac, 0xb0, 0x8b, - 0xa7, 0xb2, 0xb8, 0xb5, 0xb7, 0x1e, 0xb8, 0x14, 0x95, 0x75, 0xa6, 0x8f, 0x9a, 0x27, 0x85, 0xe4, - 0x0c, 0x26, 0x5d, 0x92, 0xe1, 0x94, 0x88, 0x59, 0x6f, 0x44, 0x73, 0xd2, 0x87, 0x91, 0xfe, 0x12, - 0x69, 0x03, 0xd6, 0x54, 0x77, 0xd5, 0xfd, 0x5b, 0x47, 0xcf, 0xac, 0xb5, 0x76, 0xeb, 0x7a, 0xc8, - 0xd3, 0x06, 0xcc, 0xbc, 0x50, 0xd1, 0x13, 0x49, 0x75, 0xce, 0x5f, 0x77, 0x20, 0x85, 0x18, 0x0b, - 0x42, 0x33, 0x5f, 0x60, 0x01, 0x1f, 0x58, 0x1f, 0x0b, 0xd0, 0xf7, 0xd0, 0xbd, 0x0a, 0x12, 0x88, - 0x69, 0x90, 0x60, 0x9e, 0x48, 0x4f, 0xdd, 0xbb, 0x53, 0x1d, 0x9f, 0x4f, 0x5d, 0xcc, 0x13, 0xfd, - 0x14, 0xd5, 0x33, 0x98, 0x04, 0xbc, 0x88, 0x36, 0xb5, 0x5d, 0x75, 0xff, 0xee, 0xd1, 0xf3, 0x0d, - 0x9d, 0xac, 0xb8, 0xc6, 0xdc, 0xab, 0x65, 0x30, 0x91, 0x5a, 0x73, 0x80, 0x1e, 0xca, 0x8e, 0x7c, - 0x48, 0x21, 0x12, 0x24, 0x07, 0x3f, 0xc5, 0x3c, 0x21, 0x59, 0xac, 0xbf, 0x47, 0x35, 0x28, 0x5a, - 0xcf, 0x22, 0xa8, 0x66, 0x3d, 0xd8, 0x60, 0x58, 0xc9, 0x9e, 0x54, 0x39, 0xef, 0x8a, 0x60, 0x7e, - 0xd9, 0x41, 0x0d, 0x29, 0xea, 0xd1, 0x09, 0x8c, 0x3a, 0x84, 0x8b, 0x6a, 0x62, 0x82, 0x10, 0x2f, - 0x62, 0xd0, 0x0f, 0xae, 0x96, 0xea, 0x6e, 0x10, 0xad, 0x03, 0x94, 0x87, 0x7e, 0x89, 0xb8, 0xbe, - 0x75, 0x57, 0xf1, 0xea, 0x15, 0xbd, 0xcb, 0xf4, 0x01, 0xaa, 0x7f, 0xc2, 0x24, 0x2d, 0x4d, 0x9a, - 0x34, 0x9d, 0xfe, 0xb3, 0xe9, 0xad, 0x24, 0xac, 0x11, 0xd5, 0x4a, 0x76, 0x97, 0xe9, 0x31, 0x6a, - 0x84, 0x22, 0x0a, 0xfa, 0x90, 0x96, 0x1f, 0x28, 0x18, 0xcb, 0x7c, 0xf3, 0x86, 0x54, 0xb6, 0xb7, - 0x29, 0x37, 0xfd, 0x18, 0xae, 0xe2, 0xdd, 0x0f, 0x45, 0xd4, 0x81, 0x74, 0xe9, 0xb0, 0x95, 0xa0, - 0xc7, 0xdb, 0xa6, 0xd7, 0x5d, 0xa4, 0xb1, 0xa1, 0xdc, 0xe9, 0x6d, 0xe7, 0xd5, 0xf7, 0x1f, 0x4f, - 0xdb, 0x31, 0x11, 0xc9, 0x38, 0xb4, 0x22, 0xfa, 0xd9, 0xae, 0x9a, 0x48, 0x71, 0xc8, 0x5f, 0x10, - 0xfa, 0xfb, 0xd5, 0x16, 0x33, 0x06, 0xdc, 0x72, 0xde, 0xf4, 0x8e, 0xdb, 0x07, 0xbd, 0x71, 0xf8, - 0x0e, 0x66, 0x9e, 0xc6, 0x86, 0xad, 0x18, 0x3d, 0xda, 0x32, 0xfd, 0xff, 0x13, 0x39, 0x3b, 0x48, - 0x83, 0xdc, 0x39, 0xfb, 0x3a, 0x37, 0xd4, 0xcb, 0xb9, 0xa1, 0xfe, 0x9c, 0x1b, 0xea, 0xc5, 0xc2, - 0x50, 0x2e, 0x17, 0x86, 0xf2, 0x6d, 0x61, 0x28, 0x1f, 0xff, 0x82, 0x3c, 0x5d, 0xbe, 0xdb, 0x52, - 0x13, 0xde, 0x94, 0x97, 0xfa, 0xf8, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x57, 0xc3, 0x08, 0x28, - 0x4f, 0x04, 0x00, 0x00, + // 531 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4d, 0x6f, 0xd3, 0x30, + 0x18, 0xc7, 0x9b, 0x30, 0x4d, 0xab, 0xc7, 0x8b, 0x88, 0x0a, 0xaa, 0x0a, 0x84, 0xa9, 0x87, 0x31, + 0x21, 0x91, 0xec, 0xa5, 0x12, 0x9c, 0x4b, 0xd7, 0x75, 0x80, 0xa6, 0x2a, 0xdd, 0x2e, 0x5c, 0x22, + 0x27, 0x7d, 0x9a, 0x98, 0x06, 0xdb, 0xaa, 0xdd, 0xb4, 0xbd, 0xf3, 0x01, 0xf6, 0xb1, 0x38, 0xee, + 0x88, 0x38, 0x20, 0xd4, 0x7e, 0x11, 0x54, 0xc7, 0xdb, 0xaa, 0xad, 0xa9, 0x98, 0xb4, 0x5b, 0x62, + 0x3d, 0xff, 0xdf, 0xef, 0xf1, 0x13, 0xc7, 0xa8, 0x1a, 0xe0, 0x60, 0x92, 0x30, 0xea, 0x06, 0x32, + 0x14, 0x12, 0xf7, 0x09, 0x8d, 0xdc, 0x74, 0xcf, 0x85, 0x14, 0xa8, 0x14, 0x0e, 0x1f, 0x30, 0xc9, + 0xac, 0x67, 0xba, 0xc6, 0xb9, 0xae, 0x71, 0xd2, 0xbd, 0x4a, 0x29, 0x62, 0x11, 0x53, 0x15, 0xee, + 0xfc, 0x29, 0x2b, 0xae, 0x6c, 0x2f, 0x07, 0x2e, 0x44, 0x55, 0x5d, 0xb5, 0x83, 0xca, 0x87, 0x73, + 0xc9, 0x09, 0x8c, 0x9a, 0x84, 0xe2, 0x84, 0xc8, 0x49, 0x7b, 0xc0, 0x52, 0xd2, 0x85, 0x81, 0xf5, + 0x1e, 0x99, 0x3d, 0x5e, 0x36, 0xb6, 0x8c, 0x9d, 0xcd, 0xfd, 0x37, 0xce, 0x52, 0xbb, 0x73, 0x33, + 0xe4, 0x99, 0x3d, 0x5e, 0x3d, 0x37, 0xd0, 0x2b, 0x45, 0xad, 0x9f, 0x7e, 0x6c, 0x40, 0x02, 0x11, + 0x96, 0x84, 0xd1, 0x8e, 0xc4, 0x12, 0xce, 0x78, 0x17, 0x4b, 0xb0, 0xb6, 0xd1, 0x13, 0x0d, 0xf1, + 0xe5, 0xd8, 0x8f, 0xb1, 0x88, 0x95, 0xa7, 0xe8, 0x3d, 0xd2, 0xcb, 0xa7, 0xe3, 0x16, 0x16, 0xb1, + 0x75, 0x84, 0x8a, 0x14, 0x46, 0xbe, 0x98, 0x47, 0xcb, 0xe6, 0x96, 0xb1, 0xf3, 0x78, 0xff, 0x6d, + 0x4e, 0x27, 0xb7, 0x5c, 0x43, 0xe1, 0x6d, 0x50, 0x18, 0x29, 0x6d, 0xb5, 0x87, 0x9e, 0xab, 0x8e, + 0x3a, 0x90, 0x40, 0x28, 0x49, 0x0a, 0x9d, 0x04, 0x8b, 0x98, 0xd0, 0xc8, 0xfa, 0x82, 0x36, 0x60, + 0xde, 0x3a, 0x0d, 0x41, 0xef, 0x75, 0x37, 0xc7, 0x70, 0x2b, 0x7b, 0xa8, 0x73, 0xde, 0x15, 0xa1, + 0xfa, 0x63, 0x1d, 0x95, 0x94, 0xa8, 0xcd, 0x46, 0x30, 0x68, 0x10, 0x21, 0xf5, 0x8e, 0x09, 0x42, + 0x62, 0x1e, 0x83, 0xae, 0x7f, 0x35, 0xd4, 0x56, 0x8e, 0x68, 0x19, 0x20, 0x5b, 0xec, 0x64, 0x88, + 0x9b, 0x53, 0x6f, 0x15, 0xbc, 0xa2, 0xa6, 0x37, 0xb9, 0xd5, 0x43, 0xc5, 0x6f, 0x98, 0x24, 0x99, + 0xc9, 0x54, 0xa6, 0xa3, 0x3b, 0x9b, 0x3e, 0x29, 0xc2, 0x12, 0xd1, 0x46, 0xc6, 0x6e, 0x72, 0x2b, + 0x41, 0x9b, 0x43, 0x7a, 0x6d, 0x7a, 0xa0, 0x4c, 0xc7, 0x77, 0x36, 0x9d, 0x69, 0xc6, 0x12, 0x17, + 0xba, 0xe4, 0x37, 0xb9, 0x15, 0xa1, 0x52, 0x20, 0x43, 0xbf, 0x0b, 0x49, 0x76, 0x1c, 0xfc, 0xa1, + 0x62, 0x94, 0xd7, 0x94, 0xb6, 0xb6, 0x4a, 0x9b, 0x77, 0x0c, 0x5b, 0x05, 0xef, 0x69, 0x20, 0xc3, + 0x06, 0x24, 0x0b, 0x8b, 0x95, 0x18, 0xbd, 0x5c, 0x35, 0x6b, 0xab, 0x85, 0x4c, 0xde, 0x57, 0x5f, + 0xf0, 0x61, 0xfd, 0xc3, 0xef, 0x3f, 0xaf, 0x6b, 0x11, 0x91, 0xf1, 0x30, 0x70, 0x42, 0xf6, 0xdd, + 0xd5, 0x4d, 0x24, 0x38, 0x10, 0xef, 0x08, 0xbb, 0x7c, 0x75, 0xe5, 0x84, 0x83, 0x70, 0xea, 0xc7, + 0xed, 0x83, 0xda, 0x6e, 0x7b, 0x18, 0x7c, 0x86, 0x89, 0x67, 0xf2, 0x7e, 0x25, 0x42, 0x2f, 0x56, + 0xcc, 0xfa, 0x1e, 0x45, 0x44, 0xff, 0x8f, 0x79, 0xa3, 0xbe, 0x3f, 0x55, 0x7d, 0x0d, 0x99, 0x90, + 0xd6, 0x4f, 0x7e, 0x4e, 0x6d, 0xe3, 0x62, 0x6a, 0x1b, 0x7f, 0xa7, 0xb6, 0x71, 0x3e, 0xb3, 0x0b, + 0x17, 0x33, 0xbb, 0xf0, 0x6b, 0x66, 0x17, 0xbe, 0xfe, 0x07, 0x79, 0xbc, 0x78, 0x69, 0x29, 0x4d, + 0xb0, 0xae, 0x6e, 0xab, 0x83, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x09, 0xde, 0x05, 0x65, 0x28, + 0x05, 0x00, 0x00, } func (m *EventNewFinalityProvider) Marshal() (dAtA []byte, err error) { @@ -594,6 +653,27 @@ func (m *EventPowerDistUpdate_JailedFp) MarshalToSizedBuffer(dAtA []byte) (int, } return len(dAtA) - i, nil } +func (m *EventPowerDistUpdate_UnjailedFp) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventPowerDistUpdate_UnjailedFp) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.UnjailedFp != nil { + { + size, err := m.UnjailedFp.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} func (m *EventPowerDistUpdate_BtcDelStateUpdate) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) @@ -611,7 +691,7 @@ func (m *EventPowerDistUpdate_BtcDelStateUpdate) MarshalToSizedBuffer(dAtA []byt i = encodeVarintEvents(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } return len(dAtA) - i, nil } @@ -685,6 +765,41 @@ func (m *EventPowerDistUpdate_EventJailedFinalityProvider) MarshalToSizedBuffer( return len(dAtA) - i, nil } +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pk != nil { + { + size := m.Pk.Size() + i -= size + if _, err := m.Pk.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { offset -= sovEvents(v) base := offset @@ -774,6 +889,18 @@ func (m *EventPowerDistUpdate_JailedFp) Size() (n int) { } return n } +func (m *EventPowerDistUpdate_UnjailedFp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.UnjailedFp != nil { + l = m.UnjailedFp.Size() + n += 1 + l + sovEvents(uint64(l)) + } + return n +} func (m *EventPowerDistUpdate_BtcDelStateUpdate) Size() (n int) { if m == nil { return 0 @@ -812,6 +939,19 @@ func (m *EventPowerDistUpdate_EventJailedFinalityProvider) Size() (n int) { return n } +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pk != nil { + l = m.Pk.Size() + n += 1 + l + sovEvents(uint64(l)) + } + return n +} + func sovEvents(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1191,6 +1331,41 @@ func (m *EventPowerDistUpdate) Unmarshal(dAtA []byte) error { m.Ev = &EventPowerDistUpdate_JailedFp{v} iNdEx = postIndex case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UnjailedFp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &EventPowerDistUpdate_EventUnjailedFinalityProvider{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Ev = &EventPowerDistUpdate_UnjailedFp{v} + iNdEx = postIndex + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BtcDelStateUpdate", wireType) } @@ -1416,6 +1591,91 @@ func (m *EventPowerDistUpdate_EventJailedFinalityProvider) Unmarshal(dAtA []byte } return nil } +func (m *EventPowerDistUpdate_EventUnjailedFinalityProvider) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EventUnjailedFinalityProvider: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventUnjailedFinalityProvider: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pk", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_babylonlabs_io_babylon_types.BIP340PubKey + m.Pk = &v + if err := m.Pk.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipEvents(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/finality/keeper/msg_server.go b/x/finality/keeper/msg_server.go index 46be42241..2392a438f 100644 --- a/x/finality/keeper/msg_server.go +++ b/x/finality/keeper/msg_server.go @@ -237,6 +237,31 @@ func (ms msgServer) CommitPubRandList(goCtx context.Context, req *types.MsgCommi return &types.MsgCommitPubRandListResponse{}, nil } +func (k Keeper) UnjailFinalityProvider(ctx context.Context, req *types.MsgUnjailFinalityProvider) (*types.MsgUnjailFinalityProviderResponse, error) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricsKeyCommitPubRandList) + + fpPk := req.FpBtcPk + info, err := k.FinalityProviderSigningTracker.Get(ctx, fpPk.MustMarshal()) + if err != nil { + return nil, fmt.Errorf("failed to get the signing info of finality provider %s: %w", fpPk.MarshalHex(), err) + } + + // cannot be unjailed until jailing period is passed + sdkCtx := sdk.UnwrapSDKContext(ctx) + curBlockTime := sdkCtx.HeaderInfo().Time + if curBlockTime.Before(info.JailedUntil) { + return nil, types.ErrJailingPeriodNotPassed.Wrapf( + fmt.Sprintf("current block time: %v, required %v", curBlockTime, info.JailedUntil)) + } + + err = k.BTCStakingKeeper.UnjailFinalityProvider(ctx, fpPk.MustMarshal()) + if err != nil { + return nil, fmt.Errorf("failed to unjail finality provider %s: %w", fpPk.MarshalHex(), err) + } + + return &types.MsgUnjailFinalityProviderResponse{}, nil +} + // slashFinalityProvider slashes a finality provider with the given evidence // including setting its voting power to zero, extracting its BTC SK, // and emit an event diff --git a/x/finality/types/errors.go b/x/finality/types/errors.go index 12a2966d8..3a561f8d1 100644 --- a/x/finality/types/errors.go +++ b/x/finality/types/errors.go @@ -17,4 +17,6 @@ var ( ErrInvalidFinalitySig = errorsmod.Register(ModuleName, 1108, "finality signature is not valid") ErrNoSlashableEvidence = errorsmod.Register(ModuleName, 1109, "there is no slashable evidence") ErrPubRandCommitNotBTCTimestamped = errorsmod.Register(ModuleName, 1110, "the public randomness commit is not BTC timestamped yet") + ErrFinalityProviderNotJailed = errorsmod.Register(ModuleName, 1111, "the finality provider is not jailed") + ErrJailingPeriodNotPassed = errorsmod.Register(ModuleName, 1112, "the jailing period is not passed") ) diff --git a/x/finality/types/expected_keepers.go b/x/finality/types/expected_keepers.go index 81f9328d4..339a7cd4b 100644 --- a/x/finality/types/expected_keepers.go +++ b/x/finality/types/expected_keepers.go @@ -18,6 +18,7 @@ type BTCStakingKeeper interface { GetBTCStakingActivatedHeight(ctx context.Context) (uint64, error) GetVotingPowerDistCache(ctx context.Context, height uint64) (*bstypes.VotingPowerDistCache, error) RemoveVotingPowerDistCache(ctx context.Context, height uint64) + UnjailFinalityProvider(ctx context.Context, fpBTCPK []byte) error } type CheckpointingKeeper interface { diff --git a/x/finality/types/mocked_keepers.go b/x/finality/types/mocked_keepers.go index a2e1f79e1..aa4859f1b 100644 --- a/x/finality/types/mocked_keepers.go +++ b/x/finality/types/mocked_keepers.go @@ -164,6 +164,20 @@ func (mr *MockBTCStakingKeeperMockRecorder) SlashFinalityProvider(ctx, fpBTCPK i return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SlashFinalityProvider", reflect.TypeOf((*MockBTCStakingKeeper)(nil).SlashFinalityProvider), ctx, fpBTCPK) } +// UnjailFinalityProvider mocks base method. +func (m *MockBTCStakingKeeper) UnjailFinalityProvider(ctx context.Context, fpBTCPK []byte) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnjailFinalityProvider", ctx, fpBTCPK) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnjailFinalityProvider indicates an expected call of UnjailFinalityProvider. +func (mr *MockBTCStakingKeeperMockRecorder) UnjailFinalityProvider(ctx, fpBTCPK interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnjailFinalityProvider", reflect.TypeOf((*MockBTCStakingKeeper)(nil).UnjailFinalityProvider), ctx, fpBTCPK) +} + // MockCheckpointingKeeper is a mock of CheckpointingKeeper interface. type MockCheckpointingKeeper struct { ctrl *gomock.Controller