From f5f53c0a8df6677f7f215d754c3b139e012d69b3 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 31 May 2018 00:55:16 +0200 Subject: [PATCH] Remove spec changes (now in #1048) --- docs/spec/staking/old/spec.md | 12 ++--- docs/spec/staking/old/spec2.md | 18 +++---- docs/spec/staking/transactions.md | 4 +- docs/spec/staking/valset-changes.md | 80 ++++++++++++----------------- 4 files changed, 51 insertions(+), 63 deletions(-) diff --git a/docs/spec/staking/old/spec.md b/docs/spec/staking/old/spec.md index 1eddc3e33d..bd87ec0285 100644 --- a/docs/spec/staking/old/spec.md +++ b/docs/spec/staking/old/spec.md @@ -297,12 +297,12 @@ type TxProveLive struct { ## Delegator bond Atom holders may delegate coins to validators, under this circumstance their -funds are held in a `Delegation`. It is owned by one delegator, and is +funds are held in a `DelegatorBond`. It is owned by one delegator, and is associated with the shares for one validator. The sender of the transaction is considered to be the owner of the bond, ``` golang -type Delegation struct { +type DelegatorBond struct { Candidate crypto.PubKey Shares rational.Rat AdjustmentFeePool coin.Coins @@ -318,11 +318,11 @@ Description: - AdjustmentRewardPool: Adjustment factor used to passively calculate each bonds entitled fees from `Candidate.ProposerRewardPool`` -Each `Delegation` is individually indexed within the store by delegator +Each `DelegatorBond` is individually indexed within the store by delegator address and candidate pubkey. - key: Delegator and Candidate-Pubkey - - value: Delegation + - value: DelegatorBond ### Delegating @@ -330,7 +330,7 @@ address and candidate pubkey. Delegator bonds are created using the TxDelegate transaction. Within this transaction the validator candidate queried with an amount of coins, whereby given the current exchange rate of candidate's delegator-shares-to-atoms the -candidate will return shares which are assigned in `Delegation.Shares`. +candidate will return shares which are assigned in `DelegatorBond.Shares`. ``` golang type TxDelegate struct { @@ -671,5 +671,5 @@ rate, all commission on fees must be simultaneously withdrawn. `candidate.Adjustment` must be set to the value of `canidate.Count` for the height which the candidate is added on the validator set. - The feePool of a new delegator bond will be 0 for the height at which the bond - was added. This is achieved by setting `Delegation.FeeWithdrawalHeight` to + was added. This is achieved by setting `DelegatorBond.FeeWithdrawalHeight` to the height which the bond was added. diff --git a/docs/spec/staking/old/spec2.md b/docs/spec/staking/old/spec2.md index 68f20703dc..72bb8a2e37 100644 --- a/docs/spec/staking/old/spec2.md +++ b/docs/spec/staking/old/spec2.md @@ -34,7 +34,7 @@ The staking module persists the following to the store: - `GlobalState`, describing the global pools - a `Candidate` for each candidate validator, indexed by public key - a `Candidate` for each candidate validator, indexed by shares in the global pool (ie. ordered) -- a `Delegation` for each delegation to a candidate by a delegator, indexed by delegator and candidate +- a `DelegatorBond` for each delegation to a candidate by a delegator, indexed by delegator and candidate public keys - a `Queue` of unbonding delegations (TODO) @@ -146,15 +146,15 @@ When validators are kicked from the validator set they are removed from this list. -### Delegation +### DelegatorBond Atom holders may delegate coins to validators, under this circumstance their -funds are held in a `Delegation`. It is owned by one delegator, and is +funds are held in a `DelegatorBond`. It is owned by one delegator, and is associated with the shares for one validator. The sender of the transaction is considered to be the owner of the bond, ``` golang -type Delegation struct { +type DelegatorBond struct { Candidate crypto.PubKey Shares rational.Rat AdjustmentFeePool coin.Coins @@ -170,11 +170,11 @@ Description: - AdjustmentRewardPool: Adjustment factor used to passively calculate each bonds entitled fees from `Candidate.ProposerRewardPool`` -Each `Delegation` is individually indexed within the store by delegator +Each `DelegatorBond` is individually indexed within the store by delegator address and candidate pubkey. - key: Delegator and Candidate-Pubkey - - value: Delegation + - value: DelegatorBond ### Unbonding Queue @@ -308,7 +308,7 @@ All bonding, whether self-bonding or delegation, is done via Delegator bonds are created using the TxDelegate transaction. Within this transaction the validator candidate queried with an amount of coins, whereby given the current exchange rate of candidate's delegator-shares-to-atoms the -candidate will return shares which are assigned in `Delegation.Shares`. +candidate will return shares which are assigned in `DelegatorBond.Shares`. ``` golang type TxDelegate struct { @@ -616,7 +616,7 @@ synced past the height of the oldest `powerChange`. This trim procedure will occur on an epoch basis. ```golang -type powerChange struct +type powerChange struct { height int64 // block height at change power rational.Rat // total power at change prevpower rational.Rat // total power at previous height-1 @@ -694,5 +694,5 @@ rate, all commission on fees must be simultaneously withdrawn. `candidate.Adjustment` must be set to the value of `canidate.Count` for the height which the candidate is added on the validator set. - The feePool of a new delegator bond will be 0 for the height at which the bond - was added. This is achieved by setting `Delegation.FeeWithdrawalHeight` to + was added. This is achieved by setting `DelegatorBond.FeeWithdrawalHeight` to the height which the bond was added. diff --git a/docs/spec/staking/transactions.md b/docs/spec/staking/transactions.md index eed082503b..52f324b0f7 100644 --- a/docs/spec/staking/transactions.md +++ b/docs/spec/staking/transactions.md @@ -203,7 +203,7 @@ unbond(tx TxUnbond): return removeShares(candidate Candidate, shares rational.Rat): - globalPoolSharesToRemove = DelegatorShareExRate(candidate) * shares + globalPoolSharesToRemove = delegatorShareExRate(candidate) * shares if candidate.Status == Bonded gs.BondedShares -= globalPoolSharesToRemove @@ -218,7 +218,7 @@ removeShares(candidate Candidate, shares rational.Rat): candidate.IssuedDelegatorShares -= shares return returnedCoins -DelegatorShareExRate(candidate Candidate): +delegatorShareExRate(candidate Candidate): if candidate.IssuedDelegatorShares.IsZero() then return rational.One return candidate.GlobalStakeShares / candidate.IssuedDelegatorShares diff --git a/docs/spec/staking/valset-changes.md b/docs/spec/staking/valset-changes.md index 0e635fd047..bc52b89980 100644 --- a/docs/spec/staking/valset-changes.md +++ b/docs/spec/staking/valset-changes.md @@ -31,8 +31,8 @@ tick(ctx Context): if time > unbondDelegationQueue.head().InitTime + UnbondingPeriod for each element elem in the unbondDelegationQueue where time > elem.InitTime + UnbondingPeriod do - transfer(unbondingQueueAddress, elem.Payout, elem.Tokens) - unbondDelegationQueue.remove(elem) + transfer(unbondingQueueAddress, elem.Payout, elem.Tokens) + unbondDelegationQueue.remove(elem) if time > reDelegationQueue.head().InitTime + UnbondingPeriod for each element elem in the unbondDelegationQueue where time > elem.InitTime + UnbondingPeriod do @@ -55,9 +55,9 @@ nextInflation(hrsPerYr rational.Rat): inflation = gs.Inflation + inflationRateChange if inflation > params.InflationMax then inflation = params.InflationMax - + if inflation < params.InflationMin then inflation = params.InflationMin - + return inflation UpdateValidatorSet(): @@ -71,26 +71,26 @@ UpdateValidatorSet(): updateVotingPower(candidates Candidates): foreach candidate in candidates do - candidate.VotingPower = (candidate.IssuedDelegatorShares - candidate.RedelegatingShares) * DelegatorShareExRate(candidate) - + candidate.VotingPower = (candidate.IssuedDelegatorShares - candidate.RedelegatingShares) * delegatorShareExRate(candidate) + candidates.Sort() - + foreach candidate in candidates do - if candidate is not in the first params.MaxVals - candidate.VotingPower = rational.Zero - if candidate.Status == Bonded then bondedToUnbondedPool(candidate Candidate) - - else if candidate.Status == UnBonded then unbondedToBondedPool(candidate) + if candidate is not in the first params.MaxVals + candidate.VotingPower = rational.Zero + if candidate.Status == Bonded then bondedToUnbondedPool(candidate Candidate) + + else if candidate.Status == UnBonded then unbondedToBondedPool(candidate) - saveCandidate(store, c) - + saveCandidate(store, c) + return candidates unbondedToBondedPool(candidate Candidate): removedTokens = exchangeRate(gs.UnbondedShares, gs.UnbondedPool) * candidate.GlobalStakeShares gs.UnbondedShares -= candidate.GlobalStakeShares gs.UnbondedPool -= removedTokens - + gs.BondedPool += removedTokens issuedShares = removedTokens / exchangeRate(gs.BondedShares, gs.BondedPool) gs.BondedShares += issuedShares @@ -155,48 +155,36 @@ The following information is stored with each validator candidate, and is only n ```go type ValidatorSigningInfo struct { - StartHeight int64 - IndexOffset int64 - JailedUntil int64 - SignedBlocksCounter int64 - SignedBlocksBitArray BitArray + StartHeight int64 + SignedBlocksBitArray BitArray } ``` Where: * `StartHeight` is set to the height that the candidate became an active validator (with non-zero voting power). -* `IndexOffset` is incremented each time the candidate was a bonded validator in a block (and may have signed a precommit or not). -* `JailedUntil` is set whenever the candidate is revoked due to downtime -* `SignedBlocksCounter` is a counter kept to avoid unnecessary array reads. `SignedBlocksBitArray.Sum() == SignedBlocksCounter` always. * `SignedBlocksBitArray` is a bit-array of size `SIGNED_BLOCKS_WINDOW` that records, for each of the last `SIGNED_BLOCKS_WINDOW` blocks, -whether or not this validator was included in the LastCommit. It uses a `1` if the validator was included, and a `0` if it was not. Note it is initialized with all 0s. +whether or not this validator was included in the LastCommit. It uses a `0` if the validator was included, and a `1` if it was not. +Note it is initialized with all 0s. At the beginning of each block, we update the signing info for each validator and check if they should be automatically unbonded: ``` -height := block.Height +h = block.Height +index = h % SIGNED_BLOCKS_WINDOW for val in block.Validators: - signInfo = val.SignInfo - index := signInfo.IndexOffset % SIGNED_BLOCKS_WINDOW - signInfo.IndexOffset++ - previous = signInfo.SignedBlocksBitArray.Get(index) + signInfo = val.SignInfo + if val in block.LastCommit: + signInfo.SignedBlocksBitArray.Set(index, 0) + else + signInfo.SignedBlocksBitArray.Set(index, 1) - // update counter if array has changed - if previous and val in block.AbsentValidators: - signInfo.SignedBlocksBitArray.Set(index, 0) - signInfo.SignedBlocksCounter-- - else if !previous and val not in block.AbsentValidators: - signInfo.SignedBlocksBitArray.Set(index, 1) - signInfo.SignedBlocksCounter++ - // else previous == val not in block.AbsentValidators, no change - - // validator must be active for at least SIGNED_BLOCKS_WINDOW - // before they can be automatically unbonded for failing to be - // included in 50% of the recent LastCommits - minHeight = signInfo.StartHeight + SIGNED_BLOCKS_WINDOW - minSigned = SIGNED_BLOCKS_WINDOW / 2 - if height > minHeight AND signInfo.SignedBlocksCounter < minSigned: - signInfo.JailedUntil = block.Time + DOWNTIME_UNBOND_DURATION - slash & unbond the validator + // validator must be active for at least SIGNED_BLOCKS_WINDOW + // before they can be automatically unbonded for failing to be + // included in 50% of the recent LastCommits + minHeight = signInfo.StartHeight + SIGNED_BLOCKS_WINDOW + minSigned = SIGNED_BLOCKS_WINDOW / 2 + blocksSigned = signInfo.SignedBlocksBitArray.Sum() + if h > minHeight AND blocksSigned < minSigned: + unbond the validator ```