Documentation
¶
Index ¶
- Constants
- Variables
- func BlacklistUpdatesAsString(updates []BlacklistUpdate) string
- func BlockRecord(bh BlockHeader, blockData []byte) ([]byte, error)
- func BlockRecordRetentionTerm(record []byte) (uint64, error)
- func EmptyVoteRecordRetentionTerm(record []byte) (uint64, error)
- func F(n int) int
- func NewEmptyNotarizationRecord(emptyNotarization *EmptyNotarization) []byte
- func NewEmptyVoteRecord(emptyVote ToBeSignedEmptyVote) []byte
- func NewQuorumRecord(qc []byte, rawVote []byte, recordType uint16) []byte
- func NewRandomSourceFromSeed(seed int64) *rand.Rand
- func OnlyVMVerifyOpt(vc *VerifyConfig)
- func Orbit(round uint64, nodeIndex uint16, nodeCount uint16) uint64
- func Quorum(n int) int
- func SortNodes(nodes Nodes)
- type AuxiliaryInfo
- func (c *AuxiliaryInfo) CachedCanotoSize() uint64
- func (c *AuxiliaryInfo) CalculateCanotoCache()
- func (*AuxiliaryInfo) CanotoSpec(...reflect.Type) *canoto.Spec
- func (ai *AuxiliaryInfo) Clone() AuxiliaryInfo
- func (c *AuxiliaryInfo) MarshalCanoto() []byte
- func (c *AuxiliaryInfo) MarshalCanotoInto(w canoto.Writer) canoto.Writer
- func (c *AuxiliaryInfo) UnmarshalCanoto(bytes []byte) error
- func (c *AuxiliaryInfo) UnmarshalCanotoFrom(r canoto.Reader) error
- func (c *AuxiliaryInfo) ValidCanoto() bool
- type BasicScheduler
- type Blacklist
- func (bl *Blacklist) ApplyUpdates(updates []BlacklistUpdate, round uint64) Blacklist
- func (bl *Blacklist) Bytes() []byte
- func (c *Blacklist) CachedCanotoSize() uint64
- func (c *Blacklist) CalculateCanotoCache()
- func (*Blacklist) CanotoSpec(types ...reflect.Type) *canoto.Spec
- func (bl *Blacklist) Clone() Blacklist
- 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 (c *Blacklist) MarshalCanoto() []byte
- func (c *Blacklist) MarshalCanotoInto(w canoto.Writer) canoto.Writer
- func (bl *Blacklist) String() string
- func (c *Blacklist) UnmarshalCanoto(bytes []byte) error
- func (c *Blacklist) UnmarshalCanotoFrom(r canoto.Reader) error
- func (c *Blacklist) ValidCanoto() bool
- func (bl *Blacklist) VerifyProposedBlacklist(candidateBlacklist Blacklist, round uint64) error
- type BlacklistOpType
- type BlacklistUpdate
- func (c *BlacklistUpdate) CachedCanotoSize() uint64
- func (c *BlacklistUpdate) CalculateCanotoCache()
- func (*BlacklistUpdate) CanotoSpec(...reflect.Type) *canoto.Spec
- func (bu *BlacklistUpdate) Clone() BlacklistUpdate
- func (bu *BlacklistUpdate) Equals(bu2 *BlacklistUpdate) bool
- func (c *BlacklistUpdate) MarshalCanoto() []byte
- func (c *BlacklistUpdate) MarshalCanotoInto(w canoto.Writer) canoto.Writer
- func (bu *BlacklistUpdate) String() string
- func (c *BlacklistUpdate) UnmarshalCanoto(bytes []byte) error
- func (c *BlacklistUpdate) UnmarshalCanotoFrom(r canoto.Reader) error
- func (c *BlacklistUpdate) ValidCanoto() bool
- 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) IsSequenceScheduled(seq uint64) bool
- 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
- func (bh *BlockHeader) Bytes() []byte
- func (c *BlockHeader) CachedCanotoSize() uint64
- func (c *BlockHeader) CalculateCanotoCache()
- func (*BlockHeader) CanotoSpec(types ...reflect.Type) *canoto.Spec
- func (bh *BlockHeader) Equals(other *BlockHeader) bool
- func (bh *BlockHeader) FromBytes(buff []byte) error
- func (c *BlockHeader) MarshalCanoto() []byte
- func (c *BlockHeader) MarshalCanotoInto(w canoto.Writer) canoto.Writer
- func (bh *BlockHeader) Size() int
- func (bh *BlockHeader) String() string
- func (c *BlockHeader) UnmarshalCanoto(bytes []byte) error
- func (c *BlockHeader) UnmarshalCanotoFrom(r canoto.Reader) error
- func (c *BlockHeader) ValidCanoto() bool
- type BlockMessage
- type Communication
- type Digest
- type EmptyNotarization
- type EmptyVote
- type EmptyVoteMetadata
- type Finalization
- type FinalizeVote
- type Logger
- type Message
- type Node
- type NodeID
- type NodeIDs
- type Nodes
- type Notarization
- type ProtocolMetadata
- func (md *ProtocolMetadata) Bytes() []byte
- func (c *ProtocolMetadata) CachedCanotoSize() uint64
- func (c *ProtocolMetadata) CalculateCanotoCache()
- func (*ProtocolMetadata) CanotoSpec(...reflect.Type) *canoto.Spec
- func (md *ProtocolMetadata) Clone() ProtocolMetadata
- func (c *ProtocolMetadata) MarshalCanoto() []byte
- func (c *ProtocolMetadata) MarshalCanotoInto(w canoto.Writer) canoto.Writer
- func (c *ProtocolMetadata) UnmarshalCanoto(bytes []byte) error
- func (c *ProtocolMetadata) UnmarshalCanotoFrom(r canoto.Reader) error
- func (c *ProtocolMetadata) ValidCanoto() bool
- type QCDeserializer
- type QuorumCertificate
- type QuorumRecord
- type QuorumRound
- type ReplicationRequest
- type ReplicationResponse
- type Scheduler
- type SealingBlockInfo
- type Signature
- type SignatureAggregator
- type SignatureAggregatorCreator
- type SignatureVerifier
- type SignedMessage
- type Signer
- type Storage
- type SuspectedNode
- func (c *SuspectedNode) CachedCanotoSize() uint64
- func (c *SuspectedNode) CalculateCanotoCache()
- func (*SuspectedNode) CanotoSpec(...reflect.Type) *canoto.Spec
- func (sn *SuspectedNode) Clone() SuspectedNode
- func (sn *SuspectedNode) Equals(sn2 *SuspectedNode) bool
- func (c *SuspectedNode) MarshalCanoto() []byte
- func (c *SuspectedNode) MarshalCanotoInto(w canoto.Writer) canoto.Writer
- func (sn *SuspectedNode) String() string
- func (c *SuspectedNode) UnmarshalCanoto(bytes []byte) error
- func (c *SuspectedNode) UnmarshalCanotoFrom(r canoto.Reader) error
- func (c *SuspectedNode) ValidCanoto() bool
- type SuspectedNodes
- type Task
- type TaskWithDependents
- type TimeoutHandler
- type ToBeSignedEmptyVote
- func (v *ToBeSignedEmptyVote) Bytes() []byte
- func (v *ToBeSignedEmptyVote) FromBytes(buff []byte) error
- func (v *ToBeSignedEmptyVote) Sign(signer Signer) ([]byte, error)
- func (v *ToBeSignedEmptyVote) Size() int
- func (v *ToBeSignedEmptyVote) Verify(signature []byte, verifier SignatureVerifier, pk []byte) error
- type ToBeSignedFinalization
- type ToBeSignedVote
- type ValidatorSetApproval
- type VerifiedBlock
- type VerifiedBlockMessage
- type VerifiedFinalizedBlock
- type VerifiedQuorumRound
- type VerifiedReplicationResponse
- type VerifyConfig
- type VerifyOptions
- type VersionID
- type Vote
- type WALRetentionReader
- type WriteAheadLog
Constants ¶
const ( UndefinedRecordType uint16 = iota BlockRecordType NotarizationRecordType EmptyVoteRecordType EmptyNotarizationRecordType FinalizationRecordType )
Variables ¶
var ( ErrorNoVotes = errors.New("no votes to notarize") ErrorInvalidFinalizationDigest = errors.New("finalization digests do not match") )
var ErrBlockNotFound = fmt.Errorf("block not found")
var ErrTooManyPendingVerifications = errors.New("too many blocks being verified to ingest another one")
Functions ¶
func BlacklistUpdatesAsString ¶
func BlacklistUpdatesAsString(updates []BlacklistUpdate) string
func BlockRecord ¶
func BlockRecord(bh BlockHeader, blockData []byte) ([]byte, error)
func NewEmptyNotarizationRecord ¶
func NewEmptyNotarizationRecord(emptyNotarization *EmptyNotarization) []byte
func NewEmptyVoteRecord ¶
func NewEmptyVoteRecord(emptyVote ToBeSignedEmptyVote) []byte
func NewRandomSourceFromSeed ¶
func OnlyVMVerifyOpt ¶
func OnlyVMVerifyOpt(vc *VerifyConfig)
Types ¶
type AuxiliaryInfo ¶
type AuxiliaryInfo struct {
// The epoch this Auxiliary info is associated with
Epoch uint64 `canoto:"uint,1"`
// Version is an identifier that identifies the application.
// Can be used for backward-compatibility and upgrade purposes.
Version VersionID `canoto:"uint,2"`
// Data is opaque bytes that can be used by applications to encode any information that describes
// the current state for the application.
Data []byte `canoto:"bytes,3"`
// contains filtered or unexported fields
}
AuxiliaryInfo defines application-specific information for applications that might care about epoch change, such as distributed key generation.
func (*AuxiliaryInfo) CachedCanotoSize ¶
func (c *AuxiliaryInfo) CachedCanotoSize() uint64
CachedCanotoSize returns the previously calculated size of the Canoto representation from CalculateCanotoCache.
If CalculateCanotoCache has not yet been called, it will return 0.
If the struct has been modified since the last call to CalculateCanotoCache, the returned size may be incorrect.
func (*AuxiliaryInfo) CalculateCanotoCache ¶
func (c *AuxiliaryInfo) CalculateCanotoCache()
CalculateCanotoCache populates size and OneOf caches based on the current values in the struct.
It is not safe to copy this struct concurrently.
func (*AuxiliaryInfo) CanotoSpec ¶
func (*AuxiliaryInfo) CanotoSpec(...reflect.Type) *canoto.Spec
CanotoSpec returns the specification of this canoto message.
func (*AuxiliaryInfo) Clone ¶
func (ai *AuxiliaryInfo) Clone() AuxiliaryInfo
Clone returns a copy of the AuxiliaryInfo.
func (*AuxiliaryInfo) MarshalCanoto ¶
func (c *AuxiliaryInfo) MarshalCanoto() []byte
MarshalCanoto returns the Canoto representation of this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*AuxiliaryInfo) MarshalCanotoInto ¶
func (c *AuxiliaryInfo) MarshalCanotoInto(w canoto.Writer) canoto.Writer
MarshalCanotoInto writes the struct into a canoto.Writer and returns the resulting canoto.Writer. Most users should just use MarshalCanoto.
It is assumed that CalculateCanotoCache has been called since the last modification to this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*AuxiliaryInfo) UnmarshalCanoto ¶
func (c *AuxiliaryInfo) UnmarshalCanoto(bytes []byte) error
UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
During parsing, the canoto cache is saved.
func (*AuxiliaryInfo) UnmarshalCanotoFrom ¶
func (c *AuxiliaryInfo) UnmarshalCanotoFrom(r canoto.Reader) error
UnmarshalCanotoFrom populates the struct from a canoto.Reader. Most users should just use UnmarshalCanoto.
During parsing, the canoto cache is saved.
This function enables configuration of reader options.
func (*AuxiliaryInfo) ValidCanoto ¶
func (c *AuxiliaryInfo) ValidCanoto() bool
ValidCanoto validates that the struct can be correctly marshaled into the Canoto format.
Specifically, ValidCanoto ensures: 1. All OneOfs are specified at most once. 2. All strings are valid utf-8. 3. All custom fields are ValidCanoto.
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) ScheduleOrReplace ¶
func (as *BasicScheduler) ScheduleOrReplace(task Task)
ScheduleOrReplace schedules a task, replacing any queued task if full. The cancel function is called before draining the old task.
func (*BasicScheduler) Size ¶
func (as *BasicScheduler) Size() int
type Blacklist ¶
type Blacklist struct {
// NodeCount is the configuration of the blacklist.
NodeCount uint16 `canoto:"uint,1"`
// SuspectedNodes is the list of nodes that are currently suspected.
// it's the inner state of the blacklist.
SuspectedNodes SuspectedNodes `canoto:"repeated value,2"`
// Updates is the list of modifications that a block builder is proposing
// to perform to the blacklist.
Updates BlacklistUpdates `canoto:"repeated value,3"`
// contains filtered or unexported fields
}
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) CachedCanotoSize ¶
CachedCanotoSize returns the previously calculated size of the Canoto representation from CalculateCanotoCache.
If CalculateCanotoCache has not yet been called, it will return 0.
If the struct has been modified since the last call to CalculateCanotoCache, the returned size may be incorrect.
func (*Blacklist) CalculateCanotoCache ¶
func (c *Blacklist) CalculateCanotoCache()
CalculateCanotoCache populates size and OneOf caches based on the current values in the struct.
It is not safe to copy this struct concurrently.
func (*Blacklist) CanotoSpec ¶
CanotoSpec returns the specification of this canoto message.
func (*Blacklist) ComputeBlacklistUpdates ¶
func (*Blacklist) IsNodeSuspected ¶
func (*Blacklist) MarshalCanoto ¶
MarshalCanoto returns the Canoto representation of this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*Blacklist) MarshalCanotoInto ¶
MarshalCanotoInto writes the struct into a canoto.Writer and returns the resulting canoto.Writer. Most users should just use MarshalCanoto.
It is assumed that CalculateCanotoCache has been called since the last modification to this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*Blacklist) UnmarshalCanoto ¶
UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
During parsing, the canoto cache is saved.
func (*Blacklist) UnmarshalCanotoFrom ¶
UnmarshalCanotoFrom populates the struct from a canoto.Reader. Most users should just use UnmarshalCanoto.
During parsing, the canoto cache is saved.
This function enables configuration of reader options.
func (*Blacklist) ValidCanoto ¶
ValidCanoto validates that the struct can be correctly marshaled into the Canoto format.
Specifically, ValidCanoto ensures: 1. All OneOfs are specified at most once. 2. All strings are valid utf-8. 3. All custom fields are ValidCanoto.
type BlacklistOpType ¶
type BlacklistOpType uint8
const ( BlacklistOpType_Undefined BlacklistOpType = iota BlacklistOpType_NodeSuspected BlacklistOpType_NodeRedeemed )
type BlacklistUpdate ¶
type BlacklistUpdate struct {
Type BlacklistOpType `canoto:"uint,1"`
NodeIndex uint16 `canoto:"uint,2"`
// contains filtered or unexported fields
}
func (*BlacklistUpdate) CachedCanotoSize ¶
func (c *BlacklistUpdate) CachedCanotoSize() uint64
CachedCanotoSize returns the previously calculated size of the Canoto representation from CalculateCanotoCache.
If CalculateCanotoCache has not yet been called, it will return 0.
If the struct has been modified since the last call to CalculateCanotoCache, the returned size may be incorrect.
func (*BlacklistUpdate) CalculateCanotoCache ¶
func (c *BlacklistUpdate) CalculateCanotoCache()
CalculateCanotoCache populates size and OneOf caches based on the current values in the struct.
It is not safe to copy this struct concurrently.
func (*BlacklistUpdate) CanotoSpec ¶
func (*BlacklistUpdate) CanotoSpec(...reflect.Type) *canoto.Spec
CanotoSpec returns the specification of this canoto message.
func (*BlacklistUpdate) Clone ¶
func (bu *BlacklistUpdate) Clone() BlacklistUpdate
func (*BlacklistUpdate) Equals ¶
func (bu *BlacklistUpdate) Equals(bu2 *BlacklistUpdate) bool
func (*BlacklistUpdate) MarshalCanoto ¶
func (c *BlacklistUpdate) MarshalCanoto() []byte
MarshalCanoto returns the Canoto representation of this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*BlacklistUpdate) MarshalCanotoInto ¶
func (c *BlacklistUpdate) MarshalCanotoInto(w canoto.Writer) canoto.Writer
MarshalCanotoInto writes the struct into a canoto.Writer and returns the resulting canoto.Writer. Most users should just use MarshalCanoto.
It is assumed that CalculateCanotoCache has been called since the last modification to this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*BlacklistUpdate) String ¶
func (bu *BlacklistUpdate) String() string
func (*BlacklistUpdate) UnmarshalCanoto ¶
func (c *BlacklistUpdate) UnmarshalCanoto(bytes []byte) error
UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
During parsing, the canoto cache is saved.
func (*BlacklistUpdate) UnmarshalCanotoFrom ¶
func (c *BlacklistUpdate) UnmarshalCanotoFrom(r canoto.Reader) error
UnmarshalCanotoFrom populates the struct from a canoto.Reader. Most users should just use UnmarshalCanoto.
During parsing, the canoto cache is saved.
This function enables configuration of reader options.
func (*BlacklistUpdate) ValidCanoto ¶
func (c *BlacklistUpdate) ValidCanoto() bool
ValidCanoto validates that the struct can be correctly marshaled into the Canoto format.
Specifically, ValidCanoto ensures: 1. All OneOfs are specified at most once. 2. All strings are valid utf-8. 3. All custom fields are ValidCanoto.
type BlacklistUpdates ¶
type BlacklistUpdates []BlacklistUpdate
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(context.Context, ...VerifyOptions) (VerifiedBlock, error)
// non nil only for sealing blocks & first ever simplex block
SealingBlockInfo() *SealingBlockInfo
}
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) IsSequenceScheduled ¶
func (bs *BlockDependencyManager) IsSequenceScheduled(seq uint64) bool
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 deserializes 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 `canoto:"value,1"`
// Digest returns a collision resistant short representation of the block's bytes
Digest Digest `canoto:"fixed bytes,2"`
// contains filtered or unexported fields
}
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) CachedCanotoSize ¶
func (c *BlockHeader) CachedCanotoSize() uint64
CachedCanotoSize returns the previously calculated size of the Canoto representation from CalculateCanotoCache.
If CalculateCanotoCache has not yet been called, it will return 0.
If the struct has been modified since the last call to CalculateCanotoCache, the returned size may be incorrect.
func (*BlockHeader) CalculateCanotoCache ¶
func (c *BlockHeader) CalculateCanotoCache()
CalculateCanotoCache populates size and OneOf caches based on the current values in the struct.
It is not safe to copy this struct concurrently.
func (*BlockHeader) CanotoSpec ¶
func (*BlockHeader) CanotoSpec(types ...reflect.Type) *canoto.Spec
CanotoSpec returns the specification of this canoto message.
func (*BlockHeader) Equals ¶
func (bh *BlockHeader) Equals(other *BlockHeader) bool
func (*BlockHeader) FromBytes ¶
func (bh *BlockHeader) FromBytes(buff []byte) error
func (*BlockHeader) MarshalCanoto ¶
func (c *BlockHeader) MarshalCanoto() []byte
MarshalCanoto returns the Canoto representation of this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*BlockHeader) MarshalCanotoInto ¶
func (c *BlockHeader) MarshalCanotoInto(w canoto.Writer) canoto.Writer
MarshalCanotoInto writes the struct into a canoto.Writer and returns the resulting canoto.Writer. Most users should just use MarshalCanoto.
It is assumed that CalculateCanotoCache has been called since the last modification to this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*BlockHeader) Size ¶
func (bh *BlockHeader) Size() int
func (*BlockHeader) String ¶
func (bh *BlockHeader) String() string
func (*BlockHeader) UnmarshalCanoto ¶
func (c *BlockHeader) UnmarshalCanoto(bytes []byte) error
UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
During parsing, the canoto cache is saved.
func (*BlockHeader) UnmarshalCanotoFrom ¶
func (c *BlockHeader) UnmarshalCanotoFrom(r canoto.Reader) error
UnmarshalCanotoFrom populates the struct from a canoto.Reader. Most users should just use UnmarshalCanoto.
During parsing, the canoto cache is saved.
This function enables configuration of reader options.
func (*BlockHeader) ValidCanoto ¶
func (c *BlockHeader) ValidCanoto() bool
ValidCanoto validates that the struct can be correctly marshaled into the Canoto format.
Specifically, ValidCanoto ensures: 1. All OneOfs are specified at most once. 2. All strings are valid utf-8. 3. All custom fields are ValidCanoto.
type BlockMessage ¶
type Communication ¶
type Communication interface {
// Validators returns all nodes that participate in consensus in the epoch.
Validators() Nodes
// 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) Size ¶
func (en *EmptyNotarization) Size() int
func (*EmptyNotarization) Verify ¶
func (en *EmptyNotarization) Verify(nodes Nodes) error
type EmptyVote ¶
type EmptyVote struct {
Vote ToBeSignedEmptyVote
Signature Signature
}
EmptyVote represents a signed vote for an empty block.
type EmptyVoteMetadata ¶
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(signatureAggregator SignatureAggregator, finalizeVotes []*FinalizeVote) (Finalization, error)
NewFinalization builds a Finalization from [finalizeVotes].
func (*Finalization) Size ¶
func (f *Finalization) Size() int
func (*Finalization) Verify ¶
func (f *Finalization) Verify(nodes Nodes) 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 {
// Simplex Messages
BlockMessage *BlockMessage
EmptyNotarization *EmptyNotarization
VoteMessage *Vote
EmptyVoteMessage *EmptyVote
Notarization *Notarization
FinalizeVote *FinalizeVote
Finalization *Finalization
// Replication Messages
ReplicationResponse *ReplicationResponse
ReplicationRequest *ReplicationRequest
BlockDigestRequest *BlockDigestRequest
// Verified Messages
VerifiedBlockMessage *VerifiedBlockMessage
VerifiedReplicationResponse *VerifiedReplicationResponse
// Epoch Transition Messages
AuxiliaryInfo *AuxiliaryInfo
EpochTransitionApproval *ValidatorSetApproval
}
func (*Message) IsReplicationMessage ¶
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) Size ¶
func (n *Notarization) Size() int
func (*Notarization) Verify ¶
func (n *Notarization) Verify(nodes Nodes) error
type ProtocolMetadata ¶
type ProtocolMetadata struct {
// Version defines the version of the protocol this block was created with.
Version uint8 `canoto:"uint,1"`
// Epoch returns the epoch in which the block was proposed
Epoch uint64 `canoto:"uint,2"`
// Round returns the round number in which the block was proposed.
// Can also be an empty block.
Round uint64 `canoto:"uint,3"`
// Seq is the order of the block among all blocks in the blockchain.
// Cannot correspond to an empty block.
Seq uint64 `canoto:"uint,4"`
// Prev returns the digest of the previous data block
Prev Digest `canoto:"fixed bytes,5"`
// contains filtered or unexported fields
}
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.
func (*ProtocolMetadata) CachedCanotoSize ¶
func (c *ProtocolMetadata) CachedCanotoSize() uint64
CachedCanotoSize returns the previously calculated size of the Canoto representation from CalculateCanotoCache.
If CalculateCanotoCache has not yet been called, it will return 0.
If the struct has been modified since the last call to CalculateCanotoCache, the returned size may be incorrect.
func (*ProtocolMetadata) CalculateCanotoCache ¶
func (c *ProtocolMetadata) CalculateCanotoCache()
CalculateCanotoCache populates size and OneOf caches based on the current values in the struct.
It is not safe to copy this struct concurrently.
func (*ProtocolMetadata) CanotoSpec ¶
func (*ProtocolMetadata) CanotoSpec(...reflect.Type) *canoto.Spec
CanotoSpec returns the specification of this canoto message.
func (*ProtocolMetadata) Clone ¶
func (md *ProtocolMetadata) Clone() ProtocolMetadata
Clone returns a copy of the ProtocolMetadata.
func (*ProtocolMetadata) MarshalCanoto ¶
func (c *ProtocolMetadata) MarshalCanoto() []byte
MarshalCanoto returns the Canoto representation of this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*ProtocolMetadata) MarshalCanotoInto ¶
func (c *ProtocolMetadata) MarshalCanotoInto(w canoto.Writer) canoto.Writer
MarshalCanotoInto writes the struct into a canoto.Writer and returns the resulting canoto.Writer. Most users should just use MarshalCanoto.
It is assumed that CalculateCanotoCache has been called since the last modification to this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*ProtocolMetadata) UnmarshalCanoto ¶
func (c *ProtocolMetadata) UnmarshalCanoto(bytes []byte) error
UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
During parsing, the canoto cache is saved.
func (*ProtocolMetadata) UnmarshalCanotoFrom ¶
func (c *ProtocolMetadata) UnmarshalCanotoFrom(r canoto.Reader) error
UnmarshalCanotoFrom populates the struct from a canoto.Reader. Most users should just use UnmarshalCanoto.
During parsing, the canoto cache is saved.
This function enables configuration of reader options.
func (*ProtocolMetadata) ValidCanoto ¶
func (c *ProtocolMetadata) ValidCanoto() bool
ValidCanoto validates that the struct can be correctly marshaled into the Canoto format.
Specifically, ValidCanoto ensures: 1. All OneOfs are specified at most once. 2. All strings are valid utf-8. 3. All custom fields are ValidCanoto.
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, nodes Nodes) error
// Bytes returns a raw representation of the given QuorumCertificate.
Bytes() []byte
// Size returns the number of bytes
Size() int
}
QuorumCertificate is equivalent to a collection of signatures from a quorum of nodes,
type QuorumRecord ¶
func (*QuorumRecord) Bytes ¶
func (qr *QuorumRecord) Bytes() []byte
func (*QuorumRecord) FromBytes ¶
func (qr *QuorumRecord) FromBytes(buff []byte) error
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 is not in one one of these formats (block, notarization), (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 SealingBlockInfo ¶
type SealingBlockInfo struct {
// ValidatorSet of the new epoch
ValidatorSet Nodes
// PrevSealingBlockHash is the hash of the previous sealing block
PrevSealingBlockHash Digest
}
SealingBlockInfo defines information that is derived from a sealing block, namely the validator set and the hash of the previous sealing block if applicable.
func (*SealingBlockInfo) String ¶
func (s *SealingBlockInfo) String() string
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)
// AppendSignatures appends signatures to an existing signature.
// If the existing signature is empty, it just aggregates the given signatures.
AppendSignatures([]byte, ...[]byte) ([]byte, 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 SignatureAggregatorCreator ¶
type SignatureAggregatorCreator func([]Node) SignatureAggregator
SignatureAggregatorCreator creates a SignatureAggregator from a list of nodes and their weights.
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 `canoto:"uint,1"`
// 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 `canoto:"uint,2"`
// 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 `canoto:"uint,3"`
// OrbitSuspected is the orbit in which the node was last suspected.
OrbitSuspected uint64 `canoto:"uint,4"`
// OrbitToRedeem is the orbit in which the node was last redeemed.
OrbitToRedeem uint64 `canoto:"uint,5"`
// contains filtered or unexported fields
}
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.
func (*SuspectedNode) CachedCanotoSize ¶
func (c *SuspectedNode) CachedCanotoSize() uint64
CachedCanotoSize returns the previously calculated size of the Canoto representation from CalculateCanotoCache.
If CalculateCanotoCache has not yet been called, it will return 0.
If the struct has been modified since the last call to CalculateCanotoCache, the returned size may be incorrect.
func (*SuspectedNode) CalculateCanotoCache ¶
func (c *SuspectedNode) CalculateCanotoCache()
CalculateCanotoCache populates size and OneOf caches based on the current values in the struct.
It is not safe to copy this struct concurrently.
func (*SuspectedNode) CanotoSpec ¶
func (*SuspectedNode) CanotoSpec(...reflect.Type) *canoto.Spec
CanotoSpec returns the specification of this canoto message.
func (*SuspectedNode) Clone ¶
func (sn *SuspectedNode) Clone() SuspectedNode
func (*SuspectedNode) Equals ¶
func (sn *SuspectedNode) Equals(sn2 *SuspectedNode) bool
func (*SuspectedNode) MarshalCanoto ¶
func (c *SuspectedNode) MarshalCanoto() []byte
MarshalCanoto returns the Canoto representation of this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*SuspectedNode) MarshalCanotoInto ¶
func (c *SuspectedNode) MarshalCanotoInto(w canoto.Writer) canoto.Writer
MarshalCanotoInto writes the struct into a canoto.Writer and returns the resulting canoto.Writer. Most users should just use MarshalCanoto.
It is assumed that CalculateCanotoCache has been called since the last modification to this struct.
It is assumed that this struct is ValidCanoto.
It is not safe to copy this struct concurrently.
func (*SuspectedNode) String ¶
func (sn *SuspectedNode) String() string
func (*SuspectedNode) UnmarshalCanoto ¶
func (c *SuspectedNode) UnmarshalCanoto(bytes []byte) error
UnmarshalCanoto unmarshals a Canoto-encoded byte slice into the struct.
During parsing, the canoto cache is saved.
func (*SuspectedNode) UnmarshalCanotoFrom ¶
func (c *SuspectedNode) UnmarshalCanotoFrom(r canoto.Reader) error
UnmarshalCanotoFrom populates the struct from a canoto.Reader. Most users should just use UnmarshalCanoto.
During parsing, the canoto cache is saved.
This function enables configuration of reader options.
func (*SuspectedNode) ValidCanoto ¶
func (c *SuspectedNode) ValidCanoto() bool
ValidCanoto validates that the struct can be correctly marshaled into the Canoto format.
Specifically, ValidCanoto ensures: 1. All OneOfs are specified at most once. 2. All strings are valid utf-8. 3. All custom fields are ValidCanoto.
type SuspectedNodes ¶
type SuspectedNodes []SuspectedNode
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) Size ¶
func (v *ToBeSignedEmptyVote) Size() int
func (*ToBeSignedEmptyVote) Verify ¶
func (v *ToBeSignedEmptyVote) Verify(signature []byte, verifier SignatureVerifier, pk []byte) 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, pk []byte) error
type ToBeSignedVote ¶
type ToBeSignedVote struct {
BlockHeader
}
func ParseNotarizationRecord ¶
func ParseNotarizationRecord(r []byte) ([]byte, ToBeSignedVote, error)
ParseNotarizationRecord parses a notarization record into the bytes of the QC and the vote
func (*ToBeSignedVote) Verify ¶
func (v *ToBeSignedVote) Verify(signature []byte, verifier SignatureVerifier, pk []byte) error
type ValidatorSetApproval ¶
type ValidatorSetApproval struct {
NodeID avalanchego.NodeID
AuxInfoDigest [32]byte
PChainHeight uint64
Signature []byte
}
ValidatorSetApproval is an approval from a validator
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
// Size returns the number of bytes in the encoding of the block
Size() int
// SealingBlockInfo returns a non-nil value for a block that is not a sealing block and that is not the first ever simplex block.
SealingBlockInfo() *SealingBlockInfo
}
type VerifiedBlockMessage ¶
type VerifiedBlockMessage struct {
VerifiedBlock VerifiedBlock
Vote Vote
}
type VerifiedFinalizedBlock ¶
type VerifiedFinalizedBlock struct {
VerifiedBlock VerifiedBlock
Finalization Finalization
}
type VerifiedQuorumRound ¶
type VerifiedQuorumRound struct {
VerifiedBlock VerifiedBlock
Notarization *Notarization
Finalization *Finalization
EmptyNotarization *EmptyNotarization
}
func (*VerifiedQuorumRound) GetRound ¶
func (q *VerifiedQuorumRound) GetRound() uint64
func (*VerifiedQuorumRound) Size ¶
func (q *VerifiedQuorumRound) Size() int
type VerifiedReplicationResponse ¶
type VerifiedReplicationResponse struct {
Data []VerifiedQuorumRound
LatestRound *VerifiedQuorumRound
LatestFinalizedSeq *VerifiedQuorumRound
}
type VerifyConfig ¶
type VerifyConfig struct {
OnlyVM bool
}
type VerifyOptions ¶
type VerifyOptions func(*VerifyConfig)
type VersionID ¶
type VersionID uint32
VersionID is an identifier for applications that care about epoch changes.
type Vote ¶
type Vote struct {
Vote ToBeSignedVote
Signature Signature
}
Vote represents a signed vote for a block.
type WALRetentionReader ¶
type WALRetentionReader struct{}
func (*WALRetentionReader) RetentionTerm ¶
func (wrr *WALRetentionReader) RetentionTerm(entry []byte) (uint64, error)