From bf6e06a41da3af29c312d7a783ff3c6e698a868c Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Mon, 28 Oct 2024 19:52:28 +0800 Subject: [PATCH 1/8] create gov prop --- proto/babylon/finality/v1/gov.proto | 25 ++ x/finality/gov.go | 29 ++ x/finality/keeper/gov.go | 11 + x/finality/types/errors.go | 2 + x/finality/types/gov.go | 81 +++++ x/finality/types/gov.pb.go | 456 ++++++++++++++++++++++++++++ 6 files changed, 604 insertions(+) create mode 100644 proto/babylon/finality/v1/gov.proto create mode 100644 x/finality/gov.go create mode 100644 x/finality/keeper/gov.go create mode 100644 x/finality/types/gov.go create mode 100644 x/finality/types/gov.pb.go diff --git a/proto/babylon/finality/v1/gov.proto b/proto/babylon/finality/v1/gov.proto new file mode 100644 index 000000000..ae71ea589 --- /dev/null +++ b/proto/babylon/finality/v1/gov.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package babylon.finality.v1; + +import "cosmos_proto/cosmos.proto"; +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/babylonlabs-io/babylon/x/finality/types"; + +// ResumeFinalityProposal is a gov Content type for resuming finality +// in case of finality is halting by jailing a list of sluggish finality +// providers from the halting height +message ResumeFinalityProposal { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + + string title = 1; + string description = 2; + // fp_pks is a list of finality provider public keys to jail + // the public key follows encoding in BIP-340 spec + repeated bytes fp_pks = 3 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ]; + // halting_height is the height where the finality halting begins + uint32 halting_height = 4; +} diff --git a/x/finality/gov.go b/x/finality/gov.go new file mode 100644 index 000000000..43dc13bc1 --- /dev/null +++ b/x/finality/gov.go @@ -0,0 +1,29 @@ +package finality + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + "github.com/babylonlabs-io/babylon/x/finality/keeper" + "github.com/babylonlabs-io/babylon/x/finality/types" +) + +// NewResumeFinalityProposalHandler is a handler for governance proposal on resume finality. +func NewResumeFinalityProposalHandler(k keeper.Keeper) govtypesv1.Handler { + return func(ctx sdk.Context, content govtypesv1.Content) error { + switch c := content.(type) { + case *types.ResumeFinalityProposal: + return handleResumeFinalityProposal(ctx, k, c) + + default: + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized resume finality proposal content type: %T", c) + } + } +} + +// handleResumeFinalityProposal is a handler for jail finality provider proposals +func handleResumeFinalityProposal(ctx sdk.Context, k keeper.Keeper, p *types.ResumeFinalityProposal) error { + return k.JailFinalityProvidersFromHeight(ctx, p.FpPks, p.HaltingHeight) +} diff --git a/x/finality/keeper/gov.go b/x/finality/keeper/gov.go new file mode 100644 index 000000000..34fc3e106 --- /dev/null +++ b/x/finality/keeper/gov.go @@ -0,0 +1,11 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + bbntypes "github.com/babylonlabs-io/babylon/types" +) + +func (k Keeper) JailFinalityProvidersFromHeight(ctx sdk.Context, fps []bbntypes.BIP340PubKey, height uint32) error { + return nil +} diff --git a/x/finality/types/errors.go b/x/finality/types/errors.go index 1b026b6dc..e70c948b6 100644 --- a/x/finality/types/errors.go +++ b/x/finality/types/errors.go @@ -22,4 +22,6 @@ var ( ErrVotingPowerTableNotUpdated = errorsmod.Register(ModuleName, 1113, "voting power table has not been updated") ErrBTCStakingNotActivated = errorsmod.Register(ModuleName, 1114, "the BTC staking protocol is not activated yet") ErrFinalityNotActivated = errorsmod.Register(ModuleName, 1115, "finality is not active yet") + ErrEmptyProposalFinalityProviders = errorsmod.Register(ModuleName, 1116, "the finality provider list in the ResumeFinality is empty") + ErrEmptyProposalHaltingHeight = errorsmod.Register(ModuleName, 1117, "the halting height in the ResumeFinality is empty") ) diff --git a/x/finality/types/gov.go b/x/finality/types/gov.go new file mode 100644 index 000000000..12808b52a --- /dev/null +++ b/x/finality/types/gov.go @@ -0,0 +1,81 @@ +package types + +import ( + "fmt" + "strings" + + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + + "github.com/babylonlabs-io/babylon/types" +) + +const ( + ProposalResumeFinality = "ResumeFinality" +) + +// Init registers proposals to update and replace pool incentives. +func init() { + govtypesv1.RegisterProposalType(ProposalResumeFinality) +} + +var ( + _ govtypesv1.Content = &ResumeFinalityProposal{} +) + +// NewResumeFinalityProposal returns a new instance of a resume finality proposal struct. +func NewResumeFinalityProposal(title, description string, fps []types.BIP340PubKey, haltingHeight uint32) govtypesv1.Content { + return &ResumeFinalityProposal{ + Title: title, + Description: description, + FpPks: fps, + HaltingHeight: haltingHeight, + } +} + +// GetTitle gets the title of the proposal +func (p *ResumeFinalityProposal) GetTitle() string { return p.Title } + +// GetDescription gets the description of the proposal +func (p *ResumeFinalityProposal) GetDescription() string { return p.Description } + +// ProposalRoute returns the router key for the proposal +func (p *ResumeFinalityProposal) ProposalRoute() string { return RouterKey } + +// ProposalType returns the type of the proposal +func (p *ResumeFinalityProposal) ProposalType() string { + return ProposalResumeFinality +} + +// ValidateBasic validates a governance proposal's abstract and basic contents +func (p *ResumeFinalityProposal) ValidateBasic() error { + err := govtypesv1.ValidateAbstract(p) + if err != nil { + return err + } + if len(p.FpPks) == 0 { + return ErrEmptyProposalFinalityProviders + } + + if p.HaltingHeight == 0 { + return ErrEmptyProposalHaltingHeight + } + + return nil +} + +// String returns a string containing the jail finality providers proposal. +func (p *ResumeFinalityProposal) String() string { + fpsStr := fmt.Sprintln("Finality providers to jail:") + for i, pk := range p.FpPks { + fpsStr = fpsStr + fmt.Sprintf("%d. %s\n", i+1, pk.MarshalHex()) + } + + var b strings.Builder + b.WriteString(fmt.Sprintf(`Resume Finality Proposal: + Title: %s + Description: %s + Halting height: %d + %s +`, p.Title, p.Description, p.HaltingHeight, fpsStr)) + return b.String() +} diff --git a/x/finality/types/gov.pb.go b/x/finality/types/gov.pb.go new file mode 100644 index 000000000..5e502f8ec --- /dev/null +++ b/x/finality/types/gov.pb.go @@ -0,0 +1,456 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: babylon/finality/v1/gov.proto + +package types + +import ( + fmt "fmt" + github_com_babylonlabs_io_babylon_types "github.com/babylonlabs-io/babylon/types" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// ResumeFinalityProposal is a gov Content type for resuming finality +// in case of finality is halting by jailing a list of sluggish finality +// providers from the halting height +type ResumeFinalityProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // fp_pks is a list of finality provider public keys to jail + // the public key follows encoding in BIP-340 spec + FpPks []github_com_babylonlabs_io_babylon_types.BIP340PubKey `protobuf:"bytes,3,rep,name=fp_pks,json=fpPks,proto3,customtype=github.com/babylonlabs-io/babylon/types.BIP340PubKey" json:"fp_pks,omitempty"` + // halting_height is the height where the finality halting begins + HaltingHeight uint32 `protobuf:"varint,4,opt,name=halting_height,json=haltingHeight,proto3" json:"halting_height,omitempty"` +} + +func (m *ResumeFinalityProposal) Reset() { *m = ResumeFinalityProposal{} } +func (*ResumeFinalityProposal) ProtoMessage() {} +func (*ResumeFinalityProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_8c9af01aea56f783, []int{0} +} +func (m *ResumeFinalityProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ResumeFinalityProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ResumeFinalityProposal.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 *ResumeFinalityProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_ResumeFinalityProposal.Merge(m, src) +} +func (m *ResumeFinalityProposal) XXX_Size() int { + return m.Size() +} +func (m *ResumeFinalityProposal) XXX_DiscardUnknown() { + xxx_messageInfo_ResumeFinalityProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_ResumeFinalityProposal proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ResumeFinalityProposal)(nil), "babylon.finality.v1.ResumeFinalityProposal") +} + +func init() { proto.RegisterFile("babylon/finality/v1/gov.proto", fileDescriptor_8c9af01aea56f783) } + +var fileDescriptor_8c9af01aea56f783 = []byte{ + // 342 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0x4a, 0x4c, 0xaa, + 0xcc, 0xc9, 0xcf, 0xd3, 0x4f, 0xcb, 0xcc, 0x4b, 0xcc, 0xc9, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, + 0x4f, 0xcf, 0x2f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0x4a, 0xeb, 0xc1, 0xa4, + 0xf5, 0xca, 0x0c, 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xe3, 0xc1, 0x4a, 0xf4, 0x21, + 0x1c, 0x88, 0x7a, 0x29, 0xc1, 0xc4, 0xdc, 0xcc, 0xbc, 0x7c, 0x7d, 0x30, 0x09, 0x15, 0x12, 0x49, + 0xcf, 0x4f, 0xcf, 0x87, 0x28, 0x05, 0xb1, 0x20, 0xa2, 0x4a, 0x1f, 0x18, 0xb9, 0xc4, 0x82, 0x52, + 0x8b, 0x4b, 0x73, 0x53, 0xdd, 0xa0, 0x26, 0x07, 0x14, 0xe5, 0x17, 0xe4, 0x17, 0x27, 0xe6, 0x08, + 0x89, 0x70, 0xb1, 0x96, 0x64, 0x96, 0xe4, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, + 0x38, 0x42, 0x0a, 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, + 0x12, 0x4c, 0x60, 0x39, 0x64, 0x21, 0x21, 0x7f, 0x2e, 0xb6, 0xb4, 0x82, 0xf8, 0x82, 0xec, 0x62, + 0x09, 0x66, 0x05, 0x66, 0x0d, 0x1e, 0x27, 0x8b, 0x5b, 0xf7, 0xe4, 0x4d, 0xd2, 0x33, 0x4b, 0x32, + 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xa1, 0x5e, 0xc9, 0x49, 0x4c, 0x2a, 0xd6, 0xcd, 0xcc, + 0x87, 0x71, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xf5, 0x9c, 0x3c, 0x03, 0x8c, 0x4d, 0x0c, 0x02, + 0x4a, 0x93, 0xbc, 0x53, 0x2b, 0x83, 0x58, 0xd3, 0x0a, 0x02, 0xb2, 0x8b, 0x85, 0x54, 0xb9, 0xf8, + 0x32, 0x12, 0x73, 0x4a, 0x32, 0xf3, 0xd2, 0xe3, 0x33, 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x58, + 0x14, 0x18, 0x35, 0x78, 0x83, 0x78, 0xa1, 0xa2, 0x1e, 0x60, 0x41, 0x2b, 0xb5, 0x8e, 0x05, 0xf2, + 0x0c, 0x33, 0x16, 0xc8, 0x33, 0x9c, 0xda, 0xa2, 0x2b, 0x05, 0x0d, 0x0d, 0x50, 0x08, 0x96, 0x19, + 0x26, 0xa5, 0x96, 0x24, 0x1a, 0xea, 0x39, 0xe7, 0xe7, 0x95, 0xa4, 0xe6, 0x95, 0x38, 0xf9, 0x9c, + 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, + 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x11, 0x61, 0x57, 0x56, 0x20, 0x22, + 0x08, 0xec, 0xe0, 0x24, 0x36, 0x70, 0x38, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x7a, + 0xed, 0x7d, 0xc1, 0x01, 0x00, 0x00, +} + +func (m *ResumeFinalityProposal) 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 *ResumeFinalityProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ResumeFinalityProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.HaltingHeight != 0 { + i = encodeVarintGov(dAtA, i, uint64(m.HaltingHeight)) + i-- + dAtA[i] = 0x20 + } + if len(m.FpPks) > 0 { + for iNdEx := len(m.FpPks) - 1; iNdEx >= 0; iNdEx-- { + { + size := m.FpPks[iNdEx].Size() + i -= size + if _, err := m.FpPks[iNdEx].MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGov(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintGov(dAtA []byte, offset int, v uint64) int { + offset -= sovGov(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ResumeFinalityProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovGov(uint64(l)) + } + if len(m.FpPks) > 0 { + for _, e := range m.FpPks { + l = e.Size() + n += 1 + l + sovGov(uint64(l)) + } + } + if m.HaltingHeight != 0 { + n += 1 + sovGov(uint64(m.HaltingHeight)) + } + return n +} + +func sovGov(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGov(x uint64) (n int) { + return sovGov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ResumeFinalityProposal) 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 ErrIntOverflowGov + } + 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: ResumeFinalityProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ResumeFinalityProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FpPks", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthGov + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthGov + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_babylonlabs_io_babylon_types.BIP340PubKey + m.FpPks = append(m.FpPks, v) + if err := m.FpPks[len(m.FpPks)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HaltingHeight", wireType) + } + m.HaltingHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGov + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HaltingHeight |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGov(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGov + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGov(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGov + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGov + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGov + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGov + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGov + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGov + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGov = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGov = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGov = fmt.Errorf("proto: unexpected end of group") +) From 88d6aec6535a87ceb3f34645fe68c7c58da37ef2 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Tue, 29 Oct 2024 22:43:19 +0800 Subject: [PATCH 2/8] add tests --- x/btcstaking/keeper/genesis.go | 3 +- x/finality/gov.go | 2 +- x/finality/keeper/gov.go | 74 ++++++++++++++++++++++- x/finality/keeper/gov_test.go | 106 +++++++++++++++++++++++++++++++++ x/finality/keeper/tallying.go | 7 ++- 5 files changed, 187 insertions(+), 5 deletions(-) create mode 100644 x/finality/keeper/gov_test.go diff --git a/x/btcstaking/keeper/genesis.go b/x/btcstaking/keeper/genesis.go index faebc7ee2..df60c060a 100644 --- a/x/btcstaking/keeper/genesis.go +++ b/x/btcstaking/keeper/genesis.go @@ -5,9 +5,10 @@ import ( "fmt" "math" + sdk "github.com/cosmos/cosmos-sdk/types" + bbn "github.com/babylonlabs-io/babylon/types" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) // InitGenesis initializes the module's state from a provided genesis state. diff --git a/x/finality/gov.go b/x/finality/gov.go index 43dc13bc1..e753e548d 100644 --- a/x/finality/gov.go +++ b/x/finality/gov.go @@ -25,5 +25,5 @@ func NewResumeFinalityProposalHandler(k keeper.Keeper) govtypesv1.Handler { // handleResumeFinalityProposal is a handler for jail finality provider proposals func handleResumeFinalityProposal(ctx sdk.Context, k keeper.Keeper, p *types.ResumeFinalityProposal) error { - return k.JailFinalityProvidersFromHeight(ctx, p.FpPks, p.HaltingHeight) + return k.HandleResumeFinalityProposal(ctx, p) } diff --git a/x/finality/keeper/gov.go b/x/finality/keeper/gov.go index 34fc3e106..734c9fc77 100644 --- a/x/finality/keeper/gov.go +++ b/x/finality/keeper/gov.go @@ -1,11 +1,81 @@ package keeper import ( + "errors" + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" - bbntypes "github.com/babylonlabs-io/babylon/types" + bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" + "github.com/babylonlabs-io/babylon/x/finality/types" ) -func (k Keeper) JailFinalityProvidersFromHeight(ctx sdk.Context, fps []bbntypes.BIP340PubKey, height uint32) error { +// HandleResumeFinalityProposal handles the resume finality proposal in the following steps: +// 1. check the validity of the proposal +// 2. jail the finality providers from the list and adjust the voting power cache from the +// halting height to the current height +// 3. tally blocks to ensure finality is resumed +func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, p *types.ResumeFinalityProposal) error { + // a valid proposal should be + // 1. the halting height along with some parameterized future heights should be indeed non-finalized + // 2. all the fps from the proposal should have missed the vote for the halting height + // TODO introduce a parameter to define the finality has been halting for at least some heights + + params := k.GetParams(ctx) + currentHeight := ctx.HeaderInfo().Height + currentTime := ctx.HeaderInfo().Time + + // jail the given finality providers + for _, fpPk := range p.FpPks { + fpHex := fpPk.MarshalHex() + voters := k.GetVoters(ctx, uint64(p.HaltingHeight)) + _, voted := voters[fpPk.MarshalHex()] + if voted { + // all the given finality providers should not have voted for the halting height + return fmt.Errorf("the finality provider has voted for height %d", p.HaltingHeight) + } + + err := k.jailSluggishFinalityProvider(ctx, &fpPk) + if err != nil && !errors.Is(err, bstypes.ErrFpAlreadyJailed) { + return fmt.Errorf("failed to jail the finality provider: %w", err) + } + + // update signing info + signInfo, err := k.FinalityProviderSigningTracker.Get(ctx, fpPk.MustMarshal()) + if err != nil { + return fmt.Errorf("the signing info is not created: %w", err) + } + signInfo.JailedUntil = currentTime.Add(params.JailDuration) + signInfo.MissedBlocksCounter = 0 + if err := k.DeleteMissedBlockBitmap(ctx, &fpPk); err != nil { + return fmt.Errorf("failed to remove the missed block bit map: %w", err) + } + err = k.FinalityProviderSigningTracker.Set(ctx, fpPk.MustMarshal(), signInfo) + k.Logger(ctx).Info( + "finality provider is jailed", + "height", p.HaltingHeight, + "public_key", fpHex, + ) + } + + // set the all the given finality providers voting power to 0 + for h := uint64(p.HaltingHeight); h <= uint64(currentHeight); h++ { + distCache := k.GetVotingPowerDistCache(ctx, h) + activeFps := distCache.GetActiveFinalityProviderSet() + for _, fpToJail := range p.FpPks { + if fp, exists := activeFps[fpToJail.MarshalHex()]; exists { + fp.IsJailed = true + k.SetVotingPower(ctx, fpToJail, h, 0) + } + } + + distCache.ApplyActiveFinalityProviders(params.MaxActiveFinalityProviders) + + // set the voting power distribution cache of the current height + k.SetVotingPowerDistCache(ctx, h, distCache) + } + + k.TallyBlocks(ctx) + return nil } diff --git a/x/finality/keeper/gov_test.go b/x/finality/keeper/gov_test.go new file mode 100644 index 000000000..0cb471c2a --- /dev/null +++ b/x/finality/keeper/gov_test.go @@ -0,0 +1,106 @@ +package keeper_test + +import ( + "math/rand" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + + "github.com/babylonlabs-io/babylon/testutil/datagen" + keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" + bbntypes "github.com/babylonlabs-io/babylon/types" + "github.com/babylonlabs-io/babylon/x/finality/keeper" + "github.com/babylonlabs-io/babylon/x/finality/types" +) + +func TestHandleResumeFinalityProposal(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().Unix())) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + bsKeeper := types.NewMockBTCStakingKeeper(ctrl) + iKeeper := types.NewMockIncentiveKeeper(ctrl) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper, cKeeper) + + haltingHeight := uint64(100) + currentHeight := uint64(110) + + activeFpNum := 3 + activeFpPks := generateNFpPks(t, r, activeFpNum) + setupActiveFps(t, activeFpPks, haltingHeight, fKeeper, ctx) + // set voting power table for each height, only the first fp votes + votedFpPk := activeFpPks[0] + for h := haltingHeight; h <= currentHeight; h++ { + fKeeper.SetBlock(ctx, &types.IndexedBlock{ + Height: h, + AppHash: datagen.GenRandomByteArray(r, 32), + Finalized: false, + }) + dc := types.NewVotingPowerDistCache() + for i := 0; i < activeFpNum; i++ { + fKeeper.SetVotingPower(ctx, activeFpPks[i].MustMarshal(), h, 1) + dc.AddFinalityProviderDistInfo(&types.FinalityProviderDistInfo{ + BtcPk: &activeFpPks[i], + TotalBondedSat: 1, + IsTimestamped: true, + }) + } + dc.ApplyActiveFinalityProviders(uint32(activeFpNum)) + votedSig, err := bbntypes.NewSchnorrEOTSSig(datagen.GenRandomByteArray(r, 32)) + require.NoError(t, err) + fKeeper.SetSig(ctx, h, &votedFpPk, votedSig) + fKeeper.SetVotingPowerDistCache(ctx, h, dc) + } + + // tally blocks and none of them should be finalised + iKeeper.EXPECT().RewardBTCStaking(gomock.Any(), gomock.Any(), gomock.Any()).Return().AnyTimes() + ctx = datagen.WithCtxHeight(ctx, currentHeight) + fKeeper.TallyBlocks(ctx) + for i := haltingHeight; i < currentHeight; i++ { + ib, err := fKeeper.GetBlock(ctx, i) + require.NoError(t, err) + require.False(t, ib.Finalized) + } + + // create a resume finality proposal to jail the last fp + bsKeeper.EXPECT().JailFinalityProvider(ctx, gomock.Any()).Return(nil).AnyTimes() + resumeProposal := &types.ResumeFinalityProposal{ + FpPks: activeFpPks[1:], + HaltingHeight: uint32(haltingHeight), + } + err := fKeeper.HandleResumeFinalityProposal(ctx, resumeProposal) + require.NoError(t, err) + + for i := haltingHeight; i < currentHeight; i++ { + ib, err := fKeeper.GetBlock(ctx, i) + require.NoError(t, err) + require.True(t, ib.Finalized) + } +} + +func generateNFpPks(t *testing.T, r *rand.Rand, n int) []bbntypes.BIP340PubKey { + fpPks := make([]bbntypes.BIP340PubKey, 0) + for i := 0; i < n; i++ { + fpPk, err := datagen.GenRandomBIP340PubKey(r) + require.NoError(t, err) + fpPks = append(fpPks, *fpPk) + } + + return fpPks +} + +func setupActiveFps(t *testing.T, fpPks []bbntypes.BIP340PubKey, height uint64, fKeeper *keeper.Keeper, ctx sdk.Context) { + for _, fpPk := range fpPks { + signingInfo := types.NewFinalityProviderSigningInfo( + &fpPk, + int64(height), + 0, + ) + err := fKeeper.FinalityProviderSigningTracker.Set(ctx, fpPk, signingInfo) + require.NoError(t, err) + } +} diff --git a/x/finality/keeper/tallying.go b/x/finality/keeper/tallying.go index 53051d29d..3e8bc4661 100644 --- a/x/finality/keeper/tallying.go +++ b/x/finality/keeper/tallying.go @@ -109,7 +109,12 @@ func tally(fpSet map[string]uint64, voterBTCPKs map[string]struct{}) bool { votedPower += power } } - return votedPower*3 > totalPower*2 + + if votedPower*3 > totalPower*2 { + return true + } + + return false } // setNextHeightToFinalize sets the next height to finalise as the given height From 5d37132cebc3bbea4a1ca335cb8c32f4c392c1b9 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Thu, 31 Oct 2024 17:55:12 +0800 Subject: [PATCH 3/8] add cli --- app/app.go | 2 + client/parsers.go | 70 ++++++++++++++++++++ x/finality/client/cli/gov.go | 93 +++++++++++++++++++++++++++ x/finality/client/proposal_handler.go | 11 ++++ 4 files changed, 176 insertions(+) create mode 100644 client/parsers.go create mode 100644 x/finality/client/cli/gov.go create mode 100644 x/finality/client/proposal_handler.go diff --git a/app/app.go b/app/app.go index e22ac0155..a72b77d0c 100644 --- a/app/app.go +++ b/app/app.go @@ -94,6 +94,7 @@ import ( "github.com/babylonlabs-io/babylon/app/ante" "github.com/babylonlabs-io/babylon/app/upgrades" bbn "github.com/babylonlabs-io/babylon/types" + finalityclient "github.com/babylonlabs-io/babylon/x/finality/client" appkeepers "github.com/babylonlabs-io/babylon/app/keepers" appparams "github.com/babylonlabs-io/babylon/app/params" @@ -327,6 +328,7 @@ func NewBabylonApp( govtypes.ModuleName: gov.NewAppModuleBasic( []govclient.ProposalHandler{ paramsclient.ProposalHandler, + finalityclient.ResumeFinalityHandler, }, ), }) diff --git a/client/parsers.go b/client/parsers.go new file mode 100644 index 000000000..8cb205850 --- /dev/null +++ b/client/parsers.go @@ -0,0 +1,70 @@ +package client + +import ( + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + "github.com/spf13/cobra" +) + +// adapted from +// https://github.com/osmosis-labs/osmosis/blob/2e85d1ee3e15e3f74898395d37b455af48649268/osmoutils/osmocli/parsers.go + +var DefaultGovAuthority = sdk.AccAddress(address.Module("gov")) + +const ( + FlagIsExpedited = "is-expedited" + FlagAuthority = "authority" +) + +func GetProposalInfo(cmd *cobra.Command) (client.Context, string, string, sdk.Coins, bool, sdk.AccAddress, error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return client.Context{}, "", "", nil, false, nil, err + } + + proposalTitle, err := cmd.Flags().GetString(cli.FlagTitle) + if err != nil { + return clientCtx, proposalTitle, "", nil, false, nil, err + } + + summary, err := cmd.Flags().GetString(cli.FlagSummary) + if err != nil { + return client.Context{}, proposalTitle, summary, nil, false, nil, err + } + + depositArg, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return client.Context{}, proposalTitle, summary, nil, false, nil, err + } + + deposit, err := sdk.ParseCoinsNormalized(depositArg) + if err != nil { + return client.Context{}, proposalTitle, summary, deposit, false, nil, err + } + + isExpedited, err := cmd.Flags().GetBool(FlagIsExpedited) + if err != nil { + return client.Context{}, proposalTitle, summary, deposit, false, nil, err + } + + authorityString, err := cmd.Flags().GetString(FlagAuthority) + if err != nil { + return client.Context{}, proposalTitle, summary, deposit, false, nil, err + } + authority, err := sdk.AccAddressFromBech32(authorityString) + if err != nil { + return client.Context{}, proposalTitle, summary, deposit, false, nil, err + } + + return clientCtx, proposalTitle, summary, deposit, isExpedited, authority, nil +} + +func AddCommonProposalFlags(cmd *cobra.Command) { + cmd.Flags().String(cli.FlagTitle, "", "Title of proposal") + cmd.Flags().String(cli.FlagSummary, "", "Summary of proposal") + cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal") + cmd.Flags().Bool(FlagIsExpedited, false, "Whether the proposal is expedited") + cmd.Flags().String(FlagAuthority, DefaultGovAuthority.String(), "The address of the governance account. Default is the sdk gov module account") +} diff --git a/x/finality/client/cli/gov.go b/x/finality/client/cli/gov.go new file mode 100644 index 000000000..7362d29b5 --- /dev/null +++ b/x/finality/client/cli/gov.go @@ -0,0 +1,93 @@ +package cli + +import ( + "fmt" + "os" + "path/filepath" + "strconv" + + tmjson "github.com/cometbft/cometbft/libs/json" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/spf13/cobra" + + bbncli "github.com/babylonlabs-io/babylon/client" + bbntypes "github.com/babylonlabs-io/babylon/types" + "github.com/babylonlabs-io/babylon/x/finality/types" +) + +type FinalityProviderPks struct { + FinalityProviders []string `json:"finality-providers"` +} + +func NewCmdSubmitResumeFinalityProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "resume-finality [fps-to-jail.json] [halting-height]", + Args: cobra.ExactArgs(2), + Short: "Submit a resume finality proposal", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, proposalTitle, summary, deposit, isExpedited, authority, err := bbncli.GetProposalInfo(cmd) + if err != nil { + return err + } + + fps, err := loadFpsFromFile(args[0]) + if err != nil { + return fmt.Errorf("cannot load finality providers from %s: %w", args[0], err) + } + + haltingHeight, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return fmt.Errorf("invalid halting-height %s: %w", args[1], err) + } + + content := types.NewResumeFinalityProposal(proposalTitle, summary, fps, uint32(haltingHeight)) + + contentMsg, err := v1.NewLegacyContent(content, authority.String()) + if err != nil { + return err + } + + msg := v1.NewMsgExecLegacyContent(contentMsg.Content, authority.String()) + + proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, isExpedited) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposalMsg) + }, + } + + bbncli.AddCommonProposalFlags(cmd) + + return cmd +} + +func loadFpsFromFile(filePath string) ([]bbntypes.BIP340PubKey, error) { + bz, err := os.ReadFile(filepath.Clean(filePath)) + if err != nil { + return nil, err + } + fps := new(FinalityProviderPks) + err = tmjson.Unmarshal(bz, fps) + if err != nil { + return nil, err + } + + if len(fps.FinalityProviders) == 0 { + return nil, fmt.Errorf("empty finality providers") + } + + fpPks := make([]bbntypes.BIP340PubKey, len(fps.FinalityProviders)) + for i, pkStr := range fps.FinalityProviders { + pk, err := bbntypes.NewBIP340PubKeyFromHex(pkStr) + if err != nil { + return nil, fmt.Errorf("invalid finality provider public key %s: %w", pkStr, err) + } + fpPks[i] = *pk + } + + return fpPks, nil +} diff --git a/x/finality/client/proposal_handler.go b/x/finality/client/proposal_handler.go new file mode 100644 index 000000000..700d86320 --- /dev/null +++ b/x/finality/client/proposal_handler.go @@ -0,0 +1,11 @@ +package client + +import ( + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + + "github.com/babylonlabs-io/babylon/x/finality/client/cli" +) + +var ( + ResumeFinalityHandler = govclient.NewProposalHandler(cli.NewCmdSubmitResumeFinalityProposal) +) From 05b7ca73e06c5c14a46d7e573038e056650d3a4c Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Thu, 31 Oct 2024 18:13:28 +0800 Subject: [PATCH 4/8] fix lint --- x/finality/keeper/gov.go | 14 +++++++++----- x/finality/keeper/tallying.go | 6 +----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x/finality/keeper/gov.go b/x/finality/keeper/gov.go index 734c9fc77..417b43491 100644 --- a/x/finality/keeper/gov.go +++ b/x/finality/keeper/gov.go @@ -32,27 +32,31 @@ func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, p *types.ResumeFin _, voted := voters[fpPk.MarshalHex()] if voted { // all the given finality providers should not have voted for the halting height - return fmt.Errorf("the finality provider has voted for height %d", p.HaltingHeight) + return fmt.Errorf("the finality provider %s has voted for height %d", fpHex, p.HaltingHeight) } err := k.jailSluggishFinalityProvider(ctx, &fpPk) if err != nil && !errors.Is(err, bstypes.ErrFpAlreadyJailed) { - return fmt.Errorf("failed to jail the finality provider: %w", err) + return fmt.Errorf("failed to jail the finality provider %s: %w", fpHex, err) } // update signing info signInfo, err := k.FinalityProviderSigningTracker.Get(ctx, fpPk.MustMarshal()) if err != nil { - return fmt.Errorf("the signing info is not created: %w", err) + return fmt.Errorf("the signing info of finality provider %s is not created: %w", fpHex, err) } signInfo.JailedUntil = currentTime.Add(params.JailDuration) signInfo.MissedBlocksCounter = 0 if err := k.DeleteMissedBlockBitmap(ctx, &fpPk); err != nil { - return fmt.Errorf("failed to remove the missed block bit map: %w", err) + return fmt.Errorf("failed to remove the missed block bit map for finality provider %s: %w", fpHex, err) } err = k.FinalityProviderSigningTracker.Set(ctx, fpPk.MustMarshal(), signInfo) + if err != nil { + return fmt.Errorf("failed to set the signing info for finality provider %s: %w", fpHex, err) + } + k.Logger(ctx).Info( - "finality provider is jailed", + "finality provider is jailed in the proposal", "height", p.HaltingHeight, "public_key", fpHex, ) diff --git a/x/finality/keeper/tallying.go b/x/finality/keeper/tallying.go index 3e8bc4661..d5cb60d09 100644 --- a/x/finality/keeper/tallying.go +++ b/x/finality/keeper/tallying.go @@ -110,11 +110,7 @@ func tally(fpSet map[string]uint64, voterBTCPKs map[string]struct{}) bool { } } - if votedPower*3 > totalPower*2 { - return true - } - - return false + return votedPower*3 > totalPower*2 } // setNextHeightToFinalize sets the next height to finalise as the given height From b3cf34a31ebdec6f35280929e5ceadb9e4281d99 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Thu, 31 Oct 2024 18:31:46 +0800 Subject: [PATCH 5/8] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57950f0f8..c7d6242f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased +### Improvements + +* [#242](https://github.com/babylonlabs-io/babylon/pull/242) Add ResumeFinalityProposal and handler + ## v0.15.0 ### State Machine Breaking From 2b1d28397e9087571b384042206b887e0fb2d66e Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Thu, 14 Nov 2024 17:22:49 +0800 Subject: [PATCH 6/8] use normal message handler for proposal --- proto/babylon/finality/v1/tx.proto | 21 ++ x/finality/keeper/gov.go | 16 +- x/finality/keeper/gov_test.go | 6 +- x/finality/keeper/msg_server.go | 14 + x/finality/types/tx.pb.go | 532 ++++++++++++++++++++++++++--- 5 files changed, 526 insertions(+), 63 deletions(-) diff --git a/proto/babylon/finality/v1/tx.proto b/proto/babylon/finality/v1/tx.proto index 90d6ee73b..9b98d2648 100644 --- a/proto/babylon/finality/v1/tx.proto +++ b/proto/babylon/finality/v1/tx.proto @@ -23,6 +23,8 @@ service Msg { // UnjailFinalityProvider defines a method for unjailing a jailed // finality provider, thus it can receive voting power rpc UnjailFinalityProvider(MsgUnjailFinalityProvider) returns (MsgUnjailFinalityProviderResponse); + // ResumeFinalityProposal handles the proposal of resuming finality. + rpc ResumeFinalityProposal(MsgResumeFinalityProposal) returns (MsgResumeFinalityProposalResponse); } // MsgCommitPubRandList defines a message for committing a list of public randomness for EOTS @@ -103,3 +105,22 @@ message MsgUnjailFinalityProvider { // MsgUnjailFinalityProviderResponse defines the Msg/UnjailFinalityProvider response type message MsgUnjailFinalityProviderResponse {} + +// MsgResumeFinalityProposal is a governance proposal to resume finality from halting +message MsgResumeFinalityProposal { + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address of the governance account. + // just FYI: cosmos.AddressString marks that this field should use type alias + // for AddressString instead of string, but the functionality is not yet implemented + // in cosmos-proto + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // fp_pks is a list of finality provider public keys to jail + // the public key follows encoding in BIP-340 spec + repeated bytes fp_pks = 2 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ]; + // halting_height is the height where the finality halting begins + uint32 halting_height = 3; +} + +// MsgResumeFinalityProposalResponse is the response to the MsgResumeFinalityProposal message. +message MsgResumeFinalityProposalResponse {} diff --git a/x/finality/keeper/gov.go b/x/finality/keeper/gov.go index 417b43491..1871eaa39 100644 --- a/x/finality/keeper/gov.go +++ b/x/finality/keeper/gov.go @@ -6,8 +6,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + types2 "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/babylonlabs-io/babylon/x/finality/types" ) // HandleResumeFinalityProposal handles the resume finality proposal in the following steps: @@ -15,7 +15,7 @@ import ( // 2. jail the finality providers from the list and adjust the voting power cache from the // halting height to the current height // 3. tally blocks to ensure finality is resumed -func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, p *types.ResumeFinalityProposal) error { +func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPks []types2.BIP340PubKey, haltingHeight uint32) error { // a valid proposal should be // 1. the halting height along with some parameterized future heights should be indeed non-finalized // 2. all the fps from the proposal should have missed the vote for the halting height @@ -26,13 +26,13 @@ func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, p *types.ResumeFin currentTime := ctx.HeaderInfo().Time // jail the given finality providers - for _, fpPk := range p.FpPks { + for _, fpPk := range fpPks { fpHex := fpPk.MarshalHex() - voters := k.GetVoters(ctx, uint64(p.HaltingHeight)) + voters := k.GetVoters(ctx, uint64(haltingHeight)) _, voted := voters[fpPk.MarshalHex()] if voted { // all the given finality providers should not have voted for the halting height - return fmt.Errorf("the finality provider %s has voted for height %d", fpHex, p.HaltingHeight) + return fmt.Errorf("the finality provider %s has voted for height %d", fpHex, haltingHeight) } err := k.jailSluggishFinalityProvider(ctx, &fpPk) @@ -57,16 +57,16 @@ func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, p *types.ResumeFin k.Logger(ctx).Info( "finality provider is jailed in the proposal", - "height", p.HaltingHeight, + "height", haltingHeight, "public_key", fpHex, ) } // set the all the given finality providers voting power to 0 - for h := uint64(p.HaltingHeight); h <= uint64(currentHeight); h++ { + for h := uint64(haltingHeight); h <= uint64(currentHeight); h++ { distCache := k.GetVotingPowerDistCache(ctx, h) activeFps := distCache.GetActiveFinalityProviderSet() - for _, fpToJail := range p.FpPks { + for _, fpToJail := range fpPks { if fp, exists := activeFps[fpToJail.MarshalHex()]; exists { fp.IsJailed = true k.SetVotingPower(ctx, fpToJail, h, 0) diff --git a/x/finality/keeper/gov_test.go b/x/finality/keeper/gov_test.go index 0cb471c2a..81c01fb1f 100644 --- a/x/finality/keeper/gov_test.go +++ b/x/finality/keeper/gov_test.go @@ -68,11 +68,7 @@ func TestHandleResumeFinalityProposal(t *testing.T) { // create a resume finality proposal to jail the last fp bsKeeper.EXPECT().JailFinalityProvider(ctx, gomock.Any()).Return(nil).AnyTimes() - resumeProposal := &types.ResumeFinalityProposal{ - FpPks: activeFpPks[1:], - HaltingHeight: uint32(haltingHeight), - } - err := fKeeper.HandleResumeFinalityProposal(ctx, resumeProposal) + err := fKeeper.HandleResumeFinalityProposal(ctx, activeFpPks[1:], uint32(haltingHeight)) require.NoError(t, err) for i := haltingHeight; i < currentHeight; i++ { diff --git a/x/finality/keeper/msg_server.go b/x/finality/keeper/msg_server.go index f414a877c..3308c6cc3 100644 --- a/x/finality/keeper/msg_server.go +++ b/x/finality/keeper/msg_server.go @@ -45,6 +45,20 @@ func (ms msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdatePara return &types.MsgUpdateParamsResponse{}, nil } +// ResumeFinalityProposal handles the proposal for resuming finality from halting +func (ms msgServer) ResumeFinalityProposal(goCtx context.Context, req *types.MsgResumeFinalityProposal) (*types.MsgResumeFinalityProposalResponse, error) { + if ms.authority != req.Authority { + return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := ms.HandleResumeFinalityProposal(ctx, req.FpPks, req.HaltingHeight); err != nil { + return nil, govtypes.ErrInvalidProposalMsg.Wrapf("failed to handle resume finality proposal: %v", err) + } + + return &types.MsgResumeFinalityProposalResponse{}, nil +} + // AddFinalitySig adds a new vote to a given block func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinalitySig) (*types.MsgAddFinalitySigResponse, error) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricsKeyAddFinalitySig) diff --git a/x/finality/types/tx.pb.go b/x/finality/types/tx.pb.go index 835433de4..cbcf8834f 100644 --- a/x/finality/types/tx.pb.go +++ b/x/finality/types/tx.pb.go @@ -442,6 +442,104 @@ func (m *MsgUnjailFinalityProviderResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgUnjailFinalityProviderResponse proto.InternalMessageInfo +// MsgResumeFinalityProposal is a governance proposal to resume finality from halting +type MsgResumeFinalityProposal struct { + // authority is the address of the governance account. + // just FYI: cosmos.AddressString marks that this field should use type alias + // for AddressString instead of string, but the functionality is not yet implemented + // in cosmos-proto + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // fp_pks is a list of finality provider public keys to jail + // the public key follows encoding in BIP-340 spec + FpPks []github_com_babylonlabs_io_babylon_types.BIP340PubKey `protobuf:"bytes,2,rep,name=fp_pks,json=fpPks,proto3,customtype=github.com/babylonlabs-io/babylon/types.BIP340PubKey" json:"fp_pks,omitempty"` + // halting_height is the height where the finality halting begins + HaltingHeight uint32 `protobuf:"varint,3,opt,name=halting_height,json=haltingHeight,proto3" json:"halting_height,omitempty"` +} + +func (m *MsgResumeFinalityProposal) Reset() { *m = MsgResumeFinalityProposal{} } +func (m *MsgResumeFinalityProposal) String() string { return proto.CompactTextString(m) } +func (*MsgResumeFinalityProposal) ProtoMessage() {} +func (*MsgResumeFinalityProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_2dd6da066b6baf1d, []int{8} +} +func (m *MsgResumeFinalityProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgResumeFinalityProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgResumeFinalityProposal.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 *MsgResumeFinalityProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgResumeFinalityProposal.Merge(m, src) +} +func (m *MsgResumeFinalityProposal) XXX_Size() int { + return m.Size() +} +func (m *MsgResumeFinalityProposal) XXX_DiscardUnknown() { + xxx_messageInfo_MsgResumeFinalityProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgResumeFinalityProposal proto.InternalMessageInfo + +func (m *MsgResumeFinalityProposal) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgResumeFinalityProposal) GetHaltingHeight() uint32 { + if m != nil { + return m.HaltingHeight + } + return 0 +} + +// MsgResumeFinalityProposalResponse is the response to the MsgResumeFinalityProposal message. +type MsgResumeFinalityProposalResponse struct { +} + +func (m *MsgResumeFinalityProposalResponse) Reset() { *m = MsgResumeFinalityProposalResponse{} } +func (m *MsgResumeFinalityProposalResponse) String() string { return proto.CompactTextString(m) } +func (*MsgResumeFinalityProposalResponse) ProtoMessage() {} +func (*MsgResumeFinalityProposalResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2dd6da066b6baf1d, []int{9} +} +func (m *MsgResumeFinalityProposalResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgResumeFinalityProposalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgResumeFinalityProposalResponse.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 *MsgResumeFinalityProposalResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgResumeFinalityProposalResponse.Merge(m, src) +} +func (m *MsgResumeFinalityProposalResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgResumeFinalityProposalResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgResumeFinalityProposalResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgResumeFinalityProposalResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgCommitPubRandList)(nil), "babylon.finality.v1.MsgCommitPubRandList") proto.RegisterType((*MsgCommitPubRandListResponse)(nil), "babylon.finality.v1.MsgCommitPubRandListResponse") @@ -451,61 +549,68 @@ func init() { proto.RegisterType((*MsgUpdateParamsResponse)(nil), "babylon.finality.v1.MsgUpdateParamsResponse") proto.RegisterType((*MsgUnjailFinalityProvider)(nil), "babylon.finality.v1.MsgUnjailFinalityProvider") proto.RegisterType((*MsgUnjailFinalityProviderResponse)(nil), "babylon.finality.v1.MsgUnjailFinalityProviderResponse") + proto.RegisterType((*MsgResumeFinalityProposal)(nil), "babylon.finality.v1.MsgResumeFinalityProposal") + proto.RegisterType((*MsgResumeFinalityProposalResponse)(nil), "babylon.finality.v1.MsgResumeFinalityProposalResponse") } func init() { proto.RegisterFile("babylon/finality/v1/tx.proto", fileDescriptor_2dd6da066b6baf1d) } var fileDescriptor_2dd6da066b6baf1d = []byte{ - // 774 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xcf, 0x4f, 0x1b, 0x47, - 0x18, 0xf5, 0x62, 0x30, 0x65, 0x6c, 0x81, 0xd8, 0x22, 0x58, 0x0c, 0x5d, 0x1b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c0, 0x6d, 0x7d, 0x09, 0x00, 0x00, 0xff, 0xff, 0x64, 0x3e, - 0x90, 0x65, 0xa0, 0x07, 0x00, 0x00, + // 851 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0xd6, 0x89, 0x43, 0xc6, 0x6e, 0xaa, 0x2e, 0x51, 0xeb, 0xb8, 0xc5, 0x76, 0x43, 0x41, + 0xa1, 0xa2, 0xbb, 0x24, 0xad, 0x02, 0x84, 0x53, 0x8c, 0x40, 0x45, 0xd4, 0xea, 0x6a, 0xdd, 0x5c, + 0x90, 0xd0, 0x6a, 0xf6, 0x87, 0x67, 0x07, 0x7b, 0x67, 0x86, 0x99, 0xd9, 0xa8, 0xbe, 0x55, 0x9c, + 0x38, 0x72, 0xe0, 0xc4, 0x89, 0x3f, 0xa1, 0x07, 0xae, 0x1c, 0x91, 0x7a, 0xac, 0xe0, 0x82, 0x82, + 0x14, 0xa1, 0xe4, 0xd0, 0x7f, 0x03, 0xed, 0xee, 0xf8, 0x57, 0xb2, 0x0b, 0x6e, 0x91, 0x72, 0xdb, + 0x99, 0xf7, 0xcd, 0xbc, 0xef, 0x7d, 0xdf, 0x7b, 0xa3, 0x05, 0x37, 0x5d, 0xe8, 0x8e, 0x86, 0x94, + 0x98, 0x7d, 0x4c, 0xe0, 0x10, 0xcb, 0x91, 0x79, 0xb8, 0x6d, 0xca, 0x27, 0x06, 0xe3, 0x54, 0x52, + 0xfd, 0x4d, 0x15, 0x35, 0xc6, 0x51, 0xe3, 0x70, 0xbb, 0xb1, 0x8e, 0x28, 0xa2, 0x69, 0xdc, 0x4c, + 0xbe, 0x32, 0x68, 0xe3, 0x2d, 0x19, 0x10, 0x3f, 0xe0, 0x11, 0x26, 0xd2, 0xf4, 0xf8, 0x88, 0x49, + 0x6a, 0x32, 0x4e, 0x69, 0x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 0x57, 0xcf, 0xbf, 0xdf, 0xef, 0xe5, 0xf6, 0x4d, 0xde, 0x1b, + 0xd5, 0xd8, 0x5e, 0x18, 0x3a, 0x4e, 0xad, 0x87, 0x60, 0xed, 0xcc, 0x53, 0xf6, 0x6e, 0xd1, 0x25, + 0xf3, 0xb8, 0x86, 0xb1, 0x18, 0x6e, 0x92, 0xc9, 0x05, 0xb5, 0xb9, 0xb9, 0xba, 0x5d, 0x74, 0x7e, + 0x16, 0xd5, 0x78, 0x7f, 0x11, 0xd4, 0x24, 0xc7, 0x53, 0x0d, 0x5c, 0x2b, 0x18, 0x85, 0x42, 0xba, + 0xf9, 0xf8, 0xc6, 0xee, 0xab, 0xe1, 0xe7, 0x28, 0x14, 0xf4, 0x72, 0x21, 0x85, 0x7c, 0x7c, 0x31, + 0x85, 0x7f, 0x6f, 0xa7, 0xc6, 0xf2, 0xd3, 0x97, 0xcf, 0xee, 0x68, 0x9d, 0x87, 0xcf, 0x4f, 0x9a, + 0xda, 0x8b, 0x93, 0xa6, 0xf6, 0xf7, 0x49, 0x53, 0xfb, 0xe1, 0xb4, 0x59, 0x7a, 0x71, 0xda, 0x2c, + 0xfd, 0x79, 0xda, 0x2c, 0x7d, 0xb5, 0xf3, 0xdf, 0x83, 0xf0, 0x64, 0xfa, 0xa7, 0x91, 0xce, 0x84, + 0x5b, 0x49, 0x7f, 0x33, 0xee, 0xfd, 0x13, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x5c, 0xbc, 0x32, 0x26, + 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -530,6 +635,8 @@ type MsgClient interface { // UnjailFinalityProvider defines a method for unjailing a jailed // finality provider, thus it can receive voting power UnjailFinalityProvider(ctx context.Context, in *MsgUnjailFinalityProvider, opts ...grpc.CallOption) (*MsgUnjailFinalityProviderResponse, error) + // ResumeFinalityProposal handles the proposal of resuming finality. + ResumeFinalityProposal(ctx context.Context, in *MsgResumeFinalityProposal, opts ...grpc.CallOption) (*MsgResumeFinalityProposalResponse, error) } type msgClient struct { @@ -576,6 +683,15 @@ func (c *msgClient) UnjailFinalityProvider(ctx context.Context, in *MsgUnjailFin return out, nil } +func (c *msgClient) ResumeFinalityProposal(ctx context.Context, in *MsgResumeFinalityProposal, opts ...grpc.CallOption) (*MsgResumeFinalityProposalResponse, error) { + out := new(MsgResumeFinalityProposalResponse) + err := c.cc.Invoke(ctx, "/babylon.finality.v1.Msg/ResumeFinalityProposal", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // CommitPubRandList commits a list of public randomness for EOTS @@ -588,6 +704,8 @@ type MsgServer interface { // UnjailFinalityProvider defines a method for unjailing a jailed // finality provider, thus it can receive voting power UnjailFinalityProvider(context.Context, *MsgUnjailFinalityProvider) (*MsgUnjailFinalityProviderResponse, error) + // ResumeFinalityProposal handles the proposal of resuming finality. + ResumeFinalityProposal(context.Context, *MsgResumeFinalityProposal) (*MsgResumeFinalityProposalResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -606,6 +724,9 @@ func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateP func (*UnimplementedMsgServer) UnjailFinalityProvider(ctx context.Context, req *MsgUnjailFinalityProvider) (*MsgUnjailFinalityProviderResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method UnjailFinalityProvider not implemented") } +func (*UnimplementedMsgServer) ResumeFinalityProposal(ctx context.Context, req *MsgResumeFinalityProposal) (*MsgResumeFinalityProposalResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ResumeFinalityProposal not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -683,6 +804,24 @@ func _Msg_UnjailFinalityProvider_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +func _Msg_ResumeFinalityProposal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgResumeFinalityProposal) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ResumeFinalityProposal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/babylon.finality.v1.Msg/ResumeFinalityProposal", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ResumeFinalityProposal(ctx, req.(*MsgResumeFinalityProposal)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "babylon.finality.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -703,6 +842,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "UnjailFinalityProvider", Handler: _Msg_UnjailFinalityProvider_Handler, }, + { + MethodName: "ResumeFinalityProposal", + Handler: _Msg_ResumeFinalityProposal_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "babylon/finality/v1/tx.proto", @@ -1043,6 +1186,78 @@ func (m *MsgUnjailFinalityProviderResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } +func (m *MsgResumeFinalityProposal) 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 *MsgResumeFinalityProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgResumeFinalityProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.HaltingHeight != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.HaltingHeight)) + i-- + dAtA[i] = 0x18 + } + if len(m.FpPks) > 0 { + for iNdEx := len(m.FpPks) - 1; iNdEx >= 0; iNdEx-- { + { + size := m.FpPks[iNdEx].Size() + i -= size + if _, err := m.FpPks[iNdEx].MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgResumeFinalityProposalResponse) 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 *MsgResumeFinalityProposalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgResumeFinalityProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1189,6 +1404,37 @@ func (m *MsgUnjailFinalityProviderResponse) Size() (n int) { return n } +func (m *MsgResumeFinalityProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.FpPks) > 0 { + for _, e := range m.FpPks { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if m.HaltingHeight != 0 { + n += 1 + sovTx(uint64(m.HaltingHeight)) + } + return n +} + +func (m *MsgResumeFinalityProposalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2127,6 +2373,192 @@ func (m *MsgUnjailFinalityProviderResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgResumeFinalityProposal) 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 ErrIntOverflowTx + } + 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: MsgResumeFinalityProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgResumeFinalityProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FpPks", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var v github_com_babylonlabs_io_babylon_types.BIP340PubKey + m.FpPks = append(m.FpPks, v) + if err := m.FpPks[len(m.FpPks)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HaltingHeight", wireType) + } + m.HaltingHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HaltingHeight |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgResumeFinalityProposalResponse) 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 ErrIntOverflowTx + } + 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: MsgResumeFinalityProposalResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgResumeFinalityProposalResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From d36cd56e1c0d16e82714a8f95995b041ab36c9fa Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Fri, 15 Nov 2024 14:37:19 +0800 Subject: [PATCH 7/8] fix gov --- x/finality/gov.go | 29 ----------------------------- x/finality/keeper/gov.go | 4 ++-- 2 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 x/finality/gov.go diff --git a/x/finality/gov.go b/x/finality/gov.go deleted file mode 100644 index e753e548d..000000000 --- a/x/finality/gov.go +++ /dev/null @@ -1,29 +0,0 @@ -package finality - -import ( - errorsmod "cosmossdk.io/errors" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - "github.com/babylonlabs-io/babylon/x/finality/keeper" - "github.com/babylonlabs-io/babylon/x/finality/types" -) - -// NewResumeFinalityProposalHandler is a handler for governance proposal on resume finality. -func NewResumeFinalityProposalHandler(k keeper.Keeper) govtypesv1.Handler { - return func(ctx sdk.Context, content govtypesv1.Content) error { - switch c := content.(type) { - case *types.ResumeFinalityProposal: - return handleResumeFinalityProposal(ctx, k, c) - - default: - return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized resume finality proposal content type: %T", c) - } - } -} - -// handleResumeFinalityProposal is a handler for jail finality provider proposals -func handleResumeFinalityProposal(ctx sdk.Context, k keeper.Keeper, p *types.ResumeFinalityProposal) error { - return k.HandleResumeFinalityProposal(ctx, p) -} diff --git a/x/finality/keeper/gov.go b/x/finality/keeper/gov.go index 1871eaa39..ac2010ded 100644 --- a/x/finality/keeper/gov.go +++ b/x/finality/keeper/gov.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - types2 "github.com/babylonlabs-io/babylon/types" + bbntypes "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" ) @@ -15,7 +15,7 @@ import ( // 2. jail the finality providers from the list and adjust the voting power cache from the // halting height to the current height // 3. tally blocks to ensure finality is resumed -func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPks []types2.BIP340PubKey, haltingHeight uint32) error { +func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPks []bbntypes.BIP340PubKey, haltingHeight uint32) error { // a valid proposal should be // 1. the halting height along with some parameterized future heights should be indeed non-finalized // 2. all the fps from the proposal should have missed the vote for the halting height From fc620e3b448c9def7b90fde3bfcac3e8443b4cab Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Mon, 18 Nov 2024 16:57:06 +0800 Subject: [PATCH 8/8] rm proposal handler --- app/app.go | 12 +- client/parsers.go | 70 ---- proto/babylon/finality/v1/gov.proto | 25 -- proto/babylon/finality/v1/tx.proto | 4 +- test/e2e/upgrades/v1.json | 4 +- x/btcstaking/keeper/keeper.go | 3 +- x/finality/README.md | 23 ++ x/finality/client/cli/gov.go | 93 ------ x/finality/client/proposal_handler.go | 11 - x/finality/keeper/gov.go | 32 +- x/finality/keeper/gov_test.go | 12 +- x/finality/keeper/msg_server.go | 2 +- x/finality/types/codec.go | 2 + x/finality/types/errors.go | 2 - x/finality/types/gov.go | 81 ----- x/finality/types/gov.pb.go | 456 -------------------------- x/finality/types/msg.go | 8 +- x/finality/types/tx.pb.go | 157 +++++---- 18 files changed, 149 insertions(+), 848 deletions(-) delete mode 100644 client/parsers.go delete mode 100644 proto/babylon/finality/v1/gov.proto delete mode 100644 x/finality/client/cli/gov.go delete mode 100644 x/finality/client/proposal_handler.go delete mode 100644 x/finality/types/gov.go delete mode 100644 x/finality/types/gov.pb.go diff --git a/app/app.go b/app/app.go index 43492e00a..924cde78e 100644 --- a/app/app.go +++ b/app/app.go @@ -23,8 +23,6 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - "github.com/babylonlabs-io/babylon/x/mint" - minttypes "github.com/babylonlabs-io/babylon/x/mint/types" abci "github.com/cometbft/cometbft/abci/types" cmtos "github.com/cometbft/cometbft/libs/os" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -91,14 +89,15 @@ import ( ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" "github.com/spf13/cast" - "github.com/babylonlabs-io/babylon/app/ante" - "github.com/babylonlabs-io/babylon/app/upgrades" - bbn "github.com/babylonlabs-io/babylon/types" - finalityclient "github.com/babylonlabs-io/babylon/x/finality/client" + "github.com/babylonlabs-io/babylon/x/mint" + minttypes "github.com/babylonlabs-io/babylon/x/mint/types" + "github.com/babylonlabs-io/babylon/app/ante" appkeepers "github.com/babylonlabs-io/babylon/app/keepers" appparams "github.com/babylonlabs-io/babylon/app/params" + "github.com/babylonlabs-io/babylon/app/upgrades" "github.com/babylonlabs-io/babylon/client/docs" + bbn "github.com/babylonlabs-io/babylon/types" "github.com/babylonlabs-io/babylon/x/btccheckpoint" btccheckpointtypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" "github.com/babylonlabs-io/babylon/x/btclightclient" @@ -328,7 +327,6 @@ func NewBabylonApp( govtypes.ModuleName: gov.NewAppModuleBasic( []govclient.ProposalHandler{ paramsclient.ProposalHandler, - finalityclient.ResumeFinalityHandler, }, ), }) diff --git a/client/parsers.go b/client/parsers.go deleted file mode 100644 index 8cb205850..000000000 --- a/client/parsers.go +++ /dev/null @@ -1,70 +0,0 @@ -package client - -import ( - "github.com/cosmos/cosmos-sdk/client" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" - "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - "github.com/spf13/cobra" -) - -// adapted from -// https://github.com/osmosis-labs/osmosis/blob/2e85d1ee3e15e3f74898395d37b455af48649268/osmoutils/osmocli/parsers.go - -var DefaultGovAuthority = sdk.AccAddress(address.Module("gov")) - -const ( - FlagIsExpedited = "is-expedited" - FlagAuthority = "authority" -) - -func GetProposalInfo(cmd *cobra.Command) (client.Context, string, string, sdk.Coins, bool, sdk.AccAddress, error) { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return client.Context{}, "", "", nil, false, nil, err - } - - proposalTitle, err := cmd.Flags().GetString(cli.FlagTitle) - if err != nil { - return clientCtx, proposalTitle, "", nil, false, nil, err - } - - summary, err := cmd.Flags().GetString(cli.FlagSummary) - if err != nil { - return client.Context{}, proposalTitle, summary, nil, false, nil, err - } - - depositArg, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return client.Context{}, proposalTitle, summary, nil, false, nil, err - } - - deposit, err := sdk.ParseCoinsNormalized(depositArg) - if err != nil { - return client.Context{}, proposalTitle, summary, deposit, false, nil, err - } - - isExpedited, err := cmd.Flags().GetBool(FlagIsExpedited) - if err != nil { - return client.Context{}, proposalTitle, summary, deposit, false, nil, err - } - - authorityString, err := cmd.Flags().GetString(FlagAuthority) - if err != nil { - return client.Context{}, proposalTitle, summary, deposit, false, nil, err - } - authority, err := sdk.AccAddressFromBech32(authorityString) - if err != nil { - return client.Context{}, proposalTitle, summary, deposit, false, nil, err - } - - return clientCtx, proposalTitle, summary, deposit, isExpedited, authority, nil -} - -func AddCommonProposalFlags(cmd *cobra.Command) { - cmd.Flags().String(cli.FlagTitle, "", "Title of proposal") - cmd.Flags().String(cli.FlagSummary, "", "Summary of proposal") - cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal") - cmd.Flags().Bool(FlagIsExpedited, false, "Whether the proposal is expedited") - cmd.Flags().String(FlagAuthority, DefaultGovAuthority.String(), "The address of the governance account. Default is the sdk gov module account") -} diff --git a/proto/babylon/finality/v1/gov.proto b/proto/babylon/finality/v1/gov.proto deleted file mode 100644 index ae71ea589..000000000 --- a/proto/babylon/finality/v1/gov.proto +++ /dev/null @@ -1,25 +0,0 @@ -syntax = "proto3"; -package babylon.finality.v1; - -import "cosmos_proto/cosmos.proto"; -import "amino/amino.proto"; -import "gogoproto/gogo.proto"; - -option go_package = "github.com/babylonlabs-io/babylon/x/finality/types"; - -// ResumeFinalityProposal is a gov Content type for resuming finality -// in case of finality is halting by jailing a list of sluggish finality -// providers from the halting height -message ResumeFinalityProposal { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; - - string title = 1; - string description = 2; - // fp_pks is a list of finality provider public keys to jail - // the public key follows encoding in BIP-340 spec - repeated bytes fp_pks = 3 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ]; - // halting_height is the height where the finality halting begins - uint32 halting_height = 4; -} diff --git a/proto/babylon/finality/v1/tx.proto b/proto/babylon/finality/v1/tx.proto index 9b98d2648..927db94fd 100644 --- a/proto/babylon/finality/v1/tx.proto +++ b/proto/babylon/finality/v1/tx.proto @@ -115,9 +115,9 @@ message MsgResumeFinalityProposal { // for AddressString instead of string, but the functionality is not yet implemented // in cosmos-proto string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - // fp_pks is a list of finality provider public keys to jail + // fp_pks_hex is a list of finality provider public keys to jail // the public key follows encoding in BIP-340 spec - repeated bytes fp_pks = 2 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ]; + repeated string fp_pks_hex = 2; // halting_height is the height where the finality halting begins uint32 halting_height = 3; } diff --git a/test/e2e/upgrades/v1.json b/test/e2e/upgrades/v1.json index 9f6d148af..c0ee936ad 100644 --- a/test/e2e/upgrades/v1.json +++ b/test/e2e/upgrades/v1.json @@ -6,7 +6,7 @@ "plan": { "name": "v1", "time": "0001-01-01T00:00:00Z", - "height": "32", + "height": "52", "info": "Msg info", "upgraded_client_state": null } @@ -17,4 +17,4 @@ "title": "any title", "summary": "any summary", "expedited": false -} \ No newline at end of file +} diff --git a/x/btcstaking/keeper/keeper.go b/x/btcstaking/keeper/keeper.go index 0720bc231..c1575fab8 100644 --- a/x/btcstaking/keeper/keeper.go +++ b/x/btcstaking/keeper/keeper.go @@ -28,7 +28,8 @@ type ( AllowedStakingTxHashesKeySet collections.KeySet[[]byte] btcNet *chaincfg.Params - // the address capable of executing a MsgUpdateParams message. Typically, this + // the address capable of executing a MsgUpdateParams or + // MsgResumeFinalityProposal message. Typically, this // should be the x/gov module account. authority string } diff --git a/x/finality/README.md b/x/finality/README.md index c4f19e6d2..09ecf0bf7 100644 --- a/x/finality/README.md +++ b/x/finality/README.md @@ -421,6 +421,29 @@ message MsgUpdateParams { } ``` +### MsgResumeFinalityProposal + +The `MsgResumeFinalityProposal` message is used for resuming finality in case +of finality halting. It can only be executed via a governance proposal. + +```protobuf +// MsgResumeFinalityProposal is a governance proposal to resume finality from halting +message MsgResumeFinalityProposal { + option (cosmos.msg.v1.signer) = "authority"; + + // authority is the address of the governance account. + // just FYI: cosmos.AddressString marks that this field should use type alias + // for AddressString instead of string, but the functionality is not yet implemented + // in cosmos-proto + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + // fp_pks_hex is a list of finality provider public keys to jail + // the public key follows encoding in BIP-340 spec + repeated string fp_pks_hex = 2; + // halting_height is the height where the finality halting begins + uint32 halting_height = 3; +} +``` + ## BeginBlocker Upon `EndBlocker`, the Finality module of each Babylon node will [execute the diff --git a/x/finality/client/cli/gov.go b/x/finality/client/cli/gov.go deleted file mode 100644 index 7362d29b5..000000000 --- a/x/finality/client/cli/gov.go +++ /dev/null @@ -1,93 +0,0 @@ -package cli - -import ( - "fmt" - "os" - "path/filepath" - "strconv" - - tmjson "github.com/cometbft/cometbft/libs/json" - "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" - v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/spf13/cobra" - - bbncli "github.com/babylonlabs-io/babylon/client" - bbntypes "github.com/babylonlabs-io/babylon/types" - "github.com/babylonlabs-io/babylon/x/finality/types" -) - -type FinalityProviderPks struct { - FinalityProviders []string `json:"finality-providers"` -} - -func NewCmdSubmitResumeFinalityProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "resume-finality [fps-to-jail.json] [halting-height]", - Args: cobra.ExactArgs(2), - Short: "Submit a resume finality proposal", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, proposalTitle, summary, deposit, isExpedited, authority, err := bbncli.GetProposalInfo(cmd) - if err != nil { - return err - } - - fps, err := loadFpsFromFile(args[0]) - if err != nil { - return fmt.Errorf("cannot load finality providers from %s: %w", args[0], err) - } - - haltingHeight, err := strconv.ParseUint(args[1], 10, 64) - if err != nil { - return fmt.Errorf("invalid halting-height %s: %w", args[1], err) - } - - content := types.NewResumeFinalityProposal(proposalTitle, summary, fps, uint32(haltingHeight)) - - contentMsg, err := v1.NewLegacyContent(content, authority.String()) - if err != nil { - return err - } - - msg := v1.NewMsgExecLegacyContent(contentMsg.Content, authority.String()) - - proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, isExpedited) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposalMsg) - }, - } - - bbncli.AddCommonProposalFlags(cmd) - - return cmd -} - -func loadFpsFromFile(filePath string) ([]bbntypes.BIP340PubKey, error) { - bz, err := os.ReadFile(filepath.Clean(filePath)) - if err != nil { - return nil, err - } - fps := new(FinalityProviderPks) - err = tmjson.Unmarshal(bz, fps) - if err != nil { - return nil, err - } - - if len(fps.FinalityProviders) == 0 { - return nil, fmt.Errorf("empty finality providers") - } - - fpPks := make([]bbntypes.BIP340PubKey, len(fps.FinalityProviders)) - for i, pkStr := range fps.FinalityProviders { - pk, err := bbntypes.NewBIP340PubKeyFromHex(pkStr) - if err != nil { - return nil, fmt.Errorf("invalid finality provider public key %s: %w", pkStr, err) - } - fpPks[i] = *pk - } - - return fpPks, nil -} diff --git a/x/finality/client/proposal_handler.go b/x/finality/client/proposal_handler.go deleted file mode 100644 index 700d86320..000000000 --- a/x/finality/client/proposal_handler.go +++ /dev/null @@ -1,11 +0,0 @@ -package client - -import ( - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" - - "github.com/babylonlabs-io/babylon/x/finality/client/cli" -) - -var ( - ResumeFinalityHandler = govclient.NewProposalHandler(cli.NewCmdSubmitResumeFinalityProposal) -) diff --git a/x/finality/keeper/gov.go b/x/finality/keeper/gov.go index ac2010ded..a5f7561f4 100644 --- a/x/finality/keeper/gov.go +++ b/x/finality/keeper/gov.go @@ -15,7 +15,7 @@ import ( // 2. jail the finality providers from the list and adjust the voting power cache from the // halting height to the current height // 3. tally blocks to ensure finality is resumed -func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPks []bbntypes.BIP340PubKey, haltingHeight uint32) error { +func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPksHex []string, haltingHeight uint32) error { // a valid proposal should be // 1. the halting height along with some parameterized future heights should be indeed non-finalized // 2. all the fps from the proposal should have missed the vote for the halting height @@ -26,39 +26,45 @@ func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPks []bbntypes.B currentTime := ctx.HeaderInfo().Time // jail the given finality providers - for _, fpPk := range fpPks { - fpHex := fpPk.MarshalHex() + fpPks := make([]*bbntypes.BIP340PubKey, 0, len(fpPksHex)) + for _, fpPkHex := range fpPksHex { + fpPk, err := bbntypes.NewBIP340PubKeyFromHex(fpPkHex) + if err != nil { + return fmt.Errorf("invalid finality provider public key %s: %w", fpPkHex, err) + } + fpPks = append(fpPks, fpPk) + voters := k.GetVoters(ctx, uint64(haltingHeight)) - _, voted := voters[fpPk.MarshalHex()] + _, voted := voters[fpPkHex] if voted { // all the given finality providers should not have voted for the halting height - return fmt.Errorf("the finality provider %s has voted for height %d", fpHex, haltingHeight) + return fmt.Errorf("the finality provider %s has voted for height %d", fpPkHex, haltingHeight) } - err := k.jailSluggishFinalityProvider(ctx, &fpPk) + err = k.jailSluggishFinalityProvider(ctx, fpPk) if err != nil && !errors.Is(err, bstypes.ErrFpAlreadyJailed) { - return fmt.Errorf("failed to jail the finality provider %s: %w", fpHex, err) + return fmt.Errorf("failed to jail the finality provider %s: %w", fpPkHex, err) } // update signing info signInfo, err := k.FinalityProviderSigningTracker.Get(ctx, fpPk.MustMarshal()) if err != nil { - return fmt.Errorf("the signing info of finality provider %s is not created: %w", fpHex, err) + return fmt.Errorf("the signing info of finality provider %s is not created: %w", fpPkHex, err) } signInfo.JailedUntil = currentTime.Add(params.JailDuration) signInfo.MissedBlocksCounter = 0 - if err := k.DeleteMissedBlockBitmap(ctx, &fpPk); err != nil { - return fmt.Errorf("failed to remove the missed block bit map for finality provider %s: %w", fpHex, err) + if err := k.DeleteMissedBlockBitmap(ctx, fpPk); err != nil { + return fmt.Errorf("failed to remove the missed block bit map for finality provider %s: %w", fpPkHex, err) } err = k.FinalityProviderSigningTracker.Set(ctx, fpPk.MustMarshal(), signInfo) if err != nil { - return fmt.Errorf("failed to set the signing info for finality provider %s: %w", fpHex, err) + return fmt.Errorf("failed to set the signing info for finality provider %s: %w", fpPkHex, err) } k.Logger(ctx).Info( "finality provider is jailed in the proposal", "height", haltingHeight, - "public_key", fpHex, + "public_key", fpPkHex, ) } @@ -69,7 +75,7 @@ func (k Keeper) HandleResumeFinalityProposal(ctx sdk.Context, fpPks []bbntypes.B for _, fpToJail := range fpPks { if fp, exists := activeFps[fpToJail.MarshalHex()]; exists { fp.IsJailed = true - k.SetVotingPower(ctx, fpToJail, h, 0) + k.SetVotingPower(ctx, fpToJail.MustMarshal(), h, 0) } } diff --git a/x/finality/keeper/gov_test.go b/x/finality/keeper/gov_test.go index 81c01fb1f..a3812d5f6 100644 --- a/x/finality/keeper/gov_test.go +++ b/x/finality/keeper/gov_test.go @@ -68,7 +68,7 @@ func TestHandleResumeFinalityProposal(t *testing.T) { // create a resume finality proposal to jail the last fp bsKeeper.EXPECT().JailFinalityProvider(ctx, gomock.Any()).Return(nil).AnyTimes() - err := fKeeper.HandleResumeFinalityProposal(ctx, activeFpPks[1:], uint32(haltingHeight)) + err := fKeeper.HandleResumeFinalityProposal(ctx, publicKeysToHex(activeFpPks[1:]), uint32(haltingHeight)) require.NoError(t, err) for i := haltingHeight; i < currentHeight; i++ { @@ -79,7 +79,7 @@ func TestHandleResumeFinalityProposal(t *testing.T) { } func generateNFpPks(t *testing.T, r *rand.Rand, n int) []bbntypes.BIP340PubKey { - fpPks := make([]bbntypes.BIP340PubKey, 0) + fpPks := make([]bbntypes.BIP340PubKey, 0, n) for i := 0; i < n; i++ { fpPk, err := datagen.GenRandomBIP340PubKey(r) require.NoError(t, err) @@ -89,6 +89,14 @@ func generateNFpPks(t *testing.T, r *rand.Rand, n int) []bbntypes.BIP340PubKey { return fpPks } +func publicKeysToHex(pks []bbntypes.BIP340PubKey) []string { + hexPks := make([]string, len(pks)) + for i, pk := range pks { + hexPks[i] = pk.MarshalHex() + } + return hexPks +} + func setupActiveFps(t *testing.T, fpPks []bbntypes.BIP340PubKey, height uint64, fKeeper *keeper.Keeper, ctx sdk.Context) { for _, fpPk := range fpPks { signingInfo := types.NewFinalityProviderSigningInfo( diff --git a/x/finality/keeper/msg_server.go b/x/finality/keeper/msg_server.go index 3308c6cc3..13410bee3 100644 --- a/x/finality/keeper/msg_server.go +++ b/x/finality/keeper/msg_server.go @@ -52,7 +52,7 @@ func (ms msgServer) ResumeFinalityProposal(goCtx context.Context, req *types.Msg } ctx := sdk.UnwrapSDKContext(goCtx) - if err := ms.HandleResumeFinalityProposal(ctx, req.FpPks, req.HaltingHeight); err != nil { + if err := ms.HandleResumeFinalityProposal(ctx, req.FpPksHex, req.HaltingHeight); err != nil { return nil, govtypes.ErrInvalidProposalMsg.Wrapf("failed to handle resume finality proposal: %v", err) } diff --git a/x/finality/types/codec.go b/x/finality/types/codec.go index 2e978d134..fadf4d2b0 100644 --- a/x/finality/types/codec.go +++ b/x/finality/types/codec.go @@ -11,6 +11,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgCommitPubRandList{}, "finality/MsgCommitPubRandList", nil) cdc.RegisterConcrete(&MsgAddFinalitySig{}, "finality/MsgAddFinalitySig", nil) cdc.RegisterConcrete(&MsgUpdateParams{}, "finality/MsgUpdateParams", nil) + cdc.RegisterConcrete(&MsgResumeFinalityProposal{}, "finality/MsgResumeFinalityProposal", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -20,6 +21,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgCommitPubRandList{}, &MsgAddFinalitySig{}, &MsgUpdateParams{}, + &MsgResumeFinalityProposal{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/finality/types/errors.go b/x/finality/types/errors.go index e70c948b6..1b026b6dc 100644 --- a/x/finality/types/errors.go +++ b/x/finality/types/errors.go @@ -22,6 +22,4 @@ var ( ErrVotingPowerTableNotUpdated = errorsmod.Register(ModuleName, 1113, "voting power table has not been updated") ErrBTCStakingNotActivated = errorsmod.Register(ModuleName, 1114, "the BTC staking protocol is not activated yet") ErrFinalityNotActivated = errorsmod.Register(ModuleName, 1115, "finality is not active yet") - ErrEmptyProposalFinalityProviders = errorsmod.Register(ModuleName, 1116, "the finality provider list in the ResumeFinality is empty") - ErrEmptyProposalHaltingHeight = errorsmod.Register(ModuleName, 1117, "the halting height in the ResumeFinality is empty") ) diff --git a/x/finality/types/gov.go b/x/finality/types/gov.go deleted file mode 100644 index 12808b52a..000000000 --- a/x/finality/types/gov.go +++ /dev/null @@ -1,81 +0,0 @@ -package types - -import ( - "fmt" - "strings" - - govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - - "github.com/babylonlabs-io/babylon/types" -) - -const ( - ProposalResumeFinality = "ResumeFinality" -) - -// Init registers proposals to update and replace pool incentives. -func init() { - govtypesv1.RegisterProposalType(ProposalResumeFinality) -} - -var ( - _ govtypesv1.Content = &ResumeFinalityProposal{} -) - -// NewResumeFinalityProposal returns a new instance of a resume finality proposal struct. -func NewResumeFinalityProposal(title, description string, fps []types.BIP340PubKey, haltingHeight uint32) govtypesv1.Content { - return &ResumeFinalityProposal{ - Title: title, - Description: description, - FpPks: fps, - HaltingHeight: haltingHeight, - } -} - -// GetTitle gets the title of the proposal -func (p *ResumeFinalityProposal) GetTitle() string { return p.Title } - -// GetDescription gets the description of the proposal -func (p *ResumeFinalityProposal) GetDescription() string { return p.Description } - -// ProposalRoute returns the router key for the proposal -func (p *ResumeFinalityProposal) ProposalRoute() string { return RouterKey } - -// ProposalType returns the type of the proposal -func (p *ResumeFinalityProposal) ProposalType() string { - return ProposalResumeFinality -} - -// ValidateBasic validates a governance proposal's abstract and basic contents -func (p *ResumeFinalityProposal) ValidateBasic() error { - err := govtypesv1.ValidateAbstract(p) - if err != nil { - return err - } - if len(p.FpPks) == 0 { - return ErrEmptyProposalFinalityProviders - } - - if p.HaltingHeight == 0 { - return ErrEmptyProposalHaltingHeight - } - - return nil -} - -// String returns a string containing the jail finality providers proposal. -func (p *ResumeFinalityProposal) String() string { - fpsStr := fmt.Sprintln("Finality providers to jail:") - for i, pk := range p.FpPks { - fpsStr = fpsStr + fmt.Sprintf("%d. %s\n", i+1, pk.MarshalHex()) - } - - var b strings.Builder - b.WriteString(fmt.Sprintf(`Resume Finality Proposal: - Title: %s - Description: %s - Halting height: %d - %s -`, p.Title, p.Description, p.HaltingHeight, fpsStr)) - return b.String() -} diff --git a/x/finality/types/gov.pb.go b/x/finality/types/gov.pb.go deleted file mode 100644 index 5e502f8ec..000000000 --- a/x/finality/types/gov.pb.go +++ /dev/null @@ -1,456 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: babylon/finality/v1/gov.proto - -package types - -import ( - fmt "fmt" - github_com_babylonlabs_io_babylon_types "github.com/babylonlabs-io/babylon/types" - _ "github.com/cosmos/cosmos-proto" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// ResumeFinalityProposal is a gov Content type for resuming finality -// in case of finality is halting by jailing a list of sluggish finality -// providers from the halting height -type ResumeFinalityProposal struct { - Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // fp_pks is a list of finality provider public keys to jail - // the public key follows encoding in BIP-340 spec - FpPks []github_com_babylonlabs_io_babylon_types.BIP340PubKey `protobuf:"bytes,3,rep,name=fp_pks,json=fpPks,proto3,customtype=github.com/babylonlabs-io/babylon/types.BIP340PubKey" json:"fp_pks,omitempty"` - // halting_height is the height where the finality halting begins - HaltingHeight uint32 `protobuf:"varint,4,opt,name=halting_height,json=haltingHeight,proto3" json:"halting_height,omitempty"` -} - -func (m *ResumeFinalityProposal) Reset() { *m = ResumeFinalityProposal{} } -func (*ResumeFinalityProposal) ProtoMessage() {} -func (*ResumeFinalityProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_8c9af01aea56f783, []int{0} -} -func (m *ResumeFinalityProposal) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ResumeFinalityProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ResumeFinalityProposal.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 *ResumeFinalityProposal) XXX_Merge(src proto.Message) { - xxx_messageInfo_ResumeFinalityProposal.Merge(m, src) -} -func (m *ResumeFinalityProposal) XXX_Size() int { - return m.Size() -} -func (m *ResumeFinalityProposal) XXX_DiscardUnknown() { - xxx_messageInfo_ResumeFinalityProposal.DiscardUnknown(m) -} - -var xxx_messageInfo_ResumeFinalityProposal proto.InternalMessageInfo - -func init() { - proto.RegisterType((*ResumeFinalityProposal)(nil), "babylon.finality.v1.ResumeFinalityProposal") -} - -func init() { proto.RegisterFile("babylon/finality/v1/gov.proto", fileDescriptor_8c9af01aea56f783) } - -var fileDescriptor_8c9af01aea56f783 = []byte{ - // 342 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0x4a, 0x4c, 0xaa, - 0xcc, 0xc9, 0xcf, 0xd3, 0x4f, 0xcb, 0xcc, 0x4b, 0xcc, 0xc9, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, - 0x4f, 0xcf, 0x2f, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x86, 0x4a, 0xeb, 0xc1, 0xa4, - 0xf5, 0xca, 0x0c, 0xa5, 0x24, 0x93, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xe3, 0xc1, 0x4a, 0xf4, 0x21, - 0x1c, 0x88, 0x7a, 0x29, 0xc1, 0xc4, 0xdc, 0xcc, 0xbc, 0x7c, 0x7d, 0x30, 0x09, 0x15, 0x12, 0x49, - 0xcf, 0x4f, 0xcf, 0x87, 0x28, 0x05, 0xb1, 0x20, 0xa2, 0x4a, 0x1f, 0x18, 0xb9, 0xc4, 0x82, 0x52, - 0x8b, 0x4b, 0x73, 0x53, 0xdd, 0xa0, 0x26, 0x07, 0x14, 0xe5, 0x17, 0xe4, 0x17, 0x27, 0xe6, 0x08, - 0x89, 0x70, 0xb1, 0x96, 0x64, 0x96, 0xe4, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, - 0x38, 0x42, 0x0a, 0x5c, 0xdc, 0x29, 0xa9, 0xc5, 0xc9, 0x45, 0x99, 0x05, 0x25, 0x99, 0xf9, 0x79, - 0x12, 0x4c, 0x60, 0x39, 0x64, 0x21, 0x21, 0x7f, 0x2e, 0xb6, 0xb4, 0x82, 0xf8, 0x82, 0xec, 0x62, - 0x09, 0x66, 0x05, 0x66, 0x0d, 0x1e, 0x27, 0x8b, 0x5b, 0xf7, 0xe4, 0x4d, 0xd2, 0x33, 0x4b, 0x32, - 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0xa1, 0x5e, 0xc9, 0x49, 0x4c, 0x2a, 0xd6, 0xcd, 0xcc, - 0x87, 0x71, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xf5, 0x9c, 0x3c, 0x03, 0x8c, 0x4d, 0x0c, 0x02, - 0x4a, 0x93, 0xbc, 0x53, 0x2b, 0x83, 0x58, 0xd3, 0x0a, 0x02, 0xb2, 0x8b, 0x85, 0x54, 0xb9, 0xf8, - 0x32, 0x12, 0x73, 0x4a, 0x32, 0xf3, 0xd2, 0xe3, 0x33, 0x52, 0x33, 0xd3, 0x33, 0x4a, 0x24, 0x58, - 0x14, 0x18, 0x35, 0x78, 0x83, 0x78, 0xa1, 0xa2, 0x1e, 0x60, 0x41, 0x2b, 0xb5, 0x8e, 0x05, 0xf2, - 0x0c, 0x33, 0x16, 0xc8, 0x33, 0x9c, 0xda, 0xa2, 0x2b, 0x05, 0x0d, 0x0d, 0x50, 0x08, 0x96, 0x19, - 0x26, 0xa5, 0x96, 0x24, 0x1a, 0xea, 0x39, 0xe7, 0xe7, 0x95, 0xa4, 0xe6, 0x95, 0x38, 0xf9, 0x9c, - 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, - 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x11, 0x61, 0x57, 0x56, 0x20, 0x22, - 0x08, 0xec, 0xe0, 0x24, 0x36, 0x70, 0x38, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x7a, - 0xed, 0x7d, 0xc1, 0x01, 0x00, 0x00, -} - -func (m *ResumeFinalityProposal) 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 *ResumeFinalityProposal) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ResumeFinalityProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.HaltingHeight != 0 { - i = encodeVarintGov(dAtA, i, uint64(m.HaltingHeight)) - i-- - dAtA[i] = 0x20 - } - if len(m.FpPks) > 0 { - for iNdEx := len(m.FpPks) - 1; iNdEx >= 0; iNdEx-- { - { - size := m.FpPks[iNdEx].Size() - i -= size - if _, err := m.FpPks[iNdEx].MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGov(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - } - if len(m.Description) > 0 { - i -= len(m.Description) - copy(dAtA[i:], m.Description) - i = encodeVarintGov(dAtA, i, uint64(len(m.Description))) - i-- - dAtA[i] = 0x12 - } - if len(m.Title) > 0 { - i -= len(m.Title) - copy(dAtA[i:], m.Title) - i = encodeVarintGov(dAtA, i, uint64(len(m.Title))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintGov(dAtA []byte, offset int, v uint64) int { - offset -= sovGov(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *ResumeFinalityProposal) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Title) - if l > 0 { - n += 1 + l + sovGov(uint64(l)) - } - l = len(m.Description) - if l > 0 { - n += 1 + l + sovGov(uint64(l)) - } - if len(m.FpPks) > 0 { - for _, e := range m.FpPks { - l = e.Size() - n += 1 + l + sovGov(uint64(l)) - } - } - if m.HaltingHeight != 0 { - n += 1 + sovGov(uint64(m.HaltingHeight)) - } - return n -} - -func sovGov(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozGov(x uint64) (n int) { - return sovGov(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *ResumeFinalityProposal) 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 ErrIntOverflowGov - } - 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: ResumeFinalityProposal: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ResumeFinalityProposal: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGov - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGov - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Title = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGov - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGov - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Description = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FpPks", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthGov - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthGov - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var v github_com_babylonlabs_io_babylon_types.BIP340PubKey - m.FpPks = append(m.FpPks, v) - if err := m.FpPks[len(m.FpPks)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field HaltingHeight", wireType) - } - m.HaltingHeight = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGov - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.HaltingHeight |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipGov(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGov - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipGov(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGov - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGov - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowGov - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthGov - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupGov - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthGov - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthGov = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowGov = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupGov = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/finality/types/msg.go b/x/finality/types/msg.go index 177e9a817..d8c315f74 100644 --- a/x/finality/types/msg.go +++ b/x/finality/types/msg.go @@ -1,17 +1,19 @@ package types import ( - fmt "fmt" + "fmt" - "github.com/babylonlabs-io/babylon/crypto/eots" - bbn "github.com/babylonlabs-io/babylon/types" "github.com/cometbft/cometbft/crypto/merkle" "github.com/cometbft/cometbft/crypto/tmhash" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/babylonlabs-io/babylon/crypto/eots" + bbn "github.com/babylonlabs-io/babylon/types" ) // ensure that these message types implement the sdk.Msg interface var ( + _ sdk.Msg = &MsgResumeFinalityProposal{} _ sdk.Msg = &MsgUpdateParams{} _ sdk.Msg = &MsgAddFinalitySig{} _ sdk.Msg = &MsgCommitPubRandList{} diff --git a/x/finality/types/tx.pb.go b/x/finality/types/tx.pb.go index cbcf8834f..e7ab123fd 100644 --- a/x/finality/types/tx.pb.go +++ b/x/finality/types/tx.pb.go @@ -449,9 +449,9 @@ type MsgResumeFinalityProposal struct { // for AddressString instead of string, but the functionality is not yet implemented // in cosmos-proto Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - // fp_pks is a list of finality provider public keys to jail + // fp_pks_hex is a list of finality provider public keys to jail // the public key follows encoding in BIP-340 spec - FpPks []github_com_babylonlabs_io_babylon_types.BIP340PubKey `protobuf:"bytes,2,rep,name=fp_pks,json=fpPks,proto3,customtype=github.com/babylonlabs-io/babylon/types.BIP340PubKey" json:"fp_pks,omitempty"` + FpPksHex []string `protobuf:"bytes,2,rep,name=fp_pks_hex,json=fpPksHex,proto3" json:"fp_pks_hex,omitempty"` // halting_height is the height where the finality halting begins HaltingHeight uint32 `protobuf:"varint,3,opt,name=halting_height,json=haltingHeight,proto3" json:"halting_height,omitempty"` } @@ -496,6 +496,13 @@ func (m *MsgResumeFinalityProposal) GetAuthority() string { return "" } +func (m *MsgResumeFinalityProposal) GetFpPksHex() []string { + if m != nil { + return m.FpPksHex + } + return nil +} + func (m *MsgResumeFinalityProposal) GetHaltingHeight() uint32 { if m != nil { return m.HaltingHeight @@ -556,61 +563,61 @@ func init() { func init() { proto.RegisterFile("babylon/finality/v1/tx.proto", fileDescriptor_2dd6da066b6baf1d) } var fileDescriptor_2dd6da066b6baf1d = []byte{ - // 851 bytes of a gzipped FileDescriptorProto + // 858 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xcf, 0x6f, 0x1b, 0x45, - 0x14, 0xf6, 0xd6, 0x89, 0x43, 0xc6, 0x6e, 0xaa, 0x2e, 0x51, 0xeb, 0xb8, 0xc5, 0x76, 0x43, 0x41, - 0xa1, 0xa2, 0xbb, 0x24, 0xad, 0x02, 0x84, 0x53, 0x8c, 0x40, 0x45, 0xd4, 0xea, 0x6a, 0xdd, 0x5c, - 0x90, 0xd0, 0x6a, 0xf6, 0x87, 0x67, 0x07, 0x7b, 0x67, 0x86, 0x99, 0xd9, 0xa8, 0xbe, 0x55, 0x9c, - 0x38, 0x72, 0xe0, 0xc4, 0x89, 0x3f, 0xa1, 0x07, 0xae, 0x1c, 0x91, 0x7a, 0xac, 0xe0, 0x82, 0x82, - 0x14, 0xa1, 0xe4, 0xd0, 0x7f, 0x03, 0xed, 0xee, 0xf8, 0x57, 0xb2, 0x0b, 0x6e, 0x91, 0x72, 0xdb, - 0x99, 0xf7, 0xcd, 0xbc, 0xef, 0x7d, 0xdf, 0x7b, 0xa3, 0x05, 0x37, 0x5d, 0xe8, 0x8e, 0x86, 0x94, - 0x98, 0x7d, 0x4c, 0xe0, 0x10, 0xcb, 0x91, 0x79, 0xb8, 0x6d, 0xca, 0x27, 0x06, 0xe3, 0x54, 0x52, - 0xfd, 0x4d, 0x15, 0x35, 0xc6, 0x51, 0xe3, 0x70, 0xbb, 0xb1, 0x8e, 0x28, 0xa2, 0x69, 0xdc, 0x4c, - 0xbe, 0x32, 0x68, 0xe3, 0x2d, 0x19, 0x10, 0x3f, 0xe0, 0x11, 0x26, 0xd2, 0xf4, 0xf8, 0x88, 0x49, - 0x6a, 0x32, 0x4e, 0x69, 0x5f, 0x85, 0x37, 0x3c, 0x2a, 0x22, 0x2a, 0x9c, 0xec, 0x5c, 0xb6, 0x50, - 0xa1, 0xeb, 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9, 0xec, + 0xbe, 0x55, 0x7b, 0xfc, 0xfc, 0xb4, 0x6c, 0xbd, 0x38, 0x2d, 0x5b, 0xff, 0x9e, 0x96, 0xad, 0x9f, + 0xce, 0xca, 0xb9, 0x17, 0x67, 0xe5, 0xdc, 0x3f, 0x67, 0xe5, 0xdc, 0x37, 0xdb, 0xaf, 0x1e, 0xda, + 0xa3, 0xd1, 0x6f, 0x43, 0x3a, 0xbf, 0xc1, 0x62, 0xfa, 0xcf, 0xf0, 0xf0, 0xbf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x28, 0x5a, 0x21, 0x35, 0xf3, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1211,16 +1218,11 @@ func (m *MsgResumeFinalityProposal) MarshalToSizedBuffer(dAtA []byte) (int, erro i-- dAtA[i] = 0x18 } - if len(m.FpPks) > 0 { - for iNdEx := len(m.FpPks) - 1; iNdEx >= 0; iNdEx-- { - { - size := m.FpPks[iNdEx].Size() - i -= size - if _, err := m.FpPks[iNdEx].MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTx(dAtA, i, uint64(size)) - } + if len(m.FpPksHex) > 0 { + for iNdEx := len(m.FpPksHex) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.FpPksHex[iNdEx]) + copy(dAtA[i:], m.FpPksHex[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.FpPksHex[iNdEx]))) i-- dAtA[i] = 0x12 } @@ -1414,9 +1416,9 @@ func (m *MsgResumeFinalityProposal) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if len(m.FpPks) > 0 { - for _, e := range m.FpPks { - l = e.Size() + if len(m.FpPksHex) > 0 { + for _, s := range m.FpPksHex { + l = len(s) n += 1 + l + sovTx(uint64(l)) } } @@ -2436,9 +2438,9 @@ func (m *MsgResumeFinalityProposal) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FpPks", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field FpPksHex", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTx @@ -2448,26 +2450,23 @@ func (m *MsgResumeFinalityProposal) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthTx } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthTx } if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_babylonlabs_io_babylon_types.BIP340PubKey - m.FpPks = append(m.FpPks, v) - if err := m.FpPks[len(m.FpPks)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.FpPksHex = append(m.FpPksHex, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex case 3: if wireType != 0 {