Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow the owner of a chain to remove the chain #2178

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
// MsgRemoveConsumer defines the message used to remove (and stop) a consumer chain.
// If it passes, all the consumer chain's state is eventually removed from the provider chain.
message MsgRemoveConsumer {
option (cosmos.msg.v1.signer) = "authority";
option (cosmos.msg.v1.signer) = "signer";

// the consumer id of the consumer chain to be stopped
string consumer_id = 1;
Expand All @@ -232,7 +232,7 @@
google.protobuf.Timestamp stop_time = 2
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
// signer address
string authority = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string signer = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];

Check failure on line 235 in proto/interchain_security/ccv/provider/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "3" with name "signer" on message "MsgRemoveConsumer" changed option "json_name" from "authority" to "signer".

Check failure on line 235 in proto/interchain_security/ccv/provider/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "3" on message "MsgRemoveConsumer" changed name from "authority" to "signer".
}

// MsgRemoveConsumerResponse defines response type for MsgRemoveConsumer messages
Expand Down
16 changes: 9 additions & 7 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,18 @@ func (k msgServer) AssignConsumerKey(goCtx context.Context, msg *types.MsgAssign
}

// RemoveConsumer defines an RPC handler method for MsgRemoveConsumer
func (k msgServer) RemoveConsumer(
goCtx context.Context,
msg *types.MsgRemoveConsumer) (*types.MsgRemoveConsumerResponse, error) {
if k.GetAuthority() != msg.Authority {
return nil, errorsmod.Wrapf(types.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Authority)
}

func (k msgServer) RemoveConsumer(goCtx context.Context, msg *types.MsgRemoveConsumer) (*types.MsgRemoveConsumerResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

consumerId := msg.ConsumerId
ownerAddress, err := k.Keeper.GetConsumerOwnerAddress(ctx, consumerId)
if err != nil {
return &types.MsgRemoveConsumerResponse{}, errorsmod.Wrapf(types.ErrNoOwnerAddress, "cannot retrieve owner address %s", ownerAddress)
}

if msg.Signer != ownerAddress {
return &types.MsgRemoveConsumerResponse{}, errorsmod.Wrapf(types.ErrUnauthorized, "expected owner address %s, got %s", ownerAddress, msg.Signer)
}

phase, found := k.Keeper.GetConsumerPhase(ctx, consumerId)
if !found || phase != Launched {
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (msg MsgUpdateConsumer) GetSigners() []sdk.AccAddress {
// NewMsgRemoveConsumer creates a new MsgRemoveConsumer instance
func NewMsgRemoveConsumer(signer string, consumerId string, stopTime time.Time) (*MsgRemoveConsumer, error) {
return &MsgRemoveConsumer{
Authority: signer,
Signer: signer,
ConsumerId: consumerId,
StopTime: stopTime,
}, nil
Expand Down Expand Up @@ -399,7 +399,7 @@ func (msg MsgRemoveConsumer) GetSignBytes() []byte {
// GetSigners implements the sdk.Msg interface. It returns the address(es) that
// must sign over msg.GetSignBytes().
func (msg MsgRemoveConsumer) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.Authority)
valAddr, err := sdk.ValAddressFromBech32(msg.Signer)
if err != nil {
// same behavior as in cosmos-sdk
panic(err)
Expand Down
Loading
Loading