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

feat: Shared Staking #209

Merged
merged 2 commits into from
Dec 13, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ An '!' indicates a state machine breaking change.

## Unreleased

### Features

- ! (`x/stakers`) [#209](https://github.com/KYVENetwork/chain/pull/209) Shared Staking: Consensus-validator stake is now used for the protocol.

### Bug Fixes

- ! [#207](https://github.com/KYVENetwork/chain/pull/207) Added test case for points.

## [v1.5.0](https://github.com/KYVENetwork/chain/releases/tag/v1.5.0) - 2024-07-05
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

v2_0 "github.com/KYVENetwork/chain/app/upgrades/v2_0"
"github.com/KYVENetwork/chain/app/upgrades/v2_0"
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down
10 changes: 6 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ accounts:
- name: dummy # kyve137v27tfyegc083w5kj9zhhrfk34n8vhjma73gq
coins:
- 1000000tkyve # 1 tkyve -> 6 decimals
mnemonic: expect crisp umbrella hospital firm exhibit future size slot update blood
deliver fat happy ghost visa recall usual path purity junior ring ordinary stove
mnemonic: expect crisp umbrella hospital firm exhibit future size slot update blood deliver fat happy ghost visa recall usual path purity junior ring ordinary stove
- name: alice # kyve1jq304cthpx0lwhpqzrdjrcza559ukyy3zsl2vd
coins:
- 1000000000acoin # 1000 acoins -> 6 decimals
- 1000000000000bcoin # 1000 bcoins -> 9 decimals
- 1000000000ccoin # 1000 ccoins -> 6 decimals
- 2000000000000tkyve # 2M tkyve -> 6 decimals
mnemonic: worry grief loyal smoke pencil arrow trap focus high pioneer tomato hedgehog
essence purchase dove pond knee custom phone gentle sunset addict mother fabric
mnemonic: worry grief loyal smoke pencil arrow trap focus high pioneer tomato hedgehog essence purchase dove pond knee custom phone gentle sunset addict mother fabric
- name: bob # kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq
coins:
- 1000000000acoin # 1000 acoins -> 6 decimals
Expand Down Expand Up @@ -167,6 +165,10 @@ genesis:
binaries: ""
scheduled_at: "0"
duration: "0"
slashing:
params:
signed_blocks_window: 10
min_signed_per_window: "0.5"
stakers:
params:
commission_change_time: 10
Expand Down
45 changes: 14 additions & 31 deletions proto/kyve/stakers/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package kyve.stakers.v1beta1;

import "gogoproto/gogo.proto";
import "kyve/stakers/v1beta1/params.proto";
import "kyve/stakers/v1beta1/stakers.proto";

option go_package = "github.com/KYVENetwork/chain/x/stakers/types";

Expand All @@ -18,37 +19,6 @@ message EventUpdateParams {
string payload = 3;
}

// EventCreateStaker is an event emitted when a protocol node stakes in a pool.
// emitted_by: MsgCreateStaker
message EventCreateStaker {
// staker is the account address of the protocol node.
string staker = 1;
// amount ...
uint64 amount = 2;
// commission
string commission = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}

// EventUpdateMetadata is an event emitted when a protocol node updates their metadata.
// emitted_by: MsgUpdateMetadata
message EventUpdateMetadata {
// staker is the account address of the protocol node.
string staker = 1;
// moniker ...
string moniker = 2;
// website ...
string website = 3;
// identity ...
string identity = 4;
// security_contact ...
string security_contact = 5;
// details ...
string details = 6;
}

// EventUpdateCommission ...
// emitted_by: EndBlock
message EventUpdateCommission {
Expand Down Expand Up @@ -92,3 +62,16 @@ message EventLeavePool {
// staker ...
string staker = 2;
}

// EventSlash is an event emitted when a protocol node is slashed.
// emitted_by: MsgSubmitBundleProposal, EndBlock
message EventSlash {
// pool_id is the unique ID of the pool.
uint64 pool_id = 1;
// staker is the account address of the protocol node.
string staker = 2;
// amount ...
uint64 amount = 3;
// slash_type
SlashType slash_type = 4;
}
15 changes: 15 additions & 0 deletions proto/kyve/stakers/v1beta1/stakers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "gogoproto/gogo.proto";

option go_package = "github.com/KYVENetwork/chain/x/stakers/types";

// deprecated
// Staker contains all metadata for a staker
// Every address can only create one staker (itself)
message Staker {
Expand Down Expand Up @@ -104,3 +105,17 @@ message QueueState {
// are added to the top.
uint64 high_index = 2;
}

// SlashType ...
enum SlashType {
option (gogoproto.goproto_enum_prefix) = false;

// SLASH_TYPE_UNSPECIFIED ...
SLASH_TYPE_UNSPECIFIED = 0;
// SLASH_TYPE_TIMEOUT ...
SLASH_TYPE_TIMEOUT = 1;
// SLASH_TYPE_VOTE ...
SLASH_TYPE_VOTE = 2;
// SLASH_TYPE_UPLOAD ...
SLASH_TYPE_UPLOAD = 3;
}
65 changes: 3 additions & 62 deletions proto/kyve/stakers/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ syntax = "proto3";

package kyve.stakers.v1beta1;

import "amino/amino.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
Expand All @@ -13,14 +11,8 @@ option go_package = "github.com/KYVENetwork/chain/x/stakers/types";
// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
// CreateStaker ...
rpc CreateStaker(MsgCreateStaker) returns (MsgCreateStakerResponse);
// UpdateMetadata ...
rpc UpdateMetadata(MsgUpdateMetadata) returns (MsgUpdateMetadataResponse);
// UpdateCommission ...
rpc UpdateCommission(MsgUpdateCommission) returns (MsgUpdateCommissionResponse);
// ClaimCommissionRewards ...
rpc ClaimCommissionRewards(MsgClaimCommissionRewards) returns (MsgClaimCommissionRewardsResponse);
// JoinPool ...
rpc JoinPool(MsgJoinPool) returns (MsgJoinPoolResponse);
// LeavePool ...
Expand All @@ -31,44 +23,6 @@ service Msg {
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgCreateStaker defines a SDK message for creating a staker.
message MsgCreateStaker {
option (cosmos.msg.v1.signer) = "creator";
// creator is the address of the staker.
string creator = 1;
// amount is the initial self-stake of the staker.
uint64 amount = 2;
// commission is the percentage that is deducted from rewards before
// distributing the staker's delegators.
string commission = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}

// MsgStakePoolResponse defines the Msg/StakePool response type.
message MsgCreateStakerResponse {}

// MsgUpdateMetadata defines a SDK message for claiming the uploader role.
message MsgUpdateMetadata {
option (cosmos.msg.v1.signer) = "creator";
// creator ...
string creator = 1;
// moniker ...
string moniker = 2;
// website ...
string website = 3;
// identity from keybase.io
string identity = 4;
// security_contact ...
string security_contact = 5;
// details ...
string details = 6;
}

// MsgUpdateMetadataResponse defines the Msg/MsgUpdateMetadata response type.
message MsgUpdateMetadataResponse {}

// MsgUpdateCommission ...
message MsgUpdateCommission {
option (cosmos.msg.v1.signer) = "creator";
Expand All @@ -84,22 +38,6 @@ message MsgUpdateCommission {
// MsgUpdateCommissionResponse ...
message MsgUpdateCommissionResponse {}

// MsgClaimCommissionRewards ...
message MsgClaimCommissionRewards {
option (cosmos.msg.v1.signer) = "creator";
// creator ...
string creator = 1;
// amounts ...
repeated cosmos.base.v1beta1.Coin amounts = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// MsgClaimCommissionRewardsResponse ...
message MsgClaimCommissionRewardsResponse {}

// MsgJoinPool ...
message MsgJoinPool {
option (cosmos.msg.v1.signer) = "creator";
Expand All @@ -111,6 +49,9 @@ message MsgJoinPool {
string valaddress = 3;
// amount ...
uint64 amount = 4;

// TODO add stake fraction (in next PR)
// TODO add commission (in next PR)
}

// MsgJoinPoolResponse ...
Expand Down
82 changes: 82 additions & 0 deletions testutil/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Create Funder

./build/kyved tx funders create-funder funder1 --from alice --keyring-backend test --yes --fees 5000tkyve --gas 200000 --home ~/.chain --chain-id kyve-local
./build/kyved tx funders fund-pool 0 100000000acoin 1000000acoin --from alice --keyring-backend test --yes --fees 5000tkyve --gas 200000 --home ~/.chain --chain-id kyve-local

Create Validator

```shell
./build/kyved tx staking create-validator validator_bob.json --from bob --keyring-backend test --yes --fees 5000tkyve --gas 200000 --home ~/.chain --chain-id kyve-local
```

```shell
./build/kyved tx staking create-validator validator_charlie.json --from charlie --keyring-backend test --yes --fees 5000tkyve --gas 200000 --home ~/.chain --chain-id kyve-local
```

Join pools

# bob - dummy
```shell
./build/kyved tx stakers join-pool 0 kyve137v27tfyegc083w5kj9zhhrfk34n8vhjma73gq 1000000 --yes --from bob --home ~/.chain --keyring-backend test --chain-id kyve-local --fees 4000tkyve
```

# charlie - faucet kyve1kahmjds2rxj2qzamdvy5m8ljnkqrf5xhetes7q
```shell
./build/kyved tx stakers join-pool 0 kyve1kahmjds2rxj2qzamdvy5m8ljnkqrf5xhetes7q 1000000 --yes --from charlie --home ~/.chain --keyring-backend test --chain-id kyve-local --fees 4000tkyve
```

Submit Bundle proposal

Charlie submit bundle:
staker pool_id storage_id ... hash, from_index, bundle_size ...

# Submit Charlie kyve1ay22rr3kz659fupu0tcswlagq4ql6rwm4nuv0s faucet
```shell
./build/kyved tx bundles submit-bundle-proposal kyve1ay22rr3kz659fupu0tcswlagq4ql6rwm4nuv0s 0 "not-empty" 1024 hash 0 100 0 99 summary --from faucet --keyring-backend test --chain-id kyve-local --home ~/.chain --yes --fees 8000tkyve --gas 400000
```

# Submit Bob kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq dummy
```shell
./build/kyved tx bundles submit-bundle-proposal kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq 0 "not-empty" 1024 hash 500 100 0 99 summary --from dummy --keyring-backend test --chain-id kyve-local --home ~/.chain --yes --fees 8000tkyve --gas 400000
```

./build/kyved tx bundles claim-uploader-role kyve1ay22rr3kz659fupu0tcswlagq4ql6rwm4nuv0s 0 --from faucet --keyring-backend test --chain-id kyve-local --home ~/.chain --yes --fees 4000tkyve
./build/kyved tx bundles claim-uploader-role kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq 0 --from bob --keyring-backend test --chain-id kyve-local --home ~/.chain --yes --fees 4000tkyve

./build/kyved tx bundles vote-bundle-proposal kyve1ay22rr3kz659fupu0tcswlagq4ql6rwm4nuv0s 0 "not-empty" 1 --from faucet --keyring-backend test --chain-id kyve-local --home ~/.chain --yes --fees 4000tkyve
./build/kyved tx bundles vote-bundle-proposal kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq 0 "not-empty" 1 --from dummy --keyring-backend test --chain-id kyve-local --home ~/.chain --yes --fees 4000tkyve





# Join Pool mynode Alice foundation
```
./build/kyved tx stakers join-pool 0 kyve1fd4qu868n7arav8vteghcppxxa0p2vna5f5ep8 1000000 --yes --from alice --home ~/.chain --keyring-backend test --chain-id kyve-alpha --fees 4000tkyve --node https://rpc.alpha.kyve.network:443
```


# Submit Charlie kyve1ay22rr3kz659fupu0tcswlagq4ql6rwm4nuv0s faucet
```shell
```
./build/kyved tx bundles submit-bundle-proposal kyve1eka2hngntu5r2yeuyz5pd45a0fadarp3zue8gd 0 "not-empty" 1024 hash 300 100 0 99 summary --from dummy --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 8000tkyve --gas 400000 --node https://rpc.alpha.kyve.network:443
./build/kyved tx bundles submit-bundle-proposal kyve1s7j6ccd4ule2cwtxsecqvfjmfm0u40g5drx8zl 0 "not-empty" 1024 hash 400 100 0 99 summary --from faucet --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 8000tkyve --gas 400000 --node https://rpc.alpha.kyve.network:443
./build/kyved tx bundles submit-bundle-proposal kyve1jq304cthpx0lwhpqzrdjrcza559ukyy3zsl2vd 0 "not-empty" 1024 hash 200 100 0 99 summary --from dummy --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 8000tkyve --gas 400000 --node https://rpc.alpha.kyve.network:443


# Submit Bob kyve1hvg7zsnrj6h29q9ss577mhrxa04rn94h7zjugq dummy
```shell
```

./build/kyved tx bundles claim-uploader-role kyve1eka2hngntu5r2yeuyz5pd45a0fadarp3zue8gd 0 --from bob --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 4000tkyve --node https://rpc.alpha.kyve.network:443
./build/kyved tx bundles claim-uploader-role kyve1s7j6ccd4ule2cwtxsecqvfjmfm0u40g5drx8zl 0 --from faucet --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 4000tkyve --node https://rpc.alpha.kyve.network:443

./build/kyved tx bundles vote-bundle-proposal kyve1eka2hngntu5r2yeuyz5pd45a0fadarp3zue8gd 0 "not-empty" 1 --from dummy --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 4000tkyve --node https://rpc.alpha.kyve.network:443
./build/kyved tx bundles vote-bundle-proposal kyve1s7j6ccd4ule2cwtxsecqvfjmfm0u40g5drx8zl 0 "not-empty" 1 --from faucet --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 4000tkyve --node https://rpc.alpha.kyve.network:443
./build/kyved tx bundles vote-bundle-proposal kyve1jq304cthpx0lwhpqzrdjrcza559ukyy3zsl2vd 0 "not-empty" 2 --from foundation --keyring-backend test --chain-id kyve-alpha --home ~/.chain --yes --fees 4000tkyve --node https://rpc.alpha.kyve.network:443


# Create Funder

./build/kyved tx funders create-funder funder1 --from alice --keyring-backend test --yes --fees 5000tkyve --gas 200000 --home ~/.chain --chain-id kyve-alpha --node https://rpc.alpha.kyve.network
./build/kyved tx funders fund-pool 0 100000000acoin 1000000acoin --from alice --keyring-backend test --yes --fees 5000tkyve --gas 200000 --home ~/.chain --chain-id kyve-alpha --node https://rpc.alpha.kyve.network
Loading
Loading