poll

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: Apache-2.0 Imports: 37 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CandidateNamespace is a namespace to store raw candidate
	CandidateNamespace = "candidates"
	// KickoutNamespace is a namespace to store kickoutlist
	KickoutNamespace = "kickout"
	// ErrIndexerNotExist is an error that shows not exist in candidate indexer DB
	ErrIndexerNotExist = errors.New("not exist in DB")
)
View Source
var (
	// ErrNoData is an error that there's no data in the contract
	ErrNoData = errors.New("no data")
	// ErrEndOfData is an error that reaching end of data in the contract
	ErrEndOfData = errors.New("end of data")
)
View Source
var ErrDelegatesNotAsExpected = errors.New("delegates are not as expected")

ErrDelegatesNotAsExpected is an error that the delegates are not as expected

View Source
var ErrDelegatesNotExist = errors.New("delegates cannot be found")

ErrDelegatesNotExist is an error that the delegates cannot be prepared

View Source
var ErrInconsistentHeight = errors.New("data is inconsistent because the state height has been changed")

ErrInconsistentHeight is an error that result of "readFromStateDB" is not consistent with others

View Source
var ErrNoElectionCommittee = errors.New("no election committee specified")

ErrNoElectionCommittee is an error that the election committee is not specified

View Source
var ErrProposedDelegatesLength = errors.New("the proposed delegate list length")

ErrProposedDelegatesLength is an error that the proposed delegate list length is not right

View Source
var NsAbi = `` /* 12350-byte string literal not displayed */

NsAbi is the ABI of native staking contract

Functions

This section is empty.

Types

type CandidateIndexer added in v0.11.0

type CandidateIndexer struct {
	// contains filtered or unexported fields
}

CandidateIndexer is an indexer to store candidate/blacklist by given height

func NewCandidateIndexer added in v0.11.0

func NewCandidateIndexer(kv db.KVStore) (*CandidateIndexer, error)

NewCandidateIndexer creates a new CandidateIndexer

func (*CandidateIndexer) CandidateList added in v0.11.0

func (cd *CandidateIndexer) CandidateList(height uint64) (state.CandidateList, error)

CandidateList gets candidate list from indexer given epoch start height

func (*CandidateIndexer) KickoutList added in v0.11.0

func (cd *CandidateIndexer) KickoutList(height uint64) (*vote.Blacklist, error)

KickoutList gets kickout list from indexer given epoch start height

func (*CandidateIndexer) PutCandidateList added in v0.11.0

func (cd *CandidateIndexer) PutCandidateList(height uint64, candidates *state.CandidateList) error

PutCandidateList puts candidate list into indexer

func (*CandidateIndexer) PutKickoutList added in v0.11.0

func (cd *CandidateIndexer) PutKickoutList(height uint64, kickoutList *vote.Blacklist) error

PutKickoutList puts kickout list into indexer

func (*CandidateIndexer) Start added in v0.11.0

func (cd *CandidateIndexer) Start(ctx context.Context) error

Start starts the indexer

func (*CandidateIndexer) Stop added in v0.11.0

func (cd *CandidateIndexer) Stop(ctx context.Context) error

Stop stops the indexer

type CandidatesByHeight added in v0.11.0

type CandidatesByHeight func(protocol.StateReader, uint64) ([]*state.Candidate, error)

CandidatesByHeight returns the candidates of a given height

type GetBlockTime

type GetBlockTime func(uint64) (time.Time, error)

GetBlockTime defines a function to get block creation time

type GetCandidates added in v0.11.0

type GetCandidates func(protocol.StateReader, bool, ...protocol.StateOption) ([]*state.Candidate, uint64, error)

GetCandidates returns the current candidates

type GetKickoutList added in v0.11.0

type GetKickoutList func(protocol.StateReader, bool, ...protocol.StateOption) (*vote.Blacklist, uint64, error)

GetKickoutList returns current the blacklist

type GetUnproductiveDelegate added in v0.11.0

type GetUnproductiveDelegate func(protocol.StateReader) (*vote.UnproductiveDelegate, error)

GetUnproductiveDelegate returns unproductiveDelegate struct which contains a cache of upd info by epochs

type NativeStaking added in v0.8.4

type NativeStaking struct {
	// contains filtered or unexported fields
}

NativeStaking represents native staking struct

func NewNativeStaking added in v0.8.4

func NewNativeStaking(readContract ReadContract) (*NativeStaking, error)

NewNativeStaking creates a NativeStaking instance

func (*NativeStaking) SetContract added in v0.9.0

func (ns *NativeStaking) SetContract(contract string)

SetContract sets the contract address

func (*NativeStaking) Votes added in v0.8.4

func (ns *NativeStaking) Votes(ctx context.Context, ts time.Time, correctGas bool) (*VoteTally, error)

Votes returns the votes on height

type ProductivityByEpoch added in v0.11.0

type ProductivityByEpoch func(context.Context, uint64) (uint64, map[string]uint64, error)

ProductivityByEpoch returns the number of produced blocks per delegate in an epoch

type Protocol

type Protocol interface {
	protocol.Protocol
	protocol.GenesisStateCreator
	DelegatesByEpoch(context.Context, uint64) (state.CandidateList, error)
	CandidatesByHeight(context.Context, uint64) (state.CandidateList, error)
	// CalculateCandidatesByHeight calculates candidate and returns candidates by chain height
	CalculateCandidatesByHeight(context.Context, uint64) (state.CandidateList, error)
}

Protocol defines the protocol of handling votes

func FindProtocol added in v0.11.0

func FindProtocol(registry *protocol.Registry) Protocol

FindProtocol finds the registered protocol from registry

func MustGetProtocol added in v0.11.0

func MustGetProtocol(registry *protocol.Registry) Protocol

MustGetProtocol return a registered protocol from registry

func NewGovernanceChainCommitteeProtocol

func NewGovernanceChainCommitteeProtocol(
	candidatesIndexer *CandidateIndexer,
	candidatesByHeight CandidatesByHeight,
	getCandidates GetCandidates,
	getKickoutList GetKickoutList,
	getUnproductiveDelegate GetUnproductiveDelegate,
	electionCommittee committee.Committee,
	initGravityChainHeight uint64,
	getBlockTime GetBlockTime,
	numCandidateDelegates uint64,
	numDelegates uint64,
	initialCandidatesInterval time.Duration,
	sr protocol.StateReader,
	productivityByEpoch ProductivityByEpoch,
	productivityThreshold uint64,
	kickoutEpochPeriod uint64,
	kickoutIntensity uint32,
	maxKickoutPeriod uint64,
) (Protocol, error)

NewGovernanceChainCommitteeProtocol creates a Poll Protocol which fetch result from governance chain

func NewLifeLongDelegatesProtocol

func NewLifeLongDelegatesProtocol(delegates []genesis.Delegate) Protocol

NewLifeLongDelegatesProtocol creates a poll protocol with life long delegates

func NewProtocol added in v0.11.0

func NewProtocol(
	cfg config.Config,
	candidateIndexer *CandidateIndexer,
	readContract ReadContract,
	candidatesByHeight CandidatesByHeight,
	getCandidates GetCandidates,
	kickoutListByEpoch GetKickoutList,
	getUnproductiveDelegate GetUnproductiveDelegate,
	electionCommittee committee.Committee,
	stakingV2 *staking.Protocol,
	getBlockTimeFunc GetBlockTime,
	sr protocol.StateReader,
	productivityByEpoch ProductivityByEpoch,
) (Protocol, error)

NewProtocol instantiates a rewarding protocol instance.

func NewStakingCommand added in v0.11.0

func NewStakingCommand(
	hu config.HeightUpgrade,
	candIndexer *CandidateIndexer,
	stkV1 Protocol,
	stkV2 *staking.Protocol,
) (Protocol, error)

NewStakingCommand creates a staking command center to manage staking committee and new native staking

func NewStakingCommittee added in v0.8.4

func NewStakingCommittee(
	ec committee.Committee,
	gs Protocol,
	readContract ReadContract,
	nativeStakingContractAddress string,
	nativeStakingContractCode string,
	scoreThreshold *big.Int,
) (Protocol, error)

NewStakingCommittee creates a staking committee which fetch result from governance chain and native staking

type ReadContract added in v0.11.0

type ReadContract func(context.Context, string, []byte, bool) ([]byte, error)

ReadContract defines a callback function to read contract

type VoteTally added in v0.8.4

type VoteTally struct {
	Candidates map[[12]byte]*state.Candidate
	Buckets    []*types.Bucket
}

VoteTally is a map of candidates on native chain

Jump to

Keyboard shortcuts

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