From 1d706093e4cc0b43512be7445062155bf9c8a2a2 Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 14 Oct 2020 15:30:25 +0530 Subject: [PATCH 01/10] Refactor x/gov according to ADR 31 --- proto/cosmos/gov/v1beta1/tx.proto | 35 +- x/gov/handler.go | 123 +----- x/gov/keeper/msg_server.go | 126 +++++++ x/gov/types/tx.pb.go | 607 ++++++++++++++++++++++++++++-- 4 files changed, 739 insertions(+), 152 deletions(-) create mode 100644 x/gov/keeper/msg_server.go diff --git a/proto/cosmos/gov/v1beta1/tx.proto b/proto/cosmos/gov/v1beta1/tx.proto index 01e3bf2be05..487b6dc33ce 100644 --- a/proto/cosmos/gov/v1beta1/tx.proto +++ b/proto/cosmos/gov/v1beta1/tx.proto @@ -8,14 +8,26 @@ import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/gov/types"; -option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.stringer_all) = false; -option (gogoproto.goproto_getters_all) = false; + +// Msg defines the bank Msg service. +service Msg { + // SubmitProposal defines a method to create new proposal given a content. + rpc SubmitProposal(MsgSubmitProposal) returns (MsgSubmitProposalResponse); + + // Vote defines a method to add a vote on a specific proposal. + rpc Vote(MsgVote) returns (MsgVoteResponse); + + // Deposit defines a method to add deposit on a specific proposal. + rpc Deposit(MsgDeposit) returns (MsgDepositResponse); +} // MsgSubmitProposal defines an sdk.Msg type that supports submitting arbitrary // proposal Content. message MsgSubmitProposal { option (gogoproto.equal) = false; + option (gogoproto.goproto_stringer) = false; + option (gogoproto.stringer) = false; + option (gogoproto.goproto_getters) = false; google.protobuf.Any content = 1 [(cosmos_proto.accepts_interface) = "Content"]; repeated cosmos.base.v1beta1.Coin initial_deposit = 2 [ @@ -26,21 +38,36 @@ message MsgSubmitProposal { string proposer = 3; } +// MsgSubmitProposalResponse defines the Msg/SubmitProposal response type. +message MsgSubmitProposalResponse {} + // MsgVote defines a message to cast a vote. message MsgVote { option (gogoproto.equal) = false; + option (gogoproto.goproto_stringer) = false; + option (gogoproto.stringer) = false; + option (gogoproto.goproto_getters) = false; uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id", (gogoproto.moretags) = "yaml:\"proposal_id\""]; string voter = 2; VoteOption option = 3; } +// MsgVoteResponse defines the Msg/Vote response type. +message MsgVoteResponse {} + // MsgDeposit defines a message to submit a deposit to an existing proposal. message MsgDeposit { option (gogoproto.equal) = false; + option (gogoproto.goproto_stringer) = false; + option (gogoproto.stringer) = false; + option (gogoproto.goproto_getters) = false; uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id", (gogoproto.moretags) = "yaml:\"proposal_id\""]; string depositor = 2; repeated cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; -} \ No newline at end of file +} + +// MsgDepositResponse defines the Msg/Deposit response type. +message MsgDepositResponse {} diff --git a/x/gov/handler.go b/x/gov/handler.go index 5eacdaf10f0..ad05817c3d0 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -1,12 +1,6 @@ package gov import ( - "fmt" - "strconv" - - metrics "github.com/armon/go-metrics" - - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/gov/keeper" @@ -14,125 +8,28 @@ import ( ) // NewHandler creates an sdk.Handler for all the gov type messages -func NewHandler(keeper keeper.Keeper) sdk.Handler { +func NewHandler(k keeper.Keeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) + msgServer := keeper.NewMsgServerImpl(k) + switch msg := msg.(type) { case *types.MsgDeposit: - return handleMsgDeposit(ctx, keeper, msg) + res, err := msgServer.Deposit(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) case types.MsgSubmitProposalI: - return handleMsgSubmitProposal(ctx, keeper, msg) + msgProposal := msg.(*types.MsgSubmitProposal) + res, err := msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), msgProposal) + return sdk.WrapServiceResult(ctx, res, err) case *types.MsgVote: - return handleMsgVote(ctx, keeper, msg) + res, err := msgServer.Vote(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) } } } - -func handleMsgSubmitProposal(ctx sdk.Context, keeper keeper.Keeper, msg types.MsgSubmitProposalI) (*sdk.Result, error) { - proposal, err := keeper.SubmitProposal(ctx, msg.GetContent()) - if err != nil { - return nil, err - } - - defer telemetry.IncrCounter(1, types.ModuleName, "proposal") - - votingStarted, err := keeper.AddDeposit(ctx, proposal.ProposalId, msg.GetProposer(), msg.GetInitialDeposit()) - if err != nil { - return nil, err - } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.GetProposer().String()), - ), - ) - - submitEvent := sdk.NewEvent(types.EventTypeSubmitProposal, sdk.NewAttribute(types.AttributeKeyProposalType, msg.GetContent().ProposalType())) - if votingStarted { - submitEvent = submitEvent.AppendAttributes( - sdk.NewAttribute(types.AttributeKeyVotingPeriodStart, fmt.Sprintf("%d", proposal.ProposalId)), - ) - } - - ctx.EventManager().EmitEvent(submitEvent) - - return &sdk.Result{ - Data: types.GetProposalIDBytes(proposal.ProposalId), - Events: ctx.EventManager().ABCIEvents(), - }, nil -} - -func handleMsgDeposit(ctx sdk.Context, keeper keeper.Keeper, msg *types.MsgDeposit) (*sdk.Result, error) { - accAddr, err := sdk.AccAddressFromBech32(msg.Depositor) - if err != nil { - return nil, err - } - votingStarted, err := keeper.AddDeposit(ctx, msg.ProposalId, accAddr, msg.Amount) - if err != nil { - return nil, err - } - - defer telemetry.IncrCounterWithLabels( - []string{types.ModuleName, "deposit"}, - 1, - []metrics.Label{ - telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))), - }, - ) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Depositor), - ), - ) - - if votingStarted { - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeProposalDeposit, - sdk.NewAttribute(types.AttributeKeyVotingPeriodStart, fmt.Sprintf("%d", msg.ProposalId)), - ), - ) - } - - return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil -} - -func handleMsgVote(ctx sdk.Context, keeper keeper.Keeper, msg *types.MsgVote) (*sdk.Result, error) { - accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter) - if accErr != nil { - return nil, accErr - } - err := keeper.AddVote(ctx, msg.ProposalId, accAddr, msg.Option) - if err != nil { - return nil, err - } - - defer telemetry.IncrCounterWithLabels( - []string{types.ModuleName, "vote"}, - 1, - []metrics.Label{ - telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))), - }, - ) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Voter), - ), - ) - - return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil -} diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go new file mode 100644 index 00000000000..48df5e62dd7 --- /dev/null +++ b/x/gov/keeper/msg_server.go @@ -0,0 +1,126 @@ +package keeper + +import ( + "context" + "fmt" + "strconv" + + "github.com/armon/go-metrics" + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gov/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the bank MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +func (k msgServer) SubmitProposal(goCtx context.Context, msg *types.MsgSubmitProposal) (*types.MsgSubmitProposalResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + proposal, err := k.Keeper.SubmitProposal(ctx, msg.GetContent()) + if err != nil { + return nil, err + } + + defer telemetry.IncrCounter(1, types.ModuleName, "proposal") + + votingStarted, err := k.Keeper.AddDeposit(ctx, proposal.ProposalId, msg.GetProposer(), msg.GetInitialDeposit()) + if err != nil { + return nil, err + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeySender, msg.GetProposer().String()), + ), + ) + + submitEvent := sdk.NewEvent(types.EventTypeSubmitProposal, sdk.NewAttribute(types.AttributeKeyProposalType, msg.GetContent().ProposalType())) + if votingStarted { + submitEvent = submitEvent.AppendAttributes( + sdk.NewAttribute(types.AttributeKeyVotingPeriodStart, fmt.Sprintf("%d", proposal.ProposalId)), + ) + } + + ctx.EventManager().EmitEvent(submitEvent) + return &types.MsgSubmitProposalResponse{}, nil +} + +func (k msgServer) Vote(goCtx context.Context, msg *types.MsgVote) (*types.MsgVoteResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + accAddr, accErr := sdk.AccAddressFromBech32(msg.Voter) + if accErr != nil { + return nil, accErr + } + err := k.Keeper.AddVote(ctx, msg.ProposalId, accAddr, msg.Option) + if err != nil { + return nil, err + } + + defer telemetry.IncrCounterWithLabels( + []string{types.ModuleName, "vote"}, + 1, + []metrics.Label{ + telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))), + }, + ) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeySender, msg.Voter), + ), + ) + + return &types.MsgVoteResponse{}, nil +} + +func (k msgServer) Deposit(goCtx context.Context, msg *types.MsgDeposit) (*types.MsgDepositResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + accAddr, err := sdk.AccAddressFromBech32(msg.Depositor) + if err != nil { + return nil, err + } + votingStarted, err := k.Keeper.AddDeposit(ctx, msg.ProposalId, accAddr, msg.Amount) + if err != nil { + return nil, err + } + + defer telemetry.IncrCounterWithLabels( + []string{types.ModuleName, "deposit"}, + 1, + []metrics.Label{ + telemetry.NewLabel("proposal_id", strconv.Itoa(int(msg.ProposalId))), + }, + ) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(sdk.AttributeKeySender, msg.Depositor), + ), + ) + + if votingStarted { + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeProposalDeposit, + sdk.NewAttribute(types.AttributeKeyVotingPeriodStart, fmt.Sprintf("%d", msg.ProposalId)), + ), + ) + } + + return &types.MsgDepositResponse{}, nil +} diff --git a/x/gov/types/tx.pb.go b/x/gov/types/tx.pb.go index a16cc62aa5f..f06e018b171 100644 --- a/x/gov/types/tx.pb.go +++ b/x/gov/types/tx.pb.go @@ -4,13 +4,18 @@ package types import ( + context "context" fmt "fmt" types "github.com/cosmos/cosmos-sdk/codec/types" + grpc1 "github.com/gogo/protobuf/grpc" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types1 "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "github.com/regen-network/cosmos-proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" io "io" math "math" math_bits "math/bits" @@ -67,6 +72,43 @@ func (m *MsgSubmitProposal) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSubmitProposal proto.InternalMessageInfo +// MsgSubmitProposalResponse defines the Msg/SubmitProposal response type. +type MsgSubmitProposalResponse struct { +} + +func (m *MsgSubmitProposalResponse) Reset() { *m = MsgSubmitProposalResponse{} } +func (m *MsgSubmitProposalResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSubmitProposalResponse) ProtoMessage() {} +func (*MsgSubmitProposalResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3c053992595e3dce, []int{1} +} +func (m *MsgSubmitProposalResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSubmitProposalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSubmitProposalResponse.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 *MsgSubmitProposalResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSubmitProposalResponse.Merge(m, src) +} +func (m *MsgSubmitProposalResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSubmitProposalResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSubmitProposalResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSubmitProposalResponse proto.InternalMessageInfo + // MsgVote defines a message to cast a vote. type MsgVote struct { ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id" yaml:"proposal_id"` @@ -77,7 +119,7 @@ type MsgVote struct { func (m *MsgVote) Reset() { *m = MsgVote{} } func (*MsgVote) ProtoMessage() {} func (*MsgVote) Descriptor() ([]byte, []int) { - return fileDescriptor_3c053992595e3dce, []int{1} + return fileDescriptor_3c053992595e3dce, []int{2} } func (m *MsgVote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -106,6 +148,43 @@ func (m *MsgVote) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVote proto.InternalMessageInfo +// MsgVoteResponse defines the Msg/Vote response type. +type MsgVoteResponse struct { +} + +func (m *MsgVoteResponse) Reset() { *m = MsgVoteResponse{} } +func (m *MsgVoteResponse) String() string { return proto.CompactTextString(m) } +func (*MsgVoteResponse) ProtoMessage() {} +func (*MsgVoteResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3c053992595e3dce, []int{3} +} +func (m *MsgVoteResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgVoteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgVoteResponse.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 *MsgVoteResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgVoteResponse.Merge(m, src) +} +func (m *MsgVoteResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgVoteResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgVoteResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgVoteResponse proto.InternalMessageInfo + // MsgDeposit defines a message to submit a deposit to an existing proposal. type MsgDeposit struct { ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id" yaml:"proposal_id"` @@ -116,7 +195,7 @@ type MsgDeposit struct { func (m *MsgDeposit) Reset() { *m = MsgDeposit{} } func (*MsgDeposit) ProtoMessage() {} func (*MsgDeposit) Descriptor() ([]byte, []int) { - return fileDescriptor_3c053992595e3dce, []int{2} + return fileDescriptor_3c053992595e3dce, []int{4} } func (m *MsgDeposit) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -145,48 +224,251 @@ func (m *MsgDeposit) XXX_DiscardUnknown() { var xxx_messageInfo_MsgDeposit proto.InternalMessageInfo +// MsgDepositResponse defines the Msg/Deposit response type. +type MsgDepositResponse struct { +} + +func (m *MsgDepositResponse) Reset() { *m = MsgDepositResponse{} } +func (m *MsgDepositResponse) String() string { return proto.CompactTextString(m) } +func (*MsgDepositResponse) ProtoMessage() {} +func (*MsgDepositResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_3c053992595e3dce, []int{5} +} +func (m *MsgDepositResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgDepositResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgDepositResponse.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 *MsgDepositResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgDepositResponse.Merge(m, src) +} +func (m *MsgDepositResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgDepositResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgDepositResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgDepositResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSubmitProposal)(nil), "cosmos.gov.v1beta1.MsgSubmitProposal") + proto.RegisterType((*MsgSubmitProposalResponse)(nil), "cosmos.gov.v1beta1.MsgSubmitProposalResponse") proto.RegisterType((*MsgVote)(nil), "cosmos.gov.v1beta1.MsgVote") + proto.RegisterType((*MsgVoteResponse)(nil), "cosmos.gov.v1beta1.MsgVoteResponse") proto.RegisterType((*MsgDeposit)(nil), "cosmos.gov.v1beta1.MsgDeposit") + proto.RegisterType((*MsgDepositResponse)(nil), "cosmos.gov.v1beta1.MsgDepositResponse") } func init() { proto.RegisterFile("cosmos/gov/v1beta1/tx.proto", fileDescriptor_3c053992595e3dce) } var fileDescriptor_3c053992595e3dce = []byte{ - // 498 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x53, 0x31, 0x8b, 0x13, 0x41, - 0x14, 0xde, 0x4d, 0xce, 0xc4, 0x9b, 0xc0, 0x89, 0x43, 0x90, 0x5c, 0x3c, 0x66, 0xc3, 0x82, 0x90, - 0xe6, 0x66, 0xbd, 0x08, 0x16, 0x67, 0x65, 0x4e, 0x04, 0x85, 0xa8, 0xac, 0x60, 0x61, 0x13, 0x76, - 0x37, 0xeb, 0x38, 0x98, 0x9d, 0xb7, 0x64, 0x26, 0xe1, 0xd2, 0x09, 0xf6, 0xe2, 0x4f, 0xb0, 0xb1, - 0xb1, 0xf6, 0x47, 0x04, 0xab, 0x2b, 0xaf, 0x31, 0x7a, 0x49, 0x23, 0x96, 0xf7, 0x0b, 0x64, 0x67, - 0x66, 0xcf, 0x43, 0x45, 0x11, 0xac, 0x92, 0xf7, 0xbe, 0xf9, 0xbe, 0xf9, 0xbe, 0xf7, 0x66, 0xd1, - 0xd5, 0x04, 0x64, 0x06, 0x32, 0x60, 0x30, 0x0b, 0x66, 0x7b, 0x71, 0xaa, 0xa2, 0xbd, 0x40, 0x1d, - 0xd2, 0x7c, 0x02, 0x0a, 0x30, 0x36, 0x20, 0x65, 0x30, 0xa3, 0x16, 0x6c, 0x13, 0x4b, 0x88, 0x23, - 0x99, 0x9e, 0x31, 0x12, 0xe0, 0xc2, 0x70, 0xda, 0x3b, 0xbf, 0x11, 0x2c, 0xf8, 0x06, 0xdd, 0x36, - 0xe8, 0x50, 0x57, 0x81, 0x95, 0x37, 0x50, 0x93, 0x01, 0x03, 0xd3, 0x2f, 0xfe, 0x95, 0x04, 0x06, - 0xc0, 0xc6, 0x69, 0xa0, 0xab, 0x78, 0xfa, 0x2c, 0x88, 0xc4, 0xdc, 0x40, 0xfe, 0xab, 0x0a, 0xba, - 0x3c, 0x90, 0xec, 0xf1, 0x34, 0xce, 0xb8, 0x7a, 0x34, 0x81, 0x1c, 0x64, 0x34, 0xc6, 0xb7, 0x50, - 0x3d, 0x01, 0xa1, 0x52, 0xa1,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x9b, 0xa8, 0x06, 0xb9, 0xe2, 0x20, 0xb4, 0x93, 0xad, - 0x1e, 0xa1, 0xbf, 0x3e, 0x0f, 0x5a, 0xf8, 0x78, 0xa8, 0x4f, 0x85, 0xf6, 0xb4, 0xf5, 0xf9, 0xc9, - 0x45, 0x68, 0x20, 0x59, 0x19, 0xec, 0x7f, 0x59, 0xdd, 0x41, 0x9b, 0x76, 0xd0, 0x50, 0xda, 0xfd, - 0xd1, 0xc0, 0x09, 0xaa, 0x45, 0x19, 0x4c, 0x85, 0x6a, 0x55, 0xff, 0xb6, 0xc5, 0xeb, 0xc5, 0x16, - 0xff, 0x69, 0x57, 0x56, 0xda, 0xe4, 0xeb, 0x3f, 0x58, 0x9c, 0x10, 0xe7, 0xf8, 0x84, 0x38, 0x2f, - 0x57, 0xc4, 0x59, 0xac, 0x88, 0x7b, 0xb4, 0x22, 0xee, 0x97, 0x15, 0x71, 0xdf, 0xac, 0x89, 0x73, - 0xb4, 0x26, 0xce, 0xf1, 0x9a, 0x38, 0x4f, 0xff, 0xac, 0x7e, 0xa8, 0xbf, 0x1a, 0x7d, 0x47, 0x5c, - 0xd3, 0xcf, 0xf5, 0xc6, 0xf7, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x32, 0xb4, 0xbb, 0xa1, 0x03, - 0x00, 0x00, + // 584 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xbf, 0x6f, 0xd3, 0x50, + 0x10, 0xb6, 0x93, 0x92, 0xd0, 0x17, 0x29, 0xa5, 0x4f, 0x11, 0x4a, 0x9c, 0xca, 0x8e, 0x8c, 0x8a, + 0xb2, 0xc4, 0xa6, 0x41, 0x62, 0x28, 0x13, 0x29, 0x42, 0x80, 0x14, 0x01, 0x46, 0x62, 0x60, 0x89, + 0xec, 0xc4, 0x35, 0x16, 0x89, 0xcf, 0xca, 0x7b, 0x89, 0x9a, 0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 0x43, 0x9b, 0x68, 0x43, 0xb4, 0x3c, 0xb7, 0xf1, + 0x4b, 0x45, 0xa8, 0x49, 0x02, 0x39, 0xa0, 0x8b, 0x72, 0xb2, 0x85, 0xd6, 0xc5, 0xc2, 0x40, 0xba, + 0x39, 0x49, 0xe0, 0x36, 0xca, 0xb8, 0x3d, 0x18, 0x44, 0xb4, 0x98, 0xfe, 0xdb, 0x35, 0xdc, 0x48, + 0xae, 0xe1, 0xbf, 0x76, 0x2e, 0xa4, 0x97, 0xd8, 0x2f, 0x20, 0x7c, 0x62, 0x55, 0x4e, 0xa0, 0xfe, + 0x26, 0x85, 0xd2, 0x4d, 0x12, 0xe0, 0x7d, 0x94, 0x3f, 0x73, 0xfb, 0xdb, 0xcb, 0x06, 0xbd, 0x70, + 0x11, 0x5a, 0xed, 0x9f, 0xca, 0xe4, 0xf7, 0xf0, 0x7d, 0xb4, 0xc6, 0x8e, 0xa6, 0x7c, 0x0e, 0x2d, + 0x01, 0xb5, 0x6b, 0x2b, 0xc0, 0xb9, 0xd2, 0x13, 0x94, 0x95, 0x7b, 0xd3, 0xcf, 0xa9, 0x17, 0xb8, + 0x76, 0x7d, 0x35, 0x2e, 0x25, 0x1b, 0x8d, 0xc3, 0xa9, 0xae, 0x1e, 0x4d, 0x75, 0xf5, 0xc7, 0x54, + 0x57, 0xdf, 0xcf, 0x74, 0xe5, 0x68, 0xa6, 0x2b, 0x5f, 0x67, 0xba, 0xf2, 0x7c, 0xf5, 0x02, 0x0e, + 0xd8, 0x03, 0xc5, 0xd6, 0xe0, 0x65, 0xd8, 0xcb, 0x70, 0xf3, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf1, 0xed, 0x36, 0xa7, 0x0c, 0x05, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // SubmitProposal defines a method to create new proposal given a content. + SubmitProposal(ctx context.Context, in *MsgSubmitProposal, opts ...grpc.CallOption) (*MsgSubmitProposalResponse, error) + // Vote defines a method to add a vote on a specific proposal. + Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error) + // Deposit defines a method to add deposit on a specific proposal. + Deposit(ctx context.Context, in *MsgDeposit, opts ...grpc.CallOption) (*MsgDepositResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) SubmitProposal(ctx context.Context, in *MsgSubmitProposal, opts ...grpc.CallOption) (*MsgSubmitProposalResponse, error) { + out := new(MsgSubmitProposalResponse) + err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta1.Msg/SubmitProposal", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Vote(ctx context.Context, in *MsgVote, opts ...grpc.CallOption) (*MsgVoteResponse, error) { + out := new(MsgVoteResponse) + err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta1.Msg/Vote", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Deposit(ctx context.Context, in *MsgDeposit, opts ...grpc.CallOption) (*MsgDepositResponse, error) { + out := new(MsgDepositResponse) + err := c.cc.Invoke(ctx, "/cosmos.gov.v1beta1.Msg/Deposit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // SubmitProposal defines a method to create new proposal given a content. + SubmitProposal(context.Context, *MsgSubmitProposal) (*MsgSubmitProposalResponse, error) + // Vote defines a method to add a vote on a specific proposal. + Vote(context.Context, *MsgVote) (*MsgVoteResponse, error) + // Deposit defines a method to add deposit on a specific proposal. + Deposit(context.Context, *MsgDeposit) (*MsgDepositResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) SubmitProposal(ctx context.Context, req *MsgSubmitProposal) (*MsgSubmitProposalResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SubmitProposal not implemented") +} +func (*UnimplementedMsgServer) Vote(ctx context.Context, req *MsgVote) (*MsgVoteResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Vote not implemented") +} +func (*UnimplementedMsgServer) Deposit(ctx context.Context, req *MsgDeposit) (*MsgDepositResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Deposit not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_SubmitProposal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSubmitProposal) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SubmitProposal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.gov.v1beta1.Msg/SubmitProposal", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SubmitProposal(ctx, req.(*MsgSubmitProposal)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Vote_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgVote) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Vote(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.gov.v1beta1.Msg/Vote", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Vote(ctx, req.(*MsgVote)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Deposit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgDeposit) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Deposit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.gov.v1beta1.Msg/Deposit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Deposit(ctx, req.(*MsgDeposit)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.gov.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SubmitProposal", + Handler: _Msg_SubmitProposal_Handler, + }, + { + MethodName: "Vote", + Handler: _Msg_Vote_Handler, + }, + { + MethodName: "Deposit", + Handler: _Msg_Deposit_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/gov/v1beta1/tx.proto", } func (m *MsgSubmitProposal) Marshal() (dAtA []byte, err error) { @@ -245,6 +527,29 @@ func (m *MsgSubmitProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgSubmitProposalResponse) 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 *MsgSubmitProposalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSubmitProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *MsgVote) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -285,6 +590,29 @@ func (m *MsgVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgVoteResponse) 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 *MsgVoteResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgVoteResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *MsgDeposit) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -334,6 +662,29 @@ func (m *MsgDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgDepositResponse) 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 *MsgDepositResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgDepositResponse) 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 @@ -368,6 +719,15 @@ func (m *MsgSubmitProposal) Size() (n int) { return n } +func (m *MsgSubmitProposalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgVote) Size() (n int) { if m == nil { return 0 @@ -387,6 +747,15 @@ func (m *MsgVote) Size() (n int) { return n } +func (m *MsgVoteResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgDeposit) Size() (n int) { if m == nil { return 0 @@ -409,6 +778,15 @@ func (m *MsgDeposit) Size() (n int) { return n } +func (m *MsgDepositResponse) 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 } @@ -570,6 +948,59 @@ func (m *MsgSubmitProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgSubmitProposalResponse) 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: MsgSubmitProposalResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSubmitProposalResponse: 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 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgVote) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -693,6 +1124,59 @@ func (m *MsgVote) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgVoteResponse) 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: MsgVoteResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgVoteResponse: 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 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgDeposit) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -831,6 +1315,59 @@ func (m *MsgDeposit) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgDepositResponse) 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: MsgDepositResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgDepositResponse: 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 { + return ErrInvalidLengthTx + } + if (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 47874c6db297bea9ef50bb9862663360d075edee Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 14 Oct 2020 16:57:17 +0530 Subject: [PATCH 02/10] fix tests --- proto/cosmos/gov/v1beta1/tx.proto | 4 +- x/gov/abci_test.go | 13 +++- x/gov/keeper/msg_server.go | 4 +- x/gov/types/tx.pb.go | 111 ++++++++++++++++++++---------- 4 files changed, 90 insertions(+), 42 deletions(-) diff --git a/proto/cosmos/gov/v1beta1/tx.proto b/proto/cosmos/gov/v1beta1/tx.proto index 487b6dc33ce..5c0560757d2 100644 --- a/proto/cosmos/gov/v1beta1/tx.proto +++ b/proto/cosmos/gov/v1beta1/tx.proto @@ -39,7 +39,9 @@ message MsgSubmitProposal { } // MsgSubmitProposalResponse defines the Msg/SubmitProposal response type. -message MsgSubmitProposalResponse {} +message MsgSubmitProposalResponse { + uint64 proposal_id = 1 [(gogoproto.jsontag) = "proposal_id", (gogoproto.moretags) = "yaml:\"proposal_id\""]; +} // MsgVote defines a message to cast a vote. message MsgVote { diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index bfe5ceac544..70a172ee1b7 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/golang/protobuf/proto" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -172,7 +173,11 @@ func TestTickPassedDepositPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - proposalID := types.GetProposalIDFromBytes(res.Data) + var proposalData types.MsgSubmitProposalResponse + err = proto.Unmarshal(res.Data, &proposalData) + require.NoError(t, err) + + proposalID := proposalData.ProposalId inactiveQueue = app.GovKeeper.InactiveProposalQueueIterator(ctx, ctx.BlockHeader().Time) require.False(t, inactiveQueue.Valid()) @@ -224,7 +229,11 @@ func TestTickPassedVotingPeriod(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - proposalID := types.GetProposalIDFromBytes(res.Data) + var proposalData types.MsgSubmitProposalResponse + err = proto.Unmarshal(res.Data, &proposalData) + require.NoError(t, err) + + proposalID := proposalData.ProposalId newHeader := ctx.BlockHeader() newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second) diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 48df5e62dd7..89afb3d7ff3 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -53,7 +53,9 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *types.MsgSubmitPro } ctx.EventManager().EmitEvent(submitEvent) - return &types.MsgSubmitProposalResponse{}, nil + return &types.MsgSubmitProposalResponse{ + ProposalId: proposal.ProposalId, + }, nil } func (k msgServer) Vote(goCtx context.Context, msg *types.MsgVote) (*types.MsgVoteResponse, error) { diff --git a/x/gov/types/tx.pb.go b/x/gov/types/tx.pb.go index f06e018b171..c1391e12efc 100644 --- a/x/gov/types/tx.pb.go +++ b/x/gov/types/tx.pb.go @@ -74,6 +74,7 @@ var xxx_messageInfo_MsgSubmitProposal proto.InternalMessageInfo // MsgSubmitProposalResponse defines the Msg/SubmitProposal response type. type MsgSubmitProposalResponse struct { + ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id" yaml:"proposal_id"` } func (m *MsgSubmitProposalResponse) Reset() { *m = MsgSubmitProposalResponse{} } @@ -109,6 +110,13 @@ func (m *MsgSubmitProposalResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSubmitProposalResponse proto.InternalMessageInfo +func (m *MsgSubmitProposalResponse) GetProposalId() uint64 { + if m != nil { + return m.ProposalId + } + return 0 +} + // MsgVote defines a message to cast a vote. type MsgVote struct { ProposalId uint64 `protobuf:"varint,1,opt,name=proposal_id,json=proposalId,proto3" json:"proposal_id" yaml:"proposal_id"` @@ -273,44 +281,44 @@ func init() { func init() { proto.RegisterFile("cosmos/gov/v1beta1/tx.proto", fileDescriptor_3c053992595e3dce) } var fileDescriptor_3c053992595e3dce = []byte{ - // 584 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xbf, 0x6f, 0xd3, 0x50, - 0x10, 0xb6, 0x93, 0x92, 0xd0, 0x17, 0x29, 0xa5, 0x4f, 0x11, 0x4a, 0x9c, 0xca, 0x8e, 0x8c, 0x8a, - 0xb2, 0xc4, 0xa6, 0x41, 0x62, 0x28, 0x13, 0x29, 0x42, 0x80, 0x14, 0x01, 0x46, 0x62, 0x60, 0x89, - 0xec, 0xc4, 0x35, 0x16, 0x89, 0xcf, 0xca, 0x7b, 0x89, 0x9a, 0x8d, 0x11, 0x31, 0x00, 0x23, 0x63, - 0x66, 0x36, 0x24, 0xfe, 0x88, 0x8a, 0xa9, 0x23, 0x03, 0x0a, 0x28, 0x59, 0x80, 0xb1, 0x7f, 0x01, - 0xf2, 0xfb, 0x91, 0x56, 0x4d, 0x1a, 0x40, 0xea, 0x94, 0xdc, 0x7d, 0xf7, 0x7d, 0xbe, 0xef, 0xee, - 0xf4, 0x50, 0xb9, 0x0d, 0xa4, 0x07, 0xc4, 0x0e, 0x60, 0x68, 0x0f, 0x77, 0x3c, 0x9f, 0xba, 0x3b, - 0x36, 0x3d, 0xb0, 0xe2, 0x3e, 0x50, 0xc0, 0x98, 0x83, 0x56, 0x00, 0x43, 0x4b, 0x80, 0x9a, 0x2e, - 0x08, 0x9e, 0x4b, 0xfc, 0x39, 0xa3, 0x0d, 0x61, 0xc4, 0x39, 0xda, 0xd6, 0x12, 0xc1, 0x84, 0xcf, - 0xd1, 0x12, 0x47, 0x5b, 0x2c, 0xb2, 0x85, 0x3c, 0x87, 0x0a, 0x01, 0x04, 0xc0, 0xf3, 0xc9, 0x3f, - 0x49, 0x08, 0x00, 0x82, 0xae, 0x6f, 0xb3, 0xc8, 0x1b, 0xec, 0xdb, 0x6e, 0x34, 0xe2, 0x90, 0xf9, - 0x2e, 0x85, 0x36, 0x9b, 0x24, 0x78, 0x3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0xcf, 0x74, 0xe5, 0x68, 0xa6, 0x2b, 0x5f, 0x67, 0xba, 0xf2, 0x7c, 0xf5, 0x02, 0x0e, - 0xd8, 0x03, 0xc5, 0xd6, 0xe0, 0x65, 0xd8, 0xcb, 0x70, 0xf3, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xf1, 0xed, 0x36, 0xa7, 0x0c, 0x05, 0x00, 0x00, + // 586 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0xb6, 0x93, 0xd2, 0xd0, 0x8b, 0x94, 0xd2, 0x53, 0x84, 0x12, 0xb7, 0xb2, 0x23, 0xa3, 0xa2, + 0x2c, 0xb1, 0x69, 0x90, 0x18, 0xca, 0x44, 0x8a, 0x10, 0x20, 0x45, 0x80, 0x91, 0x18, 0x58, 0x22, + 0xdb, 0x71, 0x8d, 0x45, 0xe2, 0x67, 0xe5, 0x2e, 0x51, 0xb3, 0x31, 0x22, 0x06, 0x60, 0x64, 0xcc, + 0xcc, 0x86, 0xc4, 0x1f, 0x51, 0x31, 0x75, 0x64, 0x40, 0x01, 0x25, 0x0b, 0x30, 0xf6, 0x2f, 0x40, + 0xbe, 0x1f, 0x69, 0xd5, 0xa4, 0x01, 0xa4, 0x4e, 0xc9, 0x7b, 0xdf, 0xfb, 0x3e, 0xdd, 0xf7, 0xdd, + 0xf3, 0xa1, 0x4d, 0x1f, 0x48, 0x17, 0x88, 0x1d, 0xc2, 0xc0, 0x1e, 0xec, 0x78, 0x01, 0x75, 0x77, + 0x6c, 0x7a, 0x60, 0x25, 0x3d, 0xa0, 0x80, 0x31, 0x07, 0xad, 0x10, 0x06, 0x96, 0x00, 0x35, 0x5d, + 0x10, 0x3c, 0x97, 0x04, 0x33, 0x86, 0x0f, 0x51, 0xcc, 0x39, 0xda, 0xd6, 0x02, 0xc1, 0x94, 0xc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xb4, 0xc2, 0x96, 0x66, 0xf3, + 0x1c, 0x5a, 0x0a, 0x6a, 0xd7, 0x96, 0x80, 0x33, 0xa5, 0x27, 0x28, 0x27, 0xef, 0x4d, 0x3f, 0x67, + 0x5e, 0xe0, 0xda, 0xf5, 0xe5, 0xb8, 0x94, 0x6c, 0x34, 0x0e, 0x27, 0xba, 0x7a, 0x34, 0xd1, 0xd5, + 0x1f, 0x13, 0x5d, 0x7d, 0x3f, 0xd5, 0x95, 0xa3, 0xa9, 0xae, 0x7c, 0x9d, 0xea, 0xca, 0xf3, 0xe5, + 0x17, 0x70, 0xc0, 0x1e, 0x3a, 0x76, 0x0d, 0xde, 0x2a, 0x7b, 0x61, 0x6e, 0xfe, 0x09, 0x00, 0x00, + 0xff, 0xff, 0x7f, 0x09, 0x3f, 0x57, 0x54, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -547,6 +555,11 @@ func (m *MsgSubmitProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l + if m.ProposalId != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ProposalId)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -725,6 +738,9 @@ func (m *MsgSubmitProposalResponse) Size() (n int) { } var l int _ = l + if m.ProposalId != 0 { + n += 1 + sovTx(uint64(m.ProposalId)) + } return n } @@ -977,6 +993,25 @@ func (m *MsgSubmitProposalResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgSubmitProposalResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ProposalId", wireType) + } + m.ProposalId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ProposalId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From 13e6314bf8512d245c5579f47ebfafcf9280fe4e Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 14 Oct 2020 19:38:38 +0530 Subject: [PATCH 03/10] Refactor x/crisis according to ADR 031 --- proto/cosmos/crisis/v1beta1/tx.proto | 8 + x/crisis/handler.go | 70 +-------- x/crisis/keeper/msg_server.go | 77 +++++++++ x/crisis/types/tx.pb.go | 226 ++++++++++++++++++++++++++- 4 files changed, 306 insertions(+), 75 deletions(-) create mode 100644 x/crisis/keeper/msg_server.go diff --git a/proto/cosmos/crisis/v1beta1/tx.proto b/proto/cosmos/crisis/v1beta1/tx.proto index 5c77a6a491a..f99c8b1176a 100644 --- a/proto/cosmos/crisis/v1beta1/tx.proto +++ b/proto/cosmos/crisis/v1beta1/tx.proto @@ -5,6 +5,11 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/crisis/types"; import "gogoproto/gogo.proto"; +service Msg { + // VerifyInvariant defines a method to verify a particular invariance. + rpc VerifyInvariant(MsgVerifyInvariant) returns (MsgVerifyInvariantResponse); +} + // MsgVerifyInvariant represents a message to verify a particular invariance. message MsgVerifyInvariant { option (gogoproto.equal) = false; @@ -14,3 +19,6 @@ message MsgVerifyInvariant { string invariant_module_name = 2 [(gogoproto.moretags) = "yaml:\"invariant_module_name\""]; string invariant_route = 3 [(gogoproto.moretags) = "yaml:\"invariant_route\""]; } + +// MsgVerifyInvariantResponse defines the Msg/VerifyInvariant response type. +message MsgVerifyInvariantResponse { } diff --git a/x/crisis/handler.go b/x/crisis/handler.go index eee27a95c11..3a70834a974 100644 --- a/x/crisis/handler.go +++ b/x/crisis/handler.go @@ -16,77 +16,11 @@ func NewHandler(k keeper.Keeper) sdk.Handler { switch msg := msg.(type) { case *types.MsgVerifyInvariant: - return handleMsgVerifyInvariant(ctx, msg, k) + res, err := k.VerifyInvariant(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) default: return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized crisis message type: %T", msg) } } } - -func handleMsgVerifyInvariant(ctx sdk.Context, msg *types.MsgVerifyInvariant, k keeper.Keeper) (*sdk.Result, error) { - constantFee := sdk.NewCoins(k.GetConstantFee(ctx)) - - sender, err := sdk.AccAddressFromBech32(msg.Sender) - if err != nil { - return nil, err - } - if err := k.SendCoinsFromAccountToFeeCollector(ctx, sender, constantFee); err != nil { - return nil, err - } - - // use a cached context to avoid gas costs during invariants - cacheCtx, _ := ctx.CacheContext() - - found := false - msgFullRoute := msg.FullInvariantRoute() - - var res string - var stop bool - for _, invarRoute := range k.Routes() { - if invarRoute.FullRoute() == msgFullRoute { - res, stop = invarRoute.Invar(cacheCtx) - found = true - - break - } - } - - if !found { - return nil, types.ErrUnknownInvariant - } - - if stop { - // NOTE currently, because the chain halts here, this transaction will never be included - // in the blockchain thus the constant fee will have never been deducted. Thus no - // refund is required. - - // TODO uncomment the following code block with implementation of the circuit breaker - //// refund constant fee - //err := k.distrKeeper.DistributeFromFeePool(ctx, constantFee, msg.Sender) - //if err != nil { - //// if there are insufficient coins to refund, log the error, - //// but still halt the chain. - //logger := ctx.Logger().With("module", "x/crisis") - //logger.Error(fmt.Sprintf( - //"WARNING: insufficient funds to allocate to sender from fee pool, err: %s", err)) - //} - - // TODO replace with circuit breaker - panic(res) - } - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeInvariant, - sdk.NewAttribute(types.AttributeKeyRoute, msg.InvariantRoute), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCrisis), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), - ), - }) - - return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil -} diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go new file mode 100644 index 00000000000..b25a3e70e88 --- /dev/null +++ b/x/crisis/keeper/msg_server.go @@ -0,0 +1,77 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/crisis/types" +) + +var _ types.MsgServer = Keeper{} + +func (k Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvariant) (*types.MsgVerifyInvariantResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + constantFee := sdk.NewCoins(k.GetConstantFee(ctx)) + + sender, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, err + } + if err := k.SendCoinsFromAccountToFeeCollector(ctx, sender, constantFee); err != nil { + return nil, err + } + + // use a cached context to avoid gas costs during invariants + cacheCtx, _ := ctx.CacheContext() + + found := false + msgFullRoute := msg.FullInvariantRoute() + + var res string + var stop bool + for _, invarRoute := range k.Routes() { + if invarRoute.FullRoute() == msgFullRoute { + res, stop = invarRoute.Invar(cacheCtx) + found = true + + break + } + } + + if !found { + return nil, types.ErrUnknownInvariant + } + + if stop { + // NOTE currently, because the chain halts here, this transaction will never be included + // in the blockchain thus the constant fee will have never been deducted. Thus no + // refund is required. + + // TODO uncomment the following code block with implementation of the circuit breaker + //// refund constant fee + //err := k.distrKeeper.DistributeFromFeePool(ctx, constantFee, msg.Sender) + //if err != nil { + //// if there are insufficient coins to refund, log the error, + //// but still halt the chain. + //logger := ctx.Logger().With("module", "x/crisis") + //logger.Error(fmt.Sprintf( + //"WARNING: insufficient funds to allocate to sender from fee pool, err: %s", err)) + //} + + // TODO replace with circuit breaker + panic(res) + } + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeInvariant, + sdk.NewAttribute(types.AttributeKeyRoute, msg.InvariantRoute), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCrisis), + sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), + ), + }) + return &types.MsgVerifyInvariantResponse{}, nil +} diff --git a/x/crisis/types/tx.pb.go b/x/crisis/types/tx.pb.go index 64102a50d06..7fed79516c1 100644 --- a/x/crisis/types/tx.pb.go +++ b/x/crisis/types/tx.pb.go @@ -4,9 +4,14 @@ package types import ( + context "context" fmt "fmt" _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" io "io" math "math" math_bits "math/bits" @@ -63,14 +68,52 @@ func (m *MsgVerifyInvariant) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVerifyInvariant proto.InternalMessageInfo +// MsgVerifyInvariantResponse defines the Msg/VerifyInvariant response type. +type MsgVerifyInvariantResponse struct { +} + +func (m *MsgVerifyInvariantResponse) Reset() { *m = MsgVerifyInvariantResponse{} } +func (m *MsgVerifyInvariantResponse) String() string { return proto.CompactTextString(m) } +func (*MsgVerifyInvariantResponse) ProtoMessage() {} +func (*MsgVerifyInvariantResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_61276163172fe867, []int{1} +} +func (m *MsgVerifyInvariantResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgVerifyInvariantResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgVerifyInvariantResponse.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 *MsgVerifyInvariantResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgVerifyInvariantResponse.Merge(m, src) +} +func (m *MsgVerifyInvariantResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgVerifyInvariantResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgVerifyInvariantResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgVerifyInvariantResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgVerifyInvariant)(nil), "cosmos.crisis.v1beta1.MsgVerifyInvariant") + proto.RegisterType((*MsgVerifyInvariantResponse)(nil), "cosmos.crisis.v1beta1.MsgVerifyInvariantResponse") } func init() { proto.RegisterFile("cosmos/crisis/v1beta1/tx.proto", fileDescriptor_61276163172fe867) } var fileDescriptor_61276163172fe867 = []byte{ - // 276 bytes of a gzipped FileDescriptorProto + // 318 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4b, 0xce, 0x2f, 0xce, 0xcd, 0x2f, 0xd6, 0x4f, 0x2e, 0xca, 0x2c, 0xce, 0x2c, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0xc8, 0xeb, 0x41, @@ -83,12 +126,96 @@ var fileDescriptor_61276163172fe867 = []byte{ 0x94, 0x82, 0x84, 0xe1, 0xe2, 0xbe, 0x60, 0x61, 0xbf, 0xc4, 0xdc, 0x54, 0x21, 0x67, 0x2e, 0x7e, 0x84, 0xf2, 0xa2, 0xfc, 0xd2, 0x92, 0x54, 0x09, 0x66, 0xb0, 0x79, 0x52, 0x9f, 0xee, 0xc9, 0x8b, 0xa1, 0x9b, 0x07, 0x56, 0xa0, 0x14, 0xc4, 0x07, 0x17, 0x09, 0x02, 0x09, 0x58, 0x71, 0x74, 0x2c, - 0x90, 0x67, 0x78, 0xb1, 0x40, 0x9e, 0xc1, 0xc9, 0xf5, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, - 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, - 0xe5, 0x18, 0xa2, 0xb4, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x61, - 0xa1, 0x08, 0xa6, 0x74, 0x8b, 0x53, 0xb2, 0xf5, 0x2b, 0x60, 0x41, 0x5a, 0x52, 0x59, 0x90, 0x5a, - 0x9c, 0xc4, 0x06, 0x0e, 0x21, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x29, 0x57, 0x7a, 0x12, - 0x70, 0x01, 0x00, 0x00, + 0x90, 0x67, 0x78, 0xb1, 0x40, 0x9e, 0x41, 0x49, 0x86, 0x4b, 0x0a, 0xd3, 0x4b, 0x41, 0xa9, 0xc5, + 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x46, 0x65, 0x5c, 0xcc, 0xbe, 0xc5, 0xe9, 0x42, 0xf9, 0x5c, 0xfc, + 0xe8, 0x9e, 0xd6, 0xd4, 0xc3, 0x1a, 0x72, 0x7a, 0x98, 0x86, 0x49, 0x19, 0x12, 0xad, 0x14, 0x66, + 0xaf, 0x93, 0xeb, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, + 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x69, 0xa7, 0x67, + 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xc3, 0xe2, 0x16, 0x4c, 0xe9, 0x16, 0xa7, + 0x64, 0xeb, 0x57, 0xc0, 0x22, 0xba, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x6f, 0xc6, + 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x60, 0x68, 0x5a, 0x06, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // VerifyInvariant defines a method to verify a particular invariance. + VerifyInvariant(ctx context.Context, in *MsgVerifyInvariant, opts ...grpc.CallOption) (*MsgVerifyInvariantResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) VerifyInvariant(ctx context.Context, in *MsgVerifyInvariant, opts ...grpc.CallOption) (*MsgVerifyInvariantResponse, error) { + out := new(MsgVerifyInvariantResponse) + err := c.cc.Invoke(ctx, "/cosmos.crisis.v1beta1.Msg/VerifyInvariant", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // VerifyInvariant defines a method to verify a particular invariance. + VerifyInvariant(context.Context, *MsgVerifyInvariant) (*MsgVerifyInvariantResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) VerifyInvariant(ctx context.Context, req *MsgVerifyInvariant) (*MsgVerifyInvariantResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VerifyInvariant not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_VerifyInvariant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgVerifyInvariant) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).VerifyInvariant(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.crisis.v1beta1.Msg/VerifyInvariant", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).VerifyInvariant(ctx, req.(*MsgVerifyInvariant)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.crisis.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "VerifyInvariant", + Handler: _Msg_VerifyInvariant_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/crisis/v1beta1/tx.proto", } func (m *MsgVerifyInvariant) Marshal() (dAtA []byte, err error) { @@ -135,6 +262,29 @@ func (m *MsgVerifyInvariant) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *MsgVerifyInvariantResponse) 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 *MsgVerifyInvariantResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgVerifyInvariantResponse) 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 @@ -167,6 +317,15 @@ func (m *MsgVerifyInvariant) Size() (n int) { return n } +func (m *MsgVerifyInvariantResponse) 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 } @@ -322,6 +481,59 @@ func (m *MsgVerifyInvariant) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgVerifyInvariantResponse) 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: MsgVerifyInvariantResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgVerifyInvariantResponse: 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 { + return ErrInvalidLengthTx + } + if (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 90d1bd53601dca6beaa3da332b21dc0f4e8e8384 Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 14 Oct 2020 19:45:39 +0530 Subject: [PATCH 04/10] fix lint --- x/crisis/handler.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/crisis/handler.go b/x/crisis/handler.go index 3a70834a974..0e6cf985f87 100644 --- a/x/crisis/handler.go +++ b/x/crisis/handler.go @@ -3,14 +3,13 @@ package crisis import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/crisis/keeper" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) // RouterKey const RouterKey = types.ModuleName -func NewHandler(k keeper.Keeper) sdk.Handler { +func NewHandler(k types.MsgServer) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) From 73fc24d8995e8f76bf4847a81c0d002f83000ec0 Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 14 Oct 2020 19:49:59 +0530 Subject: [PATCH 05/10] lint --- proto/cosmos/crisis/v1beta1/tx.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/proto/cosmos/crisis/v1beta1/tx.proto b/proto/cosmos/crisis/v1beta1/tx.proto index f99c8b1176a..c6156b8a72d 100644 --- a/proto/cosmos/crisis/v1beta1/tx.proto +++ b/proto/cosmos/crisis/v1beta1/tx.proto @@ -5,6 +5,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/crisis/types"; import "gogoproto/gogo.proto"; +// Msg defines the bank Msg service. service Msg { // VerifyInvariant defines a method to verify a particular invariance. rpc VerifyInvariant(MsgVerifyInvariant) returns (MsgVerifyInvariantResponse); From af3fe7871e52f815b4bddbed205a028566d05383 Mon Sep 17 00:00:00 2001 From: atheesh Date: Wed, 14 Oct 2020 20:14:55 +0530 Subject: [PATCH 06/10] lint --- x/crisis/keeper/msg_server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/crisis/keeper/msg_server.go b/x/crisis/keeper/msg_server.go index b25a3e70e88..304f8b17243 100644 --- a/x/crisis/keeper/msg_server.go +++ b/x/crisis/keeper/msg_server.go @@ -73,5 +73,6 @@ func (k Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvar sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), ), }) + return &types.MsgVerifyInvariantResponse{}, nil } From 9323b6d22b556f8e0fca4a1069613d7421b0745e Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 16 Oct 2020 12:13:19 +0530 Subject: [PATCH 07/10] review changes --- x/gov/handler.go | 5 ++--- x/gov/types/msgs.go | 17 ----------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/x/gov/handler.go b/x/gov/handler.go index ad05817c3d0..18cc035882c 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -19,9 +19,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler { res, err := msgServer.Deposit(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) - case types.MsgSubmitProposalI: - msgProposal := msg.(*types.MsgSubmitProposal) - res, err := msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), msgProposal) + case *types.MsgSubmitProposal: + res, err := msgServer.SubmitProposal(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) case *types.MsgVote: diff --git a/x/gov/types/msgs.go b/x/gov/types/msgs.go index 42c4ceafd12..66fd6b3949d 100644 --- a/x/gov/types/msgs.go +++ b/x/gov/types/msgs.go @@ -21,26 +21,9 @@ const ( var ( _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{} - _ MsgSubmitProposalI = &MsgSubmitProposal{} _ types.UnpackInterfacesMessage = &MsgSubmitProposal{} ) -// MsgSubmitProposalI defines the specific interface a concrete message must -// implement in order to process governance proposals. The concrete MsgSubmitProposal -// must be defined at the application-level. -type MsgSubmitProposalI interface { - sdk.Msg - - GetContent() Content - SetContent(Content) error - - GetInitialDeposit() sdk.Coins - SetInitialDeposit(sdk.Coins) - - GetProposer() sdk.AccAddress - SetProposer(sdk.AccAddress) -} - // NewMsgSubmitProposal creates a new MsgSubmitProposal. //nolint:interfacer func NewMsgSubmitProposal(content Content, initialDeposit sdk.Coins, proposer sdk.AccAddress) (*MsgSubmitProposal, error) { From 6409288ea6ee2cbf42eda0a5fd79b3454486561d Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 16 Oct 2020 12:30:36 +0530 Subject: [PATCH 08/10] lint --- x/gov/types/msgs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/gov/types/msgs.go b/x/gov/types/msgs.go index 66fd6b3949d..e97c25ce8f0 100644 --- a/x/gov/types/msgs.go +++ b/x/gov/types/msgs.go @@ -57,7 +57,7 @@ func (m *MsgSubmitProposal) SetInitialDeposit(coins sdk.Coins) { m.InitialDeposit = coins } -func (m *MsgSubmitProposal) SetProposer(address sdk.AccAddress) { +func (m *MsgSubmitProposal) SetProposer(address fmt.Stringer) { m.Proposer = address.String() } From 3df2a044eeb665f1c2043ae8e2b93237d78e8930 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 16 Oct 2020 12:39:08 +0530 Subject: [PATCH 09/10] review change --- x/gov/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/gov/handler.go b/x/gov/handler.go index 18cc035882c..25d97bfabb4 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -9,11 +9,11 @@ import ( // NewHandler creates an sdk.Handler for all the gov type messages func NewHandler(k keeper.Keeper) sdk.Handler { + msgServer := keeper.NewMsgServerImpl(k) + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) - msgServer := keeper.NewMsgServerImpl(k) - switch msg := msg.(type) { case *types.MsgDeposit: res, err := msgServer.Deposit(sdk.WrapSDKContext(ctx), msg) From 9bdb69a65c6e33a78afe0a62fc5eb738a56c1e15 Mon Sep 17 00:00:00 2001 From: atheesh Date: Fri, 16 Oct 2020 14:16:35 +0530 Subject: [PATCH 10/10] fic doc --- x/gov/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 89afb3d7ff3..aee3d3c3807 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -15,7 +15,7 @@ type msgServer struct { Keeper } -// NewMsgServerImpl returns an implementation of the bank MsgServer interface +// NewMsgServerImpl returns an implementation of the gov MsgServer interface // for the provided Keeper. func NewMsgServerImpl(keeper Keeper) types.MsgServer { return &msgServer{Keeper: keeper}