Merge PR #1724: R4R: Add Stake Genesis Intra-Tx Counter
* add revoked to human-readable validator * changelog * added failing test * add intra-tx counter to the genesis validators * changelog
This commit is contained in:
parent
3dcec8a25c
commit
46abe9f8e0
|
@ -11,12 +11,14 @@ IMPROVEMENTS
|
||||||
* [cli] Improve error messages for all txs when the account doesn't exist
|
* [cli] Improve error messages for all txs when the account doesn't exist
|
||||||
* [tendermint] Update to v0.22.6
|
* [tendermint] Update to v0.22.6
|
||||||
- Updates the crypto imports/API (#1966)
|
- Updates the crypto imports/API (#1966)
|
||||||
|
* [x/stake] Add revoked to human-readable validator
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
* [tendermint] Update to v0.22.6
|
* [tendermint] Update to v0.22.6
|
||||||
- Fixes some security vulnerabilities reported in the [Bug Bounty](https://hackerone.com/tendermint)
|
- Fixes some security vulnerabilities reported in the [Bug Bounty](https://hackerone.com/tendermint)
|
||||||
* \#1797 Fix off-by-one error in slashing for downtime
|
* \#1797 Fix off-by-one error in slashing for downtime
|
||||||
* \#1787 Fixed bug where Tally fails due to revoked/unbonding validator
|
* \#1787 Fixed bug where Tally fails due to revoked/unbonding validator
|
||||||
|
* \#1666 Add intra-tx counter to the genesis validators
|
||||||
|
|
||||||
## 0.22.0
|
## 0.22.0
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,7 @@ IMPROVEMENTS
|
||||||
* [baseapp] Allow any alphanumeric character in route
|
* [baseapp] Allow any alphanumeric character in route
|
||||||
* [tools] Remove `rm -rf vendor/` from `make get_vendor_deps`
|
* [tools] Remove `rm -rf vendor/` from `make get_vendor_deps`
|
||||||
* [x/auth] Recover ErrorOutOfGas panic in order to set sdk.Result attributes correctly
|
* [x/auth] Recover ErrorOutOfGas panic in order to set sdk.Result attributes correctly
|
||||||
* [x/stake] Add revoked to human-readable validator
|
|
||||||
* [tests] Add tests to example apps in docs
|
* [tests] Add tests to example apps in docs
|
||||||
* [x/gov] Votes on a proposal can now be queried
|
* [x/gov] Votes on a proposal can now be queried
|
||||||
* [x/bank] Unit tests are now table-driven
|
* [x/bank] Unit tests are now table-driven
|
||||||
* [tests] Fixes ansible scripts to work with AWS too
|
* [tests] Fixes ansible scripts to work with AWS too
|
||||||
|
|
||||||
BUG FIXES
|
|
||||||
* \#1666 Add intra-tx counter to the genesis validators
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) error
|
||||||
keeper.SetNewParams(ctx, data.Params)
|
keeper.SetNewParams(ctx, data.Params)
|
||||||
keeper.InitIntraTxCounter(ctx)
|
keeper.InitIntraTxCounter(ctx)
|
||||||
|
|
||||||
for _, validator := range data.Validators {
|
for i, validator := range data.Validators {
|
||||||
keeper.SetValidator(ctx, validator)
|
keeper.SetValidator(ctx, validator)
|
||||||
|
|
||||||
if validator.Tokens.IsZero() {
|
if validator.Tokens.IsZero() {
|
||||||
|
@ -29,6 +29,8 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) error
|
||||||
|
|
||||||
// Manually set indexes for the first time
|
// Manually set indexes for the first time
|
||||||
keeper.SetValidatorByPubKeyIndex(ctx, validator)
|
keeper.SetValidatorByPubKeyIndex(ctx, validator)
|
||||||
|
|
||||||
|
validator.BondIntraTxCounter = int16(i) // set the intra-tx counter to the order the validators are presented
|
||||||
keeper.SetValidatorByPowerIndex(ctx, validator, data.Pool)
|
keeper.SetValidatorByPowerIndex(ctx, validator, data.Pool)
|
||||||
|
|
||||||
if validator.Status == sdk.Bonded {
|
if validator.Status == sdk.Bonded {
|
||||||
|
|
|
@ -14,23 +14,35 @@ func TestInitGenesis(t *testing.T) {
|
||||||
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
||||||
|
|
||||||
pool := keeper.GetPool(ctx)
|
pool := keeper.GetPool(ctx)
|
||||||
pool.LooseTokens = sdk.OneRat()
|
pool.LooseTokens = sdk.NewRat(2)
|
||||||
|
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
var delegations []Delegation
|
var delegations []Delegation
|
||||||
|
|
||||||
validators := []Validator{
|
validators := []Validator{
|
||||||
NewValidator(keep.Addrs[0], keep.PKs[0], Description{Moniker: "hoop"}),
|
NewValidator(keep.Addrs[0], keep.PKs[0], Description{Moniker: "hoop"}),
|
||||||
|
NewValidator(keep.Addrs[1], keep.PKs[1], Description{Moniker: "bloop"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
genesisState := types.NewGenesisState(pool, params, validators, delegations)
|
genesisState := types.NewGenesisState(pool, params, validators, delegations)
|
||||||
err := InitGenesis(ctx, keeper, genesisState)
|
err := InitGenesis(ctx, keeper, genesisState)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
|
// initialize the validators
|
||||||
validators[0].Tokens = sdk.OneRat()
|
validators[0].Tokens = sdk.OneRat()
|
||||||
validators[0].DelegatorShares = sdk.OneRat()
|
validators[0].DelegatorShares = sdk.OneRat()
|
||||||
|
validators[1].Tokens = sdk.OneRat()
|
||||||
|
validators[1].DelegatorShares = sdk.OneRat()
|
||||||
|
|
||||||
genesisState = types.NewGenesisState(pool, params, validators, delegations)
|
genesisState = types.NewGenesisState(pool, params, validators, delegations)
|
||||||
err = InitGenesis(ctx, keeper, genesisState)
|
err = InitGenesis(ctx, keeper, genesisState)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// now make sure the validators are bonded
|
||||||
|
resVal, found := keeper.GetValidator(ctx, keep.Addrs[0])
|
||||||
|
require.True(t, found)
|
||||||
|
require.Equal(t, sdk.Bonded, resVal.Status)
|
||||||
|
|
||||||
|
resVal, found = keeper.GetValidator(ctx, keep.Addrs[1])
|
||||||
|
require.True(t, found)
|
||||||
|
require.Equal(t, sdk.Bonded, resVal.Status)
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,34 @@ func UnmarshalValidator(cdc *wire.Codec, ownerAddr, value []byte) (validator Val
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HumanReadableString returns a human readable string representation of a
|
||||||
|
// validator. An error is returned if the owner or the owner's public key
|
||||||
|
// cannot be converted to Bech32 format.
|
||||||
|
func (v Validator) HumanReadableString() (string, error) {
|
||||||
|
bechVal, err := sdk.Bech32ifyValPub(v.PubKey)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := "Validator \n"
|
||||||
|
resp += fmt.Sprintf("Owner: %s\n", v.Owner)
|
||||||
|
resp += fmt.Sprintf("Validator: %s\n", bechVal)
|
||||||
|
resp += fmt.Sprintf("Revoked: %v\n", v.Revoked)
|
||||||
|
resp += fmt.Sprintf("Status: %s\n", sdk.BondStatusToString(v.Status))
|
||||||
|
resp += fmt.Sprintf("Tokens: %s\n", v.Tokens.FloatString())
|
||||||
|
resp += fmt.Sprintf("Delegator Shares: %s\n", v.DelegatorShares.FloatString())
|
||||||
|
resp += fmt.Sprintf("Description: %s\n", v.Description)
|
||||||
|
resp += fmt.Sprintf("Bond Height: %d\n", v.BondHeight)
|
||||||
|
resp += fmt.Sprintf("Proposer Reward Pool: %s\n", v.ProposerRewardPool.String())
|
||||||
|
resp += fmt.Sprintf("Commission: %s\n", v.Commission.String())
|
||||||
|
resp += fmt.Sprintf("Max Commission Rate: %s\n", v.CommissionMax.String())
|
||||||
|
resp += fmt.Sprintf("Commission Change Rate: %s\n", v.CommissionChangeRate.String())
|
||||||
|
resp += fmt.Sprintf("Commission Change Today: %s\n", v.CommissionChangeToday.String())
|
||||||
|
resp += fmt.Sprintf("Previous Bonded Tokens: %s\n", v.LastBondedTokens.String())
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
//___________________________________________________________________
|
//___________________________________________________________________
|
||||||
|
|
||||||
// validator struct for bech output
|
// validator struct for bech output
|
||||||
|
@ -408,30 +436,3 @@ func (v Validator) GetPubKey() crypto.PubKey { return v.PubKey }
|
||||||
func (v Validator) GetPower() sdk.Rat { return v.BondedTokens() }
|
func (v Validator) GetPower() sdk.Rat { return v.BondedTokens() }
|
||||||
func (v Validator) GetDelegatorShares() sdk.Rat { return v.DelegatorShares }
|
func (v Validator) GetDelegatorShares() sdk.Rat { return v.DelegatorShares }
|
||||||
func (v Validator) GetBondHeight() int64 { return v.BondHeight }
|
func (v Validator) GetBondHeight() int64 { return v.BondHeight }
|
||||||
|
|
||||||
// HumanReadableString returns a human readable string representation of a
|
|
||||||
// validator. An error is returned if the owner or the owner's public key
|
|
||||||
// cannot be converted to Bech32 format.
|
|
||||||
func (v Validator) HumanReadableString() (string, error) {
|
|
||||||
bechVal, err := sdk.Bech32ifyValPub(v.PubKey)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := "Validator \n"
|
|
||||||
resp += fmt.Sprintf("Owner: %s\n", v.Owner)
|
|
||||||
resp += fmt.Sprintf("Validator: %s\n", bechVal)
|
|
||||||
resp += fmt.Sprintf("Status: %s\n", sdk.BondStatusToString(v.Status))
|
|
||||||
resp += fmt.Sprintf("Tokens: %s\n", v.Tokens.FloatString())
|
|
||||||
resp += fmt.Sprintf("Delegator Shares: %s\n", v.DelegatorShares.FloatString())
|
|
||||||
resp += fmt.Sprintf("Description: %s\n", v.Description)
|
|
||||||
resp += fmt.Sprintf("Bond Height: %d\n", v.BondHeight)
|
|
||||||
resp += fmt.Sprintf("Proposer Reward Pool: %s\n", v.ProposerRewardPool.String())
|
|
||||||
resp += fmt.Sprintf("Commission: %s\n", v.Commission.String())
|
|
||||||
resp += fmt.Sprintf("Max Commission Rate: %s\n", v.CommissionMax.String())
|
|
||||||
resp += fmt.Sprintf("Commission Change Rate: %s\n", v.CommissionChangeRate.String())
|
|
||||||
resp += fmt.Sprintf("Commission Change Today: %s\n", v.CommissionChangeToday.String())
|
|
||||||
resp += fmt.Sprintf("Previous Bonded Tokens: %s\n", v.LastBondedTokens.String())
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue