From 74df817d005a64da1d7477c756939adbb5fd54af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?=
 <31522760+fedekunze@users.noreply.github.com>
Date: Mon, 27 Feb 2023 07:32:50 +0100
Subject: [PATCH 1/3] feat: add MsgCancelUnbondingDelegation to Staking
 Authorization

---
 api/cosmos/staking/v1beta1/authz.pulsar.go | 49 +++++++------
 proto/cosmos/staking/v1beta1/authz.proto   |  2 +
 x/staking/types/authz.go                   | 50 ++++++++++---
 x/staking/types/authz.pb.go                | 83 ++++++++++++----------
 x/staking/types/authz_test.go              | 67 +++++++++++++++++
 5 files changed, 182 insertions(+), 69 deletions(-)

diff --git a/api/cosmos/staking/v1beta1/authz.pulsar.go b/api/cosmos/staking/v1beta1/authz.pulsar.go
index 80cc82b0db0d..6675b1355290 100644
--- a/api/cosmos/staking/v1beta1/authz.pulsar.go
+++ b/api/cosmos/staking/v1beta1/authz.pulsar.go
@@ -1228,6 +1228,8 @@ const (
 	AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE AuthorizationType = 2
 	// AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for Msg/BeginRedelegate
 	AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE AuthorizationType = 3
+	// AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION defines an authorization type for Msg/MsgCancelUnbondingDelegation
+	AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION AuthorizationType = 4
 )
 
 // Enum value maps for AuthorizationType.
@@ -1237,12 +1239,14 @@ var (
 		1: "AUTHORIZATION_TYPE_DELEGATE",
 		2: "AUTHORIZATION_TYPE_UNDELEGATE",
 		3: "AUTHORIZATION_TYPE_REDELEGATE",
+		4: "AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION",
 	}
 	AuthorizationType_value = map[string]int32{
-		"AUTHORIZATION_TYPE_UNSPECIFIED": 0,
-		"AUTHORIZATION_TYPE_DELEGATE":    1,
-		"AUTHORIZATION_TYPE_UNDELEGATE":  2,
-		"AUTHORIZATION_TYPE_REDELEGATE":  3,
+		"AUTHORIZATION_TYPE_UNSPECIFIED":                 0,
+		"AUTHORIZATION_TYPE_DELEGATE":                    1,
+		"AUTHORIZATION_TYPE_UNDELEGATE":                  2,
+		"AUTHORIZATION_TYPE_REDELEGATE":                  3,
+		"AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION": 4,
 	}
 )
 
@@ -1457,7 +1461,7 @@ var file_cosmos_staking_v1beta1_authz_proto_rawDesc = []byte{
 	0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x8a, 0xe7, 0xb0,
 	0x2a, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x53, 0x74, 0x61,
 	0x6b, 0x65, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42,
-	0x0c, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x2a, 0x9e, 0x01,
+	0x0c, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x73, 0x2a, 0xd2, 0x01,
 	0x0a, 0x11, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54,
 	0x79, 0x70, 0x65, 0x12, 0x22, 0x0a, 0x1e, 0x41, 0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x5a, 0x41,
 	0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43,
@@ -1467,22 +1471,25 @@ var file_cosmos_staking_v1beta1_authz_proto_rawDesc = []byte{
 	0x4f, 0x52, 0x49, 0x5a, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55,
 	0x4e, 0x44, 0x45, 0x4c, 0x45, 0x47, 0x41, 0x54, 0x45, 0x10, 0x02, 0x12, 0x21, 0x0a, 0x1d, 0x41,
 	0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x5a, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x54, 0x59, 0x50,
-	0x45, 0x5f, 0x52, 0x45, 0x44, 0x45, 0x4c, 0x45, 0x47, 0x41, 0x54, 0x45, 0x10, 0x03, 0x42, 0xda,
-	0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74,
-	0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x0a, 0x41,
-	0x75, 0x74, 0x68, 0x7a, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x63, 0x6f, 0x73,
-	0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f,
-	0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x62,
-	0x65, 0x74, 0x61, 0x31, 0x3b, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x76, 0x31, 0x62, 0x65,
-	0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x53, 0x58, 0xaa, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d,
-	0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74,
-	0x61, 0x31, 0xca, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x61, 0x6b,
-	0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, 0x43, 0x6f,
-	0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x62,
-	0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61,
-	0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x53, 0x74, 0x61, 0x6b, 0x69,
-	0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f,
-	0x74, 0x6f, 0x33,
+	0x45, 0x5f, 0x52, 0x45, 0x44, 0x45, 0x4c, 0x45, 0x47, 0x41, 0x54, 0x45, 0x10, 0x03, 0x12, 0x32,
+	0x0a, 0x2e, 0x41, 0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x5a, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f,
+	0x54, 0x59, 0x50, 0x45, 0x5f, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, 0x5f, 0x55, 0x4e, 0x42, 0x4f,
+	0x4e, 0x44, 0x49, 0x4e, 0x47, 0x5f, 0x44, 0x45, 0x4c, 0x45, 0x47, 0x41, 0x54, 0x49, 0x4f, 0x4e,
+	0x10, 0x04, 0x42, 0xda, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f,
+	0x73, 0x2e, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61,
+	0x31, 0x42, 0x0a, 0x41, 0x75, 0x74, 0x68, 0x7a, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a,
+	0x36, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70,
+	0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67,
+	0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x73, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67,
+	0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x53, 0x58, 0xaa, 0x02, 0x16,
+	0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x2e, 0x56,
+	0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c,
+	0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2,
+	0x02, 0x22, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67,
+	0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61,
+	0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x53,
+	0x74, 0x61, 0x6b, 0x69, 0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62,
+	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
diff --git a/proto/cosmos/staking/v1beta1/authz.proto b/proto/cosmos/staking/v1beta1/authz.proto
index 1fb04219b66e..409280c1edae 100644
--- a/proto/cosmos/staking/v1beta1/authz.proto
+++ b/proto/cosmos/staking/v1beta1/authz.proto
@@ -46,4 +46,6 @@ enum AuthorizationType {
   AUTHORIZATION_TYPE_UNDELEGATE = 2;
   // AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for Msg/BeginRedelegate
   AUTHORIZATION_TYPE_REDELEGATE = 3;
+  // AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION defines an authorization type for Msg/MsgCancelUnbondingDelegation
+  AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION = 4;
 }
diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go
index ba5103acd4b1..791d140d763a 100644
--- a/x/staking/types/authz.go
+++ b/x/staking/types/authz.go
@@ -23,14 +23,23 @@ func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, au
 
 	a := StakeAuthorization{}
 	if allowedValidators != nil {
-		a.Validators = &StakeAuthorization_AllowList{AllowList: &StakeAuthorization_Validators{Address: allowedValidators}}
+		a.Validators = &StakeAuthorization_AllowList{
+			AllowList: &StakeAuthorization_Validators{
+				Address: allowedValidators,
+			},
+		}
 	} else {
-		a.Validators = &StakeAuthorization_DenyList{DenyList: &StakeAuthorization_Validators{Address: deniedValidators}}
+		a.Validators = &StakeAuthorization_DenyList{
+			DenyList: &StakeAuthorization_Validators{
+				Address: deniedValidators,
+			},
+		}
 	}
 
 	if amount != nil {
 		a.MaxTokens = amount
 	}
+
 	a.AuthorizationType = authzType
 
 	return &a, nil
@@ -42,13 +51,18 @@ func (a StakeAuthorization) MsgTypeURL() string {
 	if err != nil {
 		panic(err)
 	}
+
 	return authzType
 }
 
+// ValidateBasic performs a stateless validation of the fields.
+// It fails if MaxTokens is either undefined or negative or if the authorization
+// is unspecified.
 func (a StakeAuthorization) ValidateBasic() error {
 	if a.MaxTokens != nil && a.MaxTokens.IsNegative() {
 		return errorsmod.Wrapf(authz.ErrNegativeMaxTokens, "negative coin amount: %v", a.MaxTokens)
 	}
+
 	if a.AuthorizationType == AuthorizationType_AUTHORIZATION_TYPE_UNSPECIFIED {
 		return authz.ErrUnknownAuthorizationType
 	}
@@ -56,10 +70,12 @@ func (a StakeAuthorization) ValidateBasic() error {
 	return nil
 }
 
-// Accept implements Authorization.Accept.
+// Accept implements Authorization.Accept. It checks if the validator
 func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) {
-	var validatorAddress string
-	var amount sdk.Coin
+	var (
+		validatorAddress string
+		amount           sdk.Coin
+	)
 
 	switch msg := msg.(type) {
 	case *MsgDelegate:
@@ -71,6 +87,9 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
 	case *MsgBeginRedelegate:
 		validatorAddress = msg.ValidatorDstAddress
 		amount = msg.Amount
+	case *MsgCancelUnbondingDelegation:
+		validatorAddress = msg.ValidatorAddress
+		amount = msg.Amount
 	default:
 		return authz.AcceptResponse{}, sdkerrors.ErrInvalidRequest.Wrap("unknown msg type")
 	}
@@ -99,8 +118,12 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
 
 	if a.MaxTokens == nil {
 		return authz.AcceptResponse{
-			Accept: true, Delete: false,
-			Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType()},
+			Accept: true,
+			Delete: false,
+			Updated: &StakeAuthorization{
+				Validators:        a.GetValidators(),
+				AuthorizationType: a.GetAuthorizationType(),
+			},
 		}, nil
 	}
 
@@ -108,12 +131,19 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
 	if err != nil {
 		return authz.AcceptResponse{}, err
 	}
+
 	if limitLeft.IsZero() {
 		return authz.AcceptResponse{Accept: true, Delete: true}, nil
 	}
+
 	return authz.AcceptResponse{
-		Accept: true, Delete: false,
-		Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType(), MaxTokens: &limitLeft},
+		Accept: true,
+		Delete: false,
+		Updated: &StakeAuthorization{
+			Validators:        a.GetValidators(),
+			AuthorizationType: a.GetAuthorizationType(),
+			MaxTokens:         &limitLeft,
+		},
 	}, nil
 }
 
@@ -151,6 +181,8 @@ func normalizeAuthzType(authzType AuthorizationType) (string, error) {
 		return sdk.MsgTypeURL(&MsgUndelegate{}), nil
 	case AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE:
 		return sdk.MsgTypeURL(&MsgBeginRedelegate{}), nil
+	case AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION:
+		return sdk.MsgTypeURL(&MsgCancelUnbondingDelegation{}), nil
 	default:
 		return "", errorsmod.Wrapf(authz.ErrUnknownAuthorizationType, "cannot normalize authz type with %T", authzType)
 	}
diff --git a/x/staking/types/authz.pb.go b/x/staking/types/authz.pb.go
index e812716038fc..5695fb0c26ca 100644
--- a/x/staking/types/authz.pb.go
+++ b/x/staking/types/authz.pb.go
@@ -40,6 +40,8 @@ const (
 	AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE AuthorizationType = 2
 	// AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for Msg/BeginRedelegate
 	AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE AuthorizationType = 3
+	// AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION defines an authorization type for Msg/MsgCancelUnbondingDelegation
+	AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION AuthorizationType = 4
 )
 
 var AuthorizationType_name = map[int32]string{
@@ -47,13 +49,15 @@ var AuthorizationType_name = map[int32]string{
 	1: "AUTHORIZATION_TYPE_DELEGATE",
 	2: "AUTHORIZATION_TYPE_UNDELEGATE",
 	3: "AUTHORIZATION_TYPE_REDELEGATE",
+	4: "AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION",
 }
 
 var AuthorizationType_value = map[string]int32{
-	"AUTHORIZATION_TYPE_UNSPECIFIED": 0,
-	"AUTHORIZATION_TYPE_DELEGATE":    1,
-	"AUTHORIZATION_TYPE_UNDELEGATE":  2,
-	"AUTHORIZATION_TYPE_REDELEGATE":  3,
+	"AUTHORIZATION_TYPE_UNSPECIFIED":                 0,
+	"AUTHORIZATION_TYPE_DELEGATE":                    1,
+	"AUTHORIZATION_TYPE_UNDELEGATE":                  2,
+	"AUTHORIZATION_TYPE_REDELEGATE":                  3,
+	"AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION": 4,
 }
 
 func (x AuthorizationType) String() string {
@@ -229,41 +233,42 @@ func init() {
 }
 
 var fileDescriptor_d6d8cdbc6f4432f0 = []byte{
-	// 533 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0xc1, 0x6e, 0x12, 0x41,
-	0x18, 0x80, 0x99, 0xd2, 0xa8, 0x8c, 0xc6, 0x94, 0x49, 0x63, 0x28, 0xa6, 0xdb, 0xca, 0xc1, 0x22,
-	0x2d, 0xb3, 0x29, 0xc6, 0x8b, 0x27, 0x97, 0xb2, 0x15, 0x92, 0xa6, 0x6d, 0x96, 0xad, 0xd1, 0x5e,
-	0x36, 0x03, 0x3b, 0x81, 0x09, 0xb0, 0x43, 0x98, 0xa1, 0x42, 0x6f, 0x26, 0x9e, 0x3c, 0xf9, 0x04,
-	0x3e, 0x80, 0xa7, 0xc6, 0xf4, 0x21, 0x8c, 0xa7, 0xc6, 0x93, 0x37, 0x0d, 0x1c, 0xfa, 0x0e, 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 0x73, 0x68, 0x3a, 0x47, 0xfb, 0xd5, 0x43, 0x73, 0xa7, 0xb2,
-	0x5b, 0x31, 0x4b, 0x4b, 0x31, 0xb4, 0x06, 0x1f, 0xce, 0x60, 0x4a, 0xe6, 0x9e, 0xf9, 0xd2, 0xb0,
-	0xcd, 0x25, 0x80, 0x1e, 0xc1, 0xd5, 0x99, 0x49, 0x22, 0x64, 0xe1, 0x1a, 0xc4, 0x32, 0x23, 0x24,
-	0x5e, 0xdc, 0xfd, 0x3a, 0xd2, 0xc0, 0xc5, 0x48, 0x03, 0xbf, 0x46, 0x1a, 0xf8, 0x38, 0xd6, 0x62,
-	0x17, 0x63, 0x2d, 0xf6, 0x63, 0xac, 0xc5, 0x8e, 0xb7, 0xe6, 0x76, 0xfb, 0x20, 0xba, 0xef, 0x41,
-	0xdf, 0xd7, 0x6e, 0x05, 0x97, 0xed, 0xe9, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x05, 0x01, 0x42,
-	0x8b, 0x0e, 0x04, 0x00, 0x00,
+	// 556 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0xc1, 0x6e, 0x12, 0x41,
+	0x18, 0xc7, 0xd9, 0xb6, 0x51, 0x19, 0x8d, 0x29, 0x93, 0xc6, 0x50, 0x4c, 0xb7, 0x95, 0x83, 0x45,
+	0x5a, 0x66, 0x53, 0x8c, 0x17, 0x4f, 0xee, 0xc2, 0xb6, 0x6c, 0x42, 0x96, 0x66, 0x59, 0x8c, 0xf6,
+	0xb2, 0x19, 0xd8, 0x0d, 0x4c, 0x80, 0x1d, 0xc2, 0x0c, 0x15, 0x7a, 0x33, 0xf1, 0xe4, 0xc9, 0xe7,
+	0xf0, 0xd4, 0x98, 0x3e, 0x84, 0xf1, 0xd4, 0xf4, 0xe4, 0x4d, 0x03, 0x87, 0xbe, 0x83, 0x27, 0xb3,
+	0xbb, 0x03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9a, 0x59, 0x3d, 0xd6, 0x0b, 0xc6, 0xa1, 0xa1,
+	0x17, 0xd7, 0x63, 0x70, 0x1b, 0x3c, 0x5e, 0xc0, 0x14, 0xf5, 0xb2, 0x7e, 0xa4, 0xda, 0xfa, 0xba,
+	0x04, 0x9f, 0x80, 0xad, 0x85, 0x4d, 0x66, 0xc8, 0xca, 0x2d, 0x88, 0xa5, 0xcf, 0x90, 0x55, 0x98,
+	0x07, 0x68, 0x01, 0x52, 0x50, 0xcd, 0x82, 0x5e, 0x76, 0x6a, 0xa6, 0x56, 0x31, 0x8b, 0x86, 0x79,
+	0x34, 0xcd, 0x35, 0x2a, 0xe6, 0xfa, 0x9a, 0x76, 0xf8, 0x75, 0x2c, 0x4b, 0x97, 0x63, 0x59, 0xfa,
+	0x39, 0x96, 0xa5, 0x4f, 0x13, 0x39, 0x76, 0x39, 0x91, 0x63, 0xdf, 0x27, 0x72, 0xec, 0x64, 0x7f,
+	0xe9, 0x0d, 0x19, 0xce, 0xde, 0x11, 0xe1, 0x5d, 0xa9, 0xdf, 0x09, 0x2f, 0xe8, 0xf3, 0xdf, 0x01,
+	0x00, 0x00, 0xff, 0xff, 0x2a, 0x15, 0x5e, 0xdc, 0x42, 0x04, 0x00, 0x00,
 }
 
 func (m *StakeAuthorization) Marshal() (dAtA []byte, err error) {
diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go
index 72251c6f1b43..d69a6847c030 100644
--- a/x/staking/types/authz_test.go
+++ b/x/staking/types/authz_test.go
@@ -279,6 +279,73 @@ func TestAuthzAuthorizations(t *testing.T) {
 			false,
 			nil,
 		},
+		{
+			"cancel unbonding delegation: expect 0 remaining coins",
+			[]sdk.ValAddress{val1},
+			[]sdk.ValAddress{},
+			stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			&coin100,
+			stakingtypes.NewMsgCancelUnbondingDelegation(delAddr, val1, ctx.BlockHeight(), coin100),
+			false,
+			true,
+			nil,
+		},
+		{
+			"cancel unbonding delegation: verify remaining coins",
+			[]sdk.ValAddress{val1},
+			[]sdk.ValAddress{},
+			stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			&coin100,
+			stakingtypes.NewMsgCancelUnbondingDelegation(delAddr, val1, ctx.BlockHeight(), coin50),
+			false,
+			false,
+			&stakingtypes.StakeAuthorization{
+				Validators: &stakingtypes.StakeAuthorization_AllowList{
+					AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
+				},
+				MaxTokens:         &coin50,
+				AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			},
+		},
+		{
+			"cancel unbonding delegation: testing with invalid validator",
+			[]sdk.ValAddress{val1, val2},
+			[]sdk.ValAddress{},
+			stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			&coin100,
+			stakingtypes.NewMsgCancelUnbondingDelegation(delAddr, val3, ctx.BlockHeight(), coin50),
+			true,
+			false,
+			nil,
+		},
+		{
+			"cancel unbonding delegation: testing delegate without spent limit",
+			[]sdk.ValAddress{val1, val2},
+			[]sdk.ValAddress{},
+			stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			nil,
+			stakingtypes.NewMsgCancelUnbondingDelegation(delAddr, val2, ctx.BlockHeight(), coin100),
+			false,
+			false,
+			&stakingtypes.StakeAuthorization{
+				Validators: &stakingtypes.StakeAuthorization_AllowList{
+					AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
+				},
+				MaxTokens:         nil,
+				AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			},
+		},
+		{
+			"cancel unbonding delegation: fail cannot undelegate, permission denied",
+			[]sdk.ValAddress{},
+			[]sdk.ValAddress{val1},
+			stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,
+			&coin100,
+			stakingtypes.NewMsgCancelUnbondingDelegation(delAddr, val1, ctx.BlockHeight(), coin100),
+			true,
+			false,
+			nil,
+		},
 	}
 
 	for _, tc := range testCases {

From 5d1f22cf388cf44e62f6d4d68f3462b32ca2cd45 Mon Sep 17 00:00:00 2001
From: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Date: Thu, 9 Mar 2023 13:22:28 +0100
Subject: [PATCH 2/3] test: fix tests for adding MsgCancelUnbondingDelegation
 to Staking Authorization (#15323)

---
 x/staking/types/authz_test.go | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go
index d69a6847c030..4eb4db9c3c9a 100644
--- a/x/staking/types/authz_test.go
+++ b/x/staking/types/authz_test.go
@@ -50,6 +50,10 @@ func TestAuthzAuthorizations(t *testing.T) {
 	beginRedelAuth, _ := stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE, &coin100)
 	require.Equal(t, beginRedelAuth.MsgTypeURL(), sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}))
 
+	// verify MethodName for CancelUnbondingDelegation
+	cancelUnbondAuth, _ := stakingtypes.NewStakeAuthorization([]sdk.ValAddress{val1, val2}, []sdk.ValAddress{}, stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION, &coin100)
+	require.Equal(t, cancelUnbondAuth.MsgTypeURL(), sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}))
+
 	validators1_2 := []string{val1.String(), val2.String()}
 
 	testCases := []struct {
@@ -301,7 +305,7 @@ func TestAuthzAuthorizations(t *testing.T) {
 			false,
 			&stakingtypes.StakeAuthorization{
 				Validators: &stakingtypes.StakeAuthorization_AllowList{
-					AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
+					AllowList: &stakingtypes.StakeAuthorization_Validators{Address: []string{val1.String()}},
 				},
 				MaxTokens:         &coin50,
 				AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_CANCEL_UNBONDING_DELEGATION,

From 09b9ad85c4227e70e75b601e46bc5103e4318e08 Mon Sep 17 00:00:00 2001
From: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Date: Thu, 9 Mar 2023 20:45:11 +0100
Subject: [PATCH 3/3] chore: address review comments on #15164 (#15336)

---
 CHANGELOG.md             | 1 +
 x/staking/types/authz.go | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 193dea1b302b..9d946fe9f4a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -66,6 +66,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
 
 ### Improvements
 
+* (x/authz) [#15164](https://github.com/cosmos/cosmos-sdk/pull/15164) Add `MsgCancelUnbondingDelegation` to staking authorization
 * [#15011](https://github.com/cosmos/cosmos-sdk/pull/15011) Introduce `cosmossdk.io/log` package to provide a consistent logging interface through the SDK. CometBFT logger is now replaced by `cosmossdk.io/log.Logger`.
 * (x/auth) [#14758](https://github.com/cosmos/cosmos-sdk/pull/14758) Allow transaction event queries to directly passed to Tendermint, which will allow for full query operator support, e.g. `>`.
 * (server) [#15041](https://github.com/cosmos/cosmos-sdk/pull/15041) Remove unnecessary sleeps from gRPC and API server initiation. The servers will start and accept requests as soon as they're ready.
diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go
index 791d140d763a..f30dfe018bc2 100644
--- a/x/staking/types/authz.go
+++ b/x/staking/types/authz.go
@@ -70,7 +70,10 @@ func (a StakeAuthorization) ValidateBasic() error {
 	return nil
 }
 
-// Accept implements Authorization.Accept. It checks if the validator
+// Accept implements Authorization.Accept. It checks, that the validator is not in the denied list,
+// and, should the allowed list not be empty, if the validator is in the allowed list.
+// If these conditions are met, the authorization amount is validated and if successful, the
+// corresponding AcceptResponse is returned.
 func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) {
 	var (
 		validatorAddress string