types

package
v0.0.0-...-df65111 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2020 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
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

View Source
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
)
View Source
const (
	VoteTypeApplication  uint16 = iota
	VoteTypeKickProposal uint16 = iota
)
View Source
const (
	// Default max number of validators
	DefaultMaxValidators uint16 = 15
	// Default quorum percentage
	DefaultQuorum uint16 = 66
)

Default parameter namespace

View Source
const (
	QueryValidators    = "validators"
	QueryValidator     = "validator"
	QueryParams        = "params"
	QueryApplications  = "applications"
	QueryKickProposals = "kick-proposals"
)

Query endpoints supported by the poa querier

View Source
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

View Source
const LeaveValidatorSetConst = "LeaveValidatorSet"
View Source
const ProposeKickConst = "ProposeKick"
View Source
const SubmitApplicationConst = "SubmitApplication"
View Source
const VoteConst = "Vote"

Variables

View Source
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")
)
View Source
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}
)
View Source
var (
	KeyMaxValidators = []byte("MaxValidators")
	KeyQuorum        = []byte("Quorum")
)

Parameter store keys

View Source
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

func MustMarshalValidator(cdc *codec.Codec, validator Validator) []byte

Validator encoding functions

func MustMarshalVote

func MustMarshalVote(cdc *codec.Codec, v Vote) []byte

Vote encoding functions

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamKeyTable for poa module

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

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

func (msg MsgVote) GetSignBytes() []byte

GetSignBytes gets the bytes for the message signer to sign on

func (MsgVote) GetSigners

func (msg MsgVote) GetSigners() []sdk.AccAddress

func (MsgVote) Route

func (msg MsgVote) Route() string

func (MsgVote) Type

func (msg MsgVote) Type() string

func (MsgVote) ValidateBasic

func (msg MsgVote) ValidateBasic() error

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

type Params struct {
	MaxValidators uint16 `json:"max_validators"`
	Quorum        uint16 `json:"quorum"`
}

Params - used for initializing default parameter for poa at genesis

func DefaultParams

func DefaultParams() Params

DefaultParams defines the parameters for this module

func NewParams

func NewParams(maxValidators uint16, quorum uint16) Params

NewParams creates a new Params object

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

ParamSetPairs - Implements params.ParamSet

func (Params) String

func (p Params) String() string

String implements the stringer interface for Params

func (Params) Validate

func (p Params) Validate() error

Validate a set of params

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 MustUnmarshalValidator

func MustUnmarshalValidator(cdc *codec.Codec, value []byte) Validator

func NewValidator

func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator

func UnmarshalValidator

func UnmarshalValidator(cdc *codec.Codec, value []byte) (v Validator, err error)

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 (v Validator) CheckValid() error

func (Validator) GetConsAddr

func (v Validator) GetConsAddr() sdk.ConsAddress

func (Validator) GetConsPubKey

func (v Validator) GetConsPubKey() crypto.PubKey

func (Validator) GetConsPubKeyString

func (v Validator) GetConsPubKeyString() string

func (Validator) GetDescription

func (v Validator) GetDescription() Description

func (Validator) GetOperator

func (v Validator) GetOperator() sdk.ValAddress

Accessors

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 MustUnmarshalVote

func MustUnmarshalVote(cdc *codec.Codec, value []byte) Vote

func NewVote

func NewVote(subject Validator) Vote

func UnmarshalVote

func UnmarshalVote(cdc *codec.Codec, value []byte) (v Vote, err error)

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

func (Vote) GetApprovals

func (v Vote) GetApprovals() uint64

The total number of approvals so far

func (Vote) GetSubject

func (v Vote) GetSubject() Validator

The subject of the vote

func (Vote) GetTotal

func (v Vote) GetTotal() uint64

The total number of votes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL