Skip to content

Commit

Permalink
fix(staking): param staking periods and token types (cosmos#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezreal1997 authored Oct 17, 2024
1 parent 77940b3 commit a806101
Show file tree
Hide file tree
Showing 67 changed files with 2,687 additions and 2,234 deletions.
1,279 changes: 722 additions & 557 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Large diffs are not rendered by default.

521 changes: 256 additions & 265 deletions api/cosmos/staking/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

36 changes: 14 additions & 22 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,11 @@ message Description {
string details = 5;
}

enum TokenType {
LOCKED = 0;
UNLOCKED = 1;
}

message TokenTypeInfo {
TokenType token_type = 1;
string rewards_multiplier = 2 [
option (gogoproto.equal) = true;

int32 token_type = 1;
string rewards_multiplier = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false,
Expand Down Expand Up @@ -150,7 +147,7 @@ message Validator {
// list of unbonding ids, each uniquely identifing an unbonding of this validator
repeated uint64 unbonding_ids = 13;

TokenType support_token_type = 14;
int32 support_token_type = 14;

string delegator_rewards_shares = 15 [
(cosmos_proto.scalar) = "cosmos.Dec",
Expand Down Expand Up @@ -212,16 +209,12 @@ message DVVTriplets {
repeated DVVTriplet triplets = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

enum PeriodType {
FLEXIBLE = 0;
THREE_MONTHS = 1;
ONE_YEAR = 2;
EIGHTEEN_MONTHS = 3;
}
// Message representing the Period
message Period {
option (gogoproto.equal) = true;

// type defines the type of the staking period.
PeriodType period_type = 1; // Enum for period type
int32 period_type = 1;
// duration defines, if staked, the min time for the delegation.
google.protobuf.Duration duration = 2
[(gogoproto.nullable) = false, (amino.dont_omitempty) = true, (gogoproto.stdduration) = true];
Expand Down Expand Up @@ -249,7 +242,7 @@ message PeriodDelegation {
(gogoproto.nullable) = false
];

PeriodType period_type = 4;
int32 period_type = 4;

google.protobuf.Timestamp end_time = 5
[(gogoproto.nullable) = false, (amino.dont_omitempty) = true, (gogoproto.stdtime) = true];
Expand Down Expand Up @@ -402,12 +395,11 @@ message Params {
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// min_undelegation is the chain-wide minimum undelegation that an undelegation can set
string min_undelegation = 8 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];

int32 flexible_period_type = 8;
repeated Period periods = 9 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

repeated TokenTypeInfo token_types = 10 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// DelegationResponse is equivalent to Delegation except that it contains a
Expand Down
4 changes: 2 additions & 2 deletions proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ message MsgCreateValidator {
string validator_address = 5 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
TokenType support_token_type = 8 [(amino.dont_omitempty) = true];
int32 support_token_type = 8 [(amino.dont_omitempty) = true];
}

// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
Expand Down Expand Up @@ -114,7 +114,7 @@ message MsgDelegate {
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
string period_delegation_id = 4 [(amino.dont_omitempty) = true];
PeriodType period_type = 5 [(amino.dont_omitempty) = true];
int32 period_type = 5 [(amino.dont_omitempty) = true];
}

// MsgDelegateResponse defines the Msg/Delegate response type.
Expand Down
1 change: 1 addition & 0 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func initTestnetFiles(
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(math.LegacyOneDec(), math.LegacyOneDec(), math.LegacyOneDec()),
math.OneInt(),
0,
)
if err != nil {
return err
Expand Down
34 changes: 33 additions & 1 deletion tests/fixtures/adr-024-coin-metadata_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,39 @@
"historical_entries": 100,
"bond_denom": "stake",
"min_delegation": "1",
"min_undelegation": "1"
"flexible_period_type": 0,
"periods":[
{
"period_type": 0,
"duration": "0s",
"rewards_multiplier": "1"
},
{
"period_type": 1,
"duration": "2592000s",
"rewards_multiplier": "1.051"
},
{
"period_type": 2,
"duration": "31536000s",
"rewards_multiplier": "1.16"
},
{
"period_type": 3,
"duration": "46656000s",
"rewards_multiplier": "1.34"
}
],
"token_types":[
{
"token_type": 0,
"rewards_multiplier": "0.5"
},
{
"token_type": 1,
"rewards_multiplier": "1"
}
]
},
"last_total_power": "0",
"last_validator_powers": null,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/distribution/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func TestGRPCDelegationRewards(t *testing.T) {
stakingtypes.FlexiblePeriodDelegationID,
issuedShares,
issuedShares,
stakingtypes.PeriodType_FLEXIBLE,
stakingtypes.DefaultFlexiblePeriodType,
time.Time{},
)
assert.NilError(t, f.stakingKeeper.SetPeriodDelegation(f.sdkCtx, delAddr, f.valAddr, periodDel))
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
}

// setup staking validator
validator, err := stakingtypes.NewValidator(f.valAddr.String(), PKS[0], stakingtypes.Description{}, stakingtypes.TokenType_LOCKED)
validator, err := stakingtypes.NewValidator(f.valAddr.String(), PKS[0], stakingtypes.Description{}, 0)
assert.NilError(t, err)
commission := stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyOneDec(), math.LegacyOneDec())
validator, err = validator.SetInitialCommission(commission)
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
stakingtypes.FlexiblePeriodDelegationID,
issuedShares,
issuedShares,
stakingtypes.PeriodType_FLEXIBLE,
stakingtypes.DefaultFlexiblePeriodType,
time.Time{},
)
assert.NilError(t, f.stakingKeeper.SetPeriodDelegation(f.sdkCtx, delAddr, f.valAddr, periodDel))
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
pks := simtestutil.CreateTestPubKeys(5)

val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}, stakingtypes.TokenType_LOCKED)
val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}, 0)
assert.NilError(t, err)
val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}, stakingtypes.TokenType_LOCKED)
val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}, 0)
assert.NilError(t, err)
val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}, stakingtypes.TokenType_LOCKED)
val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}, 0)
assert.NilError(t, err)

f.stakingKeeper.SetValidator(f.ctx, val1)
Expand All @@ -58,9 +58,9 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
f.stakingKeeper.SetNewValidatorByPowerIndex(f.ctx, val2)
f.stakingKeeper.SetNewValidatorByPowerIndex(f.ctx, val3)

_, _, _ = f.stakingKeeper.Delegate(f.ctx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[0]), stakingtypes.Unbonded, val1, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, _ = f.stakingKeeper.Delegate(f.ctx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[1]), stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, _ = f.stakingKeeper.Delegate(f.ctx, addrs[2], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[2]), stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, _ = f.stakingKeeper.Delegate(f.ctx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[0]), stakingtypes.Unbonded, val1, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
_, _, _ = f.stakingKeeper.Delegate(f.ctx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[1]), stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
_, _, _ = f.stakingKeeper.Delegate(f.ctx, addrs[2], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[2]), stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))

f.stakingKeeper.EndBlocker(f.ctx)

Expand Down
18 changes: 9 additions & 9 deletions tests/integration/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestTallyDelgatorOverride(t *testing.T) {
val1, found := f.stakingKeeper.GetValidator(ctx, valAddrs[0])
assert.Assert(t, found)

_, _, err := f.stakingKeeper.Delegate(ctx, addrs[4], delTokens, stakingtypes.Unbonded, val1, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err := f.stakingKeeper.Delegate(ctx, addrs[4], delTokens, stakingtypes.Unbonded, val1, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)

f.stakingKeeper.EndBlocker(ctx)
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestTallyDelgatorInherit(t *testing.T) {
val3, found := f.stakingKeeper.GetValidator(ctx, vals[2])
assert.Assert(t, found)

_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)

f.stakingKeeper.EndBlocker(ctx)
Expand Down Expand Up @@ -358,9 +358,9 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
val2, found := f.stakingKeeper.GetValidator(ctx, vals[1])
assert.Assert(t, found)

_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val1, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val1, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)
_, _, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)

f.stakingKeeper.EndBlocker(ctx)
Expand Down Expand Up @@ -403,9 +403,9 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) {
val3, found := f.stakingKeeper.GetValidator(ctx, vals[2])
assert.Assert(t, found)

_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)
_, _, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)

f.stakingKeeper.EndBlocker(ctx)
Expand Down Expand Up @@ -445,9 +445,9 @@ func TestTallyJailedValidator(t *testing.T) {
val3, found := f.stakingKeeper.GetValidator(ctx, valAddrs[2])
assert.Assert(t, found)

_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)
_, _, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val3, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)

f.stakingKeeper.EndBlocker(ctx)
Expand Down Expand Up @@ -489,7 +489,7 @@ func TestTallyValidatorMultipleDelegations(t *testing.T) {
val2, found := f.stakingKeeper.GetValidator(ctx, valAddrs[1])
assert.Assert(t, found)

_, _, err := f.stakingKeeper.Delegate(ctx, addrs[0], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0))
_, _, err := f.stakingKeeper.Delegate(ctx, addrs[0], delTokens, stakingtypes.Unbonded, val2, true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0))
assert.NilError(t, err)

tp := TestProposal
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres

_, _, err := f.stakingKeeper.Delegate(
f.sdkCtx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[0]), types.Unbonded, val1,
true, types.FlexiblePeriodDelegationID, types.PeriodType_FLEXIBLE, time.Unix(0, 0),
true, types.FlexiblePeriodDelegationID, types.DefaultFlexiblePeriodType, time.Unix(0, 0),
)
assert.NilError(t, err)
_, _, err = f.stakingKeeper.Delegate(
f.sdkCtx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[1]), types.Unbonded, val2,
true, types.FlexiblePeriodDelegationID, types.PeriodType_FLEXIBLE, time.Unix(0, 0),
true, types.FlexiblePeriodDelegationID, types.DefaultFlexiblePeriodType, time.Unix(0, 0),
)
assert.NilError(t, err)
_, _, err = f.stakingKeeper.Delegate(
f.sdkCtx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[2]), types.Unbonded, val2,
true, types.FlexiblePeriodDelegationID, types.PeriodType_FLEXIBLE, time.Unix(0, 0),
true, types.FlexiblePeriodDelegationID, types.DefaultFlexiblePeriodType, time.Unix(0, 0),
)
assert.NilError(t, err)
applyValidatorSetUpdates(t, f.sdkCtx, f.stakingKeeper, -1)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
types.FlexiblePeriodDelegationID,
issuedShares,
issuedShares,
types.PeriodType_FLEXIBLE,
types.DefaultFlexiblePeriodType,
time.Time{},
)
assert.NilError(t, f.stakingKeeper.SetPeriodDelegation(f.sdkCtx, addrDel, addrVal, periodDel))
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/staking/keeper/determinstic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func createValidator(rt *rapid.T, f *deterministicFixture, t *testing.T) staking
),
MinSelfDelegation: math.NewInt(rapid.Int64Min(1).Draw(rt, "tokens")),
DelegatorRewardsShares: math.LegacyNewDecWithPrec(rapid.Int64Range(1, 100).Draw(rt, "commission"), 2),
SupportTokenType: stakingtypes.TokenType_LOCKED,
SupportTokenType: 0,
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes.

_, _, err = f.stakingKeeper.Delegate(
f.ctx, delegatorAddress, validator.BondedTokens(), stakingtypes.Unbonded, validator,
true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0),
true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0),
)
assert.NilError(t, err)
}
Expand Down Expand Up @@ -280,7 +280,7 @@ func getStaticValidator(f *deterministicFixture, t *testing.T) stakingtypes.Vali
),
MinSelfDelegation: math.NewInt(10),
DelegatorRewardsShares: math.LegacyNewDecWithPrec(5, 2),
SupportTokenType: stakingtypes.TokenType_LOCKED,
SupportTokenType: 0,
}

setValidator(f, t, validator)
Expand Down Expand Up @@ -316,7 +316,7 @@ func getStaticValidator2(f *deterministicFixture, t *testing.T) stakingtypes.Val
),
MinSelfDelegation: math.NewInt(1),
DelegatorRewardsShares: math.LegacyNewDecWithPrec(96, 2),
SupportTokenType: stakingtypes.TokenType_LOCKED,
SupportTokenType: 0,
}
setValidator(f, t, validator)

Expand All @@ -338,7 +338,7 @@ func fundAccountAndDelegate(f *deterministicFixture, t *testing.T, delegator sdk

shares, _, err := f.stakingKeeper.Delegate(
f.ctx, delegator, amt, stakingtypes.Unbonded, validator,
true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.PeriodType_FLEXIBLE, time.Unix(0, 0),
true, stakingtypes.FlexiblePeriodDelegationID, stakingtypes.DefaultFlexiblePeriodType, time.Unix(0, 0),
)
return shares, err
}
Expand Down
Loading

0 comments on commit a806101

Please sign in to comment.