Skip to content

Commit

Permalink
Distr-PR-1 Staking ConsPubKey -> ConsAddr index (#2369)
Browse files Browse the repository at this point in the history
* pulling in stuff from fee-distr PR
* revert some gov changes
* fix using cons address, also remove old commented distr code
* doc update
* val comments
* remove GetValidatorByConsPubKey
  • Loading branch information
rigelrozanski authored and jaekwon committed Sep 25, 2018
1 parent 1a5d122 commit 6b59584
Show file tree
Hide file tree
Showing 35 changed files with 248 additions and 519 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ BREAKING CHANGES
* [codec] \#2324 All referrences to wire have been renamed to codec. Additionally, wire.NewCodec is now codec.New().
* [types] \#2343 Make sdk.Msg have a names field, to facilitate automatic tagging.
* [baseapp] \#2366 Automatically add action tags to all messages
* [x/staking] \#2244 staking now holds a consensus-address-index instead of a consensus-pubkey-index

* Tendermint

Expand Down
11 changes: 6 additions & 5 deletions docs/spec/staking/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ type Params struct {
Validators are identified according to the `OperatorAddr`, an SDK validator
address for the operator 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 also have a `ConsPubKey`, the public key of the validator used in
Tendermint consensus. The validator can be retrieved from it's `ConsPubKey`
once it can be converted into the corresponding `ConsAddr`. Validators are
indexed in the store using the following maps:

- Validators: `0x02 | OperatorAddr -> amino(validator)`
- ValidatorsByPubKey: `0x03 | ConsPubKey -> OperatorAddr`
- ValidatorsByConsAddr: `0x03 | ConsAddr -> OperatorAddr`
- ValidatorsByPower: `0x05 | power | blockHeight | blockTx -> OperatorAddr`

`Validators` is the primary index - it ensures that each operator can have only one
Expand All @@ -69,7 +70,7 @@ validator.

```golang
type Validator struct {
ConsensusPubKey crypto.PubKey // Tendermint consensus pubkey of validator
ConsPubKey crypto.PubKey // Tendermint consensus pubkey of validator
Jailed bool // has the validator been jailed?

Status sdk.BondStatus // validator status (bonded/unbonding/unbonded)
Expand Down
22 changes: 16 additions & 6 deletions examples/democoin/mock/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ func (v Validator) GetOperator() sdk.ValAddress {
}

// Implements sdk.Validator
func (v Validator) GetPubKey() crypto.PubKey {
func (v Validator) GetConsPubKey() crypto.PubKey {
return nil
}

// Implements sdk.Validator
func (v Validator) GetConsAddr() sdk.ConsAddress {
return nil
}

Expand Down Expand Up @@ -88,7 +93,12 @@ func (vs *ValidatorSet) Validator(ctx sdk.Context, addr sdk.ValAddress) sdk.Vali
}

// ValidatorByPubKey implements sdk.ValidatorSet
func (vs *ValidatorSet) ValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) sdk.Validator {
func (vs *ValidatorSet) ValidatorByConsPubKey(_ sdk.Context, _ crypto.PubKey) sdk.Validator {
panic("not implemented")
}

// ValidatorByPubKey implements sdk.ValidatorSet
func (vs *ValidatorSet) ValidatorByConsAddr(_ sdk.Context, _ sdk.ConsAddress) sdk.Validator {
panic("not implemented")
}

Expand Down Expand Up @@ -122,21 +132,21 @@ func (vs *ValidatorSet) RemoveValidator(addr sdk.AccAddress) {
}

// Implements sdk.ValidatorSet
func (vs *ValidatorSet) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, power int64, amt sdk.Dec) {
func (vs *ValidatorSet) Slash(_ sdk.Context, _ sdk.ConsAddress, _ int64, _ int64, _ sdk.Dec) {
panic("not implemented")
}

// Implements sdk.ValidatorSet
func (vs *ValidatorSet) Jail(ctx sdk.Context, pubkey crypto.PubKey) {
func (vs *ValidatorSet) Jail(_ sdk.Context, _ sdk.ConsAddress) {
panic("not implemented")
}

// Implements sdk.ValidatorSet
func (vs *ValidatorSet) Unjail(ctx sdk.Context, pubkey crypto.PubKey) {
func (vs *ValidatorSet) Unjail(_ sdk.Context, _ sdk.ConsAddress) {
panic("not implemented")
}

// Implements sdk.ValidatorSet
func (vs *ValidatorSet) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.ValAddress) sdk.Delegation {
func (vs *ValidatorSet) Delegation(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) sdk.Delegation {
panic("not implemented")
}
5 changes: 5 additions & 0 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ func ConsAddressFromBech32(address string) (addr ConsAddress, err error) {
return ConsAddress(bz), nil
}

// get ConsAddress from pubkey
func GetConsAddress(pubkey crypto.PubKey) ConsAddress {
return ConsAddress(pubkey.Address())
}

// Returns boolean for whether two ConsAddress are Equal
func (ca ConsAddress) Equals(ca2 ConsAddress) bool {
if ca.Empty() && ca2.Empty() {
Expand Down
35 changes: 18 additions & 17 deletions types/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ func (b BondStatus) Equal(b2 BondStatus) bool {

// validator for a delegated proof of stake system
type Validator interface {
GetJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOperator() ValAddress // operator address to receive/return validators coins
GetPubKey() crypto.PubKey // validation pubkey
GetPower() Dec // validation power
GetTokens() Dec // validation tokens
GetDelegatorShares() Dec // Total out standing delegator shares
GetBondHeight() int64 // height in which the validator became active
GetJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOperator() ValAddress // operator address to receive/return validators coins
GetConsPubKey() crypto.PubKey // validation consensus pubkey
GetConsAddr() ConsAddress // validation consensus address
GetPower() Dec // validation power
GetTokens() Dec // validation tokens
GetDelegatorShares() Dec // Total out standing delegator shares
GetBondHeight() int64 // height in which the validator became active
}

// validator which fulfills abci validator interface for use in Tendermint
func ABCIValidator(v Validator) abci.Validator {
return abci.Validator{
PubKey: tmtypes.TM2PB.PubKey(v.GetPubKey()),
Address: v.GetPubKey().Address(),
PubKey: tmtypes.TM2PB.PubKey(v.GetConsPubKey()),
Address: v.GetConsPubKey().Address(),
Power: v.GetPower().RoundInt64(),
}
}
Expand All @@ -67,14 +68,14 @@ type ValidatorSet interface {
IterateValidatorsBonded(Context,
func(index int64, validator Validator) (stop bool))

Validator(Context, ValAddress) Validator // get a particular validator by operator
ValidatorByPubKey(Context, crypto.PubKey) Validator // get a particular validator by signing PubKey
Validator(Context, ValAddress) Validator // get a particular validator by operator address
ValidatorByConsAddr(Context, ConsAddress) Validator // get a particular validator by consensus address
TotalPower(Context) Dec // total power of the validator set

// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(Context, crypto.PubKey, int64, int64, Dec)
Jail(Context, crypto.PubKey) // jail a validator
Unjail(Context, crypto.PubKey) // unjail a validator
Slash(Context, ConsAddress, int64, int64, Dec)
Jail(Context, ConsAddress) // jail a validator
Unjail(Context, ConsAddress) // unjail a validator

// Delegation allows for getting a particular delegation for a given validator
// and delegator outside the scope of the staking module.
Expand All @@ -87,7 +88,7 @@ type ValidatorSet interface {
type Delegation interface {
GetDelegator() AccAddress // delegator AccAddress for the bond
GetValidator() ValAddress // validator operator address
GetBondShares() Dec // amount of validator's shares
GetShares() Dec // amount of validator's shares held in this delegation
}

// properties for the set of all delegations for a particular
Expand Down
91 changes: 0 additions & 91 deletions x/distribution/keeper.go

This file was deleted.

31 changes: 0 additions & 31 deletions x/distribution/keeper_test.go

This file was deleted.

72 changes: 0 additions & 72 deletions x/distribution/movement.go

This file was deleted.

Loading

0 comments on commit 6b59584

Please sign in to comment.