Versions in this module Expand all Collapse all v0 v0.1.6 Sep 2, 2022 v0.1.5 Sep 2, 2022 v0.1.4 Aug 12, 2022 Changes in this version + const AddressLength + const HashLen + const RRRActiveMethodRotateCandidates + const RRRActiveMethodSampleAged + const RRRActiveMethodSortEndorsers + var DefaultConfig = &Config + var ErrBadHeaderSeal = errors.New("invalid or corrupt header seal") + var ErrBranchDetected = errors.New("branch detected") + var ErrDecodingGenesisExtra = errors.New("failed to decode extra field from genesis block") + var ErrEngineStopped = errors.New("consensus not running") + var ErrFutureBlock = errors.New(...) + var ErrGenesisExtraDigestMismatch = errors.New("the included digest of the genesis extra doesn't match the actual") + var ErrIncompatibleChainReader = errors.New("chainreader missing required interfaces for RRR") + var ErrIntentAndConfirmPhaseToLarge = errors.New("intent + confirm phase can not be longer than the round") + var ErrNoGenesisHeader = errors.New("failed to get genesis header") + var ErrNotLeaderCandidate = errors.New("expected to be leader candidate") + var ErrRMsgInvalidCode = errors.New("recevived RMsg with invalid code") + var ErrSignedDecodeSignedFailed = errors.New("decoding signed rlp struct failed") + var ErrUnknownAncestor = errors.New("unknown ancestor") + func BytesToPublic(c CipherSuite, b []byte) (*ecdsa.PublicKey, error) + func ConditionSeed(seed []byte) (uint64, error) + func NodeIDBytesFromPub(c CipherSuite, pub *ecdsa.PublicKey) []byte + func PubMarshal(c CipherSuite, pub *ecdsa.PublicKey) []byte + func RandSampleRange(source DRNG, limit int, s []int) []int + func RandSelect(source DRNG, limit, nsamples int) map[int]bool + func ReadBits(bigint *big.Int, buf []byte) + func RecoverPublic(c CipherSuite, h []byte, sig []byte) (*ecdsa.PublicKey, error) + func RoundsInRange(start time.Time, end time.Time, roundLength uint64) uint64 + func RoundsSince(when time.Time, roundLength uint64) uint64 + func VerifyNodeSig(c CipherSuite, nodeID Hash, digest, sig []byte) bool + func VerifyRecoverNodeSig(c CipherSuite, nodeID Hash, digest, sig []byte) (bool, []byte, error) + type ActiveSelection interface + AccumulateActive func(roundNumber uint64, chainID Hash, chain BlockHeaderReader, head BlockHeader) error + AgeOf func(nodeID Address) (uint64, bool) + IsActive func(roundNumber uint64, addr Address) bool + NOldest func(roundNumber uint64, n int) []Address + NextActiveSample func(roundNumber uint64, source DRNG, s []int) []int + NumActive func() int + Prime func(head BlockHeader) + Reset func(head BlockHeader) + SelectCandidatesAndEndorsers func(roundNumber uint64, permutation []int) (map[Address]bool, map[Address]bool, error) + func NewActiveSelection(config *Config, codec *CipherCodec, selfNodeID Hash, logger Logger) ActiveSelection + func NewActiveSelection3(config *Config, codec *CipherCodec, selfNodeID Hash, logger Logger) ActiveSelection + type Address [20]byte + func PubToAddress(c CipherSuite, pub *ecdsa.PublicKey) Address + func (a Address) Hex() string + func (a Address) HexShort() string + type Alpha struct + Contribution Hash + Sig [65]byte + type BlockActivity struct + Confirm []Endorsement + Enrol []Enrolment + RoundNumber uint64 + SealerID Hash + SealerPub []byte + type BlockHeader interface + GetExtra func() []byte + GetNonce func() [8]byte + GetNumber func() *big.Int + GetParentHash func() [32]byte + GetRoot func() [32]byte + GetRound func(SignedExtraDecoder) (uint64, error) + GetSeal func() []byte + GetTime func() uint64 + GetTxHash func() [32]byte + Hash func() [32]byte + HashForSeal func() [32]byte + type BlockHeaderReader interface + GetHeaderByHash func(hash [32]byte) BlockHeader + type Broadcaster interface + Broadcast func(Address, map[Address]Peer, []byte) error + SendSignedEndorsement func(intenderAddr Address, et *EngSignedIntent) error + type ByAge []selectionItem + func (a ByAge) Len() int + func (a ByAge) Less(i, j int) bool + func (a ByAge) Swap(i, j int) + type BytesCodec interface + type BytesDecoder interface + DecodeBytes func(b []byte, val interface{}) error + type BytesEncoder interface + EncodeToBytes func(val interface{}) ([]byte, error) + type ChainInit struct + Alpha []Alpha + type CipherCodec struct + func NewCodec(c CipherSuite, ed BytesCodec) *CipherCodec + func (codec *CipherCodec) BytesToPublic(pub []byte) (*ecdsa.PublicKey, error) + func (codec *CipherCodec) ChainID(ci *ChainInit) (Hash, error) + func (codec *CipherCodec) DecodeBlockActivity(a *BlockActivity, chainID Hash, header BlockHeader) error + func (codec *CipherCodec) DecodeBytes(b []byte, val interface{}) error + func (codec *CipherCodec) DecodeGenesisExtra(genesisExtra []byte, extra *GenesisExtraData) error + func (codec *CipherCodec) DecodeHeaderSeal(header BlockHeader) (*SignedExtraData, Hash, []byte, error) + func (codec *CipherCodec) DecodeSigned(msg []byte) ([65]byte, []byte, []byte, error) + func (codec *CipherCodec) DecodeSignedEndorsement(e *SignedEndorsement, b []byte) ([]byte, error) + func (codec *CipherCodec) DecodeSignedExtraData(e *SignedExtraData, b []byte) ([]byte, error) + func (codec *CipherCodec) DecodeSignedIntent(i *SignedIntent, b []byte) ([]byte, error) + func (codec *CipherCodec) EncodeHashGenesisExtraData(gd *GenesisExtraData) ([]byte, error) + func (codec *CipherCodec) EncodeSignEndorsement(e *SignedEndorsement, k *ecdsa.PrivateKey) ([]byte, error) + func (codec *CipherCodec) EncodeSignExtraData(e *SignedExtraData, k *ecdsa.PrivateKey) ([]byte, error) + func (codec *CipherCodec) EncodeSignIntent(i *SignedIntent, k *ecdsa.PrivateKey) ([]byte, error) + func (codec *CipherCodec) EncodeToBytes(val interface{}) ([]byte, error) + func (codec *CipherCodec) FillEnrolmentQuote(q []byte, u Hash, a *ecdsa.PrivateKey) error + func (codec *CipherCodec) HashEnrolmentBinding(e *EnrolmentBinding) (Hash, error) + func (codec *CipherCodec) HashIntent(i *Intent) (Hash, error) + func (codec *CipherCodec) Keccak256Hash(b ...[]byte) Hash + func (codec *CipherCodec) NodeIDBytesFromPub(pub *ecdsa.PublicKey) []byte + func (codec *CipherCodec) NodeIDFromPub(pub *ecdsa.PublicKey) Hash + func (codec *CipherCodec) NodeIDFromPubBytes(pub []byte) (Hash, error) + func (codec *CipherCodec) PopulateChainInit(ci *ChainInit, ck *ecdsa.PrivateKey, initIdents []Enrolment, ...) error + func (codec *CipherCodec) RecoverEnrolerID(q Quote, u Hash) (Hash, error) + func (codec *CipherCodec) RecoverEnrolmentPublic(q Quote, u Hash) (*ecdsa.PublicKey, error) + func (codec *CipherCodec) SignEnrolmentBindingHash(q *Quote, key *ecdsa.PrivateKey, chainID Hash, nodeid Hash, round uint64, ...) error + func (codec *CipherCodec) SignedEncode(k *ecdsa.PrivateKey, v interface{}) ([65]byte, []byte, error) + func (codec *CipherCodec) VerifyNodeSig(nodeID Hash, digest, sig []byte) bool + func (codec *CipherCodec) VerifyRecoverNodeSig(nodeID Hash, digest, sig []byte) (bool, []byte, error) + type CipherSuite interface + Curve func() elliptic.Curve + Ecrecover func(digest, sig []byte) ([]byte, error) + Keccak256 func(b ...[]byte) []byte + Sign func(digest []byte, key *ecdsa.PrivateKey) ([]byte, error) + VerifySignature func(bub, digest, sig []byte) bool + type Config struct + Activity uint64 + ActivityMethod string + Candidates uint64 + ConfirmPhase uint64 + Endorsers uint64 + GossipFanout int + IntentPhase uint64 + MinIdleAttempts uint64 + Quorum uint64 + RoundLength uint64 + StablePrefixDepth uint64 + type DRNG interface + Intn func(n int) int + NumSamplesRead func() int + type Endorsement struct + ChainID Hash + EndorserID Hash + IntentHash Hash + type EndorsmentProtocol struct + FailedAttempts uint32 + Number uint64 + Phase RoundPhase + T RoundTime + func NewRoundState(codec *CipherCodec, key *ecdsa.PrivateKey, config *Config, logger Logger) *EndorsmentProtocol + func (r *EndorsmentProtocol) CalcDifficulty(nodeAddr Address) *big.Int + func (r *EndorsmentProtocol) CheckGenesis(chain headerByNumberChainReader) error + func (r *EndorsmentProtocol) GetChainHeadRoundStart() time.Time + func (r *EndorsmentProtocol) GetSealTime(header BlockHeader) (time.Time, error) + func (r *EndorsmentProtocol) IsEnrolmentPending(nodeID Hash) bool + func (r *EndorsmentProtocol) NewChainHead(b Broadcaster, chain EngineChainReader, head BlockHeader) + func (r *EndorsmentProtocol) NewSealTask(b Broadcaster, et *EngSealTask) + func (r *EndorsmentProtocol) NewSignedEndorsement(et *EngSignedEndorsement) + func (r *EndorsmentProtocol) NewSignedIntent(et *EngSignedIntent) + func (r *EndorsmentProtocol) PhaseTick(b Broadcaster, chain EngineChainReader) + func (r *EndorsmentProtocol) PrimeActiveSelection(chain EngineChainReader) error + func (r *EndorsmentProtocol) QueueEnrolment(et *EngEnrolIdentity) + func (r *EndorsmentProtocol) SetState(state RoundState) RoundState + func (r *EndorsmentProtocol) StableSeed(chain EngineChainReader, headNumber uint64) (uint64, uint64, error) + func (r *EndorsmentProtocol) StartRounds(b Broadcaster, chain EngineChainReader) + func (r *EndorsmentProtocol) State() RoundState + func (r *EndorsmentProtocol) UntilRoundEnd() time.Duration + func (r *EndorsmentProtocol) VerifyBranchHeaders(chain VerifyBranchChainReader, header BlockHeader, parents []BlockHeader) error + func (r *EndorsmentProtocol) VerifyHeader(chain headerByHashChainReader, header BlockHeader) (*SignedExtraData, error) + type EngEnrolIdentity struct + NodeID [32]byte + ReEnrol bool + Round uint64 + type EngNewChainHead struct + BlockHeader BlockHeader + type EngSealTask struct + BlockHeader BlockHeader + Committer SealCommitter + RoundNumber uint64 + type EngSignedEndorsement struct + Pub []byte + type EngSignedIntent struct + Pub []byte + type Engine struct + func NewEngine(config *Config, codec *CipherCodec, privateKey *ecdsa.PrivateKey, ...) (*Engine, error) + func (e *Engine) Author(header BlockHeader) (Address, error) + func (e *Engine) Broadcast(self Address, peers map[Address]Peer, msg []byte) error + func (e *Engine) CalcDifficulty(chain interface{}, time uint64, parent BlockHeader) *big.Int + func (e *Engine) ChainID() Hash + func (e *Engine) FindPeers(peers map[Address]bool) map[Address]Peer + func (e *Engine) HandleMsg(peerAddr Address, msg []byte) (bool, error) + func (e *Engine) IsEnrolmentPending(nodeID [32]byte) bool + func (e *Engine) IsRunning() bool + func (e *Engine) NodeAddress() Address + func (e *Engine) NodeID() Hash + func (e *Engine) NodePublic() []byte + func (e *Engine) PostIfRunning(i interface{}) bool + func (e *Engine) RunLock() + func (e *Engine) RunUnlock() + func (e *Engine) Seal(blockHeader BlockHeader, sealCommitter SealCommitter) error + func (e *Engine) Send(peerAddr Address, rmsg RMsg) error + func (e *Engine) SendSignedEndorsement(intenderAddr Address, et *EngSignedIntent) error + func (e *Engine) SetPeerFinder(f PeerFinder) + func (e *Engine) Start(chain EngineChainReader, withLock WithLock) error + func (e *Engine) Stop(withLock WithLock) + func (e *Engine) VerifyBranchHeaders(chain VerifyBranchChainReader, header BlockHeader, parents []BlockHeader) error + func (e *Engine) VerifyHeader(chain headerByHashChainReader, header BlockHeader) error + func (e *Engine) VerifySeal(chain VerifyBranchChainReader, header BlockHeader) error + type EngineChainReader interface + CurrentHeader func() BlockHeader + GetHeaderByHash func(hash [32]byte) BlockHeader + GetHeaderByNumber func(number uint64) BlockHeader + type EngineOption func(e *Engine) + func WithClockCheck(checker func()) EngineOption + type Enrolment struct + ID Hash + Q Quote + U Hash + func IdentInit(codec *CipherCodec, ck *ecdsa.PrivateKey, init []Enrolment, nodeids ...Hash) ([]Enrolment, error) + type EnrolmentBinding struct + BlockHash Hash + ChainID Hash + NodeID Hash + ReEnrol bool + Round uint64 + type ExtraData struct + Confirm []Endorsement + Intent Intent + type ExtraHeader struct + Enrol []Enrolment + Proof []byte + SealTime []byte + Seed []byte + type GenesisExtraData struct + ChainID Hash + type Hash [32]byte + func Hex2Hash(s string) Hash + func Keccak256Hash(c CipherSuite, b ...[]byte) Hash + func NodeIDFromPub(c CipherSuite, pub *ecdsa.PublicKey) Hash + func NodeIDFromPubBytes(c CipherSuite, pub []byte) (Hash, error) + func (h Hash) Address() Address + func (h Hash) EnodeIDFromSig(c CipherSuite, sig []byte) ([]byte, error) + func (h Hash) Hex() string + func (h Hash) NodeIDFromSig(c CipherSuite, sig []byte) (Hash, error) + func (h Hash) SignerPub(c CipherSuite, sig []byte) (*ecdsa.PublicKey, error) + type Intent struct + ChainID Hash + NodeID Hash + ParentHash Hash + RoundNumber uint64 + TxHash Hash + type Logger interface + Crit func(msg string, ctx ...interface{}) + Debug func(msg string, ctx ...interface{}) + Info func(msg string, ctx ...interface{}) + LazyValue func(func() string) interface{} + Trace func(msg string, ctx ...interface{}) + Warn func(msg string, ctx ...interface{}) + type Participant struct + type ParticipantByAge []*Participant + func (a ParticipantByAge) Len() int + func (a ParticipantByAge) Less(i, j int) bool + func (a ParticipantByAge) Swap(i, j int) + type ParticipantByID []*Participant + func (a ParticipantByID) Len() int + func (a ParticipantByID) Less(i, j int) bool + func (a ParticipantByID) Swap(i, j int) + type Peer interface + SendConsensus func(data interface{}) error + type PeerFinder interface + FindPeers func(map[Address]bool) map[Address]Peer + type Quote [65]byte + type RMsg struct + Code RMsgCode + PathLength uint32 + Raw []byte + Round uint64 + To []Address + type RMsgCode uint + const RMsgConfirm + const RMsgEnrol + const RMsgIntent + const RMsgInvalid + const RMsgRandAgreement + const RMsgRandAgreementSolicit + const RMsgRandContrib + const RMsgRandContribSolicit + func (c RMsgCode) String() string + type RoundPhase int + const RoundPhaseBroadcast + const RoundPhaseConfirm + const RoundPhaseIntent + const RoundPhaseInvalid + const RoundPhaseStartup + func (p RoundPhase) String() string + type RoundState int + const RoundStateActive + const RoundStateEndorserCommittee + const RoundStateInactive + const RoundStateInvalid + const RoundStateLeaderCandidate + func (s RoundState) String() string + type RoundTime struct + Broadcast time.Duration + Confirm time.Duration + Intent time.Duration + RoundLength time.Duration + Ticker *time.Timer + func NewRoundTime(config *Config, opts ...RoundTimeOption) RoundTime + func (t *RoundTime) Reset(d time.Duration) + func (t *RoundTime) ResetForBroadcastPhase() + func (t *RoundTime) ResetForConfirmPhase() + func (t *RoundTime) ResetForIntentPhase() + func (t *RoundTime) Start(offset time.Duration) + func (t *RoundTime) Stop() + type RoundTimeOption func(r *RoundTime) + type SealCommitter interface + Canceled func() bool + CommitSeal func([]byte) + CurrentBlockHash func() [32]byte + type SignedEndorsement struct + Sig [65]byte + type SignedExtraData struct + Sig [65]byte + type SignedExtraDecoder interface + DecodeSignedExtraData func(se *SignedExtraData, b []byte) ([]byte, error) + type SignedIntent struct + Sig [65]byte + type VerifyBranchChainReader interface + GetHeader func(hash [32]byte, number uint64) BlockHeader + GetHeaderByHash func(hash [32]byte) BlockHeader + GetHeaderByNumber func(number uint64) BlockHeader + type WithLock func()