election

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: GPL-3.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ElectModeEtrue for etrue
	ElectModeEtrue = iota
	// ElectModeFake for Test purpose
	ElectModeFake
)

Variables

View Source
var (
	ErrCommittee     = errors.New("get committee failed")
	ErrInvalidMember = errors.New("invalid committee member")
	ErrInvalidSwitch = errors.New("invalid switch block info")
)

Functions

func ElectCommittee

func ElectCommittee(snailchain snailReader, defaultMembers []*types.CommitteeMember, snailBeginNumber *big.Int, snailEndNumber *big.Int) *types.ElectionCommittee

ElectCommittee elect committee members from snail block.

Types

type BlockChain

type BlockChain interface {
	CurrentBlock() *types.Block

	CurrentHeader() *types.Header

	GetBlockByNumber(number uint64) *types.Block

	StateAt(root common.Hash) (*state.StateDB, error)
}

type Config

type Config interface {
	GetNodeType() bool
}

type ElectMode

type ElectMode uint

type Election

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

func NewElection

func NewElection(chainConfig *params.ChainConfig, fastBlockChain BlockChain, snailBlockChain SnailBlockChain, config Config) *Election

NewElection create election processor and load genesis committee

func NewFakeElection

func NewFakeElection() *Election

NewFakeElection create fake mode election only for testing

func NewLightElection

func NewLightElection(fastBlockChain BlockChain, snailBlockChain SnailBlockChain) *Election

func (*Election) FinalizeCommittee added in v0.10.1

func (e *Election) FinalizeCommittee(block *types.Block) error

FinalizeCommittee upddate current committee state

func (*Election) GenerateFakeSigns

func (e *Election) GenerateFakeSigns(fb *types.Block) ([]*types.PbftSign, error)

func (*Election) GetCommittee

func (e *Election) GetCommittee(fastNumber *big.Int) []*types.CommitteeMember

GetCommittee gets committee members propose this fast block

func (*Election) GetCommitteeById added in v0.10.2

func (e *Election) GetCommitteeById(id *big.Int) map[string]interface{}

GetCommitteeById return committee info sepecified by Committee ID

func (*Election) GetCurrentCommittee

func (e *Election) GetCurrentCommittee() *committee

func (*Election) GetCurrentCommitteeNumber

func (e *Election) GetCurrentCommitteeNumber() *big.Int

func (*Election) GetGenesisCommittee

func (e *Election) GetGenesisCommittee() []*types.CommitteeMember

func (*Election) GetMemberByPubkey

func (e *Election) GetMemberByPubkey(members []*types.CommitteeMember, publickey []byte) *types.CommitteeMember

GetMemberByPubkey returns committeeMember specified by public key bytes

func (*Election) GetMemberFlag

func (e *Election) GetMemberFlag(members []*types.CommitteeMember, publickey []byte) uint32

IsCommitteeMember reports whether the provided public key is in committee

func (*Election) IsCommitteeMember

func (e *Election) IsCommitteeMember(members []*types.CommitteeMember, publickey []byte) bool

func (*Election) IsTIP8

func (e *Election) IsTIP8(fastHeadNumber *big.Int) bool

func (*Election) SetEngine

func (e *Election) SetEngine(engine consensus.Engine)

SetEngine set election backend consesus

func (*Election) Start

func (e *Election) Start() error

Start load current committ and starts election processing

func (*Election) SubscribeElectionEvent

func (e *Election) SubscribeElectionEvent(ch chan<- types.ElectionEvent) event.Subscription

SubscribeElectionEvent adds a channel to feed on committee change event

func (*Election) VerifyPublicKey

func (e *Election) VerifyPublicKey(fastHeight *big.Int, pubKeyByte []byte) (*types.CommitteeMember, error)

VerifyPublicKey get the committee member by public key

func (*Election) VerifySign

func (e *Election) VerifySign(sign *types.PbftSign) (*types.CommitteeMember, error)

VerifySign lookup the pbft sign and return the committee member who signs it

func (*Election) VerifySigns

func (e *Election) VerifySigns(signs []*types.PbftSign) ([]*types.CommitteeMember, []error)

VerifySigns verify signatures of bft committee in batches

func (*Election) VerifySwitchInfo

func (e *Election) VerifySwitchInfo(fastNumber *big.Int, info []*types.CommitteeMember) error

VerifySwitchInfo verify committee members and it's state

type SnailBlockChain

type SnailBlockChain interface {
	SnailLightChain

	SubscribeChainEvent(ch chan<- types.SnailChainEvent) event.Subscription

	GetDatabase() etruedb.Database

	GetFruitByFastHash(fastHash common.Hash) (*types.SnailBlock, uint64)

	GetBlockByNumber(number uint64) *types.SnailBlock

	GetFruitsHead(number uint64) []*types.SnailHeader

	GetHeaderByNumber(number uint64) *types.SnailHeader
}

SnailBlockChain encapsulates functions required to sync a (full or fast) blockchain.

type SnailLightChain

type SnailLightChain interface {
	// CurrentHeader retrieves the head header from the local chain.
	CurrentHeader() *types.SnailHeader
}

SnailLightChain encapsulates functions required to synchronise a light chain.

Jump to

Keyboard shortcuts

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