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

LSM Staking and Slashing #9

Merged
merged 26 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
00e671a
proto-gen
sampocs Jun 20, 2023
319337f
copied over staking protos
sampocs Jun 20, 2023
e81ad50
updated proto package name and fixed lint errors
sampocs Jun 20, 2023
25460ac
generated staking protos
sampocs Jun 20, 2023
01505b7
copied over module level files
sampocs Jun 20, 2023
988802b
removed min self delegation
sampocs Jun 20, 2023
b175c50
copied over staking types
sampocs Jun 20, 2023
c86a47b
copied over staking client
sampocs Jun 20, 2023
29052f5
copied over teststaking
sampocs Jun 20, 2023
b59ecbf
fixed build errors related to teststaking or min-self-delegation
sampocs Jun 20, 2023
cc8b59c
copied over staking simulation
sampocs Jun 20, 2023
0cfb4cb
copied over staking keeper
sampocs Jun 21, 2023
af19f65
removed GetLiquidDelegation
sampocs Jun 21, 2023
aa8b986
removed GetLiquidValidator
sampocs Jun 21, 2023
fd8434f
removed GetLiquidHistoricalInfo
sampocs Jun 21, 2023
b941dc8
removed GetLiquidBondedValidatorsByPower
sampocs Jun 21, 2023
38b5c5d
removed GetAllLiquidDelegations
sampocs Jun 21, 2023
c087b45
resolved batch of build errors in staking
sampocs Jun 21, 2023
7881f29
resolved batch of build errors from staking in other modules
sampocs Jun 21, 2023
c351d6d
fixed simulation tests for non-lsm txs
sampocs Jun 21, 2023
a1b58ed
misc small changes while fixing staking unit tests
sampocs Jun 21, 2023
fba2912
added back delegation_test that was removed
sampocs Jun 21, 2023
da29a2d
copied over slashing files
sampocs Jun 21, 2023
62289c7
removed/fixed tests that reference min_self_delegation
sampocs Jun 21, 2023
5743c84
fixed unit tests related to jailing a validator
sampocs Jun 22, 2023
7a79d16
fixed staking cli tests
sampocs Jun 22, 2023
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
2 changes: 1 addition & 1 deletion codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) {

func TestAminoCodecFullDecodeAndEncode(t *testing.T) {
// This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117.
txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}`
txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}`
legacyCdc := simapp.MakeTestEncodingConfig().Amino
var tx legacytx.StdTx
err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx)
Expand Down
587 changes: 581 additions & 6 deletions docs/core/proto-docs.md

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions proto/cosmos/base/store/v1beta1/listening.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ message StoreKVPair {
// BlockMetadata contains all the abci event data of a block
// the file streamer dump them into files together with the state changes.
message BlockMetadata {
// DeliverTx encapulate deliver tx request and response.
message DeliverTx {
tendermint.abci.RequestDeliverTx request = 1;
tendermint.abci.ResponseDeliverTx response = 2;
}
tendermint.abci.RequestBeginBlock request_begin_block = 1;
tendermint.abci.ResponseBeginBlock response_begin_block = 2;
repeated DeliverTx deliver_txs = 3;
tendermint.abci.RequestEndBlock request_end_block = 4;
tendermint.abci.ResponseEndBlock response_end_block = 5;
tendermint.abci.ResponseCommit response_commit = 6;
// DeliverTx encapulate deliver tx request and response.
message DeliverTx {
tendermint.abci.RequestDeliverTx request = 1;
tendermint.abci.ResponseDeliverTx response = 2;
}
tendermint.abci.RequestBeginBlock request_begin_block = 1;
tendermint.abci.ResponseBeginBlock response_begin_block = 2;
repeated DeliverTx deliver_txs = 3;
tendermint.abci.RequestEndBlock request_end_block = 4;
tendermint.abci.ResponseEndBlock response_end_block = 5;
tendermint.abci.ResponseCommit response_commit = 6;
}
6 changes: 6 additions & 0 deletions proto/cosmos/staking/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ message GenesisState {
repeated Redelegation redelegations = 7 [(gogoproto.nullable) = false];

bool exported = 8;

// store tokenize share records to provide reward to record owners
repeated TokenizeShareRecord tokenize_share_records = 9 [(gogoproto.nullable) = false];

// last tokenize share record id, used for next share record id calculation
uint64 last_tokenize_share_record_id = 10;
}

// LastValidatorPower required for validator set update logic.
Expand Down
127 changes: 124 additions & 3 deletions proto/cosmos/staking/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/staking/v1beta1/staking.proto";
import "cosmos/base/v1beta1/coin.proto";

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

Expand Down Expand Up @@ -90,6 +91,34 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/staking/v1beta1/params";
}

// Query for individual tokenize share record information by share by id
rpc TokenizeShareRecordById(QueryTokenizeShareRecordByIdRequest) returns (QueryTokenizeShareRecordByIdResponse) {}

// Query for individual tokenize share record information by share denom
rpc TokenizeShareRecordByDenom(QueryTokenizeShareRecordByDenomRequest)
returns (QueryTokenizeShareRecordByDenomResponse) {}

// Query tokenize share records by address
rpc TokenizeShareRecordsOwned(QueryTokenizeShareRecordsOwnedRequest)
returns (QueryTokenizeShareRecordsOwnedResponse) {}

// Query for all tokenize share records
rpc AllTokenizeShareRecords(QueryAllTokenizeShareRecordsRequest) returns (QueryAllTokenizeShareRecordsResponse) {}

// Query for last tokenize share record id
rpc LastTokenizeShareRecordId(QueryLastTokenizeShareRecordIdRequest)
returns (QueryLastTokenizeShareRecordIdResponse) {}

// Query for total tokenized staked assets
rpc TotalTokenizeSharedAssets(QueryTotalTokenizeSharedAssetsRequest)
returns (QueryTotalTokenizeSharedAssetsResponse) {}

// Query for total liquid staked (including tokenized shares or owned by an liquid staking provider)
rpc TotalLiquidStaked(QueryTotalLiquidStaked) returns (QueryTotalLiquidStakedResponse) {}

// Query tokenize share locks
rpc TokenizeShareLockInfo(QueryTokenizeShareLockInfo) returns (QueryTokenizeShareLockInfoResponse) {}
}

// QueryValidatorsRequest is request type for Query/Validators RPC method.
Expand Down Expand Up @@ -118,7 +147,7 @@ message QueryValidatorRequest {

// QueryValidatorResponse is response type for the Query/Validator RPC method
message QueryValidatorResponse {
// validator defines the the validator info.
// validator defines the validator info.
Validator validator = 1 [(gogoproto.nullable) = false];
}

Expand Down Expand Up @@ -288,7 +317,7 @@ message QueryDelegatorValidatorsRequest {
// QueryDelegatorValidatorsResponse is response type for the
// Query/DelegatorValidators RPC method.
message QueryDelegatorValidatorsResponse {
// validators defines the the validators' info of a delegator.
// validators defines the validators' info of a delegator.
repeated Validator validators = 1 [(gogoproto.nullable) = false];

// pagination defines the pagination in the response.
Expand All @@ -311,7 +340,7 @@ message QueryDelegatorValidatorRequest {
// QueryDelegatorValidatorResponse response type for the
// Query/DelegatorValidator RPC method.
message QueryDelegatorValidatorResponse {
// validator defines the the validator info.
// validator defines the validator info.
Validator validator = 1 [(gogoproto.nullable) = false];
}

Expand Down Expand Up @@ -346,3 +375,95 @@ message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}

// QueryTokenizeShareRecordByIdRequest is request type for the
// Query/QueryTokenizeShareRecordById RPC method.
message QueryTokenizeShareRecordByIdRequest {
uint64 id = 1;
}

// QueryTokenizeShareRecordByIdRequest is response type for the
// Query/QueryTokenizeShareRecordById RPC method.
message QueryTokenizeShareRecordByIdResponse {
TokenizeShareRecord record = 1 [(gogoproto.nullable) = false];
}

// QueryTokenizeShareRecordByDenomRequest is request type for the
// Query/QueryTokenizeShareRecordByDenom RPC method.
message QueryTokenizeShareRecordByDenomRequest {
string denom = 1;
}

// QueryTokenizeShareRecordByDenomResponse is response type for the
// Query/QueryTokenizeShareRecordByDenom RPC method.
message QueryTokenizeShareRecordByDenomResponse {
TokenizeShareRecord record = 1 [(gogoproto.nullable) = false];
}

// QueryTokenizeShareRecordsOwnedRequest is request type for the
// Query/QueryTokenizeShareRecordsOwned RPC method.
message QueryTokenizeShareRecordsOwnedRequest {
string owner = 1;
}

// QueryTokenizeShareRecordsOwnedResponse is response type for the
// Query/QueryTokenizeShareRecordsOwned RPC method.
message QueryTokenizeShareRecordsOwnedResponse {
repeated TokenizeShareRecord records = 1 [(gogoproto.nullable) = false];
}

// QueryAllTokenizeShareRecordsRequest is request type for the
// Query/QueryAllTokenizeShareRecords RPC method.
message QueryAllTokenizeShareRecordsRequest {}

// QueryAllTokenizeShareRecordsResponse is response type for the
// Query/QueryAllTokenizeShareRecords RPC method.
message QueryAllTokenizeShareRecordsResponse {
repeated TokenizeShareRecord records = 1 [(gogoproto.nullable) = false];
}

// QueryLastTokenizeShareRecordIdRequest is request type for the
// Query/QueryLastTokenizeShareRecordId RPC method.
message QueryLastTokenizeShareRecordIdRequest {}

// QueryLastTokenizeShareRecordIdResponse is response type for the
// Query/QueryLastTokenizeShareRecordId RPC method.
message QueryLastTokenizeShareRecordIdResponse {
uint64 id = 1;
}

// QueryTotalTokenizeSharedAssetsRequest is request type for the
// Query/QueryTotalTokenizeSharedAssets RPC method.
message QueryTotalTokenizeSharedAssetsRequest {}

// QueryTotalTokenizeSharedAssetsResponse is response type for the
// Query/QueryTotalTokenizeSharedAssets RPC method.
message QueryTotalTokenizeSharedAssetsResponse {
cosmos.base.v1beta1.Coin value = 1 [(gogoproto.nullable) = false];
}

// QueryQueryTotalLiquidStakedRequest is request type for the
// Query/QueryQueryTotalLiquidStaked RPC method.
message QueryTotalLiquidStaked {}

// QueryQueryTotalLiquidStakedResponse is response type for the
// Query/QueryQueryTotalLiquidStaked RPC method.
message QueryTotalLiquidStakedResponse {
string tokens = 1 [
(gogoproto.moretags) = "yaml:\"tokens\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// QueryTokenizeShareLockInfo queries the tokenize share lock information
// associated with given account
message QueryTokenizeShareLockInfo {
string address = 1;
}
// QueryTokenizeShareLockInfoResponse is the response from the
// QueryTokenizeShareLockInfo query
message QueryTokenizeShareLockInfoResponse {
string status = 1;
string expiration_time = 2;
}
82 changes: 74 additions & 8 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,23 @@ message Validator {
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true, (gogoproto.moretags) = "yaml:\"unbonding_time\""];
// commission defines the commission parameters.
Commission commission = 10 [(gogoproto.nullable) = false];
// min_self_delegation is the validator's self declared minimum self delegation.
string min_self_delegation = 11 [
(gogoproto.moretags) = "yaml:\"min_self_delegation\"",
(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;
// Number of shares self bonded from the validator
string total_validator_bond_shares = 14 [
(gogoproto.moretags) = "yaml:\"total_validator_bond_shares\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Total number of shares either tokenized or owned by a liquid staking provider
string total_liquid_shares = 15 [
(gogoproto.moretags) = "yaml:\"total_liquid_shares\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
reserved 11;
}

// BondStatus is the status of a validator.
Expand Down Expand Up @@ -198,6 +203,8 @@ message Delegation {
string validator_address = 2 [(gogoproto.moretags) = "yaml:\"validator_address\""];
// shares define the delegation shares received.
string shares = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
// has this delegation been marked as a validator self bond.
bool validator_bond = 4;
}

// UnbondingDelegation stores all of a single delegator's unbonding bonds
Expand Down Expand Up @@ -301,6 +308,33 @@ message Params {
uint32 historical_entries = 4 [(gogoproto.moretags) = "yaml:\"historical_entries\""];
// bond_denom defines the bondable coin denomination.
string bond_denom = 5 [(gogoproto.moretags) = "yaml:\"bond_denom\""];
// min_commission_rate is the chain-wide minimum commission rate that a validator can charge their delegators
string min_commission_rate = 6 [
(gogoproto.moretags) = "yaml:\"min_commission_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// validator_bond_factor is required as a safety check for tokenizing shares and
// delegations from liquid staking providers
string validator_bond_factor = 7 [
(gogoproto.moretags) = "yaml:\"validator_bond_factor\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// global_liquid_staking_cap represents a cap on the portion of stake that
// comes from liquid staking providers
string global_liquid_staking_cap = 8 [
(gogoproto.moretags) = "yaml:\"global_liquid_staking_cap\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// validator_liquid_staking_cap represents a cap on the portion of stake that
// comes from liquid staking providers for a specific validator
string validator_liquid_staking_cap = 9 [
(gogoproto.moretags) = "yaml:\"validator_liquid_staking_cap\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// DelegationResponse is equivalent to Delegation except that it contains a
Expand Down Expand Up @@ -367,4 +401,36 @@ enum InfractionType {
// ValidatorUpdates defines an array of abci.ValidatorUpdate objects.
message ValidatorUpdates {
repeated tendermint.abci.ValidatorUpdate updates = 1 [(gogoproto.nullable) = false];
}

// TokenizeShareRecord represents a tokenized delegation
message TokenizeShareRecord {
option (gogoproto.description) = true;
option (gogoproto.equal) = true;

uint64 id = 1;
string owner = 2;
string module_account = 3; // module account take the role of delegator
string validator = 4; // validator delegated to for tokenize share record creation
}

// PendingTokenizeShareAuthorizations stores a list of addresses that have their
// tokenize share enablement in progress
message PendingTokenizeShareAuthorizations {
repeated string addresses = 1;
}

// TokenizeShareLockStatus indicates whether the address is able to tokenize shares
enum TokenizeShareLockStatus {
option (gogoproto.goproto_enum_prefix) = false;

// UNSPECIFIED defines an empty tokenize share lock status
TOKENIZE_SHARE_LOCK_STATUS_UNSPECIFIED = 0;
// LOCKED indicates the account is locked and cannot tokenize shares
TOKENIZE_SHARE_LOCK_STATUS_LOCKED = 1;
// UNLOCKED indicates the account is unlocked and can tokenize shares
TOKENIZE_SHARE_LOCK_STATUS_UNLOCKED = 2;
// LOCK_EXPIRING indicates the account is unable to tokenize shares, but
// will be able to tokenize shortly (after 1 unbonding period)
TOKENIZE_SHARE_LOCK_STATUS_LOCK_EXPIRING = 3;
}
Loading