Documentation ¶
Index ¶
- Constants
- Variables
- func GetApplicationByConsAddrKey(addr sdk.ConsAddress) []byte
- func GetApplicationKey(operatorAddr sdk.ValAddress) []byte
- func GetKickProposalKey(operatorAddr sdk.ValAddress) []byte
- func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte
- func GetValidatorKey(operatorAddr sdk.ValAddress) []byte
- func GetValidatorStateKey(operatorAddr sdk.ValAddress) []byte
- func MustMarshalValidator(cdc *codec.Codec, validator Validator) []byte
- func MustMarshalVote(cdc *codec.Codec, v Vote) []byte
- func ParamKeyTable() params.KeyTable
- func RegisterCodec(cdc *codec.Codec)
- func ValidateGenesis(data GenesisState) error
- type Description
- type GenesisState
- type MsgLeaveValidatorSet
- type MsgProposeKick
- type MsgSubmitApplication
- type MsgVote
- type ParamSubspace
- type Params
- type QueryValidatorParams
- type Validator
- func (v Validator) ABCIValidatorUpdateAppend() abci.ValidatorUpdate
- func (v Validator) ABCIValidatorUpdateRemove() abci.ValidatorUpdate
- func (v Validator) CheckValid() error
- func (v Validator) GetConsAddr() sdk.ConsAddress
- func (v Validator) GetConsPubKey() crypto.PubKey
- func (v Validator) GetConsPubKeyString() string
- func (v Validator) GetDescription() Description
- func (v Validator) GetOperator() sdk.ValAddress
- type Vote
Constants ¶
const ( EventTypeSubmitApplication = "submit_application" EventTypeAppendValidator = "append_validator" EventTypeProposeKick = "propose_kick" EventTypeKickValidator = "kick_validator" EventTypeLeaveValidatorSet = "leave_validator_set" EventTypeApproveApplication = "approve_application" EventTypeRejectApplication = "reject_application" EventTypeRejectValidator = "reject_validator" EventTypeApproveKickProposal = "approve_kick_proposal" EventTypeRejectKickProposal = "reject_kick_proposal" EventTypeKeepValidator = "keep_validator" AttributeKeyValidator = "validator" AttributeKeyCandidate = "candidate" AttributeKeyVoter = "voter" AttributeKeyProposer = "proposer" AttributeValueCategory = ModuleName )
poa module event types
const ( // ModuleName is the name of the module ModuleName = "poa" // StoreKey to be used when creating the KVStore StoreKey = ModuleName // RouterKey to be used for routing msgs RouterKey = ModuleName // QuerierRoute to be used for querier msgs QuerierRoute = ModuleName )
const ( VoteTypeApplication uint16 = iota VoteTypeKickProposal uint16 = iota )
const ( // Default max number of validators DefaultMaxValidators uint16 = 15 // Default quorum percentage DefaultQuorum uint16 = 66 )
Default parameter namespace
const ( QueryValidators = "validators" QueryValidator = "validator" QueryParams = "params" QueryApplications = "applications" QueryKickProposals = "kick-proposals" )
Query endpoints supported by the poa querier
const ( ValidatorStateJoining uint16 = iota // The validator is joining the validator set, it is not yet present in Tendermint validator set ValidatorStateJoined uint16 = iota // The validator is already present in Tendermind validator set ValidatorStateLeaving uint16 = iota // The validator is leaving the validator set, it will leave Tendermint validator set at the end of the block )
Validator states
const LeaveValidatorSetConst = "LeaveValidatorSet"
const ProposeKickConst = "ProposeKick"
const SubmitApplicationConst = "SubmitApplication"
const VoteConst = "Vote"
Variables ¶
var ( ErrNoValidatorFound = sdkerrors.Register(ModuleName, 1, "no validator found") ErrInvalidValidator = sdkerrors.Register(ModuleName, 2, "invalid validator") ErrInvalidQuorumValue = sdkerrors.Register(ModuleName, 3, "quorum should be a percentage") ErrInvalidVoterPoolSize = sdkerrors.Register(ModuleName, 4, "the voter pool size is incorrect") ErrAlreadyApplying = sdkerrors.Register(ModuleName, 5, "the candidate is already applying to become a validator") ErrAlreadyValidator = sdkerrors.Register(ModuleName, 6, "the candidate is already a validator") ErrMaxValidatorsReached = sdkerrors.Register(ModuleName, 7, "the maximum number of validators has been reached") ErrInvalidVoteMsg = sdkerrors.Register(ModuleName, 8, "the vote message is invalid") ErrVoterNotValidator = sdkerrors.Register(ModuleName, 9, "the voter is not a validator") ErrNoApplicationFound = sdkerrors.Register(ModuleName, 10, "no application found") ErrAlreadyVoted = sdkerrors.Register(ModuleName, 11, "the validator already voted") ErrInvalidKickProposal = sdkerrors.Register(ModuleName, 12, "the kick proposal is invalid") ErrNotValidator = sdkerrors.Register(ModuleName, 13, "the candidate is not a validator") ErrValidatorLeaving = sdkerrors.Register(ModuleName, 14, "the candidate is leaving the validator set") ErrProposerNotValidator = sdkerrors.Register(ModuleName, 15, "the proposer is not a validator") ErrAlreadyInKickProposal = sdkerrors.Register(ModuleName, 16, "the candidate is already in a kick proposal") ErrNoKickProposalFound = sdkerrors.Register(ModuleName, 17, "no kick proposal found") ErrVoterIsCandidate = sdkerrors.Register(ModuleName, 18, "the voter cannot be the candidate") ErrProposerIsCandidate = sdkerrors.Register(ModuleName, 19, "the proposer cannot be the candidate") ErrOnlyOneValidator = sdkerrors.Register(ModuleName, 20, "there is only one validator in the validator set") )
var ( // Prefix for each key to a validator ValidatorsKey = []byte{0x21} // Prefix for each key to a validator index, by pubkey ValidatorsByConsAddrKey = []byte{0x22} // Prefix for each key to a validator state index ValidatorStatesKey = []byte{0x23} // Prefix for the validator application pool ApplicationPoolKey = []byte{0x24} // Prefix for each key to a application index, by pubkey ApplicationByConsAddrKey = []byte{0x25} // Prefix for the validator kick proposal pool KickProposalPoolKey = []byte{0x26} )
var ( KeyMaxValidators = []byte("MaxValidators") KeyQuorum = []byte("Quorum") )
Parameter store keys
var ModuleCdc *codec.Codec
ModuleCdc defines the module codec
Functions ¶
func GetApplicationByConsAddrKey ¶
func GetApplicationByConsAddrKey(addr sdk.ConsAddress) []byte
Get the key for a validator canditate application with pubkey
func GetApplicationKey ¶
func GetApplicationKey(operatorAddr sdk.ValAddress) []byte
Get the key for a validator canditate application with address
func GetKickProposalKey ¶
func GetKickProposalKey(operatorAddr sdk.ValAddress) []byte
Get the key for a validator canditate application with pubkey
func GetValidatorByConsAddrKey ¶
func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte
Get the key for the validator with pubkey
func GetValidatorKey ¶
func GetValidatorKey(operatorAddr sdk.ValAddress) []byte
Get the key for the validator with address
func GetValidatorStateKey ¶
func GetValidatorStateKey(operatorAddr sdk.ValAddress) []byte
Get the key for the validator state with address
func MustMarshalValidator ¶
Validator encoding functions
func MustMarshalVote ¶
Vote encoding functions
func RegisterCodec ¶
RegisterCodec registers concrete types on codec
func ValidateGenesis ¶
func ValidateGenesis(data GenesisState) error
ValidateGenesis validates the poa genesis parameters
Types ¶
type Description ¶
type Description struct { Moniker string `json:"moniker"` Identity string `json:"identity"` Website string `json:"website"` SecurityContact string `json:"security_contact"` Details string `json:"details"` }
Description defines a validator description
func NewDescription ¶
func NewDescription(moniker, identity, website, securityContact, details string) Description
Create a new Description
type GenesisState ¶
type GenesisState struct { Params Params `json:"params"` Validators []Validator `json:"validators"` }
GenesisState - all poa state that must be provided at genesis
func DefaultGenesisState ¶
func DefaultGenesisState() GenesisState
DefaultGenesisState - default GenesisState used by Cosmos Hub
func NewGenesisState ¶
func NewGenesisState(params Params, validators []Validator) GenesisState
NewGenesisState creates a new GenesisState object
type MsgLeaveValidatorSet ¶
type MsgLeaveValidatorSet struct {
ValidatorAddr sdk.ValAddress `json:"validator"`
}
func NewMsgLeaveValidatorSet ¶
func NewMsgLeaveValidatorSet(validatorAddr sdk.ValAddress) MsgLeaveValidatorSet
func (MsgLeaveValidatorSet) GetSignBytes ¶
func (msg MsgLeaveValidatorSet) GetSignBytes() []byte
GetSignBytes gets the bytes for the message signer to sign on
func (MsgLeaveValidatorSet) GetSigners ¶
func (msg MsgLeaveValidatorSet) GetSigners() []sdk.AccAddress
func (MsgLeaveValidatorSet) Route ¶
func (msg MsgLeaveValidatorSet) Route() string
func (MsgLeaveValidatorSet) Type ¶
func (msg MsgLeaveValidatorSet) Type() string
func (MsgLeaveValidatorSet) ValidateBasic ¶
func (msg MsgLeaveValidatorSet) ValidateBasic() error
ValidateBasic validity check for the AnteHandler
type MsgProposeKick ¶
type MsgProposeKick struct { CandidateAddr sdk.ValAddress `json:"candidate"` ProposerAddr sdk.ValAddress `json:"proposer"` }
func NewMsgProposeKick ¶
func NewMsgProposeKick(candidate sdk.ValAddress, proposer sdk.ValAddress) MsgProposeKick
func (MsgProposeKick) GetSignBytes ¶
func (msg MsgProposeKick) GetSignBytes() []byte
GetSignBytes gets the bytes for the message signer to sign on
func (MsgProposeKick) GetSigners ¶
func (msg MsgProposeKick) GetSigners() []sdk.AccAddress
func (MsgProposeKick) Route ¶
func (msg MsgProposeKick) Route() string
func (MsgProposeKick) Type ¶
func (msg MsgProposeKick) Type() string
func (MsgProposeKick) ValidateBasic ¶
func (msg MsgProposeKick) ValidateBasic() error
ValidateBasic validity check for the AnteHandler
type MsgSubmitApplication ¶
type MsgSubmitApplication struct {
Candidate Validator `json:"validator"`
}
*
- MsgSubmitApplication
func NewMsgSubmitApplication ¶
func NewMsgSubmitApplication(candidate Validator) MsgSubmitApplication
func (MsgSubmitApplication) GetSignBytes ¶
func (msg MsgSubmitApplication) GetSignBytes() []byte
GetSignBytes gets the bytes for the message signer to sign on
func (MsgSubmitApplication) GetSigners ¶
func (msg MsgSubmitApplication) GetSigners() []sdk.AccAddress
func (MsgSubmitApplication) Route ¶
func (msg MsgSubmitApplication) Route() string
func (MsgSubmitApplication) Type ¶
func (msg MsgSubmitApplication) Type() string
func (MsgSubmitApplication) ValidateBasic ¶
func (msg MsgSubmitApplication) ValidateBasic() error
ValidateBasic validity check for the AnteHandler
type MsgVote ¶
type MsgVote struct { VoteType uint16 `json:"votetype"` VoterAddr sdk.ValAddress `json:"voter"` CandidateAddr sdk.ValAddress `json:"candidate"` Approve bool `json:"approve"` }
func NewMsgVote ¶
func NewMsgVote(voteType uint16, voter sdk.ValAddress, candidate sdk.ValAddress, approve bool) MsgVote
func (MsgVote) GetSignBytes ¶
GetSignBytes gets the bytes for the message signer to sign on
func (MsgVote) GetSigners ¶
func (msg MsgVote) GetSigners() []sdk.AccAddress
func (MsgVote) ValidateBasic ¶
ValidateBasic validity check for the AnteHandler
type ParamSubspace ¶
type ParamSubspace interface { WithKeyTable(table params.KeyTable) params.Subspace Get(ctx sdk.Context, key []byte, ptr interface{}) GetParamSet(ctx sdk.Context, ps params.ParamSet) SetParamSet(ctx sdk.Context, ps params.ParamSet) }
ParamSubspace defines the expected Subspace interface
type Params ¶
Params - used for initializing default parameter for poa at genesis
func DefaultParams ¶
func DefaultParams() Params
DefaultParams defines the parameters for this module
func (*Params) ParamSetPairs ¶
func (p *Params) ParamSetPairs() params.ParamSetPairs
ParamSetPairs - Implements params.ParamSet
type QueryValidatorParams ¶
type QueryValidatorParams struct {
ValidatorAddr sdk.ValAddress
}
Defines the params for the following queries: - 'custom/poa/validator'
func NewQueryValidatorParams ¶
func NewQueryValidatorParams(validatorAddr sdk.ValAddress) QueryValidatorParams
type Validator ¶
type Validator struct { OperatorAddress sdk.ValAddress `json:"operator_address"` ConsensusPubkey string `json:"consensus_pubkey"` Description Description `json:"description"` }
Information about a validator
func NewValidator ¶
func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator
func UnmarshalValidator ¶
func (Validator) ABCIValidatorUpdateAppend ¶
func (v Validator) ABCIValidatorUpdateAppend() abci.ValidatorUpdate
Get a ABCI validator update object from the validator
func (Validator) ABCIValidatorUpdateRemove ¶
func (v Validator) ABCIValidatorUpdateRemove() abci.ValidatorUpdate
Get a ABCI validator update with no voting power from the validator
func (Validator) CheckValid ¶
func (Validator) GetConsAddr ¶
func (v Validator) GetConsAddr() sdk.ConsAddress
func (Validator) GetConsPubKey ¶
func (Validator) GetConsPubKeyString ¶
func (Validator) GetDescription ¶
func (v Validator) GetDescription() Description
type Vote ¶
type Vote struct { Subject Validator `json:"subject"` Approvals uint64 `json:"approvals"` Total uint64 `json:"totals"` Voters []sdk.ValAddress `json:"voter"` }
Structure to track the vote for: - An application to become validator - A proposal to kick a validator
func (*Vote) AddVote ¶
func (v *Vote) AddVote(voter sdk.ValAddress, approve bool) (alreadyVoted bool)
Add a vote
func (Vote) CheckQuorum ¶
func (v Vote) CheckQuorum(voterPoolSize uint64, quorum uint64) (reached bool, approved bool, err error)
Check if the quorum has been reached voterPoolSize is the total number of possible voters in the vote Quorum is the percentage of voters to reach to approve or reject the vote Reached true -> the quorum has been reached Approved true -> the vote has been approved, otherwise it has been rejected