Merge PR #2251: Refactor Bech32 Prefixes and Nomenclature of Validator Pubkey and Operator

This commit is contained in:
Alexander Bezobchuk 2018-09-08 04:44:58 -04:00 committed by Christopher Goes
parent f68e5a7542
commit 0edfa17b53
34 changed files with 226 additions and 223 deletions

View File

@ -13,10 +13,10 @@ BREAKING CHANGES
* [cli] [\#2061](https://github.com/cosmos/cosmos-sdk/issues/2061) changed proposalID in governance REST endpoints to proposal-id
* [cli] [\#2014](https://github.com/cosmos/cosmos-sdk/issues/2014) `gaiacli advanced` no longer exists - to access `ibc`, `rest-server`, and `validator-set` commands use `gaiacli ibc`, `gaiacli rest-server`, and `gaiacli tendermint`, respectively
* [makefile] `get_vendor_deps` no longer updates lock file it just updates vendor directory. Use `update_vendor_deps` to update the lock file. [#2152](https://github.com/cosmos/cosmos-sdk/pull/2152)
* [cli] [\#2221](https://github.com/cosmos/cosmos-sdk/issues/2221) All commands that
utilize a validator's operator address must now use the new Bech32 prefix,
`cosmosvaloper`.
* [cli] [\#2190](https://github.com/cosmos/cosmos-sdk/issues/2190) `gaiacli init --gen-txs` is now `gaiacli init --with-txs` to reduce confusion
* [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) All commands that utilize a validator's address must now use the new
bech32 prefix, `cosmosval`. A validator's Tendermint signing key and address
now use a new bech32 prefix, `cosmoscons`.
* Gaia
* Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013)
@ -25,11 +25,15 @@ BREAKING CHANGES
* [x/stake, x/slashing] [#1305](https://github.com/cosmos/cosmos-sdk/issues/1305) - Rename "revoked" to "jailed"
* [x/stake] [#1676] Revoked and jailed validators put into the unbonding state
* [x/stake] [#1877] Redelegations/unbonding-delegation from unbonding validator have reduced time
* [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator operator type has now changed to `sdk.ValAddress`
* A new bech32 prefix has been introduced for Tendermint signing keys and
addresses, `cosmosconspub` and `cosmoscons` respectively.
* [x/gov] \#2195 Made governance use BFT Time instead of Block Heights for deposit and voting periods.
* [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator
operator type has now changed to `sdk.ValAddress`
* [x/stake] [\#2221](https://github.com/cosmos/cosmos-sdk/issues/2221) New
Bech32 prefixes have been introduced for a validator's consensus address and
public key: `cosmosvalcons` and `cosmosvalconspub` respectively. Also, existing Bech32 prefixes have been
renamed for accounts and validator operators:
* `cosmosaccaddr` / `cosmosaccpub` => `cosmos` / `cosmospub`
* `cosmosvaladdr` / `cosmosvalpub` => `cosmosvaloper` / `cosmosvaloperpub`
* SDK
* [core] [\#1807](https://github.com/cosmos/cosmos-sdk/issues/1807) Switch from use of rational to decimal
* [types] [\#1901](https://github.com/cosmos/cosmos-sdk/issues/1901) Validator interface's GetOwner() renamed to GetOperator()

View File

@ -206,8 +206,8 @@ func TestValidators(t *testing.T) {
require.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals)
require.Contains(t, resultVals.Validators[0].Address.String(), "cosmosval")
require.Contains(t, resultVals.Validators[0].PubKey, "cosmosconspub")
require.Contains(t, resultVals.Validators[0].Address.String(), "cosmosvaloper")
require.Contains(t, resultVals.Validators[0].PubKey, "cosmosvalconspub")
// --
@ -461,10 +461,11 @@ func TestValidatorsQuery(t *testing.T) {
// make sure all the validators were found (order unknown because sorted by operator addr)
foundVal := false
pkBech := sdk.MustBech32ifyConsPub(pks[0])
if validators[0].PubKey == pkBech {
if validators[0].ConsPubKey == pkBech {
foundVal = true
}
require.True(t, foundVal, "pkBech %v, operator %v", pkBech, validators[0].Operator)
require.True(t, foundVal, "pkBech %v, operator %v", pkBech, validators[0].OperatorAddr)
}
func TestValidatorQuery(t *testing.T) {
@ -474,7 +475,7 @@ func TestValidatorQuery(t *testing.T) {
validator1Operator := sdk.ValAddress(pks[0].Address())
validator := getValidator(t, port, validator1Operator)
assert.Equal(t, validator.Operator, validator1Operator, "The returned validator does not hold the correct data")
assert.Equal(t, validator.OperatorAddr, validator1Operator, "The returned validator does not hold the correct data")
}
func TestBonding(t *testing.T) {
@ -510,11 +511,11 @@ func TestBonding(t *testing.T) {
bondedValidators := getDelegatorValidators(t, port, addr)
require.Len(t, bondedValidators, 1)
require.Equal(t, validator1Operator, bondedValidators[0].Operator)
require.Equal(t, validator1Operator, bondedValidators[0].OperatorAddr)
require.Equal(t, validator.DelegatorShares.Add(sdk.NewDec(60)).String(), bondedValidators[0].DelegatorShares.String())
bondedValidator := getDelegatorValidator(t, port, addr, validator1Operator)
require.Equal(t, validator1Operator, bondedValidator.Operator)
require.Equal(t, validator1Operator, bondedValidator.OperatorAddr)
//////////////////////
// testing unbonding

View File

@ -151,7 +151,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
var validatorsPKs []crypto.PubKey
// NOTE: It's bad practice to reuse public key address for the owner
// NOTE: It's bad practice to reuse public key address for the operator
// address but doing in the test for simplicity.
var appGenTxs []json.RawMessage
for _, gdValidator := range genDoc.Validators {

View File

@ -205,8 +205,8 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState
// create the self-delegation from the issuedDelShares
delegation := stake.Delegation{
DelegatorAddr: sdk.AccAddress(validator.Operator),
ValidatorAddr: validator.Operator,
DelegatorAddr: sdk.AccAddress(validator.OperatorAddr),
ValidatorAddr: validator.OperatorAddr,
Shares: issuedDelShares,
Height: 0,
}

View File

@ -188,7 +188,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)
validator := executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
require.Equal(t, validator.Operator, sdk.ValAddress(barAddr))
require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr))
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
// unbond a single share

View File

@ -65,7 +65,7 @@ func runHackCmd(cmd *cobra.Command, args []string) error {
// The following powerKey was there, but the corresponding "trouble" validator did not exist.
// So here we do a binary search on the past states to find when the powerKey first showed up ...
// owner of the validator the bonds, gets revoked, later unbonds, and then later is still found in the bypower store
// operator of the validator the bonds, gets revoked, later unbonds, and then later is still found in the bypower store
trouble := hexToBytes("D3DC0FF59F7C3B548B7AFA365561B87FD0208AF8")
// this is his "bypower" key
powerKey := hexToBytes("05303030303030303030303033FFFFFFFFFFFF4C0C0000FFFED3DC0FF59F7C3B548B7AFA365561B87FD0208AF8")

View File

@ -213,7 +213,7 @@ Note that the distribution scenario structures are found in `state.md`.
#### Delegation's entitlement to Global.Pool
For delegations (including validator's self-delegation) all fees from fee pool
are subject to commission rate from the owner of the validator. The global
are subject to commission rate from the operator of the validator. The global
shares should be taken as true number of global bonded shares. The recipients
shares should be taken as the bonded tokens less the validator's commission.

View File

@ -714,7 +714,7 @@ definitions:
ValidatorAddress:
type: string
description: bech32 encoded addres
example: cosmosval:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
example: cosmosvaloper:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
PubKey:
type: string
description: bech32 encoded public key
@ -722,7 +722,7 @@ definitions:
ValidatorPubKey:
type: string
description: bech32 encoded public key
example: cosmosvalpub:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
example: cosmosvalconspub:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
Coins:
type: object
properties:

View File

@ -22,17 +22,17 @@ There are three types of key representations that are used:
- Derived from account keys generated by `gaiacli keys add`
- Used to receive funds
- e.g. `cosmos15h6vd5f0wqps26zjlwrc6chah08ryu4hzzdwhc`
* `cosmosval`
* `cosmosvaloper`
* Used to associate a validator to it's operator
* Used to invoke staking commands
* e.g. `cosmosval1carzvgq3e6y3z5kz5y6gxp3wpy3qdrv928vyah`
* e.g. `cosmosvaloper1carzvgq3e6y3z5kz5y6gxp3wpy3qdrv928vyah`
- `cosmospub`
- Derived from account keys generated by `gaiacli keys add`
- e.g. `cosmospub1zcjduc3q7fu03jnlu2xpl75s2nkt7krm6grh4cc5aqth73v0zwmea25wj2hsqhlqzm`
- `cosmosconspub`
- `cosmosvalconspub`
- Generated when the node is created with `gaiad init`.
- Get this value with `gaiad tendermint show-validator`
- e.g. `cosmosconspub1zcjduepq0ms2738680y72v44tfyqm3c9ppduku8fs6sr73fx7m666sjztznqzp2emf`
- e.g. `cosmosvalconspub1zcjduepq0ms2738680y72v44tfyqm3c9ppduku8fs6sr73fx7m666sjztznqzp2emf`
#### Generate Keys

View File

@ -6,14 +6,14 @@ In the Cosmos network, keys and addresses may refer to a number of different rol
## HRP table
| HRP | Definition |
|---------------|--------------------------------------|
| cosmos | Cosmos Account Address |
| cosmospub | Cosmos Account Public Key |
| cosmoscons | Cosmos Consensus Address |
| cosmosconspub | Cosmos Consensus Public Key |
| cosmosval | Cosmos Validator Operator Address |
| cosmosvalpub | Cosmos Validator Operator Public Key |
| HRP | Definition |
|-------------------|---------------------------------------|
| cosmos | Cosmos Account Address |
| cosmospub | Cosmos Account Public Key |
| cosmosvalcons | Cosmos Validator Consensus Address |
| cosmosvalconspub | Cosmos Validator Consensus Public Key |
| cosmosvaloper | Cosmos Validator Operator Address |
| cosmosvaloperpub | Cosmos Validator Operator Public Key |
## Encoding

View File

@ -14,7 +14,7 @@ type Pool struct {
BondedTokens int64 // reserve of bonded tokens
InflationLastTime int64 // block which the last inflation was processed // TODO make time
Inflation sdk.Dec // current annual inflation rate
DateLastCommissionReset int64 // unix timestamp for last commission accounting reset (daily)
}
```
@ -29,41 +29,40 @@ overall functioning of the stake module.
```golang
type Params struct {
InflationRateChange sdk.Dec // maximum annual change in inflation rate
InflationMax sdk.Dec // maximum inflation rate
InflationMin sdk.Dec // minimum inflation rate
GoalBonded sdk.Dec // Goal of percent bonded atoms
InflationMax sdk.Dec // maximum inflation rate
InflationMin sdk.Dec // minimum inflation rate
GoalBonded sdk.Dec // Goal of percent bonded atoms
MaxValidators uint16 // maximum number of validators
BondDenom string // bondable coin denomination
MaxValidators uint16 // maximum number of validators
BondDenom string // bondable coin denomination
}
```
### Validator
Validators are identified according to the `ValOwnerAddr`,
an SDK account address for the owner of the validator.
Validators are identified according to the `OperatorAddr`, an SDK validator
address for the operator of the validator.
Validators also have a `ValTendermintAddr`, the address
of the public key of the validator.
Validators also have a `ConsPubKey`, the public key of the validator.
Validators are indexed in the store using the following maps:
- Validators: `0x02 | ValOwnerAddr -> amino(validator)`
- ValidatorsByPubKey: `0x03 | ValTendermintAddr -> ValOwnerAddr`
- ValidatorsByPower: `0x05 | power | blockHeight | blockTx -> ValOwnerAddr`
- Validators: `0x02 | OperatorAddr -> amino(validator)`
- ValidatorsByPubKey: `0x03 | ConsPubKey -> OperatorAddr`
- ValidatorsByPower: `0x05 | power | blockHeight | blockTx -> OperatorAddr`
`Validators` is the primary index - it ensures that each owner can have only one
associated validator, where the public key of that validator can change in the
future. Delegators can refer to the immutable owner of the validator, without
concern for the changing public key.
`Validators` is the primary index - it ensures that each operator can have only one
associated validator, where the public key of that validator can change in the
future. Delegators can refer to the immutable operator of the validator, without
concern for the changing public key.
`ValidatorsByPubKey` is a secondary index that enables lookups for slashing.
When Tendermint reports evidence, it provides the validator address, so this
map is needed to find the owner.
`ValidatorsByPubKey` is a secondary index that enables lookups for slashing.
When Tendermint reports evidence, it provides the validator address, so this
map is needed to find the operator.
`ValidatorsByPower` is a secondary index that provides a sorted list of
potential validators to quickly determine the current active set. For instance,
the first 100 validators in this list can be returned with every EndBlock.
`ValidatorsByPower` is a secondary index that provides a sorted list of
potential validators to quickly determine the current active set. For instance,
the first 100 validators in this list can be returned with every EndBlock.
The `Validator` holds the current state and some historical actions of the
validator.
@ -72,18 +71,18 @@ validator.
type Validator struct {
ConsensusPubKey crypto.PubKey // Tendermint consensus pubkey of validator
Jailed bool // has the validator been jailed?
Status sdk.BondStatus // validator status (bonded/unbonding/unbonded)
Tokens sdk.Dec // delegated tokens (incl. self-delegation)
Status sdk.BondStatus // validator status (bonded/unbonding/unbonded)
Tokens sdk.Dec // delegated tokens (incl. self-delegation)
DelegatorShares sdk.Dec // total shares issued to a validator's delegators
SlashRatio sdk.Dec // increases each time the validator is slashed
Description Description // description terms for the validator
// Needed for ordering vals in the by-power key
BondHeight int64 // earliest height as a bonded validator
BondIntraTxCounter int16 // block-local tx index of validator change
CommissionInfo CommissionInfo // info about the validator's commission
}
@ -96,42 +95,41 @@ type CommissionInfo struct {
}
type Description struct {
Moniker string // name
Identity string // optional identity signature (ex. UPort or Keybase)
Website string // optional website link
Details string // optional details
Moniker string // name
Identity string // optional identity signature (ex. UPort or Keybase)
Website string // optional website link
Details string // optional details
}
```
### Delegation
Delegations are identified by combining `DelegatorAddr` (the address of the delegator) with the ValOwnerAddr
Delegators are indexed in the store as follows:
Delegations are identified by combining `DelegatorAddr` (the address of the delegator)
with the `OperatorAddr` Delegators are indexed in the store as follows:
- Delegation: ` 0x0A | DelegatorAddr | ValOwnerAddr -> amino(delegation)`
- Delegation: ` 0x0A | DelegatorAddr | OperatorAddr -> amino(delegation)`
Atom holders may delegate coins to validators; under this circumstance their
funds are held in a `Delegation` data structure. It is owned by one
delegator, and is associated with the shares for one validator. The sender of
funds are held in a `Delegation` data structure. It is owned by one
delegator, and is associated with the shares for one validator. The sender of
the transaction is the owner of the bond.
```golang
type Delegation struct {
Shares sdk.Dec // delegation shares recieved
Height int64 // last height bond updated
Shares sdk.Dec // delegation shares received
Height int64 // last height bond updated
}
```
### UnbondingDelegation
Shares in a `Delegation` can be unbonded, but they must for some time exist as an `UnbondingDelegation`,
where shares can be reduced if Byzantine behaviour is detected.
Shares in a `Delegation` can be unbonded, but they must for some time exist as an `UnbondingDelegation`, where shares can be reduced if Byzantine behavior is detected.
`UnbondingDelegation` are indexed in the store as:
- UnbondingDelegationByDelegator: ` 0x0B | DelegatorAddr | ValOwnerAddr ->
- UnbondingDelegationByDelegator: ` 0x0B | DelegatorAddr | OperatorAddr ->
amino(unbondingDelegation)`
- UnbondingDelegationByValOwner: ` 0x0C | ValOwnerAddr | DelegatorAddr | ValOwnerAddr ->
- UnbondingDelegationByValOwner: ` 0x0C | OperatorAddr | DelegatorAddr | OperatorAddr ->
nil`
The first map here is used in queries, to lookup all unbonding delegations for
@ -148,26 +146,26 @@ type UnbondingDelegation struct {
Tokens sdk.Coins // the value in Atoms of the amount of shares which are unbonding
CompleteTime int64 // unix time to complete redelegation
}
```
```
### Redelegation
Shares in a `Delegation` can be rebonded to a different validator, but they must for some time exist as a `Redelegation`,
where shares can be reduced if Byzantine behaviour is detected. This is tracked
as moving a delegation from a `FromValOwnerAddr` to a `ToValOwnerAddr`.
Shares in a `Delegation` can be rebonded to a different validator, but they must
for some time exist as a `Redelegation`, where shares can be reduced if Byzantine
behavior is detected. This is tracked as moving a delegation from a `FromOperatorAddr`
to a `ToOperatorAddr`.
`Redelegation` are indexed in the store as:
- Redelegations: `0x0D | DelegatorAddr | FromValOwnerAddr | ToValOwnerAddr ->
- Redelegations: `0x0D | DelegatorAddr | FromOperatorAddr | ToOperatorAddr ->
amino(redelegation)`
- RedelegationsBySrc: `0x0E | FromValOwnerAddr | ToValOwnerAddr |
- RedelegationsBySrc: `0x0E | FromOperatorAddr | ToOperatorAddr |
DelegatorAddr -> nil`
- RedelegationsByDst: `0x0F | ToValOwnerAddr | FromValOwnerAddr | DelegatorAddr
- RedelegationsByDst: `0x0F | ToOperatorAddr | FromOperatorAddr | DelegatorAddr
-> nil`
The first map here is used for queries, to lookup all redelegations for a given
delegator. The second map is used for slashing based on the FromValOwnerAddr,
delegator. The second map is used for slashing based on the `FromOperatorAddr`,
while the third map is for slashing based on the ToValOwnerAddr.
A redelegation object is created every time a redelegation occurs. The

View File

@ -77,14 +77,14 @@ We view testnet participation as a great way to signal to the community that you
In short, there are two types of keys:
* **Tendermint Key**: This is a unique key used to sign block hashes. It is associated with a public key `cosmosconspub`.
* **Tendermint Key**: This is a unique key used to sign block hashes. It is associated with a public key `cosmosvalconspub`.
* Generated when the node is created with gaiad init.
* Get this value with `gaiad tendermint show-validator`
e.g. `cosmosconspub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c`
e.g. `cosmosvalconspub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c`
* **Application keys**: These keys are created from the application and used to sign transactions. As a validator, you will probably use one key to sign staking-related transactions, and another key to sign governance-related transactions. Application keys are associated with a public key `cosmospub` and an address `cosmos`. Both are derived from account keys generated by `gaiacli keys add`.
* Note: A validator's operator key is directly tied to an application key, but
uses reserved prefixes solely for this purpose: `cosmosval` and `cosmosvalpub`
uses reserved prefixes solely for this purpose: `cosmosvaloper` and `cosmosvaloperpub`
### What are the different states a validator can be in?

View File

@ -16,7 +16,7 @@ If you want to become a validator for the Hub's `mainnet`, you should [research
### Create Your Validator
Your `cosmosconspub` can be used to create a new validator by staking tokens. You can find your validator pubkey by running:
Your `cosmosvalconspub` can be used to create a new validator by staking tokens. You can find your validator pubkey by running:
```bash
gaiad tendermint show-validator

View File

@ -22,13 +22,13 @@ const (
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = "cosmospub"
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = "cosmosval"
Bech32PrefixValAddr = "cosmosvaloper"
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = "cosmosvalpub"
Bech32PrefixValPub = "cosmosvaloperpub"
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = "cosmoscons"
Bech32PrefixConsAddr = "cosmosvalcons"
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = "cosmosconspub"
Bech32PrefixConsPub = "cosmosvalconspub"
)
// ----------------------------------------------------------------------------
@ -146,7 +146,7 @@ func (aa AccAddress) Format(s fmt.State, verb rune) {
}
// ----------------------------------------------------------------------------
// validator owner
// validator operator
// ----------------------------------------------------------------------------
// ValAddress defines a wrapper around bytes meant to present a validator's

View File

@ -40,7 +40,7 @@ type Validator interface {
GetJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOperator() ValAddress // owner address to receive/return validators coins
GetOperator() ValAddress // operator address to receive/return validators coins
GetPubKey() crypto.PubKey // validation pubkey
GetPower() Dec // validation power
GetTokens() Dec // validation tokens
@ -59,11 +59,11 @@ func ABCIValidator(v Validator) abci.Validator {
// properties for the set of all validators
type ValidatorSet interface {
// iterate through validator by owner-AccAddress, execute func for each validator
// iterate through validators by operator address, execute func for each validator
IterateValidators(Context,
func(index int64, validator Validator) (stop bool))
// iterate through bonded validator by pubkey-AccAddress, execute func for each validator
// iterate through bonded validators by operator address, execute func for each validator
IterateValidatorsBonded(Context,
func(index int64, validator Validator) (stop bool))

View File

@ -440,7 +440,7 @@ func TestTallyJailedValidator(t *testing.T) {
val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1]))
require.True(t, found)
sk.Jail(ctx, val2.PubKey)
sk.Jail(ctx, val2.ConsPubKey)
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
proposalID := proposal.GetProposalID()

View File

@ -107,10 +107,10 @@ func TestSlashingMsgs(t *testing.T) {
mapp.BeginBlock(abci.RequestBeginBlock{})
validator := checkValidator(t, mapp, stakeKeeper, addr1, true)
require.Equal(t, sdk.ValAddress(addr1), validator.Operator)
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddr)
require.Equal(t, sdk.Bonded, validator.Status)
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.PubKey.Address())}
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.ConsPubKey.Address())}
// no signing info yet
checkValidatorSigningInfo(t, mapp, keeper, sdk.ConsAddress(addr1), false)

View File

@ -14,24 +14,24 @@ var (
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
)
// stored by *Tendermint* address (not owner address)
// stored by *Tendermint* address (not operator address)
func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
return append(ValidatorSigningInfoKey, v.Bytes()...)
}
// stored by *Tendermint* address (not owner address)
// stored by *Tendermint* address (not operator address)
func GetValidatorSigningBitArrayKey(v sdk.ConsAddress, i int64) []byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(i))
return append(ValidatorSigningBitArrayKey, append(v.Bytes(), b...)...)
}
// stored by *Tendermint* address (not owner address)
// stored by *Tendermint* address (not operator address)
func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
return append(ValidatorSlashingPeriodKey, v.Bytes()...)
}
// stored by *Tendermint* address (not owner address) followed by start height
// stored by *Tendermint* address (not operator address) followed by start height
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(startHeight))

View File

@ -15,7 +15,7 @@ var _ sdk.Msg = &MsgUnjail{}
// MsgUnjail - struct for unjailing jailed validator
type MsgUnjail struct {
ValidatorAddr sdk.ValAddress `json:"address"` // address of the validator owner
ValidatorAddr sdk.ValAddress `json:"address"` // address of the validator operator
}
func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail {

View File

@ -12,5 +12,5 @@ func TestMsgUnjailGetSignBytes(t *testing.T) {
addr := sdk.AccAddress("abcd")
msg := NewMsgUnjail(sdk.ValAddress(addr))
bytes := msg.GetSignBytes()
require.Equal(t, string(bytes), `{"address":"cosmosval1v93xxeq7xkcrf"}`)
require.Equal(t, string(bytes), `{"address":"cosmosvaloper1v93xxeqhg9nn6"}`)
}

View File

@ -7,7 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Stored by *validator* address (not owner address)
// Stored by *validator* address (not operator address)
func (k Keeper) getValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info ValidatorSigningInfo, found bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(GetValidatorSigningInfoKey(address))
@ -20,14 +20,14 @@ func (k Keeper) getValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress
return
}
// Stored by *validator* address (not owner address)
// Stored by *validator* address (not operator address)
func (k Keeper) setValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinary(info)
store.Set(GetValidatorSigningInfoKey(address), bz)
}
// Stored by *validator* address (not owner address)
// Stored by *validator* address (not operator address)
func (k Keeper) getValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (signed bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(GetValidatorSigningBitArrayKey(address, index))
@ -40,7 +40,7 @@ func (k Keeper) getValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAdd
return
}
// Stored by *validator* address (not owner address)
// Stored by *validator* address (not operator address)
func (k Keeper) setValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, signed bool) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinary(signed)

View File

@ -32,7 +32,7 @@ func (k Keeper) capBySlashingPeriod(ctx sdk.Context, address sdk.ConsAddress, fr
return
}
// Stored by validator Tendermint address (not owner address)
// Stored by validator Tendermint address (not operator address)
// This function retrieves the most recent slashing period starting
// before a particular height - so the slashing period that was "in effect"
// at the time of an infraction committed at that height.
@ -49,7 +49,7 @@ func (k Keeper) getValidatorSlashingPeriodForHeight(ctx sdk.Context, address sdk
return
}
// Stored by validator Tendermint address (not owner address)
// Stored by validator Tendermint address (not operator address)
// This function sets a validator slashing period for a particular validator,
// start height, end height, and current slashed-so-far total, or updates
// an existing slashing period for the same validator and start height.

View File

@ -136,7 +136,7 @@ func TestStakeMsgs(t *testing.T) {
mApp.BeginBlock(abci.RequestBeginBlock{})
validator := checkValidator(t, mApp, keeper, sdk.ValAddress(addr1), true)
require.Equal(t, sdk.ValAddress(addr1), validator.Operator)
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddr)
require.Equal(t, sdk.Bonded, validator.Status)
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
@ -150,7 +150,7 @@ func TestStakeMsgs(t *testing.T) {
mApp.BeginBlock(abci.RequestBeginBlock{})
validator = checkValidator(t, mApp, keeper, sdk.ValAddress(addr2), true)
require.Equal(t, sdk.ValAddress(addr2), validator.Operator)
require.Equal(t, sdk.ValAddress(addr2), validator.OperatorAddr)
require.Equal(t, sdk.Bonded, validator.Status)
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))

View File

@ -126,7 +126,7 @@ func delegatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Handler
}
for _, validator := range validators {
valAddr = validator.Operator
valAddr = validator.OperatorAddr
// Delegations
delegations, statusCode, errMsg, err := getDelegatorDelegations(cliCtx, cdc, delAddr, valAddr)
@ -410,7 +410,7 @@ func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) ht
for _, validator := range validators {
// get all transactions from the delegator to val and append
valAddr = validator.Operator
valAddr = validator.OperatorAddr
validator, statusCode, errMsg, errRes := getDelegatorValidator(cliCtx, cdc, delegatorAddr, valAddr)
if errRes != nil {

View File

@ -138,7 +138,7 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper)
return ErrBadDenom(k.Codespace()).Result()
}
if validator.Jailed && !bytes.Equal(validator.Operator, msg.DelegatorAddr) {
if validator.Jailed && !bytes.Equal(validator.OperatorAddr, msg.DelegatorAddr) {
return ErrValidatorJailed(k.Codespace()).Result()
}

View File

@ -136,8 +136,8 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
require.True(t, found)
assert.Equal(t, sdk.Bonded, validator.Status)
assert.Equal(t, addr1, validator.Operator)
assert.Equal(t, pk1, validator.PubKey)
assert.Equal(t, addr1, validator.OperatorAddr)
assert.Equal(t, pk1, validator.ConsPubKey)
assert.Equal(t, sdk.NewDec(10), validator.BondedTokens())
assert.Equal(t, sdk.NewDec(10), validator.DelegatorShares)
assert.Equal(t, Description{}, validator.Description)
@ -160,8 +160,8 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
require.True(t, found)
assert.Equal(t, sdk.Bonded, validator.Status)
assert.Equal(t, addr2, validator.Operator)
assert.Equal(t, pk2, validator.PubKey)
assert.Equal(t, addr2, validator.OperatorAddr)
assert.Equal(t, pk2, validator.ConsPubKey)
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
assert.Equal(t, Description{}, validator.Description)
@ -180,8 +180,8 @@ func TestDuplicatesMsgCreateValidatorOnBehalfOf(t *testing.T) {
require.True(t, found)
assert.Equal(t, sdk.Bonded, validator.Status)
assert.Equal(t, validatorAddr, validator.Operator)
assert.Equal(t, pk, validator.PubKey)
assert.Equal(t, validatorAddr, validator.OperatorAddr)
assert.Equal(t, pk, validator.ConsPubKey)
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
assert.Equal(t, Description{}, validator.Description)

View File

@ -223,11 +223,11 @@ func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Co
validator types.Validator, subtractAccount bool) (newShares sdk.Dec, err sdk.Error) {
// Get or create the delegator delegation
delegation, found := k.GetDelegation(ctx, delAddr, validator.Operator)
delegation, found := k.GetDelegation(ctx, delAddr, validator.OperatorAddr)
if !found {
delegation = types.Delegation{
DelegatorAddr: delAddr,
ValidatorAddr: validator.Operator,
ValidatorAddr: validator.OperatorAddr,
Shares: sdk.ZeroDec(),
}
}
@ -286,7 +286,7 @@ func (k Keeper) unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValA
// if the delegation is the operator of the validator then
// trigger a jail validator
if bytes.Equal(delegation.DelegatorAddr, validator.Operator) && validator.Jailed == false {
if bytes.Equal(delegation.DelegatorAddr, validator.OperatorAddr) && validator.Jailed == false {
validator.Jailed = true
}
@ -306,7 +306,7 @@ func (k Keeper) unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValA
// update then remove validator if necessary
validator = k.UpdateValidator(ctx, validator)
if validator.DelegatorShares.IsZero() {
k.RemoveValidator(ctx, validator.Operator)
k.RemoveValidator(ctx, validator.OperatorAddr)
}
return amount, nil

View File

@ -26,10 +26,10 @@ var (
IntraTxCounterKey = []byte{0x09} // key for intra-block tx index
DelegationKey = []byte{0x0A} // key for a delegation
UnbondingDelegationKey = []byte{0x0B} // key for an unbonding-delegation
UnbondingDelegationByValIndexKey = []byte{0x0C} // prefix for each key for an unbonding-delegation, by validator owner
UnbondingDelegationByValIndexKey = []byte{0x0C} // prefix for each key for an unbonding-delegation, by validator operator
RedelegationKey = []byte{0x0D} // key for a redelegation
RedelegationByValSrcIndexKey = []byte{0x0E} // prefix for each key for an redelegation, by source validator owner
RedelegationByValDstIndexKey = []byte{0x0F} // prefix for each key for an redelegation, by destination validator owner
RedelegationByValSrcIndexKey = []byte{0x0E} // prefix for each key for an redelegation, by source validator operator
RedelegationByValDstIndexKey = []byte{0x0F} // prefix for each key for an redelegation, by destination validator operator
)
const maxDigitsForAccount = 12 // ~220,000,000 atoms created at launch
@ -41,7 +41,7 @@ func GetValidatorKey(operatorAddr sdk.ValAddress) []byte {
}
// gets the key for the validator with pubkey
// VALUE: validator owner address ([]byte)
// VALUE: validator operator address ([]byte)
func GetValidatorByPubKeyIndexKey(pubkey crypto.PubKey) []byte {
return append(ValidatorsByPubKeyIndexKey, pubkey.Bytes()...)
}
@ -52,7 +52,7 @@ func GetValidatorsBondedIndexKey(operatorAddr sdk.ValAddress) []byte {
return append(ValidatorsBondedIndexKey, operatorAddr.Bytes()...)
}
// Get the validator owner address from ValBondedIndexKey
// Get the validator operator address from ValBondedIndexKey
func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte {
return IndexKey[1:] // remove prefix bytes
}
@ -60,7 +60,7 @@ func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte {
// get the validator by power index.
// Power index is the key used in the power-store, and represents the relative
// power ranking of the validator.
// VALUE: validator owner address ([]byte)
// VALUE: validator operator address ([]byte)
func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) []byte {
// NOTE the address doesn't need to be stored because counter bytes must always be different
return getValidatorPowerRank(validator, pool)

View File

@ -112,7 +112,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in
// remove validator if it has no more tokens
if validator.Tokens.IsZero() {
k.RemoveValidator(ctx, validator.Operator)
k.RemoveValidator(ctx, validator.OperatorAddr)
}
// Log that a slash occurred!

View File

@ -38,7 +38,7 @@ func (k Keeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator ty
if val, ok := validatorCache[strValue]; ok {
valToReturn := val.val
// Doesn't mutate the cache's value
valToReturn.Operator = addr
valToReturn.OperatorAddr = addr
return valToReturn, true
}
@ -72,25 +72,25 @@ func (k Keeper) GetValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) (val
func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
store := ctx.KVStore(k.storeKey)
bz := types.MustMarshalValidator(k.cdc, validator)
store.Set(GetValidatorKey(validator.Operator), bz)
store.Set(GetValidatorKey(validator.OperatorAddr), bz)
}
// validator index
func (k Keeper) SetValidatorByPubKeyIndex(ctx sdk.Context, validator types.Validator) {
store := ctx.KVStore(k.storeKey)
store.Set(GetValidatorByPubKeyIndexKey(validator.PubKey), validator.Operator)
store.Set(GetValidatorByPubKeyIndexKey(validator.ConsPubKey), validator.OperatorAddr)
}
// validator index
func (k Keeper) SetValidatorByPowerIndex(ctx sdk.Context, validator types.Validator, pool types.Pool) {
store := ctx.KVStore(k.storeKey)
store.Set(GetValidatorsByPowerIndexKey(validator, pool), validator.Operator)
store.Set(GetValidatorsByPowerIndexKey(validator, pool), validator.OperatorAddr)
}
// validator index
func (k Keeper) SetValidatorBondedIndex(ctx sdk.Context, validator types.Validator) {
store := ctx.KVStore(k.storeKey)
store.Set(GetValidatorsBondedIndexKey(validator.Operator), []byte{})
store.Set(GetValidatorsBondedIndexKey(validator.OperatorAddr), []byte{})
}
// used in testing
@ -239,7 +239,7 @@ func (k Keeper) ClearTendermintUpdates(ctx sdk.Context) {
func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) types.Validator {
store := ctx.KVStore(k.storeKey)
pool := k.GetPool(ctx)
oldValidator, oldFound := k.GetValidator(ctx, validator.Operator)
oldValidator, oldFound := k.GetValidator(ctx, validator.OperatorAddr)
validator = k.updateForJailing(ctx, oldFound, oldValidator, validator)
powerIncreasing := k.getPowerIncreasing(ctx, oldFound, oldValidator, validator)
@ -257,11 +257,11 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
(oldFound && oldValidator.Status == sdk.Bonded):
bz := k.cdc.MustMarshalBinary(validator.ABCIValidator())
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bz)
if cliffPower != nil {
cliffAddr := sdk.ValAddress(k.GetCliffValidator(ctx))
if bytes.Equal(cliffAddr, validator.Operator) {
if bytes.Equal(cliffAddr, validator.OperatorAddr) {
k.updateCliffValidator(ctx, validator)
}
}
@ -293,7 +293,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
// if decreased in power but still bonded, update Tendermint validator
if oldFound && oldValidator.BondedTokens().GT(validator.BondedTokens()) {
bz := k.cdc.MustMarshalBinary(validator.ABCIValidator())
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bz)
}
}
@ -344,7 +344,7 @@ func (k Keeper) updateCliffValidator(ctx sdk.Context, affectedVal types.Validato
affectedValRank := GetValidatorsByPowerIndexKey(affectedVal, pool)
newCliffValRank := GetValidatorsByPowerIndexKey(newCliffVal, pool)
if bytes.Equal(affectedVal.Operator, newCliffVal.Operator) {
if bytes.Equal(affectedVal.OperatorAddr, newCliffVal.OperatorAddr) {
// The affected validator remains the cliff validator, however, since
// the store does not contain the new power, update the new power rank.
@ -407,7 +407,7 @@ func (k Keeper) updateValidatorPower(ctx sdk.Context, oldFound bool, oldValidato
store.Delete(GetValidatorsByPowerIndexKey(oldValidator, pool))
}
valPower = GetValidatorsByPowerIndexKey(newValidator, pool)
store.Set(valPower, newValidator.Operator)
store.Set(valPower, newValidator.OperatorAddr)
return valPower
}
@ -449,7 +449,7 @@ func (k Keeper) UpdateBondedValidators(
// situation that this is the "affected validator" just use the
// validator provided because it has not yet been updated in the store
ownerAddr := iterator.Value()
if bytes.Equal(ownerAddr, affectedValidator.Operator) {
if bytes.Equal(ownerAddr, affectedValidator.OperatorAddr) {
validator = affectedValidator
} else {
var found bool
@ -486,7 +486,7 @@ func (k Keeper) UpdateBondedValidators(
iterator.Close()
if newValidatorBonded && bytes.Equal(oldCliffValidatorAddr, validator.Operator) {
if newValidatorBonded && bytes.Equal(oldCliffValidatorAddr, validator.OperatorAddr) {
panic("cliff validator has not been changed, yet we bonded a new validator")
}
@ -506,7 +506,7 @@ func (k Keeper) UpdateBondedValidators(
panic(fmt.Sprintf("validator record not found for address: %v\n", oldCliffValidatorAddr))
}
if bytes.Equal(validatorToBond.Operator, affectedValidator.Operator) {
if bytes.Equal(validatorToBond.OperatorAddr, affectedValidator.OperatorAddr) {
// begin unbonding the old cliff validator iff the affected
// validator was newly bonded and has greater power
@ -520,7 +520,7 @@ func (k Keeper) UpdateBondedValidators(
}
validator = k.bondValidator(ctx, validatorToBond)
if bytes.Equal(validator.Operator, affectedValidator.Operator) {
if bytes.Equal(validator.OperatorAddr, affectedValidator.OperatorAddr) {
return validator, true
}
@ -637,10 +637,10 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
// add to accumulated changes for tendermint
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorZero())
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bzABCI)
// also remove from the Bonded types.Validators Store
store.Delete(GetValidatorsBondedIndexKey(validator.Operator))
store.Delete(GetValidatorsBondedIndexKey(validator.OperatorAddr))
// call the unbond hook if present
if k.validatorHooks != nil {
@ -668,11 +668,11 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
// save the now bonded validator record to the three referenced stores
k.SetValidator(ctx, validator)
store.Set(GetValidatorsBondedIndexKey(validator.Operator), []byte{})
store.Set(GetValidatorsBondedIndexKey(validator.OperatorAddr), []byte{})
// add to accumulated changes for tendermint
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidator())
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bzABCI)
// call the bond hook if present
if k.validatorHooks != nil {
@ -696,15 +696,15 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
store := ctx.KVStore(k.storeKey)
pool := k.GetPool(ctx)
store.Delete(GetValidatorKey(address))
store.Delete(GetValidatorByPubKeyIndexKey(validator.PubKey))
store.Delete(GetValidatorByPubKeyIndexKey(validator.ConsPubKey))
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
// delete from the current and power weighted validator groups if the validator
// is bonded - and add validator with zero power to the validator updates
if store.Get(GetValidatorsBondedIndexKey(validator.Operator)) == nil {
if store.Get(GetValidatorsBondedIndexKey(validator.OperatorAddr)) == nil {
return
}
store.Delete(GetValidatorsBondedIndexKey(validator.Operator))
store.Delete(GetValidatorsBondedIndexKey(validator.OperatorAddr))
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorZero())
store.Set(GetTendermintUpdatesKey(address), bz)
@ -729,7 +729,7 @@ func (k Keeper) setCliffValidator(ctx sdk.Context, validator types.Validator, po
store := ctx.KVStore(k.storeKey)
bz := GetValidatorsByPowerIndexKey(validator, pool)
store.Set(ValidatorPowerCliffKey, bz)
store.Set(ValidatorCliffIndexKey, validator.Operator)
store.Set(ValidatorCliffIndexKey, validator.OperatorAddr)
}
// clear the current validator and power of the validator on the cliff

View File

@ -129,7 +129,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
// require the cliff validator has changed
cliffVal := validators[numVals-maxVals-1]
require.Equal(t, cliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, cliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
// require the cliff validator power has changed
cliffPower := keeper.GetCliffValidatorPower(ctx)
@ -142,7 +142,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
// require all the validators have their respective statuses
for valIdx, status := range expectedValStatus {
valAddr := validators[valIdx].Operator
valAddr := validators[valIdx].OperatorAddr
val, _ := keeper.GetValidator(ctx, valAddr)
assert.Equal(
@ -192,7 +192,7 @@ func TestCliffValidatorChange(t *testing.T) {
// assert new cliff validator to be set to the second lowest bonded validator by power
newCliffVal := validators[numVals-maxVals+1]
require.Equal(t, newCliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, newCliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
// assert cliff validator power should have been updated
cliffPower := keeper.GetCliffValidatorPower(ctx)
@ -205,7 +205,7 @@ func TestCliffValidatorChange(t *testing.T) {
// assert cliff validator has not change but increased in power
cliffPower = keeper.GetCliffValidatorPower(ctx)
require.Equal(t, newCliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, newCliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, GetValidatorsByPowerIndexKey(newCliffVal, pool), cliffPower)
// add enough power to cliff validator to be equal in rank to next validator
@ -215,7 +215,7 @@ func TestCliffValidatorChange(t *testing.T) {
// assert new cliff validator due to power rank construction
newCliffVal = validators[numVals-maxVals+2]
require.Equal(t, newCliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, newCliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
// assert cliff validator power should have been updated
cliffPower = keeper.GetCliffValidatorPower(ctx)
@ -317,7 +317,7 @@ func TestValidatorBasics(t *testing.T) {
assert.True(ValEq(t, validators[2], resVals[2]))
// remove a record
keeper.RemoveValidator(ctx, validators[1].Operator)
keeper.RemoveValidator(ctx, validators[1].OperatorAddr)
_, found = keeper.GetValidator(ctx, addrVals[1])
require.False(t, found)
}
@ -346,11 +346,11 @@ func GetValidatorSortingUnmixed(t *testing.T) {
assert.Equal(t, sdk.NewDec(100), resValidators[2].BondedTokens(), "%v", resValidators)
assert.Equal(t, sdk.NewDec(1), resValidators[3].BondedTokens(), "%v", resValidators)
assert.Equal(t, sdk.NewDec(0), resValidators[4].BondedTokens(), "%v", resValidators)
assert.Equal(t, validators[3].Operator, resValidators[0].Operator, "%v", resValidators)
assert.Equal(t, validators[4].Operator, resValidators[1].Operator, "%v", resValidators)
assert.Equal(t, validators[1].Operator, resValidators[2].Operator, "%v", resValidators)
assert.Equal(t, validators[2].Operator, resValidators[3].Operator, "%v", resValidators)
assert.Equal(t, validators[0].Operator, resValidators[4].Operator, "%v", resValidators)
assert.Equal(t, validators[3].OperatorAddr, resValidators[0].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[4].OperatorAddr, resValidators[1].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[1].OperatorAddr, resValidators[2].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[2].OperatorAddr, resValidators[3].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[0].OperatorAddr, resValidators[4].OperatorAddr, "%v", resValidators)
// test a basic increase in voting power
validators[3].Tokens = sdk.NewDec(500)
@ -457,11 +457,11 @@ func GetValidatorSortingMixed(t *testing.T) {
assert.Equal(t, sdk.NewDec(100), resValidators[2].BondedTokens(), "%v", resValidators)
assert.Equal(t, sdk.NewDec(1), resValidators[3].BondedTokens(), "%v", resValidators)
assert.Equal(t, sdk.NewDec(0), resValidators[4].BondedTokens(), "%v", resValidators)
assert.Equal(t, validators[3].Operator, resValidators[0].Operator, "%v", resValidators)
assert.Equal(t, validators[4].Operator, resValidators[1].Operator, "%v", resValidators)
assert.Equal(t, validators[1].Operator, resValidators[2].Operator, "%v", resValidators)
assert.Equal(t, validators[2].Operator, resValidators[3].Operator, "%v", resValidators)
assert.Equal(t, validators[0].Operator, resValidators[4].Operator, "%v", resValidators)
assert.Equal(t, validators[3].OperatorAddr, resValidators[0].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[4].OperatorAddr, resValidators[1].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[1].OperatorAddr, resValidators[2].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[2].OperatorAddr, resValidators[3].OperatorAddr, "%v", resValidators)
assert.Equal(t, validators[0].OperatorAddr, resValidators[4].OperatorAddr, "%v", resValidators)
}
// TODO separate out into multiple tests
@ -488,7 +488,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
}
for i := range amts {
validators[i], found = keeper.GetValidator(ctx, validators[i].Operator)
validators[i], found = keeper.GetValidator(ctx, validators[i].OperatorAddr)
require.True(t, found)
}
resValidators := keeper.GetValidatorsByPower(ctx)
@ -512,7 +512,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
// validator 3 enters bonded validator set
ctx = ctx.WithBlockHeight(40)
validators[3], found = keeper.GetValidator(ctx, validators[3].Operator)
validators[3], found = keeper.GetValidator(ctx, validators[3].OperatorAddr)
require.True(t, found)
validators[3], pool, _ = validators[3].AddTokensFromDel(pool, sdk.NewInt(1))
keeper.SetPool(ctx, pool)
@ -539,7 +539,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
require.Equal(t, nMax, uint16(len(resValidators)))
assert.True(ValEq(t, validators[0], resValidators[0]))
assert.True(ValEq(t, validators[2], resValidators[1]))
validator, exists := keeper.GetValidator(ctx, validators[3].Operator)
validator, exists := keeper.GetValidator(ctx, validators[3].OperatorAddr)
require.Equal(t, exists, true)
require.Equal(t, int64(40), validator.BondHeight)
}
@ -609,7 +609,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
}
for i := range amts {
var found bool
validators[i], found = keeper.GetValidator(ctx, validators[i].Operator)
validators[i], found = keeper.GetValidator(ctx, validators[i].OperatorAddr)
require.True(t, found)
}
assert.Equal(t, sdk.Unbonding, validators[0].Status)
@ -682,13 +682,13 @@ func TestGetTendermintUpdatesAllNone(t *testing.T) {
keeper.ClearTendermintUpdates(ctx)
require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx)))
keeper.RemoveValidator(ctx, validators[0].Operator)
keeper.RemoveValidator(ctx, validators[1].Operator)
keeper.RemoveValidator(ctx, validators[0].OperatorAddr)
keeper.RemoveValidator(ctx, validators[1].OperatorAddr)
updates = keeper.GetTendermintUpdates(ctx)
assert.Equal(t, 2, len(updates))
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[0].PubKey), updates[0].PubKey)
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[1].PubKey), updates[1].PubKey)
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[0].ConsPubKey), updates[0].PubKey)
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[1].ConsPubKey), updates[1].PubKey)
assert.Equal(t, int64(0), updates[0].Power)
assert.Equal(t, int64(0), updates[1].Power)
}

View File

@ -37,7 +37,7 @@ func ErrNoValidatorFound(codespace sdk.CodespaceType) sdk.Error {
}
func ErrValidatorOwnerExists(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidValidator, "validator already exist for this owner-address, must use new validator-owner address")
return sdk.NewError(codespace, CodeInvalidValidator, "validator already exist for this operator address, must use new validator operator address")
}
func ErrValidatorPubKeyExists(codespace sdk.CodespaceType) sdk.Error {

View File

@ -21,9 +21,9 @@ import (
// exchange rate. Voting power can be calculated as total bonds multiplied by
// exchange rate.
type Validator struct {
Operator sdk.ValAddress `json:"operator"` // sender of BondTx - UnbondTx returns here
PubKey crypto.PubKey `json:"pub_key"` // pubkey of validator
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
OperatorAddr sdk.ValAddress `json:"operator_address"` // address of the validator's operator
ConsPubKey crypto.PubKey `json:"consensus_pubkey"` // the consensus public key of the validator
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)
Tokens sdk.Dec `json:"tokens"` // delegated tokens (incl. self-delegation)
@ -45,8 +45,8 @@ type Validator struct {
// NewValidator - initialize a new validator
func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator {
return Validator{
Operator: operator,
PubKey: pubKey,
OperatorAddr: operator,
ConsPubKey: pubKey,
Jailed: false,
Status: sdk.Unbonded,
Tokens: sdk.ZeroDec(),
@ -65,7 +65,7 @@ func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Des
// what's kept in the store value
type validatorValue struct {
PubKey crypto.PubKey
ConsPubKey crypto.PubKey
Jailed bool
Status sdk.BondStatus
Tokens sdk.Dec
@ -84,7 +84,7 @@ type validatorValue struct {
// return the redelegation without fields contained within the key for the store
func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte {
val := validatorValue{
PubKey: validator.PubKey,
ConsPubKey: validator.ConsPubKey,
Jailed: validator.Jailed,
Status: validator.Status,
Tokens: validator.Tokens,
@ -124,8 +124,8 @@ func UnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) (validator
}
return Validator{
Operator: operatorAddr,
PubKey: storeValue.PubKey,
OperatorAddr: operatorAddr,
ConsPubKey: storeValue.ConsPubKey,
Jailed: storeValue.Jailed,
Tokens: storeValue.Tokens,
Status: storeValue.Status,
@ -146,14 +146,14 @@ func UnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) (validator
// validator. An error is returned if the operator or the operator's public key
// cannot be converted to Bech32 format.
func (v Validator) HumanReadableString() (string, error) {
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.PubKey)
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.ConsPubKey)
if err != nil {
return "", err
}
resp := "Validator \n"
resp += fmt.Sprintf("Operator: %s\n", v.Operator)
resp += fmt.Sprintf("Validator: %s\n", bechConsPubKey)
resp += fmt.Sprintf("Operator Address: %s\n", v.OperatorAddr)
resp += fmt.Sprintf("Validator Consensus Pubkey: %s\n", bechConsPubKey)
resp += fmt.Sprintf("Jailed: %v\n", v.Jailed)
resp += fmt.Sprintf("Status: %s\n", sdk.BondStatusToString(v.Status))
resp += fmt.Sprintf("Tokens: %s\n", v.Tokens.String())
@ -174,9 +174,9 @@ func (v Validator) HumanReadableString() (string, error) {
// validator struct for bech output
type BechValidator struct {
Operator sdk.ValAddress `json:"operator"` // in bech32
PubKey string `json:"pub_key"` // in bech32
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
OperatorAddr sdk.ValAddress `json:"operator_address"` // the bech32 address of the validator's operator
ConsPubKey string `json:"consensus_pubkey"` // the bech32 consensus public key of the validator
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)
Tokens sdk.Dec `json:"tokens"` // delegated tokens (incl. self-delegation)
@ -197,15 +197,15 @@ type BechValidator struct {
// get the bech validator from the the regular validator
func (v Validator) Bech32Validator() (BechValidator, error) {
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.PubKey)
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.ConsPubKey)
if err != nil {
return BechValidator{}, err
}
return BechValidator{
Operator: v.Operator,
PubKey: bechConsPubKey,
Jailed: v.Jailed,
OperatorAddr: v.OperatorAddr,
ConsPubKey: bechConsPubKey,
Jailed: v.Jailed,
Status: v.Status,
Tokens: v.Tokens,
@ -229,8 +229,8 @@ func (v Validator) Bech32Validator() (BechValidator, error) {
// only the vitals - does not check bond height of IntraTxCounter
// nolint gocyclo - why dis fail?
func (v Validator) Equal(c2 Validator) bool {
return v.PubKey.Equals(c2.PubKey) &&
bytes.Equal(v.Operator, c2.Operator) &&
return v.ConsPubKey.Equals(c2.ConsPubKey) &&
bytes.Equal(v.OperatorAddr, c2.OperatorAddr) &&
v.Status.Equal(c2.Status) &&
v.Tokens.Equal(c2.Tokens) &&
v.DelegatorShares.Equal(c2.DelegatorShares) &&
@ -243,7 +243,7 @@ func (v Validator) Equal(c2 Validator) bool {
// return the TM validator address
func (v Validator) ConsAddress() sdk.ConsAddress {
return sdk.ConsAddress(v.PubKey.Address())
return sdk.ConsAddress(v.ConsPubKey.Address())
}
// constant used in flags to indicate that description field should not be updated
@ -312,8 +312,8 @@ func (d Description) EnsureLength() (Description, sdk.Error) {
// ABCIValidator returns an abci.Validator from a staked validator type.
func (v Validator) ABCIValidator() abci.Validator {
return abci.Validator{
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
Address: v.PubKey.Address(),
PubKey: tmtypes.TM2PB.PubKey(v.ConsPubKey),
Address: v.ConsPubKey.Address(),
Power: v.BondedTokens().RoundInt64(),
}
}
@ -322,8 +322,8 @@ func (v Validator) ABCIValidator() abci.Validator {
// with with zero power used for validator updates.
func (v Validator) ABCIValidatorZero() abci.Validator {
return abci.Validator{
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
Address: v.PubKey.Address(),
PubKey: tmtypes.TM2PB.PubKey(v.ConsPubKey),
Address: v.ConsPubKey.Address(),
Power: 0,
}
}
@ -446,8 +446,8 @@ var _ sdk.Validator = Validator{}
func (v Validator) GetJailed() bool { return v.Jailed }
func (v Validator) GetMoniker() string { return v.Description.Moniker }
func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
func (v Validator) GetOperator() sdk.ValAddress { return v.Operator }
func (v Validator) GetPubKey() crypto.PubKey { return v.PubKey }
func (v Validator) GetOperator() sdk.ValAddress { return v.OperatorAddr }
func (v Validator) GetPubKey() crypto.PubKey { return v.ConsPubKey }
func (v Validator) GetPower() sdk.Dec { return v.BondedTokens() }
func (v Validator) GetTokens() sdk.Dec { return v.Tokens }
func (v Validator) GetDelegatorShares() sdk.Dec { return v.DelegatorShares }

View File

@ -57,7 +57,7 @@ func TestABCIValidator(t *testing.T) {
validator := NewValidator(addr1, pk1, Description{})
abciVal := validator.ABCIValidator()
require.Equal(t, tmtypes.TM2PB.PubKey(validator.PubKey), abciVal.PubKey)
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
require.Equal(t, validator.BondedTokens().RoundInt64(), abciVal.Power)
}
@ -65,15 +65,15 @@ func TestABCIValidatorZero(t *testing.T) {
validator := NewValidator(addr1, pk1, Description{})
abciVal := validator.ABCIValidatorZero()
require.Equal(t, tmtypes.TM2PB.PubKey(validator.PubKey), abciVal.PubKey)
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
require.Equal(t, int64(0), abciVal.Power)
}
func TestRemoveTokens(t *testing.T) {
validator := Validator{
Operator: addr1,
PubKey: pk1,
OperatorAddr: addr1,
ConsPubKey: pk1,
Status: sdk.Bonded,
Tokens: sdk.NewDec(100),
DelegatorShares: sdk.NewDec(100),
@ -148,8 +148,8 @@ func TestAddTokensValidatorUnbonded(t *testing.T) {
// TODO refactor to make simpler like the AddToken tests above
func TestRemoveDelShares(t *testing.T) {
valA := Validator{
Operator: addr1,
PubKey: pk1,
OperatorAddr: addr1,
ConsPubKey: pk1,
Status: sdk.Bonded,
Tokens: sdk.NewDec(100),
DelegatorShares: sdk.NewDec(100),
@ -176,8 +176,8 @@ func TestRemoveDelShares(t *testing.T) {
poolTokens := sdk.NewDec(5102)
delShares := sdk.NewDec(115)
validator := Validator{
Operator: addr1,
PubKey: pk1,
OperatorAddr: addr1,
ConsPubKey: pk1,
Status: sdk.Bonded,
Tokens: poolTokens,
DelegatorShares: delShares,
@ -229,8 +229,8 @@ func TestPossibleOverflow(t *testing.T) {
poolTokens := sdk.NewDec(2159)
delShares := sdk.NewDec(391432570689183511).Quo(sdk.NewDec(40113011844664))
validator := Validator{
Operator: addr1,
PubKey: pk1,
OperatorAddr: addr1,
ConsPubKey: pk1,
Status: sdk.Bonded,
Tokens: poolTokens,
DelegatorShares: delShares,