Documentation
¶
Index ¶
- Constants
- Variables
- func BlockRecord(bh BlockHeader, blockData []byte) []byte
- func NewEmptyNotarizationRecord(emptyNotarization *EmptyNotarization) []byte
- func NewEmptyVoteRecord(emptyVote ToBeSignedEmptyVote) []byte
- func NewQuorumRecord(qc []byte, rawVote []byte, recordType uint16) []byte
- func Orbit(round uint64, nodeIndex uint16, nodeCount uint16) uint64
- func Quorum(n int) int
- func SortNodes(nodes []NodeID)
- func VerifyQC(qc QuorumCertificate, logger Logger, messageType string, ...) error
- type BasicScheduler
- type Blacklist
- func (bl *Blacklist) ApplyUpdates(updates []BlacklistUpdate, round uint64) Blacklist
- func (bl *Blacklist) Bytes() []byte
- func (bl *Blacklist) ComputeBlacklistUpdates(round uint64, nodeCount uint16, timedOut, redeemed map[uint16]uint64) []BlacklistUpdate
- func (bl *Blacklist) Equals(b2 *Blacklist) bool
- func (bl *Blacklist) FromBytes(buff []byte) error
- func (bl *Blacklist) IsEmpty() bool
- func (bl *Blacklist) IsNodeSuspected(nodeIndex uint16) bool
- func (bl *Blacklist) String() string
- func (bl *Blacklist) VerifyProposedBlacklist(candidateBlacklist Blacklist, round uint64) error
- type BlacklistOpType
- type BlacklistUpdate
- type BlacklistUpdates
- type Block
- type BlockBuilder
- type BlockDependencyManager
- func (bs *BlockDependencyManager) Close()
- func (bs *BlockDependencyManager) ExecuteBlockDependents(prev Digest)
- func (bs *BlockDependencyManager) ExecuteEmptyRoundDependents(emptyRound uint64)
- func (bs *BlockDependencyManager) RemoveOldTasks(seq uint64)
- func (bs *BlockDependencyManager) ScheduleTaskWithDependencies(task Task, blockSeq uint64, prev *Digest, emptyRounds []uint64) error
- type BlockDeserializer
- type BlockDigestRequest
- type BlockHeader
- type BlockMessage
- type Communication
- type Digest
- type EmptyNotarization
- type EmptyVote
- type EmptyVoteMetadata
- type EmptyVoteSet
- type Epoch
- type EpochConfig
- type Finalization
- type FinalizeVote
- type Logger
- type Message
- type Monitor
- type NodeID
- type NodeIDs
- type Notarization
- type NotarizationTime
- type ProtocolMetadata
- type QCDeserializer
- type QuorumCertificate
- type QuorumRecord
- type QuorumRound
- type ReplicationRequest
- type ReplicationResponse
- type ReplicationState
- func (r *ReplicationState) AdvanceTime(now time.Time)
- func (r *ReplicationState) Close()
- func (r *ReplicationState) CreateDependencyTasks(parent *Digest, parentSeq uint64, emptyRounds []uint64)
- func (r *ReplicationState) DeleteRound(round uint64)
- func (r *ReplicationState) DeleteSeq(seq uint64)
- func (r *ReplicationState) GetBlockWithSeq(seq uint64) Block
- func (r *ReplicationState) GetFinalizedBlockForSequence(seq uint64) (Block, *Finalization, bool)
- func (r *ReplicationState) GetLowestRound() *QuorumRound
- func (r *ReplicationState) MaybeAdvanceState(nextSequenceToCommit uint64, currentRound uint64, lastCommittedRound uint64)
- func (r *ReplicationState) ReceivedFutureFinalization(finalization *Finalization, nextSeqToCommit uint64)
- func (r *ReplicationState) ReceivedFutureRound(round, seq, currentRound uint64, signers []NodeID)
- func (r *ReplicationState) ResendFinalizationRequest(seq uint64, signers []NodeID) error
- func (r *ReplicationState) StoreQuorumRound(round *QuorumRound)
- type Round
- type Scheduler
- type Segment
- type Signature
- type SignatureAggregator
- type SignatureVerifier
- type SignedMessage
- type Signer
- type Storage
- type SuspectedNode
- type SuspectedNodes
- type Task
- type TaskWithDependents
- type TimeoutHandler
- type ToBeSignedEmptyVote
- type ToBeSignedFinalization
- type ToBeSignedVote
- type VerifiedBlock
- type VerifiedBlockMessage
- type VerifiedFinalizedBlock
- type VerifiedQuorumRound
- type VerifiedReplicationResponse
- type Vote
- type WriteAheadLog
Constants ¶
const ( DefaultMaxRoundWindow = 10 DefaultProcessingBlocks = 500 DefaultMaxProposalWaitTime = 5 * time.Second DefaultReplicationRequestTimeout = 5 * time.Second DefaultEmptyVoteRebroadcastTimeout = 5 * time.Second DefaultFinalizeVoteRebroadcastTimeout = 6 * time.Second EmptyVoteTimeoutID = "rebroadcast_empty_vote" )
const ( ProtocolMetadataLen = metadataVersionLen + metadataEpochLen + metadataRoundLen + metadataSeqLen + metadataPrevLen BlockHeaderLen = ProtocolMetadataLen + metadataDigestLen )
Variables ¶
var ( ErrorNoVotes = errors.New("no votes to notarize") ErrorInvalidFinalizationDigest = errors.New("finalization digests do not match") )
var ErrAlreadyStarted = errors.New("epoch already started")
var ErrBlockNotFound = fmt.Errorf("block not found")
var ErrTooManyPendingVerifications = errors.New("too many blocks being verified to ingest another one")
Functions ¶
func BlockRecord ¶
func BlockRecord(bh BlockHeader, blockData []byte) []byte
func NewEmptyNotarizationRecord ¶
func NewEmptyNotarizationRecord(emptyNotarization *EmptyNotarization) []byte
func NewEmptyVoteRecord ¶
func NewEmptyVoteRecord(emptyVote ToBeSignedEmptyVote) []byte
func Orbit ¶
Orbit returns the total number of times the given node has been selected as leader from genesis up to and including the specified round.
Types ¶
type BasicScheduler ¶
type BasicScheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶
func NewScheduler(logger Logger, maxTasks uint64) *BasicScheduler
func (*BasicScheduler) Close ¶
func (as *BasicScheduler) Close()
func (*BasicScheduler) Schedule ¶
func (as *BasicScheduler) Schedule(task Task)
func (*BasicScheduler) Size ¶
func (as *BasicScheduler) Size() int
type Blacklist ¶
type Blacklist struct {
// NodeCount is the configuration of the blacklist.
NodeCount uint16
// SuspectedNodes is the list of nodes that are currently suspected.
// it's the inner state of the blacklist.
SuspectedNodes SuspectedNodes
// Updates is the list of modifications that a block builder is proposing
// to perform to the blacklist.
Updates BlacklistUpdates
}
Blacklist stores the state of the blacklist. It can be derived by applying the recorded Updates to the parent block's blacklist.
func NewBlacklist ¶
func (*Blacklist) ApplyUpdates ¶
func (bl *Blacklist) ApplyUpdates(updates []BlacklistUpdate, round uint64) Blacklist
ApplyUpdates applies the given updates in the given round to the current blacklist and returns a new blacklist. The current blacklist is not modified.
func (*Blacklist) Bytes ¶
Bytes returns the byte representation of the blacklist. The bytes of a blacklist are encoded as follows: 2 bytes for the node count 2 bytes for the number of updates N bytes for the suspected nodes section The rest of the bytes encode the updates section.
func (*Blacklist) ComputeBlacklistUpdates ¶
func (*Blacklist) IsNodeSuspected ¶
type BlacklistOpType ¶
type BlacklistOpType uint8
const ( BlacklistOpType_Undefined BlacklistOpType = iota BlacklistOpType_NodeSuspected BlacklistOpType_NodeRedeemed )
type BlacklistUpdate ¶
type BlacklistUpdate struct {
Type BlacklistOpType
NodeIndex uint16
}
func (*BlacklistUpdate) Equals ¶
func (bu *BlacklistUpdate) Equals(bu2 *BlacklistUpdate) bool
func (*BlacklistUpdate) String ¶
func (bu *BlacklistUpdate) String() string
type BlacklistUpdates ¶
type BlacklistUpdates []BlacklistUpdate
func (BlacklistUpdates) Bytes ¶
func (updates BlacklistUpdates) Bytes() []byte
func (*BlacklistUpdates) FromBytes ¶
func (updates *BlacklistUpdates) FromBytes(buff []byte) error
func (BlacklistUpdates) Len ¶
func (updates BlacklistUpdates) Len() int
type Block ¶
type Block interface {
// BlockHeader encodes a succinct and collision-free representation of a block.
BlockHeader() BlockHeader
Blacklist() Blacklist
// Verify verifies the block by speculatively executing it on top of its ancestor.
Verify(ctx context.Context) (VerifiedBlock, error)
}
func BlockFromRecord ¶
type BlockBuilder ¶
type BlockBuilder interface {
// BuildBlock blocks until some transactions are available to be batched into a block,
// in which case a block and true are returned.
// When the given context is cancelled by the caller, returns false.
// The given metadata and blacklist are encoded into the built block.
BuildBlock(ctx context.Context, metadata ProtocolMetadata, blacklist Blacklist) (VerifiedBlock, bool)
// WaitForPendingBlock returns when either the given context is cancelled,
// or when the application signals that a block should be built.
WaitForPendingBlock(ctx context.Context)
}
type BlockDependencyManager ¶
type BlockDependencyManager struct {
// contains filtered or unexported fields
}
BlockDependencyManager manages block verification tasks with dependencies on previous blocks and empty rounds. It schedules tasks when their dependencies are resolved.
func NewBlockVerificationScheduler ¶
func NewBlockVerificationScheduler(logger Logger, maxDeps uint64, scheduler Scheduler) *BlockDependencyManager
func (*BlockDependencyManager) Close ¶
func (bs *BlockDependencyManager) Close()
func (*BlockDependencyManager) ExecuteBlockDependents ¶
func (bs *BlockDependencyManager) ExecuteBlockDependents(prev Digest)
ExecuteBlockDependents removes the given digest from dependent tasks and schedules any whose dependencies are now resolved.
func (*BlockDependencyManager) ExecuteEmptyRoundDependents ¶
func (bs *BlockDependencyManager) ExecuteEmptyRoundDependents(emptyRound uint64)
ExecuteEmptyRoundDependents removes the given empty round from dependent tasks and schedules any whose dependencies are now resolved.
func (*BlockDependencyManager) RemoveOldTasks ¶
func (bs *BlockDependencyManager) RemoveOldTasks(seq uint64)
We can remove all tasks that have an empty notarization dependency for a round that has been finalized.
func (*BlockDependencyManager) ScheduleTaskWithDependencies ¶
type BlockDeserializer ¶
type BlockDeserializer interface {
// DeserializeBlock parses the given bytes and initializes a VerifiedBlock.
// Returns an error upon failure.
DeserializeBlock(ctx context.Context, bytes []byte) (Block, error)
}
BlockDeserializer deserializes blocks according to formatting enforced by the application.
type BlockDigestRequest ¶
type BlockHeader ¶
type BlockHeader struct {
ProtocolMetadata
// Digest returns a collision resistant short representation of the block's bytes
Digest Digest
}
BlockHeader encodes a succinct and collision-free representation of a block. It's included in votes and finalizations in order to convey which block is voted on, or which block is finalized.
func ParseBlockRecord ¶
func ParseBlockRecord(buff []byte) (BlockHeader, []byte, error)
func (*BlockHeader) Bytes ¶
func (bh *BlockHeader) Bytes() []byte
func (*BlockHeader) Equals ¶
func (bh *BlockHeader) Equals(other *BlockHeader) bool
func (*BlockHeader) FromBytes ¶
func (bh *BlockHeader) FromBytes(buff []byte) error
func (BlockHeader) String ¶
func (bh BlockHeader) String() string
type BlockMessage ¶
type Communication ¶
type Communication interface {
// Nodes returns all nodes that participate in the epoch.
Nodes() []NodeID
// Send sends a message to the given destination node
Send(msg *Message, destination NodeID)
// Broadcast broadcasts the given message to all nodes.
// Does not send it to yourself.
Broadcast(msg *Message)
}
type EmptyNotarization ¶
type EmptyNotarization struct {
Vote ToBeSignedEmptyVote
QC QuorumCertificate
}
func EmptyNotarizationFromRecord ¶
func EmptyNotarizationFromRecord(record []byte, qd QCDeserializer) (EmptyNotarization, error)
func (*EmptyNotarization) Verify ¶
func (en *EmptyNotarization) Verify() error
type EmptyVote ¶
type EmptyVote struct {
Vote ToBeSignedEmptyVote
Signature Signature
}
EmptyVote represents a signed vote for an empty block.
type EmptyVoteMetadata ¶
type EmptyVoteSet ¶
type EmptyVoteSet struct {
// contains filtered or unexported fields
}
type Epoch ¶
type Epoch struct {
EpochConfig
// contains filtered or unexported fields
}
func NewEpoch ¶
func NewEpoch(conf EpochConfig) (*Epoch, error)
func (*Epoch) AdvanceTime ¶
AdvanceTime hints the engine that the given amount of time has passed.
func (*Epoch) HandleMessage ¶
HandleMessage notifies the engine about a reception of a message.
func (*Epoch) Metadata ¶
func (e *Epoch) Metadata() ProtocolMetadata
Metadata returns the metadata of the next expected block of the epoch.
func (*Epoch) VerifyBlockMessageVote ¶
func (e *Epoch) VerifyBlockMessageVote(from NodeID, md BlockHeader, vote Vote) error
VerifyBlockMessageVote checks if we have the block in the future messages map. If so, it means we have already verified the vote associated with this proposal. If not, it verifies that the vote corresponds to the block proposed, and that the vote is properly signed.
type EpochConfig ¶
type EpochConfig struct {
MaxProposalWait time.Duration
MaxRoundWindow uint64
MaxRebroadcastWait time.Duration
FinalizeRebroadcastTimeout time.Duration
QCDeserializer QCDeserializer
Logger Logger
ID NodeID
Signer Signer
Verifier SignatureVerifier
BlockDeserializer BlockDeserializer
SignatureAggregator SignatureAggregator
Comm Communication
Storage Storage
WAL WriteAheadLog
BlockBuilder BlockBuilder
Epoch uint64
StartTime time.Time
ReplicationEnabled bool
}
type Finalization ¶
type Finalization struct {
Finalization ToBeSignedFinalization
QC QuorumCertificate
}
Finalization represents a block that has reached quorum on block. This means that block can be included in the chain and finalized.
func FinalizationFromRecord ¶
func FinalizationFromRecord(record []byte, qd QCDeserializer) (Finalization, error)
func NewFinalization ¶
func NewFinalization(logger Logger, signatureAggregator SignatureAggregator, finalizeVotes []*FinalizeVote) (Finalization, error)
NewFinalization builds a Finalization from [finalizeVotes].
func (*Finalization) Verify ¶
func (f *Finalization) Verify() error
type FinalizeVote ¶
type FinalizeVote struct {
Finalization ToBeSignedFinalization
Signature Signature
}
FinalizeVote represents a vote to finalize a block.
func (*FinalizeVote) Signer ¶
func (v *FinalizeVote) Signer() NodeID
type Logger ¶
type Logger interface {
// Log that a fatal error has occurred. The program should likely exit soon
// after this is called
Fatal(msg string, fields ...zap.Field)
// Log that an error has occurred. The program should be able to recover
// from this error
Error(msg string, fields ...zap.Field)
// Log that an event has occurred that may indicate a future error or
// vulnerability
Warn(msg string, fields ...zap.Field)
// Log an event that may be useful for a user to see to measure the progress
// of the protocol
Info(msg string, fields ...zap.Field)
// Log an event that may be useful for understanding the order of the
// execution of the protocol
Trace(msg string, fields ...zap.Field)
// Log an event that may be useful for a programmer to see when debuging the
// execution of the protocol
Debug(msg string, fields ...zap.Field)
// Log extremely detailed events that can be useful for inspecting every
// aspect of the program
Verbo(msg string, fields ...zap.Field)
}
type Message ¶
type Message struct {
BlockMessage *BlockMessage
VerifiedBlockMessage *VerifiedBlockMessage
EmptyNotarization *EmptyNotarization
VoteMessage *Vote
EmptyVoteMessage *EmptyVote
Notarization *Notarization
FinalizeVote *FinalizeVote
Finalization *Finalization
ReplicationResponse *ReplicationResponse
VerifiedReplicationResponse *VerifiedReplicationResponse
ReplicationRequest *ReplicationRequest
BlockDigestRequest *BlockDigestRequest
}
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
func (*Monitor) AdvanceTime ¶
func (*Monitor) CancelFutureTask ¶
func (m *Monitor) CancelFutureTask()
func (*Monitor) CancelTask ¶
func (m *Monitor) CancelTask()
func (*Monitor) FutureTask ¶
type NodeID ¶
type NodeID []byte
func LeaderForRound ¶
func NodeIDsFromVotes ¶
func NodeIDsFromVotes[VS voteSigner](votes []VS) []NodeID
type Notarization ¶
type Notarization struct {
Vote ToBeSignedVote
QC QuorumCertificate
}
Notarization represents a block that has reached a quorum of votes.
func NewNotarization ¶
func NewNotarization(logger Logger, signatureAggregator SignatureAggregator, votesForCurrentRound map[string]*Vote, blockHeader BlockHeader) (Notarization, error)
NewNotarization builds a Notarization for a block described by [blockHeader] from [votesForCurrentRound].
func NotarizationFromRecord ¶
func NotarizationFromRecord(record []byte, qd QCDeserializer) (Notarization, error)
func (*Notarization) Verify ¶
func (n *Notarization) Verify() error
type NotarizationTime ¶
type NotarizationTime struct {
// contains filtered or unexported fields
}
func NewNotarizationTime ¶
func (*NotarizationTime) CheckForNotFinalizedNotarizedBlocks ¶
func (nt *NotarizationTime) CheckForNotFinalizedNotarizedBlocks(now time.Time)
type ProtocolMetadata ¶
type ProtocolMetadata struct {
// Version defines the version of the protocol this block was created with.
Version uint8
// Epoch returns the epoch in which the block was proposed
Epoch uint64
// Round returns the round number in which the block was proposed.
// Can also be an empty block.
Round uint64
// Seq is the order of the block among all blocks in the blockchain.
// Cannot correspond to an empty block.
Seq uint64
// Prev returns the digest of the previous data block
Prev Digest
}
ProtocolMetadata encodes information about the protocol state at a given point in time.
func ProtocolMetadataFromBytes ¶
func ProtocolMetadataFromBytes(buff []byte) (*ProtocolMetadata, error)
Serializes a ProtocolMetadata from a byte slice.
func (*ProtocolMetadata) Bytes ¶
func (md *ProtocolMetadata) Bytes() []byte
Bytes returns a byte encoding of the ProtocolMetadata. it is encoded as follows: [Version (1 byte), Epoch (8 bytes), Round (8 bytes), Seq (8 bytes), Prev (32 bytes)]
type QCDeserializer ¶
type QCDeserializer interface {
// DeserializeQuorumCertificate parses the given bytes and initializes a QuorumCertificate.
// Returns an error upon failure.
DeserializeQuorumCertificate(bytes []byte) (QuorumCertificate, error)
}
QCDeserializer deserializes QuorumCertificates according to formatting
type QuorumCertificate ¶
type QuorumCertificate interface {
// Signers returns who participated in creating this QuorumCertificate.
Signers() []NodeID
// Verify checks whether the nodes participated in creating this QuorumCertificate,
// signed the given message.
Verify(msg []byte) error
// Bytes returns a raw representation of the given QuorumCertificate.
Bytes() []byte
}
QuorumCertificate is equivalent to a collection of signatures from a quorum of nodes,
type QuorumRecord ¶
type QuorumRound ¶
type QuorumRound struct {
Block Block
Notarization *Notarization
Finalization *Finalization
EmptyNotarization *EmptyNotarization
}
QuorumRound represents a round that has achieved quorum on either (empty notarization), (block & notarization), or (block, finalization)
func (*QuorumRound) GetRound ¶
func (q *QuorumRound) GetRound() uint64
func (*QuorumRound) GetSequence ¶
func (q *QuorumRound) GetSequence() uint64
func (*QuorumRound) IsWellFormed ¶
func (q *QuorumRound) IsWellFormed() error
isWellFormed returns an error if the QuorumRound has either (block, notarization) or (block, finalization) or (empty notarization)
func (*QuorumRound) String ¶
func (q *QuorumRound) String() string
String returns a string representation of the QuorumRound. It is meant as a debugging aid for logs.
func (*QuorumRound) VerifyQCConsistentWithBlock ¶
func (q *QuorumRound) VerifyQCConsistentWithBlock() error
type ReplicationRequest ¶
type ReplicationResponse ¶
type ReplicationResponse struct {
Data []QuorumRound
LatestRound *QuorumRound
LatestSeq *QuorumRound
}
type ReplicationState ¶
type ReplicationState struct {
// contains filtered or unexported fields
}
func NewReplicationState ¶
func NewReplicationState(logger Logger, comm Communication, myNodeID NodeID, maxRoundWindow uint64, enabled bool, start time.Time, lock *sync.Mutex) *ReplicationState
func (*ReplicationState) AdvanceTime ¶
func (r *ReplicationState) AdvanceTime(now time.Time)
func (*ReplicationState) Close ¶
func (r *ReplicationState) Close()
func (*ReplicationState) CreateDependencyTasks ¶
func (r *ReplicationState) CreateDependencyTasks(parent *Digest, parentSeq uint64, emptyRounds []uint64)
CreateDependencyTasks creates tasks to refetch the given parent digest and empty rounds. If there are no dependencies, no tasks are created.
func (*ReplicationState) DeleteRound ¶
func (r *ReplicationState) DeleteRound(round uint64)
func (*ReplicationState) DeleteSeq ¶
func (r *ReplicationState) DeleteSeq(seq uint64)
func (*ReplicationState) GetBlockWithSeq ¶
func (r *ReplicationState) GetBlockWithSeq(seq uint64) Block
func (*ReplicationState) GetFinalizedBlockForSequence ¶
func (r *ReplicationState) GetFinalizedBlockForSequence(seq uint64) (Block, *Finalization, bool)
func (*ReplicationState) GetLowestRound ¶
func (r *ReplicationState) GetLowestRound() *QuorumRound
func (*ReplicationState) MaybeAdvanceState ¶
func (r *ReplicationState) MaybeAdvanceState(nextSequenceToCommit uint64, currentRound uint64, lastCommittedRound uint64)
MaybeAdvanceState attempts to collect future sequences if there are more to be collected and the round has caught up for us to send the request.
func (*ReplicationState) ReceivedFutureFinalization ¶
func (r *ReplicationState) ReceivedFutureFinalization(finalization *Finalization, nextSeqToCommit uint64)
receivedFutureFinalization notifies the replication state a finalization was created in a future round.
func (*ReplicationState) ReceivedFutureRound ¶
func (r *ReplicationState) ReceivedFutureRound(round, seq, currentRound uint64, signers []NodeID)
receivedFutureRound notifies the replication state of a future round.
func (*ReplicationState) ResendFinalizationRequest ¶
func (r *ReplicationState) ResendFinalizationRequest(seq uint64, signers []NodeID) error
ResendFinalizationRequest notifies the replication state that `seq` should be re-requested.
func (*ReplicationState) StoreQuorumRound ¶
func (r *ReplicationState) StoreQuorumRound(round *QuorumRound)
StoreQuorumRound stores the quorum round into the replication state.
type Round ¶
type Round struct {
// contains filtered or unexported fields
}
func NewRound ¶
func NewRound(block VerifiedBlock) *Round
func SetRound ¶
func SetRound(block VerifiedBlock, notarization *Notarization, finalization *Finalization) *Round
SetRound is a helper function that is used for tests to create a round.
type Segment ¶
func CompressSequences ¶
compressSequences takes a slice of uint64 values representing missing sequence numbers and compresses consecutive numbers into segments. Each segment represents a continuous block of missing sequence numbers.
func DistributeSequenceRequests ¶
DistributeSequenceRequests evenly creates segments amongst [numNodes] over the range [start, end].
type Signature ¶
type Signature struct {
// Signer is the NodeID of the creator of the signature.
Signer NodeID
// Value is the byte representation of the signature.
Value []byte
}
Signature encodes a signature and the node that signed it, without the message it was signed on.
type SignatureAggregator ¶
type SignatureAggregator interface {
// Aggregate aggregates several signatures into a QuorumCertificate
Aggregate([]Signature) (QuorumCertificate, error)
// IsQuorum returns true if the given signers constitute a quorum.
// In the case of PoA, this means at least a quorum of the nodes are given.
// In the case of PoS, this means at least two thirds of the st.
IsQuorum([]NodeID) bool
}
SignatureAggregator aggregates signatures into a QuorumCertificate
type SignatureVerifier ¶
type SignedMessage ¶
type Storage ¶
type Storage interface {
NumBlocks() uint64
// Retrieve returns the block and finalization at [seq].
// If [seq] the block cannot be found, returns ErrBlockNotFound.
Retrieve(seq uint64) (VerifiedBlock, Finalization, error)
Index(ctx context.Context, block VerifiedBlock, certificate Finalization) error
}
type SuspectedNode ¶
type SuspectedNode struct {
// NodeIndex is the index of the suspected node among the nodes of the validator set.
NodeIndex uint16
// SuspectingCount is the number of nodes that have suspected this node in the current orbit denoted by OrbitSuspected.
// If this count is >= f+1, then the node is considered blacklisted.
SuspectingCount uint16
// RedeemingCount is the number of nodes that have redeemed this node in the current orbit denoted by OrbitToRedeem.
// If this count reaches >= f+1, the node is removed from the blacklist.
RedeemingCount uint16
// OrbitSuspected is the orbit in which the node was last suspected.
OrbitSuspected uint64
// OrbitToRedeem is the orbit in which the node was last redeemed.
OrbitToRedeem uint64
}
SuspectedNode is the information we keep for each suspected node. A suspected node records the number of accusations and when it was accused in. A suspected node that has above f+1 accusations is considered as blacklisted. A suspected node that is blacklisted can be redeemed by gathering f+1 redeeming votes. A suspected node that has been redeemed by f+1 votes or more is removed from the blacklist. Each suspected node is encoded in the following manner: A bitmask byte for the fields except the node index that are non-zero. 4 top bits of the bitmask are the bitmask for { suspectingCount, redeemingCount, orbitSuspected, orbitToRedeem }. A bit is set to 1 if the corresponding field is non-zero. The next 2 bytes are the node index. The next bytes correspond to the non-zero fields in the order of the bitmask. [bitmask byte] [node index (2 bytes)] [suspectingCount (2 bytes, if non-zero)] [redeemingCount (2 bytes, if non-zero)] [orbitSuspected (8 bytes, if non-zero)] [orbitToRedeem (8 bytes, if non-zero)]
func (*SuspectedNode) Equals ¶
func (sn *SuspectedNode) Equals(sn2 *SuspectedNode) bool
func (*SuspectedNode) Len ¶
func (sn *SuspectedNode) Len() int
func (*SuspectedNode) Read ¶
func (sn *SuspectedNode) Read(buff []byte) (int, error)
Read reads the suspected node from the given buffer. It returns the number of bytes read and an error if occurs.
func (*SuspectedNode) String ¶
func (sn *SuspectedNode) String() string
type SuspectedNodes ¶
type SuspectedNodes []SuspectedNode
func (*SuspectedNodes) Bytes ¶
func (sns *SuspectedNodes) Bytes() []byte
func (*SuspectedNodes) FromBytes ¶
func (sns *SuspectedNodes) FromBytes(buff []byte) error
func (*SuspectedNodes) Len ¶
func (sns *SuspectedNodes) Len() int
type TaskWithDependents ¶
type TaskWithDependents struct {
Task Task
// contains filtered or unexported fields
}
func (*TaskWithDependents) String ¶
func (t *TaskWithDependents) String() string
type TimeoutHandler ¶
type TimeoutHandler[T comparable] struct { // contains filtered or unexported fields }
func NewTimeoutHandler ¶
func NewTimeoutHandler[T comparable](log Logger, name string, startTime time.Time, runInterval time.Duration, taskRunner timeoutRunner[T]) *TimeoutHandler[T]
NewTimeoutHandler returns a TimeoutHandler and starts a new goroutine that listens for ticks and executes TimeoutTasks.
func (*TimeoutHandler[T]) AddTask ¶
func (t *TimeoutHandler[T]) AddTask(id T)
func (*TimeoutHandler[T]) Close ¶
func (t *TimeoutHandler[T]) Close()
func (*TimeoutHandler[T]) RemoveOldTasks ¶
func (t *TimeoutHandler[T]) RemoveOldTasks(shouldRemove func(id T, _ struct{}) bool)
func (*TimeoutHandler[T]) RemoveTask ¶
func (t *TimeoutHandler[T]) RemoveTask(ID T)
func (*TimeoutHandler[T]) Tick ¶
func (t *TimeoutHandler[T]) Tick(now time.Time)
type ToBeSignedEmptyVote ¶
type ToBeSignedEmptyVote struct {
EmptyVoteMetadata
}
func ParseEmptyNotarizationRecord ¶
func ParseEmptyNotarizationRecord(buff []byte) ([]byte, ToBeSignedEmptyVote, error)
func ParseEmptyVoteRecord ¶
func ParseEmptyVoteRecord(rawEmptyVote []byte) (ToBeSignedEmptyVote, error)
func (*ToBeSignedEmptyVote) Bytes ¶
func (v *ToBeSignedEmptyVote) Bytes() []byte
func (*ToBeSignedEmptyVote) FromBytes ¶
func (v *ToBeSignedEmptyVote) FromBytes(buff []byte) error
func (*ToBeSignedEmptyVote) Sign ¶
func (v *ToBeSignedEmptyVote) Sign(signer Signer) ([]byte, error)
func (*ToBeSignedEmptyVote) Verify ¶
func (v *ToBeSignedEmptyVote) Verify(signature []byte, verifier SignatureVerifier, signers NodeID) error
type ToBeSignedFinalization ¶
type ToBeSignedFinalization struct {
BlockHeader
}
func (*ToBeSignedFinalization) Sign ¶
func (f *ToBeSignedFinalization) Sign(signer Signer) ([]byte, error)
func (*ToBeSignedFinalization) Verify ¶
func (f *ToBeSignedFinalization) Verify(signature []byte, verifier SignatureVerifier, signers NodeID) error
type ToBeSignedVote ¶
type ToBeSignedVote struct {
BlockHeader
}
func ParseNotarizationRecord ¶
func ParseNotarizationRecord(r []byte) ([]byte, ToBeSignedVote, error)
ParseNotarizationRecordBytes parses a notarization record into the bytes of the QC and the vote
func (*ToBeSignedVote) Verify ¶
func (v *ToBeSignedVote) Verify(signature []byte, verifier SignatureVerifier, signers NodeID) error
type VerifiedBlock ¶
type VerifiedBlock interface {
// BlockHeader encodes a succinct and collision-free representation of a block.
BlockHeader() BlockHeader
Blacklist() Blacklist
// Bytes returns a byte encoding of the block
Bytes() ([]byte, error)
}
type VerifiedBlockMessage ¶
type VerifiedBlockMessage struct {
VerifiedBlock VerifiedBlock
Vote Vote
}
type VerifiedFinalizedBlock ¶
type VerifiedFinalizedBlock struct {
VerifiedBlock VerifiedBlock
Finalization Finalization
}
func RetrieveLastIndexFromStorage ¶
func RetrieveLastIndexFromStorage(s Storage) (*VerifiedFinalizedBlock, error)
RetrieveLastIndexFromStorage retrieves the latest block and finalization from storage. Returns an error if it cannot be retrieved but the storage has some block. Returns (nil, nil) if the storage is empty.
type VerifiedQuorumRound ¶
type VerifiedQuorumRound struct {
VerifiedBlock VerifiedBlock
Notarization *Notarization
Finalization *Finalization
EmptyNotarization *EmptyNotarization
}
func GetLatestVerifiedQuorumRound ¶
func GetLatestVerifiedQuorumRound(round *Round, emptyNotarization *EmptyNotarization) *VerifiedQuorumRound
GetLatestVerifiedQuorumRound returns the latest verified quorum round given a round and empty notarization. If both are nil, it returns nil.
func (*VerifiedQuorumRound) GetRound ¶
func (q *VerifiedQuorumRound) GetRound() uint64
type VerifiedReplicationResponse ¶
type VerifiedReplicationResponse struct {
Data []VerifiedQuorumRound
LatestRound *VerifiedQuorumRound
LatestFinalizedSeq *VerifiedQuorumRound
}
type Vote ¶
type Vote struct {
Vote ToBeSignedVote
Signature Signature
}
Vote represents a signed vote for a block.
