Cosmos-sdk: Generic ValidatorSetKeeper in types

Created on 12 Apr 2018  路  8Comments  路  Source: cosmos/cosmos-sdk

Some modules such as gov use validator set information on their logic. They are getting Keeper from stake module directly now, but it is not flexible enough for support various validator set updating methods - PoA, another staking implementation, synced valset, etc. So wee need the generic interface for getting information about current validator set.

type Validator interface {
    Address() sdk.Address
    // Do we have to get PubKey?
    Power() sdk.Rat
}

//  https://github.com/tendermint/tendermint/blob/master/types/validator_set.go
type ValidatorSetKeeper interface {
    Hash() []byte
    GetValidators() []Validator
    IsValidator(sdk.Address) bool
    GetByAddress(sdk.Address) (int, Validator)
    GetByIndex(int) Validator
    TotalPower() sdk.Rat
    Size() int64
}

Keepers those implement ValidatorSetKeeper should always provide the information of current validator set.

Most helpful comment

Let's use abci.Validator instead of this new Validator type.

But yeah it makes sense to have this be in types/

All 8 comments

This is cool, I like it. Although, just a note, that governance is pretty dependent on the stake module because it is also dependent on all staked accounts (including delegators) not just the validators.

Is there a way to add the concept of delegation to this interface, or is that defeating the point of its simplicity?

I think this is nice, interface standardization will make future SDK users' lives easier and different validator set management algorithms seem likely.

We may need to use structs instead of interfaces to preserve the desired safety guarantees, see https://github.com/cosmos/cosmos-sdk/issues/802#issuecomment-381290865.

@rigelrozanski Thoughts?

Let's use abci.Validator instead of this new Validator type.

But yeah it makes sense to have this be in types/

abci.Validator does not have a field of address, and unfortunately, its pubkey is pure byte slice so we have to unmarshal it every time.

hmm okay yeah that sucks but I see why we would want this interface then

@sunnya97 I reckon it would be nice to add the idea of delegation to this interface as well - it would be nice to have governance not depend on staking but only on the interfaces in types :+1:

Implemented, works, used by x/slashing. We can add more functionality as needed.

1069 also using this. See that if someone needs an example to use this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mossid picture mossid  路  3Comments

ValarDragon picture ValarDragon  路  3Comments

rigelrozanski picture rigelrozanski  路  3Comments

rigelrozanski picture rigelrozanski  路  3Comments

ValarDragon picture ValarDragon  路  3Comments