Skip to content

Commit

Permalink
Interchain security rebase (#13722)
Browse files Browse the repository at this point in the history
* feat: store ABCI validator updates in transient store

* fix test build

* change transient key name

* add UnbondingDelegationEntryCreated hook

* add id to UnbondingDelegationEntry

* changes to add simple version of staking ccv hooks

* ubde id to string

* rough draft of more efficient technique

* change hook api and do some clean ups

* use ByEntry index and keep stopped entries in Entries array

* correct error convention

* add comment

* some cleanups

* comment cleanup

* finish hooking up hooks

* get the tests to pass

* proof of concept with embedded mock hooks

* first unit test of CCV hooks

* fix forgotten pointer bug

* move hook mocks into own file

* added test for completing stopped unbonding early

* added staking hooks template

* correct file and module names

* clean up and fix import error

* move staking hooks template to types

* fix hooks after merge

* fix silly proto bug

* feat: Add AfterValidatorDowntime hook in slashing module (#10938)

Create a slashing hook that allows external modules to register an execution when a validator has downtime.

Implementation details:

* Call hook in HandleValidatorSignature (x/slashing/keeper/infractions.go) which updates validator SignInfo data

* Defer hook execution in case it also wants to update validator SignInfo data

* Add methods to update SignInfo to slashing keeper interface(/x/slashing/types/expected_keepers.go)

* update: Remove slashing module hooks (#11425)

* update: Remove slashing module hooks

Hooks are not required anymore to implement the slashing for downtime in CCV. The logic is now using the staking keeper interface definition from the slashing module.

The SDK changes are the following:
- /x/slashing/keeper/infractions.go - remove hook calls and don't update validators missed blocks when jailed

- /x/slashing/types/expected_keepers.go - remove `AfterValidatorDowntime` hook interface and add `IsJailed()` method to staking interface definition

- /x/staking/keeper/validator.go - implement `IsJailed()` method

* fix last details

* Finish staking hooks merge (#11677)

* allow stopping and completing of redelegations

* refactor to remove BeforeUnbondingDelegationEntryComplete hook and notes for validator unbonding

* WIP rough draft of validator unbonding hooks

* add many of marius's suggested changes

* More review changes

* unbonding delegation tests pass

* WIP adding redelegation tests

* WIP redelegation tests work

* unbondingDelegation and redelegation tests pass and cleanup

* WIP validator unbonding tests almost pass

* tests for all new functionality pass

* fix index deleting logic

* clean up TODOs

* fix small logic bug

* fix slashing tests

* Rename statements containing 'UnbondingOp' to 'Unbond' in code, docs and proto files

Co-authored-by: Simon <[email protected]>

* feat: enable double-signing evidence in Interchain-Security (#11921)

* Add a `InfractionType` enum to Slash function arguments

* Remove pubkey condition in HandleEquivocation

* Update docs/core/proto-docs.md

Co-authored-by: billy rennekamp <[email protected]>

* Update proto/cosmos/staking/v1beta1/staking.proto

Co-authored-by: billy rennekamp <[email protected]>

* add a possible solution to the evidence module issue

Co-authored-by: billy rennekamp <[email protected]>

* chore: remove direct reliance on staking from slashing (backport #12177) (#12181)

* fix: make ModuleAccountInvariants pass for IS SDK changes (#12554)

* fix bug breaking ModuleAccountInvariants

* set UnbondingOnHold to false explicitly

* Fixes staking hooks safety issues (#12578)

Co-authored-by: Daniel T <[email protected]>

* Revert "fix: make ModuleAccountInvariants pass for IS SDK changes (#12554)" (#12782)

This reverts commit 67c8163.

* fix: make ModuleAccountInvariants pass for IS SDK changes (#12783)

* fix bug breaking ModuleAccountInvariants

* set UnbondingOnHold to false explicitly

* fix: [Interchain Security] `validatorUnbondingCanComplete` must take into account (re)bonded validators (#12796)

* replace val.UnbondingOnHold w/ UnbondingOnHoldRefCount

* add UnbondingOnHoldRefCount for undel and red (for consistency)

* improve comments

* improve TestValidatorUnbondingOnHold test

* ret error if UnbondingOnHoldRefCount is negative

* adding extra validator unbonding test

* change OnHold() def

* fix: [Interchain Security] Fix leak in unbonding hooks (#12849)

* remove leak for UBDEs and REDEs

* remove leak for val unbondings

* docs: [Interchain Security] update spec (#12848)

* updating staking spec

* clarify code

* fix typo

* store ValidatorUpdates in normal store (#12845)

* Update x/slashing/keeper/signing_info.go

Co-authored-by: Simon Noetzlin <[email protected]>

* Update x/staking/keeper/val_state_change.go

* Update x/staking/keeper/val_state_change.go

* Update x/slashing/keeper/infractions.go

Co-authored-by: Simon Noetzlin <[email protected]>

* Update x/staking/keeper/val_state_change.go

* Update x/staking/keeper/val_state_change.go

* fix compile errors

* remove stakingtypes.TStoreKey

* fix: decrease minimums for genesis parameters (#13106)

* Update genesis.go

* Update genesis.go

Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: Aditya Sripal <[email protected]>
Co-authored-by: Simon Noetzlin <[email protected]>
Co-authored-by: billy rennekamp <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Marius Poke <[email protected]>
Co-authored-by: Daniel T <[email protected]>
Co-authored-by: Shawn Marshall-Spitzbart <[email protected]>
  • Loading branch information
9 people authored Nov 1, 2022
1 parent 3d54be5 commit 8f913f8
Show file tree
Hide file tree
Showing 45 changed files with 2,747 additions and 964 deletions.
36 changes: 36 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,10 @@
- [UnbondingDelegationEntry](#cosmos.staking.v1beta1.UnbondingDelegationEntry)
- [ValAddresses](#cosmos.staking.v1beta1.ValAddresses)
- [Validator](#cosmos.staking.v1beta1.Validator)
- [ValidatorUpdates](#cosmos.staking.v1beta1.ValidatorUpdates)

- [BondStatus](#cosmos.staking.v1beta1.BondStatus)
- [InfractionType](#cosmos.staking.v1beta1.InfractionType)

- [cosmos/staking/v1beta1/genesis.proto](#cosmos/staking/v1beta1/genesis.proto)
- [GenesisState](#cosmos.staking.v1beta1.GenesisState)
Expand Down Expand Up @@ -6745,6 +6747,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_ref_count` | [int64](#int64) | | Strictly positive if this entry's unbonding has been stopped by external modules |



Expand Down Expand Up @@ -6819,6 +6823,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. |
| `unbonding_id` | [uint64](#uint64) | | Incrementing id that uniquely identifies this entry |
| `unbonding_on_hold_ref_count` | [int64](#int64) | | Strictly positive if this entry's unbonding has been stopped by external modules |



Expand Down Expand Up @@ -6866,6 +6872,23 @@ 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_ref_count` | [int64](#int64) | | strictly positive if this validator's unbonding has been stopped by external modules |
| `unbonding_ids` | [uint64](#uint64) | repeated | list of unbonding ids, each uniquely identifing an unbonding of this validator |






<a name="cosmos.staking.v1beta1.ValidatorUpdates"></a>

### ValidatorUpdates
ValidatorUpdates defines an array of abci.ValidatorUpdate objects.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `updates` | [tendermint.abci.ValidatorUpdate](#tendermint.abci.ValidatorUpdate) | repeated | |



Expand All @@ -6887,6 +6910,19 @@ BondStatus is the status of a validator.
| BOND_STATUS_BONDED | 3 | BONDED defines a validator that is bonded. |



<a name="cosmos.staking.v1beta1.InfractionType"></a>

### InfractionType
InfractionType indicates the infraction type a validator commited.

| Name | Number | Description |
| ---- | ------ | ----------- |
| INFRACTION_TYPE_UNSPECIFIED | 0 | UNSPECIFIED defines an empty infraction type. |
| INFRACTION_TYPE_DOUBLE_SIGN | 1 | DOUBLE_SIGN defines a validator that double-signs a block. |
| INFRACTION_TYPE_DOWNTIME | 2 | DOWNTIME defines a validator that missed signing too many blocks. |


<!-- end enums -->

<!-- end HasExtensions -->
Expand Down
2 changes: 0 additions & 2 deletions proto/cosmos/bank/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ message QueryAllBalancesResponse {
// balances is the 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;
}
Expand All @@ -113,7 +112,6 @@ 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;
}
Expand Down
36 changes: 36 additions & 0 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "google/protobuf/timestamp.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "tendermint/types/types.proto";
import "tendermint/abci/types.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/staking/types";

Expand Down Expand Up @@ -117,6 +118,12 @@ message Validator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

// strictly positive if this validator's unbonding has been stopped by external modules
int64 unbonding_on_hold_ref_count = 12;

// list of unbonding ids, each uniquely identifing an unbonding of this validator
repeated uint64 unbonding_ids = 13;
}

// BondStatus is the status of a validator.
Expand Down Expand Up @@ -226,6 +233,12 @@ message UnbondingDelegationEntry {
];
// balance defines the tokens to receive at completion.
string balance = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];

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

// Strictly positive if this entry's unbonding has been stopped by external modules
int64 unbonding_on_hold_ref_count = 6;
}

// RedelegationEntry defines a redelegation object with relevant metadata.
Expand All @@ -247,6 +260,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;

// Strictly positive if this entry's unbonding has been stopped by external modules
int64 unbonding_on_hold_ref_count = 6;
}

// Redelegation contains the list of a particular delegator's redelegating bonds
Expand Down Expand Up @@ -332,3 +351,20 @@ message Pool {
(gogoproto.moretags) = "yaml:\"bonded_tokens\""
];
}

// InfractionType indicates the infraction type a validator commited.
enum InfractionType {
option (gogoproto.goproto_enum_prefix) = false;

// UNSPECIFIED defines an empty infraction type.
INFRACTION_TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "InfractionEmpty"];
// DOUBLE_SIGN defines a validator that double-signs a block.
INFRACTION_TYPE_DOUBLE_SIGN = 1 [(gogoproto.enumvalue_customname) = "DoubleSign"];
// DOWNTIME defines a validator that missed signing too many blocks.
INFRACTION_TYPE_DOWNTIME = 2 [(gogoproto.enumvalue_customname) = "Downtime"];
}

// ValidatorUpdates defines an array of abci.ValidatorUpdate objects.
message ValidatorUpdates {
repeated tendermint.abci.ValidatorUpdate updates = 1 [(gogoproto.nullable) = false];
}
1 change: 1 addition & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func NewSimApp(
authzkeeper.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)

// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
// not include this key.
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, "testingkey")
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.

Loading

0 comments on commit 8f913f8

Please sign in to comment.