Skip to content

Commit

Permalink
[Release] Cosmos SDK version bump (#217)
Browse files Browse the repository at this point in the history
* simulator: readme added, refactoring, new Cosmos SDK query results added to the report

* Cosmos SDK version bump

* genesis update: LPRation 1.0 -> 2.0
  • Loading branch information
Mikhail Kornilov authored Oct 12, 2020
1 parent 19b6b84 commit fa06394
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 136 deletions.
2 changes: 1 addition & 1 deletion cmd/config/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func OverrideGenesisStateDefaults(cdc *codec.Codec, genState map[string]json.Raw
//
moduleState.Params.BondDenom = defaults.StakingDenom
moduleState.Params.LPDenom = defaults.LiquidityProviderDenom
moduleState.Params.LPDistrRatio = sdk.NewDecWithPrec(1, 0) // 100%
moduleState.Params.LPDistrRatio = sdk.NewDecWithPrec(2, 0) // 200%
//
moduleState.Params.MinSelfDelegationLvl = defaults.MinSelfDelegationCoin.Amount // 2500.0
moduleState.Params.MaxDelegationsRatio = sdk.NewDecWithPrec(10, 0) // 10.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/dfinance/dnode

go 1.14

replace github.com/cosmos/cosmos-sdk => github.com/dfinance/cosmos-sdk v0.38.4-0.20201006151646-1ac22b3a4a09
replace github.com/cosmos/cosmos-sdk => github.com/dfinance/cosmos-sdk v0.38.4-0.20201009185146-b579213ebb05

// Local development option
//replace github.com/cosmos/cosmos-sdk => /Users/boris/go/src/github.com/dfinance/cosmos-sdk
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ github.com/dfinance/cosmos-sdk v0.38.4-0.20201002151830-6c83c28b89f4 h1:sUQDCT0d
github.com/dfinance/cosmos-sdk v0.38.4-0.20201002151830-6c83c28b89f4/go.mod h1:6A7WcR5vEsVN5MSi5gkMJmJIMulHZftD7q63tBdt2r0=
github.com/dfinance/cosmos-sdk v0.38.4-0.20201006151646-1ac22b3a4a09 h1:hNzQYh6QR6K097fL0HYDtgfyN2KgUXLu17/zRxSJezc=
github.com/dfinance/cosmos-sdk v0.38.4-0.20201006151646-1ac22b3a4a09/go.mod h1:6A7WcR5vEsVN5MSi5gkMJmJIMulHZftD7q63tBdt2r0=
github.com/dfinance/cosmos-sdk v0.38.4-0.20201008094428-b46810ed3864/go.mod h1:6A7WcR5vEsVN5MSi5gkMJmJIMulHZftD7q63tBdt2r0=
github.com/dfinance/cosmos-sdk v0.38.4-0.20201009185146-b579213ebb05/go.mod h1:6A7WcR5vEsVN5MSi5gkMJmJIMulHZftD7q63tBdt2r0=
github.com/dfinance/dvm-proto/go v0.0.0-20200819065410-6b70956c85de h1:PZfrjeOs9epAU0n+FpX/JAr/e+5m5/GdfUsgtO8gCOY=
github.com/dfinance/dvm-proto/go v0.0.0-20200819065410-6b70956c85de/go.mod h1:Vt1T0G56AYXbsduNKzSkq1RDTNa8PFraSqB9DaTCV0U=
github.com/dfinance/glav v0.0.0-20200814081332-c4701f6c12a6 h1:fZIYncA5BRad0+YnP88cfBfo0ZPgxPSVeuh/jvoGrLc=
Expand Down
148 changes: 148 additions & 0 deletions helpers/tests/simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Simulation parameters

Simulation:
* `ID` - simulation id;
* `SimDuration` - simulation duration;
* `BlockTimeMin` - minimum block duration;
* `BlockTimeMax` - maximum block duration;

Account balances:
* `MainTokens` - initial account balance for main tokens (`xfi`);
* `StakingTokens` - initial account balance for staking tokens (`sxfi`);
* `LPTokens` - initial account balance for LP tokens (`lpt`);

Validators:
* `PoA validator` - number of PegZone validators, ATM has no influence on simulation;
* `TM validators (total)` - total number of PoS validators (some of them might become `unbonded`);
* `TM validators (active)` - number of active PoS validators (they would be `bonded`);

`DelegateBondingOp` / `DelegateLPOp` operation:
* `Delegate bonding/LP tokens every` - period of operation in simulated time;
* `Delegate amount ratio (of acc balance)` - % of account balance for delegation;
* `Max limit ratio (staked ratio)` - operation limit: % of staked tokens to total tokens supply;

`RedelegateBondingOp` / `RedelegateLPOp` operation:
* `Redelegate bonding/LP tokens every` - period of operation in simulated time;
* `Redelegate amount ratio (of del shares)` - % of delegation shares for redelegation;

`UndelegateBondingOp` / `UndelegateLPOp` operation:
* `Undelegate bonding/LP tokens every` - period of operation in simulated time;
* `Undelegate amount ratio (of del shares)` - % of delegation shares for undelegation;

`ValidatorRewardOp` operation:
* `Withdraw all validators comissions every` - period of operation in simulated time;

`DelegatorRewardOp` operation:
* `Withdraw all delegators rewards every` - period of operation in simulated time;

`LockValidatorRewardsOp` operation:
* `Lock rewards every` - period of operation in simulated time;
* `Ratio of all validators` - operation limit: % of all validators to lock rewards;

# Operations

## `DelegateBondingOp` / `DelegateLPOp` operation

Picks a validator and searches for an account to delegate bonding tokens.
* SelfStake increment is allowed;
* Delegation amount = current account balance * {delegateRatio};
* Delegation is allowed if ratio (current staking bonding pools supply / total bonding tokens supply) < {maxBondingRatio};

Op priorities:
- validator:
- bonded;
- lowest bonding tokens amount;
- account:
- highest bonding tokens balance;
- enough coins;

## `RedelegateBondingOp` / `RedelegateLPOp` operation

* Picks a validator and redelegate bonding tokens to an other validator;
* Redelegation amount = current account delegation amount * {redelegateRatio};

Op priorities:
- dstValidator:
- bonded;
- lowest bonding tokens amount;
- srcValidator - highest account delegation bonding shares;
- account:
- random;
- has no active redelegations with srcValidator and dstValidator;
- has enough bonding coins;
- not a dstValidator owner;

## `UndelegateBondingOp` / `UndelegateLPOp` operation

Picks a validator and undelegates bonding tokens.
* Undelegation amount = current account delegation amount * {undelegateRatio}.

Op priorities:
- validator - highest bonding tokens amount (all statuses);
- account:
- random;
- has a validators bonding delegation;
- not a validator owner;

## `ValidatorRewardOp` operation

Takes all validators commissions rewards.

## `DelegatorRewardOp` operation

Takes all delegators rewards (excluding locked ones).

## `LockValidatorRewardsOp` operation

Takes validator commissions rewards.

Op priority:
- validator - random;

# CSV report

Report item is generated every simulated day.

* `BlockHeight` - block height;
* `BlockTime` - block time;
* `SimDuration` - simulation time (real world time);
* `Validators: Bonded` - number of `bonded` PoS validator;
* `Validators: Unbonding` - number of `unbonding` PoS validator;;
* `Validators: Unbonded` - number of `unbonded` PoS validator;;
* `Staking: Bonded` - amount of bonded staking tokens (`bonded` validators);
* `Staking: NotBonded` - amount of not-bonded staking tokens (`unbonding`/`unbonded` validators);
* `Staking: LPs` - amount of staked LP tokens;
* `Staking: ActiveRedelegations` - number of current redelegations;
* `Mint: MinInflation` - minimum inflation rate;
* `Mint: MaxInflation` - maximum inflation rate;
* `Mint: AnnualProvision` - annual minted tokens estimation (tokens per year);
* `Mint: BlocksPerYear` - number of blocks per year estimation;
* `Dist: FoundationPool` - FoundationPool supply (decimals);
* `Dist: PTreasuryPool` - PublicTreasuryPool supply (decimals);
* `Dist: LiquidityPPool` - LiquidityProvidersPool supply (decimals);
* `Dist: HARP` - HARP supply (decimals);
* `Dist: MAccBalance [main]` - rewards balance keeped by the distribution module (mail tokens);
* `Dist: MAccBalance [staking]` - rewards balance keeped by the distribution module (staking tokens);
* `Dist: BankBalance [main]` - rewards balance keeped by the distribution bank (mail tokens);
* `Dist: BankBalance [staking]` - rewards balance keeped by the distribution bank (staking tokens);
* `Dist: LockedRatio` - rate of bonded delegated tokens for locked validators to all bonded delegated tokens;
* `Supply: Total [main]` - total tokens supply (main tokens);
* `Supply: Total [staking]` - total tokens supply (staking tokens);
* `Supply: Total [LP]` - total tokens supply (LP tokens);
* `Stats: Staked/TotalSupply [staking]` - rate of (bonded + not-bonded tokens) to total supply of staking tokens;
* `Stats: Staked/TotalSupply [LPs]` - rate of staked LP tokens to total supply;
* `Accounts: TotalBalance [main]` - sum of all accounts balances (main tokens);
* `Accounts: TotalBalance [staking]` - sum of all accounts balances (staking tokens);
* `Counters: Bonding: Delegations` - number of bonding delegation operations;
* `Counters: Bonding: Redelegations` - number of bonding redelegation operations;
* `Counters: Bonding: Undelegations` - number of bonding undelegation operations;
* `Counters: LP: Delegations` - number of LP delegation operations;
* `Counters: LP: Redelegations` - number of LP redelegation operations;
* `Counters: LP: Undelegations` - number of LP undelegation operations;
* `Counters: RewardWithdraws` - number of delegators rewards withdraw operations;
* `Counters: RewardsCollected [main]` - accumulated amount of delegators rewards collected (main tokens);
* `Counters: RewardsCollected [staking]` - accumulated amount of delegators rewards collected (staking tokens);
* `Counters: CommissionWithdraws` - number of validators commission rewards operations;
* `Counters: CommissionsCollected [main]` - accumulated amount of validators commission rewards collected (main tokens);
* `Counters: CommissionsCollected [staking]` - accumulated amount of validators commission rewards collected (staking tokens);
* `Counters: LockedRewards` - number of validators rewards lock operations;
70 changes: 35 additions & 35 deletions helpers/tests/simulator/inflation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,38 @@ func (p SimProfile) String() string {
str := strings.Builder{}
str.WriteString("Simulation:\n")
str.WriteString(fmt.Sprintf(" - ID: %s\n", p.ID))
str.WriteString(fmt.Sprintf(" - SimDuration: %s\n", FormatDuration(p.SimDuration)))
str.WriteString(fmt.Sprintf(" - BlockTimeMin: %s\n", FormatDuration(p.BlockTimeMin)))
str.WriteString(fmt.Sprintf(" - BlockTimeMax: %s\n", FormatDuration(p.BlockTimeMax)))
str.WriteString(fmt.Sprintf(" - SimDuration: %v\n", p.SimDuration))
str.WriteString(fmt.Sprintf(" - BlockTimeMin: %v\n", p.BlockTimeMin))
str.WriteString(fmt.Sprintf(" - BlockTimeMax: %v\n", p.BlockTimeMax))
str.WriteString("Initial balances:\n")
str.WriteString(fmt.Sprintf(" - MainTokens: %d.0%s\n", p.MainTokensBalanceWODec, defaults.MainDenom))
str.WriteString(fmt.Sprintf(" - StakingTokens: %d.0%s\n", p.BondingTokensBalanceWODec, defaults.StakingDenom))
str.WriteString(fmt.Sprintf(" - LPTokens: %d.0%s\n", p.LPTokensBalanceWODec, defaults.LiquidityProviderDenom))
str.WriteString("Total number of:\n")
str.WriteString(fmt.Sprintf(" - Account: %d\n", p.Accounts))
str.WriteString(fmt.Sprintf(" - Accounts: %d\n", p.Accounts))
str.WriteString(fmt.Sprintf(" - PoA validators: %d\n", p.POAValidators))
str.WriteString(fmt.Sprintf(" - TM validators (total): %d\n", p.TMValidatorsTotal))
str.WriteString(fmt.Sprintf(" - TM validators (active): %d\n", p.TMValidatorsActive))
str.WriteString("Operations:\n")
str.WriteString(fmt.Sprintf(" - Create validators: %s\n", FormatDuration(p.OpCreateValidator)))
str.WriteString(fmt.Sprintf(" - Delegate bonding tokens: %s\n", FormatDuration(p.OpDelegateBonding)))
str.WriteString(fmt.Sprintf(" Amount ratio: %s\n", p.OpDelegateBondingAmountRatio))
str.WriteString(fmt.Sprintf(" Max limit ratio: %s\n", p.OpDelegateBondingMaxSupplyRatio))
str.WriteString(fmt.Sprintf(" - Delegate LP tokens: %s\n", FormatDuration(p.OpDelegateLP)))
str.WriteString(fmt.Sprintf(" Amount ratio: %s\n", p.OpDelegateLPAmountRatio))
str.WriteString(fmt.Sprintf(" Max limit ratio: %s\n", p.OpDelegateLPMaxSupplyRatio))
str.WriteString(fmt.Sprintf(" - Redelegate bonding tokens: %s\n", FormatDuration(p.OpRedelegateBonding)))
str.WriteString(fmt.Sprintf(" Amount ratio: %s\n", p.OpRedelegateBondingAmountRatio))
str.WriteString(fmt.Sprintf(" - Redelegate LP tokens: %s\n", FormatDuration(p.OpRedelegateLP)))
str.WriteString(fmt.Sprintf(" Amount ratio: %s\n", p.OpRedelegateLPAmountRatio))
str.WriteString(fmt.Sprintf(" - Undelegate bonding tokens: %s\n", FormatDuration(p.OpUndelegateBonding)))
str.WriteString(fmt.Sprintf(" Amount ratio: %s\n", p.OpUndelegateBondingAmountRatio))
str.WriteString(fmt.Sprintf(" - Undelegate LP tokens: %s\n", FormatDuration(p.OpUndelegateLP)))
str.WriteString(fmt.Sprintf(" Amount ratio: %s\n", p.OpUndelegateLPAmountRatio))
str.WriteString(fmt.Sprintf(" - Withdraw validator comission: %s\n", FormatDuration(p.OpGetValidatorRewards)))
str.WriteString(fmt.Sprintf(" - Withdraw delegator reward: %s\n", FormatDuration(p.OpGetDelegatorRewards)))
str.WriteString(fmt.Sprintf(" - Lock rewards: %s\n", FormatDuration(p.OpLockRewards)))
str.WriteString(fmt.Sprintf(" Ratio: %s\n", p.OpLockRewardsRatio))
str.WriteString(fmt.Sprintf(" - Create validator every: %s\n", FormatDuration(p.OpCreateValidator)))
str.WriteString(fmt.Sprintf(" - Delegate bonding tokens every: %s\n", FormatDuration(p.OpDelegateBonding)))
str.WriteString(fmt.Sprintf(" Delegate amount ratio (of acc balance): %s\n", p.OpDelegateBondingAmountRatio))
str.WriteString(fmt.Sprintf(" Max limit ratio (staked ratio): %s\n", p.OpDelegateBondingMaxSupplyRatio))
str.WriteString(fmt.Sprintf(" - Delegate LP tokens every: %s\n", FormatDuration(p.OpDelegateLP)))
str.WriteString(fmt.Sprintf(" Delegate amount ratio (of acc balance): %s\n", p.OpDelegateLPAmountRatio))
str.WriteString(fmt.Sprintf(" Max limit ratio (staked ratio): %s\n", p.OpDelegateLPMaxSupplyRatio))
str.WriteString(fmt.Sprintf(" - Redelegate bonding tokens every: %s\n", FormatDuration(p.OpRedelegateBonding)))
str.WriteString(fmt.Sprintf(" Redelegate amount ratio (of del shares): %s\n", p.OpRedelegateBondingAmountRatio))
str.WriteString(fmt.Sprintf(" - Redelegate LP tokens every: %s\n", FormatDuration(p.OpRedelegateLP)))
str.WriteString(fmt.Sprintf(" Redelegate amount ratio (of del shares): %s\n", p.OpRedelegateLPAmountRatio))
str.WriteString(fmt.Sprintf(" - Undelegate bonding tokens every: %s\n", FormatDuration(p.OpUndelegateBonding)))
str.WriteString(fmt.Sprintf(" Undelegate amount ratio (of del shares): %s\n", p.OpUndelegateBondingAmountRatio))
str.WriteString(fmt.Sprintf(" - Undelegate LP tokens every: %s\n", FormatDuration(p.OpUndelegateLP)))
str.WriteString(fmt.Sprintf(" Undelegate amount ratio (of del shares): %s\n", p.OpUndelegateLPAmountRatio))
str.WriteString(fmt.Sprintf(" - Withdraw all validators comissions every: %s\n", FormatDuration(p.OpGetValidatorRewards)))
str.WriteString(fmt.Sprintf(" - Withdraw all delegators rewards every: %s\n", FormatDuration(p.OpGetDelegatorRewards)))
str.WriteString(fmt.Sprintf(" - Lock rewards every: %s\n", FormatDuration(p.OpLockRewards)))
str.WriteString(fmt.Sprintf(" Ratio of all validators: %s\n", p.OpLockRewardsRatio))

return str.String()
}
Expand Down Expand Up @@ -187,27 +187,27 @@ func simulate(t *testing.T, profile SimProfile) {
func TestSimInflation(t *testing.T) {
profile := SimProfile{
ID: "low_staking",
SimDuration: 1*Year + 6*Month,
BlockTimeMin: 120 * time.Second,
BlockTimeMax: 125 * time.Second,
SimDuration: 3*Month,
BlockTimeMin: 300 * time.Second,
BlockTimeMax: 305 * time.Second,
//
MainTokensBalanceWODec: 50000,
BondingTokensBalanceWODec: 500000,
LPTokensBalanceWODec: 100000,
//
Accounts: 300,
Accounts: 150,
POAValidators: 3,
TMValidatorsTotal: 150,
TMValidatorsTotal: 110,
TMValidatorsActive: 100,
//
OpCreateValidator: 3 * time.Hour,
//
OpDelegateBonding: 6 * time.Hour,
OpDelegateBondingAmountRatio: sdk.NewDecWithPrec(40, 2),
OpDelegateBonding: 2 * time.Hour,
OpDelegateBondingAmountRatio: sdk.NewDecWithPrec(50, 2),
OpDelegateBondingMaxSupplyRatio: sdk.NewDecWithPrec(30, 2),
//
OpDelegateLP: 1 * Day,
OpDelegateLPAmountRatio: sdk.NewDecWithPrec(40, 2),
OpDelegateLP: 4 * time.Hour,
OpDelegateLPAmountRatio: sdk.NewDecWithPrec(50, 2),
OpDelegateLPMaxSupplyRatio: sdk.NewDecWithPrec(30, 2),
//
OpRedelegateBonding: 4 * Day,
Expand All @@ -222,10 +222,10 @@ func TestSimInflation(t *testing.T) {
OpUndelegateLP: 4 * Day,
OpUndelegateLPAmountRatio: sdk.NewDecWithPrec(15, 2),
//
OpGetValidatorRewards: 1 * Week,
OpGetDelegatorRewards: 1 * Day,
OpGetValidatorRewards: 1 * Month,
OpGetDelegatorRewards: 1 * Month,
//
OpLockRewards: 1 * Week,
OpLockRewards: 4 * Day,
OpLockRewardsRatio: sdk.NewDecWithPrec(30, 2),
}

Expand Down
30 changes: 17 additions & 13 deletions helpers/tests/simulator/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ type Simulator struct {
}

type Counter struct {
BDelegations int64
BUndelegations int64
BRedelegations int64
LPDelegations int64
LPUndelegations int64
LPRedelegations int64
LockedRewards int64
Rewards int64
Commissions int64
RewardsCollected sdk.Coins
CommissionsCollected sdk.Coins
BDelegations int64
BUndelegations int64
BRedelegations int64
LPDelegations int64
LPUndelegations int64
LPRedelegations int64
LockedRewards int64
RewardsWithdraws int64
CommissionWithdraws int64
RewardsCollectedMain sdk.Int
RewardsCollectedStaking sdk.Int
CommissionsCollectedMain sdk.Int
CommissionsCollectedStaking sdk.Int
}

// BuildTmpFilePath builds file name inside of the Simulator working dir.
Expand Down Expand Up @@ -338,8 +340,10 @@ func NewSimulator(t *testing.T, workingDir string, defferQueue *DefferOps, optio
cdc: app.MakeCodec(),
defferQueue: defferQueue,
}
s.counter.RewardsCollected = sdk.NewCoins()
s.counter.CommissionsCollected = sdk.NewCoins()
s.counter.RewardsCollectedMain = sdk.ZeroInt()
s.counter.RewardsCollectedStaking = sdk.ZeroInt()
s.counter.CommissionsCollectedMain = sdk.ZeroInt()
s.counter.CommissionsCollectedStaking = sdk.ZeroInt()

defaultGenesis, err := genesis.OverrideGenesisStateDefaults(s.cdc, app.ModuleBasics.DefaultGenesis())
require.NoError(t, err)
Expand Down
4 changes: 3 additions & 1 deletion helpers/tests/simulator/sim_ops_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func delegateOpFindTarget(s *Simulator, bondingD bool, delegateRatio sdk.Dec) (t

// pick an account with max tokens
var delAmt sdk.Int
for _, acc := range s.GetAllAccounts().GetSortedByBalance(denom, true) {
accs := s.GetAllAccounts().GetSortedByBalance(denom, true)
for _, acc := range accs {
// estimate delegation amount
accCoinAmtDec := sdk.NewDecFromInt(acc.Coins.AmountOf(denom))
delAmt = accCoinAmtDec.Mul(delegateRatio).TruncateInt()
Expand All @@ -128,6 +129,7 @@ func delegateOpFindTarget(s *Simulator, bondingD bool, delegateRatio sdk.Dec) (t

targetAcc = acc
delCoin = sdk.NewCoin(denom, delAmt)
return
}

return
Expand Down
6 changes: 4 additions & 2 deletions helpers/tests/simulator/sim_ops_redelegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func redelegateOpFindTarget(s *Simulator, bondingRD bool, rdRatio sdk.Dec) (targ
}

// pick a target account
for _, acc := range s.GetAllAccounts().GetShuffled() {
accs := s.GetAllAccounts().GetShuffled()
for _, acc := range accs {
accValAddr := sdk.ValAddress{}
if acc.IsValOperator() {
accValAddr = acc.OperatedValidator.GetAddress()
Expand All @@ -110,7 +111,8 @@ func redelegateOpFindTarget(s *Simulator, bondingRD bool, rdRatio sdk.Dec) (targ
}

// pick a delegation with the highest share
for _, delegation := range acc.GetSortedDelegations(bondingRD, true) {
delegations := acc.GetSortedDelegations(bondingRD, true)
for _, delegation := range delegations {
srcValidatorApplicant := validators.GetByAddress(delegation.ValidatorAddress)

// check if applicant was found (that validator can be unbonded by now)
Expand Down
Loading

0 comments on commit fa06394

Please sign in to comment.