From 275ae8043eeaf98dc153b80509351168af19a2fc Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Tue, 7 Nov 2023 09:52:12 +0100 Subject: [PATCH] Added message handlers for new proposals --- x/ccv/provider/keeper/msg_server.go | 25 ++++++++++------ x/ccv/provider/keeper/proposal.go | 44 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/x/ccv/provider/keeper/msg_server.go b/x/ccv/provider/keeper/msg_server.go index 134a4d621b..ff7137d805 100644 --- a/x/ccv/provider/keeper/msg_server.go +++ b/x/ccv/provider/keeper/msg_server.go @@ -117,8 +117,11 @@ func (k msgServer) ConsumerAddition(goCtx context.Context, msg *types.MsgConsume return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer) } - // TODO: Call keeper implementation ! - + ctx := sdk.UnwrapSDKContext(goCtx) + err := k.Keeper.HandleNewConsumerAdditionProposal(ctx, msg) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed handling ConsumerAddition proposal") + } return &types.MsgConsumerAdditionResponse{}, nil } @@ -130,20 +133,26 @@ func (k msgServer) ConsumerRemoval( return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer) } - // TODO: Call keeper implementation ! + ctx := sdk.UnwrapSDKContext(goCtx) + err := k.Keeper.HandleNewConsumerRemovalProposal(ctx, msg) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed handling ConsumerAddition proposal") + } return &types.MsgConsumerRemovalResponse{}, nil } -// ConsumerRemoval defines a rpc handler method for MsgConsumerRemoval -func (k msgServer) ChangeRewardDenoms( - goCtx context.Context, - msg *types.MsgChangeRewardDenoms) (*types.MsgChangeRewardDenomsResponse, error) { +// ChangeRewardDenoms defines a rpc handler method for MsgChangeRewardDenoms +func (k msgServer) ChangeRewardDenoms(goCtx context.Context, msg *types.MsgChangeRewardDenoms) (*types.MsgChangeRewardDenomsResponse, error) { if k.GetAuthority() != msg.Signer { return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Signer) } - // TODO: Call keeper implementation ! + sdkCtx := sdk.UnwrapSDKContext(goCtx) + err := k.Keeper.HandleNewConsumerRewardDenomProposal(sdkCtx, msg) + if err != nil { + return nil, errorsmod.Wrapf(err, "failed handling Change Reward Denoms proposal") + } return &types.MsgChangeRewardDenomsResponse{}, nil } diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index a1e1242e7a..c59705cf22 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -24,6 +24,50 @@ import ( ccv "github.com/cosmos/interchain-security/v3/x/ccv/types" ) +// Wrapper for the new proposal messages MsgConsumerAddition. +// Will replace legacy handler HandleConsumerAdditionProposal +func (k Keeper) HandleNewConsumerAdditionProposal(ctx sdk.Context, proposal *types.MsgConsumerAddition) error { + p := types.ConsumerAdditionProposal{ + Title: "New ConsumerAddition Proposal", + ChainId: proposal.ChainId, + InitialHeight: proposal.InitialHeight, + GenesisHash: proposal.GenesisHash, + BinaryHash: proposal.BinaryHash, + SpawnTime: proposal.SpawnTime, + UnbondingPeriod: proposal.UnbondingPeriod, + CcvTimeoutPeriod: proposal.CcvTimeoutPeriod, + TransferTimeoutPeriod: proposal.TransferTimeoutPeriod, + ConsumerRedistributionFraction: proposal.ConsumerRedistributionFraction, + BlocksPerDistributionTransmission: proposal.BlocksPerDistributionTransmission, + HistoricalEntries: proposal.HistoricalEntries, + DistributionTransmissionChannel: proposal.DistributionTransmissionChannel, + } + return k.HandleConsumerAdditionProposal(ctx, &p) + +} + +// Wrapper for the new proposal messages MsgConsumerRemoval. +// Will replace legacy handler HandleConsumerRemovalProposal +func (k Keeper) HandleNewConsumerRemovalProposal(ctx sdk.Context, proposal *types.MsgConsumerRemoval) error { + p := types.ConsumerRemovalProposal{ + ChainId: proposal.ChainId, + StopTime: proposal.StopTime, + } + return k.HandleConsumerRemovalProposal(ctx, &p) + +} + +// Wrapper for the new proposal messages MsgChangeRewardDenoms. +// Will replace legacy handler HandleConsumerRewardDenomProposal +func (k Keeper) HandleNewConsumerRewardDenomProposal(ctx sdk.Context, proposal *types.MsgChangeRewardDenoms) error { + p := types.ChangeRewardDenomsProposal{ + Title: "New ChangeRewardDenomsProposal", + DenomsToAdd: proposal.DenomsToAdd, + DenomsToRemove: proposal.DenomsToRemove, + } + return k.HandleConsumerRewardDenomProposal(ctx, &p) +} + // HandleConsumerAdditionProposal will receive the consumer chain's client state from the proposal. // If the client can be successfully created in a cached context, it stores the proposal as a pending proposal. //