ucon

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: LGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidatorProportionThreshold = 0.685
	CertValProportionThreshold   = 0.585

	DefaultMsgTimerProportion = 0.5

	DefaultStartVoteProportion = 0.34
)
View Source
const (
	MsgNamePriority  = "msgPriorityProposal"
	MsgNameBlock     = "msgBlockProposal"
	MsgNamePrevote   = "msgPrevote"
	MsgNamePrecommit = "msgPrecommit"
	MsgNameNext      = "msgNext"
	MsgNameCert      = "msgCertificate"
)
View Source
const (
	VoteMsgSize     = 384 //293
	PriorityMsgSize = 384 //261
)
View Source
const (
	UConStepStart       uint32 = 0
	UConStepProposal           = 1 // 1
	UConStepPrevote            = 2 // 2
	UConStepPrecommit          = 4 // 4
	UConStepCertificate        = 5
)
View Source
const MaxCachedMsgsCount = 1024
View Source
const MaxMsgsSingleInterval int64 = 10 // s
View Source
const OutdateFaultTolerance int64 = 10
View Source
const (
	// HashLength is the expected length of the hash
	RoundIndexHashLength = 12
)

Lengths of RoundIndexHash in bytes.

View Source
const VrfHashSizeInBits int64 = 256

Variables

View Source
var (
	// ErrInvalidConsensusData is returned if the length of extra-data is less than 32 bytes
	ErrInvalidConsensusData = errors.New("invalid consensus data")
)
View Source
var ErrInvalidConsensusMsg = errors.New("invalid consensus message")

Functions

func AddrTypeKey

func AddrTypeKey(address common.Address, voteType VoteType, index uint8) []byte

func CompareCommonHash

func CompareCommonHash(p1, p2 common.Hash) int

func ComputeSeed

func ComputeSeed(sk vrf.PrivateKey, round *big.Int, roundIndex uint32, preSeed common.Hash) (seed common.Hash, proof []byte)

func Encode

func Encode(val interface{}) ([]byte, error)

func GenerateEmptyBlock

func GenerateEmptyBlock(parent *types.Block, sk *ecdsa.PrivateKey) *types.Block

func GetInfoFromHash

func GetInfoFromHash(h RoundIndexHash) (uint64, uint32)

func GetSignatureAddress

func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)

func GetSignaturePublicKey

func GetSignaturePublicKey(data []byte, sig []byte) (*ecdsa.PublicKey, error)

func GetVoteFromBool

func GetVoteFromBool(vote bool) uint32

func MakeM

func MakeM(seed common.Hash, role uint32, index uint32) []byte

func MessageCodeToString

func MessageCodeToString(code MsgType) string

func MillionSecond

func MillionSecond(time time.Time) int64

func OppositeValidatorType

func OppositeValidatorType(kind params.ValidatorKind) params.ValidatorKind

func OverThreshold

func OverThreshold(count uint32, threshold uint64, isPos bool) bool

func PrepareConsensusData

func PrepareConsensusData(header *types.Header, data *BlockConsensusData) ([]byte, error)

func ProbabilityForLimitedSampleing

func ProbabilityForLimitedSampleing(communitySize int64, threshold float64, k uint32) float64

For: the probability of K's nodes be choosed

func ProbabilityForSampleing

func ProbabilityForSampleing(threshold float64, k uint32) float64

For: the probability of K's nodes be k where community size is big enough

func ProbabilityForViolateCondition1

func ProbabilityForViolateCondition1(honest, threshold, portion float64) float64

func Sign

func Sign(key *ecdsa.PrivateKey, data []byte) ([]byte, error)

func VerifySignature

func VerifySignature(vote *VoteItem, address common.Address) bool

func VoteTypeToString

func VoteTypeToString(voteType VoteType) string

func VrfComputePriority

func VrfComputePriority(hash common.Hash, j uint32) common.Hash

func VrfSortition

func VrfSortition(sk vrf.PrivateKey, seed common.Hash, index uint32, role uint32, threshold uint64, stake, totalStake *big.Int) (common.Hash, []byte, uint32)

func VrfVerifyPriority

func VrfVerifyPriority(pk vrf.PublicKey, seed common.Hash, index uint32, role uint32, proof []byte, priority common.Hash, subUsers uint32, threshold uint64, stake, totalStake *big.Int) (bool, error)

proof: sortition proof

func VrfVerifySortition

func VrfVerifySortition(pk vrf.PublicKey, seed common.Hash, index uint32, role uint32, proof []byte, subUsers uint32, threshold uint64, stake, totalStake *big.Int) (bool, error)

Types

type AddrVoteStatus

type AddrVoteStatus struct {
	Hash        common.Hash
	Signature   []byte
	DoubleVoted bool
}

type AddrVoteType

type AddrVoteType uint8

type AddressMap

type AddressMap map[common.Address]*AddressMsgInfo //time.Time

type AddressMsgInfo

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

type AddressMsgs

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

func NewAddressMsgs

func NewAddressMsgs() *AddressMsgs

func (*AddressMsgs) NewAddressMsg

func (am *AddressMsgs) NewAddressMsg(ev ReceivedMsgEvent, validatorKind params.ValidatorKind, chamberNum, houseNum uint64) (oldOver, futureOver, isValid bool)

type BlockConsensusData

type BlockConsensusData struct {
	Round              *big.Int
	RoundIndex         uint32
	Seed               common.Hash
	SortitionProof     []byte
	Priority           common.Hash
	SubUsers           uint32
	Signature          []byte
	ProposerThreshold  uint64
	ValidatorThreshold uint64
	CertValThreshold   uint64
}

func ExtractConsensusData

func ExtractConsensusData(header *types.Header) (*BlockConsensusData, error)

func GetConsensusDataFromHeader

func GetConsensusDataFromHeader(header *types.Header) (*BlockConsensusData, error)

BlockConsensusData should be added to types.Block, so that node can get parameters from local blockchain

func (*BlockConsensusData) GetPublicKey

func (data *BlockConsensusData) GetPublicKey() (*ecdsa.PublicKey, error)

extract public key from Signature

func (*BlockConsensusData) IsValidRound

func (data *BlockConsensusData) IsValidRound() (bool, error)

func (*BlockConsensusData) IsValidSeed

func (data *BlockConsensusData) IsValidSeed() (bool, error)

func (*BlockConsensusData) IsValidTime

func (data *BlockConsensusData) IsValidTime() (bool, error)

func (*BlockConsensusData) SetSignature

func (data *BlockConsensusData) SetSignature(key *ecdsa.PrivateKey) error

type BlockHashWithMaxPriorityFn

type BlockHashWithMaxPriorityFn func(round *big.Int, roundIndex uint32) (common.Hash, common.Hash, bool)

type BlockHashWithVotes

type BlockHashWithVotes struct {
	Priority   common.Hash
	BlockHash  common.Hash
	Round      *big.Int
	RoundIndex uint32
	Vote       *SingleVote
	Timestamp  uint64
}

type BlockProposalEvent

type BlockProposalEvent struct {
	Block *types.Block
}

type BlsVerifier

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

func NewBlsVerifier

func NewBlsVerifier(mgr bls.BlsManager) *BlsVerifier

func (*BlsVerifier) AggregateSignatures

func (v *BlsVerifier) AggregateSignatures(rawSigs [][]byte) (aggregatedSig []byte, err error)

func (*BlsVerifier) GetBlsPubKey

func (v *BlsVerifier) GetBlsPubKey(bspubKey []byte) (bls.PublicKey, error)

func (*BlsVerifier) GetBlsSig

func (v *BlsVerifier) GetBlsSig(sig []byte) (bls.Signature, error)

func (*BlsVerifier) GetVrfPubKey

func (v *BlsVerifier) GetVrfPubKey(bspubKey []byte) (*ecdsa.PublicKey, error)

func (*BlsVerifier) PackVotes

func (v *BlsVerifier) PackVotes(ev CommitEvent, backType params.LookBackType) (*UconValidators, error)

func (*BlsVerifier) RecoverSignerInfo

func (v *BlsVerifier) RecoverSignerInfo(vs *state.Validators, vote *SingleVote) (signer *state.Validator, pk bls.PublicKey, vrfpk *ecdsa.PublicKey, err error)

type CachedBlockMessage

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

func (*CachedBlockMessage) GetContext

func (m *CachedBlockMessage) GetContext() (*big.Int, uint32)

func (*CachedBlockMessage) Hash

func (m *CachedBlockMessage) Hash() common.Hash

type CachedMessage

type CachedMessage interface {
	GetContext() (*big.Int, uint32)
	Hash() common.Hash
}

type CachedMsgMgr

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

future round's message cache

func InitCachedMessages

func InitCachedMessages() *CachedMsgMgr

func (*CachedMsgMgr) Clear

func (c *CachedMsgMgr) Clear(round uint64, roundIndex uint32)

func (*CachedMsgMgr) GetMessages

func (c *CachedMsgMgr) GetMessages(round uint64, roundIndex uint32, code MsgType) CachedMsgs

func (*CachedMsgMgr) NewMessage

func (c *CachedMsgMgr) NewMessage(msg CachedMessage, code MsgType, addr common.Address, timestamp time.Time)

func (*CachedMsgMgr) RemoveMessages

func (c *CachedMsgMgr) RemoveMessages(round uint64, roundIndex uint32, code MsgType)

type CachedMsgs

type CachedMsgs []CachedMessage

type CachedPriorityMessage

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

func (*CachedPriorityMessage) GetContext

func (m *CachedPriorityMessage) GetContext() (*big.Int, uint32)

func (*CachedPriorityMessage) Hash

func (m *CachedPriorityMessage) Hash() common.Hash

type CachedVotesMessage

type CachedVotesMessage struct {
	VotesData *BlockHashWithVotes
	// contains filtered or unexported fields
}

func (*CachedVotesMessage) GetContext

func (m *CachedVotesMessage) GetContext() (*big.Int, uint32)

func (*CachedVotesMessage) Hash

func (m *CachedVotesMessage) Hash() common.Hash

type CommitEvent

type CommitEvent struct {
	Round             *big.Int
	RoundIndex        uint32
	Block             *types.Block
	ChamberPrecommits VotesInfoForBlockHash
	HousePrecommits   VotesInfoForBlockHash
	ChamberCerts      VotesInfoForBlockHash
}

type ConsensusCommon

type ConsensusCommon struct {
	Round          *big.Int
	RoundIndex     uint32
	Step           uint32
	Priority       common.Hash
	SortitionProof []byte
	SubUsers       uint32
	BlockHash      common.Hash
	ParentHash     common.Hash
	Timestamp      uint64
}

type ContextChangeEvent

type ContextChangeEvent struct {
	Round       *big.Int
	RoundIndex  uint32
	Step        uint32
	Certificate bool
}

type DatabaseDeleter

type DatabaseDeleter interface {
	Delete(key []byte) error
}

DatabaseDeleter wraps the Delete method of a backing data store.

type DatabaseReader

type DatabaseReader interface {
	Has(key []byte) (bool, error)
	Get(key []byte) ([]byte, error)
}

DatabaseReader wraps the Has and Get method of a backing data store.

type DatabaseWriter

type DatabaseWriter interface {
	Put(key []byte, value []byte) error
}

DatabaseWriter wraps the Put method of a backing data store.

type GetBlockInCacheFn

type GetBlockInCacheFn func(blockHash common.Hash, priority common.Hash) *types.Block

type GetCurrentParamsFn

type GetCurrentParamsFn func() *params.CaravelParams

type GetLookBackValidatorFn

type GetLookBackValidatorFn func(round *big.Int, addr common.Address, lbType params.LookBackType) (*state.Validator, bool)

type InvalidMsgMaker

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

func (*InvalidMsgMaker) DecodeFailedMsg

func (m *InvalidMsgMaker) DecodeFailedMsg() []byte

func (*InvalidMsgMaker) DecodePayloadFailed

func (m *InvalidMsgMaker) DecodePayloadFailed() []byte

func (*InvalidMsgMaker) EmptyRound

func (m *InvalidMsgMaker) EmptyRound() []byte

func (*InvalidMsgMaker) InvalidAddress

func (m *InvalidMsgMaker) InvalidAddress() []byte

func (*InvalidMsgMaker) InvalidSignature

func (m *InvalidMsgMaker) InvalidSignature() []byte

func (*InvalidMsgMaker) InvalidSize

func (m *InvalidMsgMaker) InvalidSize() []byte

func (*InvalidMsgMaker) InvalidVoteMsg

func (m *InvalidMsgMaker) InvalidVoteMsg() []byte

type IsValidatorFn

type IsValidatorFn func(round *big.Int, roundIndex uint32, step uint32, lbType params.LookBackType) (bool, *StepView)

type LookBackMgr

type LookBackMgr interface {
	CurrentCaravelParams() *params.CaravelParams

	// GetLookBackVldReader gets canonical look back validator reader
	GetLookBackVldReader(cp *params.CaravelParams, num *big.Int, lbType params.LookBackType) (state.ValidatorReader, error)
}

type MarkedBlockInfo

type MarkedBlockInfo struct {
	Priority   common.Hash
	BlockHash  common.Hash
	Round      *big.Int
	RoundIndex uint32
	Block      *types.Block
}

type Message

type Message struct {
	Code      MsgType
	Payload   []byte
	Signature []byte
}

func Decode

func Decode(b []byte) (*Message, error)

func (*Message) DecodePayload

func (m *Message) DecodePayload(val interface{}) error

func (*Message) DecodeRLP

func (m *Message) DecodeRLP(s *rlp.Stream) error

func (*Message) Encode

func (m *Message) Encode() ([]byte, error)

func (*Message) EncodeNoSig

func (m *Message) EncodeNoSig() ([]byte, error)

func (*Message) EncodeRLP

func (m *Message) EncodeRLP(w io.Writer) error

func (*Message) PayloadHash

func (m *Message) PayloadHash() common.Hash

type MessageEvent

type MessageEvent struct {
	Payload []byte
	Code    string
	Round   *big.Int
}

type MessageHandler

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

func NewMessageHandler

func NewMessageHandler(rawSk *ecdsa.PrivateKey,
	eventMux *event.TypeMux,
	getValidatorFn GetLookBackValidatorFn,
	processMsgFn ProcessReceivedMsgFn,
	processPriotiryMsg ProcessPriorityMsg,
	processProposedBlockMsg ProcessProposedBlockMsg,
	processVoteMsg ProcessVoteMsg) *MessageHandler

func (*MessageHandler) HandleMsg

func (mh *MessageHandler) HandleMsg(data []byte, receivedAt time.Time) error

func (*MessageHandler) Start

func (mh *MessageHandler) Start()

func (*MessageHandler) Stop

func (mh *MessageHandler) Stop()

func (*MessageHandler) UpdateAllowedFutureMsgTime added in v0.10.2

func (mh *MessageHandler) UpdateAllowedFutureMsgTime(t time.Duration)

type MsgReceivedStatus

type MsgReceivedStatus uint8

type MsgType

type MsgType uint8

func StringToMessageCode

func StringToMessageCode(code string) MsgType

func VoteTypeToMsgCode

func VoteTypeToMsgCode(voteType VoteType) MsgType

type OverThresholdFn

type OverThresholdFn func(voteType VoteType, count uint32) bool

type PriorityForRound

type PriorityForRound map[common.Hash]common.Hash

type PriorityManager

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

func NewPriorityMgr

func NewPriorityMgr() *PriorityManager

type PriorityMsgEvent

type PriorityMsgEvent struct {
	Msg *CachedPriorityMessage
}

type ProcessPriorityMsg

type ProcessPriorityMsg func(msg *CachedPriorityMessage, status MsgReceivedStatus) (error, bool)

type ProcessProposedBlockMsg

type ProcessProposedBlockMsg func(msg *CachedBlockMessage, status MsgReceivedStatus) (error, bool)

type ProcessReceivedMsgFn

type ProcessReceivedMsgFn func(event ReceivedMsgEvent) (error, bool)

type ProcessStepFn

type ProcessStepFn func(step uint32)

type ProcessTimeoutFn

type ProcessTimeoutFn func(round *big.Int, roundIndex uint32)

type ProcessVoteMsg

type ProcessVoteMsg func(ev VoteMsgEvent, status MsgReceivedStatus) (error, bool)

type Proposal

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

func NewProposal

func NewProposal(eventMux *event.TypeMux, verifyFn VerifyPriorityFn, startVoteFn StartVoteFn) *Proposal

func (*Proposal) Start

func (p *Proposal) Start()

func (*Proposal) Stop

func (p *Proposal) Stop()

type ProposedBlockMsgEvent

type ProposedBlockMsgEvent struct {
	Msg *CachedBlockMessage
}

type ReceivedMsgEvent

type ReceivedMsgEvent struct {
	Round      *big.Int
	RoundIndex uint32
	Addr       common.Address
	ReceivedAt time.Time
	SendAt     uint64
}

type RoundIndexChangeEvent

type RoundIndexChangeEvent struct {
	Round      *big.Int
	RoundIndex uint32
	BlockHash  common.Hash
	Priority   common.Hash
}

type RoundIndexHash

type RoundIndexHash [RoundIndexHashLength]byte

func GenerateRoundIndexHash

func GenerateRoundIndexHash(round uint64, index uint32) RoundIndexHash

func (*RoundIndexHash) SetBytes

func (h *RoundIndexHash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

type SendMessageEvent

type SendMessageEvent struct {
	Code    MsgType
	Payload []byte
	Round   *big.Int
}

type Server

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

func NewVRFServer

func NewVRFServer(db youdb.Database) (*Server, error)

func (*Server) Author

func (s *Server) Author(header *types.Header) (common.Address, error)

func (*Server) CertificateParams

func (s *Server) CertificateParams(round *big.Int) (*params.CaravelParams, error)

func (*Server) CheckValidatorVotes

func (s *Server) CheckValidatorVotes(chain consensus.ChainReader, header *types.Header) (map[common.Address]bool, error)

CheckValidatorVotes Check voting

func (*Server) CompareBlocks

func (s *Server) CompareBlocks(blockA *types.Block, blockB *types.Block) int

fork-selection rules

-1 if blockA <  blockB
 0 if blockA == blockB
+1 if blockA >  blockB

func (*Server) CurrentCaravelParams

func (s *Server) CurrentCaravelParams() *params.CaravelParams

CurrentCaravelParams returns current round caravel parameters

func (*Server) CurrentYouParams added in v1.0.0

func (s *Server) CurrentYouParams() *params.YouParams

func (*Server) Finalize

func (s *Server) Finalize(chain consensus.ChainReader, header *types.Header, statedb *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt)

func (*Server) FinalizeAndAssemble

func (s *Server) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error)

func (*Server) GetLookBackBlockHash

func (s *Server) GetLookBackBlockHash(cp *params.CaravelParams, num *big.Int, lbType params.LookBackType) (common.Hash, error)

func (*Server) GetLookBackBlockNumber

func (s *Server) GetLookBackBlockNumber(cp *params.CaravelParams, num *big.Int, lbType params.LookBackType) *big.Int

GetLookBackBlockNumber return the stake-look-back block number for the specific block number. when round > config.StakeLookBack, it returns round - config.StakeLookBack else it always return 0 (the genesis block number)

func (*Server) GetLookBackValidator

func (s *Server) GetLookBackValidator(round *big.Int, addr common.Address, lbType params.LookBackType) (*state.Validator, bool)

func (*Server) GetLookBackVldReader

func (s *Server) GetLookBackVldReader(cp *params.CaravelParams, num *big.Int, lbType params.LookBackType) (state.ValidatorReader, error)

func (*Server) GetValMainAddress

func (s *Server) GetValMainAddress() common.Address

func (*Server) GetValidatorAddrs

func (s *Server) GetValidatorAddrs(chain consensus.ChainReader, header *types.Header) (*params.YouParams, *UconValidators, []common.Address, []common.Address, error)

func (*Server) GetValidatorByAddress

func (s *Server) GetValidatorByAddress(blockHash common.Hash, addr common.Address) *state.Validator

func (*Server) HandleMsg

func (s *Server) HandleMsg(data []byte, receivedAt time.Time) error

HandleMsg handles related consensus messages or fallback to default procotol manager's handler

func (*Server) NewChainHead

func (s *Server) NewChainHead(block *types.Block)

NewChainHead implements consensus.Ucon.NewChainHead

func (*Server) NextRound

func (s *Server) NextRound(ev RoundIndexChangeEvent) error

NextRound will broadcast ChainHeadEvent to trigger next seal()

func (*Server) Pause added in v0.9.6

func (s *Server) Pause() error

func (*Server) Prepare

func (s *Server) Prepare(chain consensus.ChainReader, header *types.Header) error

func (*Server) Resume added in v0.9.6

func (s *Server) Resume() error

func (*Server) Seal

func (s *Server) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)

Seal generates a new block for the given input block with the local miner's seal place on top.

func (*Server) SetValKey

func (s *Server) SetValKey(sk *ecdsa.PrivateKey, blsKeyBytes []byte) (err error)

SetValKey sets the validator key

func (*Server) StartMining

func (s *Server) StartMining(chain consensus.ChainReader, inserter consensus.MineInserter, eventMux *event.TypeMux) error

StartMining starts the engine to mine

func (*Server) StartNewRound

func (s *Server) StartNewRound(newRound bool) error

func (*Server) Stop

func (s *Server) Stop() error

Stop the engine

func (*Server) TotalStakeOfKind

func (s *Server) TotalStakeOfKind(blockHash common.Hash, kind params.ValidatorKind) *big.Int

TotalStakeOfKind 获取指定块上某类节点的 total stake

func (*Server) UpdateContextForNewBlock

func (s *Server) UpdateContextForNewBlock(block *types.Block) error

func (*Server) ValidatorsNumOfKind

func (s *Server) ValidatorsNumOfKind(blockHash common.Hash, kind params.ValidatorKind) uint64

TotalStakeOfKind 获取指定块上某类节点的数量

func (*Server) VerifyAcHeader

func (s *Server) VerifyAcHeader(chain consensus.ChainReader, acHeader *types.Header, verifiedAcParents []*types.Header) error

VerifyAcHeader verifies the header using and only using cht certificates

func (*Server) VerifyHeader

func (s *Server) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header confirms to the consensus rules of a given engine. Verifying the seal may be done optionally here, or explicitly via the VerifySeal method.

func (*Server) VerifyHeaders

func (s *Server) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).

func (*Server) VerifySeal

func (s *Server) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal checks whether the crypto seal on a header is valid according to the consensus rules of the given engine.

func (*Server) VerifySideChainHeader

func (s *Server) VerifySideChainHeader(cp *params.CaravelParams, seedHeader *types.Header, vldReader state.ValidatorReader, certHeader *types.Header, certVldReader state.ValidatorReader, block *types.Block, parents []*types.Block) error

VerifySideChainHeader checks whether a side chain block confirms to the consensus rules

type SingleVote

type SingleVote struct {
	VoterIdx  uint32
	Votes     uint32
	Signature []byte
	Proof     []byte // used to verify whether is a validator
}

data structure for statistics

type SortitionData

type SortitionData struct {
	Round      *big.Int
	RoundIndex uint32
	Step       uint32
	Proof      []byte
	Votes      uint32
}

type SortitionManager

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

one round, multiple roundIndex

func NewSortitionManager

func NewSortitionManager(vrfSk vrf.PrivateKey, getStake getStakeFn, getLookBackSeed getLookBackSeedFn, addr common.Address) *SortitionManager

func (*SortitionManager) ClearStepView

func (sm *SortitionManager) ClearStepView(round *big.Int)

func (*SortitionManager) GetStepView

func (sm *SortitionManager) GetStepView(round *big.Int, roundIndex uint32, step uint32) *StepView

func (*SortitionManager) NewStepView

func (sm *SortitionManager) NewStepView(round *big.Int, roundIndex uint32, step uint32, stepview *StepView)

type StartVoteFn

type StartVoteFn func(round *big.Int, roundIndex uint32) bool

type StepView

type StepView struct {
	Priority       common.Hash
	SortitionProof []byte
	//SortitionValue common.Hash
	SubUsers uint32
	//SeedProof      []byte
	SeedValue     common.Hash
	ValidatorType params.ValidatorKind
	Threshold     uint64
}

data structure for StepView info

type StepViews

type StepViews map[uint32]*StepView

func NewStepViews

func NewStepViews() StepViews

type TimerManager

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

func NewTimerManager

func NewTimerManager(timeoutFn ProcessTimeoutFn, stepFn ProcessStepFn) *TimerManager

func (*TimerManager) NewAddressMsg

func (tm *TimerManager) NewAddressMsg(ev ReceivedMsgEvent, validatorKind params.ValidatorKind, chamberNum, houseNum uint64) bool

func (*TimerManager) Pause added in v0.9.6

func (tm *TimerManager) Pause()

func (*TimerManager) Start

func (tm *TimerManager) Start()

func (*TimerManager) Stop

func (tm *TimerManager) Stop()

should be called when stop the consensus server

type TransferMessageEvent

type TransferMessageEvent struct {
	Code        MsgType
	Payload     []byte
	Round       *big.Int
	PayloadHash common.Hash
}

type TypedCacheMsgs

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

func NewTypedCacheMsgs

func NewTypedCacheMsgs() *TypedCacheMsgs

func (*TypedCacheMsgs) Clear

func (m *TypedCacheMsgs) Clear(round uint64, roundIndex uint32)

func (*TypedCacheMsgs) GetMessages

func (m *TypedCacheMsgs) GetMessages(round uint64, roundIndex uint32) CachedMsgs

func (*TypedCacheMsgs) NewMessage

func (m *TypedCacheMsgs) NewMessage(msg CachedMessage)

func (*TypedCacheMsgs) RemoveMessages

func (m *TypedCacheMsgs) RemoveMessages(round uint64, roundIndex uint32)

type UconValidators

type UconValidators struct {
	RoundIndex        uint32
	ChamberCommitters []SingleVote
	HouseCommitters   []SingleVote
	ChamberCerts      []SingleVote
	SCAggrSig         []byte // bls aggregated signature for ChamberCommitters
	MCAggrSig         []byte // bls aggregated signature for HouseCommitters
	CCAggrSig         []byte // bls aggregated signature for ChamberCerts
}

func ExtractUconValidators

func ExtractUconValidators(h *types.Header, backType params.LookBackType) (*UconValidators, error)

ExtractUconValidators extracts all values of the UconValidators from the header. It returns an error if the length of the given validator-data is less than 32 bytes or the validator-data can not be decoded.

func NewUconValidators

func NewUconValidators(ev CommitEvent, backType params.LookBackType) *UconValidators

func (*UconValidators) ValidatorsToByte

func (uc *UconValidators) ValidatorsToByte() ([]byte, error)

type UpdateExistedHeaderEvent

type UpdateExistedHeaderEvent struct {
	Round             *big.Int
	RoundIndex        uint32
	BlockHash         common.Hash
	ChamberPrecommits VotesInfoForBlockHash
	HousePrecommits   VotesInfoForBlockHash
}

type VerifyPriorityFn

type VerifyPriorityFn func(pubkey *ecdsa.PublicKey, data *ConsensusCommon) error

type VerifySortitionFn

type VerifySortitionFn func(pubKey *ecdsa.PublicKey, data *SortitionData, lbType params.LookBackType) error

type VoteBLSMgr

type VoteBLSMgr struct {
	Verifier *BlsVerifier
	// contains filtered or unexported fields
}

func NewVoteBLSMgr

func NewVoteBLSMgr(rawSk *ecdsa.PrivateKey, blsSk bls.SecretKey) *VoteBLSMgr

func (*VoteBLSMgr) RecoverSignerInfo

func (vb *VoteBLSMgr) RecoverSignerInfo(vs *state.Validators, vote *SingleVote) (signer *state.Validator, pk bls.PublicKey, vrfpk *ecdsa.PublicKey, err error)

func (*VoteBLSMgr) SetLookBackMgr

func (vb *VoteBLSMgr) SetLookBackMgr(lbmgr LookBackMgr)

func (*VoteBLSMgr) SignVote

func (vb *VoteBLSMgr) SignVote(voteType VoteType, voteInfo *SingleVote, payload []byte) error

type VoteDB

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

func NewVoteDB

func NewVoteDB(db youdb.Database, rawSk *ecdsa.PrivateKey) *VoteDB

func (*VoteDB) ExistVoteData

func (v *VoteDB) ExistVoteData(voteType VoteType, round *big.Int, roundIndex uint32) bool

func (*VoteDB) Stop

func (v *VoteDB) Stop()

func (*VoteDB) UpdateContext

func (v *VoteDB) UpdateContext(round *big.Int, roundIndex uint32)

func (*VoteDB) UpdateVoteData

func (v *VoteDB) UpdateVoteData(voteType VoteType, round *big.Int, roundIndex uint32) error

type VoteItem

type VoteItem struct {
	VoteType   VoteType
	Round      *big.Int
	RoundIndex uint32
	Addr       common.Address
	Signature  []byte
}

func ReadVoteData

func ReadVoteData(db youdb.Database, address common.Address, voteType VoteType, index uint8) *VoteItem

type VoteMsgEvent

type VoteMsgEvent struct {
	Msg   *CachedVotesMessage
	VType VoteType
}

type VoteSta

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

func NewVoteSta

func NewVoteSta(vtype VoteType) *VoteSta

type VoteStatus

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

type VoteType

type VoteType uint8
const (
	VoteNone VoteType = iota
	Propose
	Prevote
	Precommit
	NextIndex
	Certificate
)

func MsgCodeToVoteType

func MsgCodeToVoteType(msgCode MsgType) VoteType

type Voter

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

func NewVoter

func NewVoter(db youdb.Database,
	rawSk *ecdsa.PrivateKey,
	blsSk bls.SecretKey,
	eventMux *event.TypeMux,
	verifySortitionFn VerifySortitionFn,
	isValidatorFn IsValidatorFn,
	getHashFn BlockHashWithMaxPriorityFn,
	blockInCacheFn GetBlockInCacheFn,
	getStake getStakeFn,
	getValidatorsCount getValidatorsCountFn,
	pmgr paramsManager) *Voter

func (*Voter) PackVotes

func (v *Voter) PackVotes(ev CommitEvent, backType params.LookBackType) (*UconValidators, error)

func (*Voter) RecoverSignerInfo

func (v *Voter) RecoverSignerInfo(vs *state.Validators, vote *SingleVote) (signer *state.Validator, pk bls.PublicKey, vrfpk *ecdsa.PublicKey, err error)

func (*Voter) SetLookBackMgr

func (v *Voter) SetLookBackMgr(lbmgr LookBackMgr)

func (*Voter) Start

func (v *Voter) Start(lbmgr LookBackMgr)

func (*Voter) Stop

func (v *Voter) Stop()

type VotesInfoForBlockHash

type VotesInfoForBlockHash map[common.Address]*SingleVote

func NewVotesInfoForBlockHash

func NewVotesInfoForBlockHash() VotesInfoForBlockHash

type VotesManager

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

func NewVotesManager

func NewVotesManager() *VotesManager

type VotesWrapper

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

func NewVotesWrapper

func NewVotesWrapper() *VotesWrapper

type VotesWrapperList

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

func NewVotesWrapperList

func NewVotesWrapperList() *VotesWrapperList

func (*VotesWrapperList) GetWrapper

func (v *VotesWrapperList) GetWrapper(round *big.Int, roundIndex uint32) *VotesWrapper

func (*VotesWrapperList) NewWrapper

func (v *VotesWrapperList) NewWrapper(round *big.Int, roundIndex uint32) *VotesWrapper

Jump to

Keyboard shortcuts

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