Skip to content

Commit

Permalink
Finish staking hooks merge (#11677)
Browse files Browse the repository at this point in the history
* allow stopping and completing of redelegations

* refactor to remove BeforeUnbondingDelegationEntryComplete hook and notes for validator unbonding

Co-authored-by: Simon <[email protected]>
  • Loading branch information
sainoe committed Feb 9, 2023
1 parent f749811 commit 179f43a
Show file tree
Hide file tree
Showing 30 changed files with 1,814 additions and 1,229 deletions.
7 changes: 5 additions & 2 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6784,6 +6784,8 @@ RedelegationEntry defines a redelegation object with relevant metadata.
| `completion_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | completion_time defines the unix time for redelegation completion. |
| `initial_balance` | [string](#string) | | initial_balance defines the initial balance when redelegation started. |
| `shares_dst` | [string](#string) | | shares_dst is the amount of destination-validator shares created by redelegation. |
| `unbonding_id` | [uint64](#uint64) | | Incrementing id that uniquely identifies this entry |
| `unbonding_on_hold` | [bool](#bool) | | True if this entry's unbonding has been stopped by an external module |



Expand Down Expand Up @@ -6858,8 +6860,8 @@ UnbondingDelegationEntry defines an unbonding object with relevant metadata.
| `completion_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | completion_time is the unix time for unbonding completion. |
| `initial_balance` | [string](#string) | | initial_balance defines the tokens initially scheduled to receive at completion. |
| `balance` | [string](#string) | | balance defines the tokens to receive at completion. |
| `id` | [uint64](#uint64) | | Incrementing id that uniquely identifies this entry |
| `on_hold` | [bool](#bool) | | True if this entry's unbonding has been stopped by an external module |
| `unbonding_id` | [uint64](#uint64) | | Incrementing id that uniquely identifies this entry |
| `unbonding_on_hold` | [bool](#bool) | | True if this entry's unbonding has been stopped by an external module |



Expand Down Expand Up @@ -6907,6 +6909,7 @@ multiplied by exchange rate.
| `unbonding_time` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | unbonding_time defines, if unbonding, the min time for the validator to complete unbonding. |
| `commission` | [Commission](#cosmos.staking.v1beta1.Commission) | | commission defines the commission parameters. |
| `min_self_delegation` | [string](#string) | | min_self_delegation is the validator's self declared minimum self delegation. |
| `unbonding_on_hold` | [bool](#bool) | | True if this validator's unbonding has been stopped by an external module |



Expand Down
24 changes: 0 additions & 24 deletions proto/cosmos/bank/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,6 @@ message QueryAllBalancesResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySpendableBalancesRequest defines the gRPC request structure for querying
// an account's spendable balances.
message QuerySpendableBalancesRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// address is the address to query spendable balances for.
string address = 1;

// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QuerySpendableBalancesResponse defines the gRPC response structure for querying
// an account's spendable balances.
message QuerySpendableBalancesResponse {
// balances is the spendable balances of all the coins.
repeated cosmos.base.v1beta1.Coin balances = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryTotalSupplyRequest is the request type for the Query/TotalSupply RPC
// method.
message QueryTotalSupplyRequest {
Expand Down
15 changes: 12 additions & 3 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ message Validator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// True if this validator's unbonding has been stopped by an external module
bool unbonding_on_hold = 12;
}

// BondStatus is the status of a validator.
Expand Down Expand Up @@ -225,13 +228,13 @@ message UnbondingDelegationEntry {
(gogoproto.moretags) = "yaml:\"initial_balance\""
];
// balance defines the tokens to receive at completion.
string balance = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string balance = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];

// Incrementing id that uniquely identifies this entry
uint64 id = 5;
uint64 unbonding_id = 5;

// True if this entry's unbonding has been stopped by an external module
bool on_hold = 6;
bool unbonding_on_hold = 6;
}

// RedelegationEntry defines a redelegation object with relevant metadata.
Expand All @@ -253,6 +256,12 @@ message RedelegationEntry {
// shares_dst is the amount of destination-validator shares created by redelegation.
string shares_dst = 4
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];

// Incrementing id that uniquely identifies this entry
uint64 unbonding_id = 5;

// True if this entry's unbonding has been stopped by an external module
bool unbonding_on_hold = 6;
}

// Redelegation contains the list of a particular delegator's redelegating bonds
Expand Down
110 changes: 53 additions & 57 deletions x/bank/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions x/distribution/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keeper

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -107,8 +105,5 @@ func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress)
func (h Hooks) AfterValidatorBonded(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {}
func (h Hooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {}
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
func (h Hooks) UnbondingDelegationEntryCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress, _ int64, _ time.Time, _ sdk.Int, _ uint64) {
}
func (h Hooks) BeforeUnbondingDelegationEntryComplete(_ sdk.Context, _ uint64) bool {
return false
func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) {
}
8 changes: 4 additions & 4 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ func TestHandleAbsentValidator(t *testing.T) {
// validator should have been slashed
require.True(t, amt.Sub(slashAmt).Equal(validator.GetTokens()))

// 502nd block *also* missed (since the LastCommit would have still included the just-unbonded validator)
height++
ctx = ctx.WithBlockHeight(height)
app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), power, false)
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(0), info.StartHeight)
require.Equal(t, int64(1), info.MissedBlocksCounter)
// validator missed block should not be incremented since it is jailed (#11425)
require.Equal(t, int64(0), info.MissedBlocksCounter)

// end block
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -260,8 +260,8 @@ func TestHandleAbsentValidator(t *testing.T) {
info, found = app.SlashingKeeper.GetValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
require.True(t, found)
require.Equal(t, int64(0), info.StartHeight)
// we've missed 2 blocks more than the maximum, so the counter was reset to 0 at 1 block more and is now 1
require.Equal(t, int64(1), info.MissedBlocksCounter)
// validator missed block should not have been changed
require.Equal(t, int64(0), info.MissedBlocksCounter)

// validator should not be immediately jailed again
height++
Expand Down
6 changes: 2 additions & 4 deletions x/slashing/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Hooks struct {
k Keeper
}

// Implements StakingHooks interface
var _ types.StakingHooks = Hooks{}

// Return the wrapper struct
Expand Down Expand Up @@ -76,8 +77,5 @@ func (h Hooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _
func (h Hooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
func (h Hooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {}
func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec) {}
func (h Hooks) UnbondingDelegationEntryCreated(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress, _ int64, _ time.Time, _ sdk.Int, _ uint64) {
}
func (h Hooks) BeforeUnbondingDelegationEntryComplete(_ sdk.Context, _ uint64) bool {
return false
func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) {
}
Loading

0 comments on commit 179f43a

Please sign in to comment.