types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 12 Imported by: 4

Documentation

Overview

Package types implements the network messages for cosipbft.

The messages are implemented in a different package to prevent cycle imports when importing the serde formats.

Documentation Last Review: 13.10.2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterBlockFormat

func RegisterBlockFormat(f serde.Format, e serde.FormatEngine)

RegisterBlockFormat registers the engine for the provided format.

func RegisterChainFormat

func RegisterChainFormat(f serde.Format, e serde.FormatEngine)

RegisterChainFormat registers the engine for the provided format.

func RegisterGenesisFormat

func RegisterGenesisFormat(f serde.Format, e serde.FormatEngine)

RegisterGenesisFormat registers the engine for the provided format.

func RegisterLinkFormat

func RegisterLinkFormat(f serde.Format, e serde.FormatEngine)

RegisterLinkFormat registers the engine for the provided format.

func RegisterMessageFormat

func RegisterMessageFormat(f serde.Format, e serde.FormatEngine)

RegisterMessageFormat registers the engine for the provided format.

Types

type AddressKey

type AddressKey struct{}

AddressKey is the key of the address factory.

type AggregateKey

type AggregateKey struct{}

AggregateKey is the key of the collective signature factory.

type Block

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

Block is a block of a chain. It holds an index which is the height of the block from the genesis block, the Merkle tree root and the validation result of the transactions.

- implements serde.Message

func NewBlock

func NewBlock(data validation.Result, opts ...BlockOption) (Block, error)

NewBlock creates a new block.

func (Block) Fingerprint

func (b Block) Fingerprint(w io.Writer) error

Fingerprint implements serde.Fingerprinter. It deterministically writes a binary representation of the block into the writer.

func (Block) GetData

func (b Block) GetData() validation.Result

GetData returns the validated data of the block.

func (Block) GetHash

func (b Block) GetHash() Digest

GetHash returns the digest of the block.

func (Block) GetIndex

func (b Block) GetIndex() uint64

GetIndex returns the index of the block.

func (Block) GetTransactions

func (b Block) GetTransactions() []txn.Transaction

GetTransactions is a helper to extract the transactions from the validation result.

func (Block) GetTreeRoot

func (b Block) GetTreeRoot() Digest

GetTreeRoot returns the tree root of the block.

func (Block) Serialize

func (b Block) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data of the block.

type BlockFactory

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

BlockFactory is a factory to deserialize block messages.

- implements serde.Factory

func NewBlockFactory

func NewBlockFactory(fac validation.ResultFactory) BlockFactory

NewBlockFactory creates a new block factory.

func (BlockFactory) Deserialize

func (f BlockFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error)

Deserialize implements serde.Factory. It populates the block from the data if appropriate, otherwise it returns an error.

type BlockKey

type BlockKey struct{}

BlockKey is the key of the block factory.

type BlockLink interface {
	Link

	// GetBlock returns the block the link is pointing at.
	GetBlock() Block

	// Reduce returns the forward link equivalent to this block link but without
	// the block to allow a lighter serialization.
	Reduce() Link
}

BlockLink is an extension of the Link interface to include the block the link is pointing at. It also provides a function to get a lighter link without the block.

func NewBlockLink(from Digest, to Block, opts ...LinkOption) (BlockLink, error)

NewBlockLink creates a new block link between from and to.

type BlockMessage

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

BlockMessage is a message sent to participants to share a block.

- implements serde.Message

func NewBlockMessage

func NewBlockMessage(block Block, views map[mino.Address]ViewMessage) BlockMessage

NewBlockMessage creates a new block message with the provided block.

func (BlockMessage) GetBlock

func (m BlockMessage) GetBlock() Block

GetBlock returns the block of the message.

func (BlockMessage) GetViews

func (m BlockMessage) GetViews() map[mino.Address]ViewMessage

GetViews returns the view messages if any.

func (BlockMessage) Serialize

func (m BlockMessage) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data of the block.

type BlockOption

type BlockOption func(*blockTemplate)

BlockOption is the type of option to set some fields of a block.

func WithHashFactory

func WithHashFactory(fac crypto.HashFactory) BlockOption

WithHashFactory is an option to set the hash factory for the block.

func WithIndex

func WithIndex(index uint64) BlockOption

WithIndex is an option to set the index of the block.

func WithTreeRoot

func WithTreeRoot(root Digest) BlockOption

WithTreeRoot is an option to set the tree root for the block.

type Chain

type Chain interface {
	serde.Message

	// GetLinks returns all the links that defines the chain in order.
	GetLinks() []Link

	// GetBlock returns the latest block that the chain is pointing at.
	GetBlock() Block

	// Verify takes the genesis block and the verifier factory that should
	// verify the chain. Performs the verification starting at the link Digest.
	Verify(genesis Genesis, from Digest, fac crypto.VerifierFactory) error
}

Chain is the interface to combine several links in order to create a chain that can prove the integrity of the blocks from the genesis block.

func NewChain

func NewChain(last BlockLink, prevs []Link) Chain

NewChain creates a new chain from the block link and the previous forward links.

type ChainFactory

type ChainFactory interface {
	serde.Factory

	// ChainOf returns the chain from the data if appropriate, otherwise it
	// returns an error.
	ChainOf(serde.Context, []byte) (Chain, error)
}

ChainFactory is the interface to serialize and deserialize chains.

func NewChainFactory

func NewChainFactory(fac LinkFactory) ChainFactory

NewChainFactory creates a new factory from the link factory.

type ChangeSetKey

type ChangeSetKey struct{}

ChangeSetKey is the key of the change set factory.

type CommitMessage

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

CommitMessage is a message containing the signature of the prepare phase of a PBFT execution.

- implements serde.Message

func NewCommit

func NewCommit(id Digest, sig crypto.Signature) CommitMessage

NewCommit creates a new commit message.

func (CommitMessage) GetID

func (m CommitMessage) GetID() Digest

GetID returns the block digest to commit.

func (CommitMessage) GetSignature

func (m CommitMessage) GetSignature() crypto.Signature

GetSignature returns the prepare signature.

func (CommitMessage) Serialize

func (m CommitMessage) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data of the commit message.

type DataKey

type DataKey struct{}

DataKey is the key for the validated data factory.

type Digest

type Digest [32]byte

Digest defines the result of a fingerprint. It expects a digest of 256 bits.

- implements fmt.Stringer

func (Digest) Bytes

func (d Digest) Bytes() []byte

Bytes return the bytes of the digest.

func (Digest) String

func (d Digest) String() string

String implements fmt.Stringer. It returns a short representation of the digest.

type DoneMessage

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

DoneMessage is a message containing the signature of the commit phase of a PBFT execution.

- implements serde.Message

func NewDone

func NewDone(id Digest, sig crypto.Signature) DoneMessage

NewDone creates a new done message.

func (DoneMessage) GetID

func (m DoneMessage) GetID() Digest

GetID returns the digest of the block that has been accepted.

func (DoneMessage) GetSignature

func (m DoneMessage) GetSignature() crypto.Signature

GetSignature returns the commit signature that proves the commitment of the block.

func (DoneMessage) Serialize

func (m DoneMessage) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data of the done message.

type Genesis

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

Genesis is the very first block of a chain. It contains the initial roster and tree root.

- implements serde.Message

func NewGenesis

func NewGenesis(ro authority.Authority, opts ...GenesisOption) (Genesis, error)

NewGenesis creates a new genesis block with the provided roster.

func (Genesis) Fingerprint

func (g Genesis) Fingerprint(w io.Writer) error

Fingerprint implements serde.Fingerprinter. It deterministically writes a binary representation of the genesis block into the writer.

func (Genesis) GetHash

func (g Genesis) GetHash() Digest

GetHash returns the digest of the block.

func (Genesis) GetRoot

func (g Genesis) GetRoot() Digest

GetRoot returns the tree root.

func (Genesis) GetRoster

func (g Genesis) GetRoster() authority.Authority

GetRoster returns the roster of the genesis block.

func (Genesis) Serialize

func (g Genesis) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data for this genesis block.

type GenesisFactory

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

GenesisFactory is a factory to deserialize the genesis messages.

- implements serde.Factory

func NewGenesisFactory

func NewGenesisFactory(rf authority.Factory) GenesisFactory

NewGenesisFactory creates a new genesis factory.

func (GenesisFactory) Deserialize

func (f GenesisFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error)

Deserialize implements serde.Factory. It populates the genesis block if appropriate, otherwise it returns an error.

type GenesisKey

type GenesisKey struct{}

GenesisKey is the key of the genesis factory.

type GenesisMessage

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

GenesisMessage is a message to send a genesis to distant participants.

- implements serde.Message

func NewGenesisMessage

func NewGenesisMessage(genesis Genesis) GenesisMessage

NewGenesisMessage creates a new genesis message.

func (GenesisMessage) GetGenesis

func (m GenesisMessage) GetGenesis() *Genesis

GetGenesis returns the genesis block contained in the message.

func (GenesisMessage) Serialize

func (m GenesisMessage) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data for this message.

type GenesisOption

type GenesisOption func(*genesisTemplate)

GenesisOption is the option type to set some fields of a genesis block.

func WithGenesisHashFactory

func WithGenesisHashFactory(fac crypto.HashFactory) GenesisOption

WithGenesisHashFactory is an option to set the hash factory.

func WithGenesisRoot

func WithGenesisRoot(root Digest) GenesisOption

WithGenesisRoot is an option to set the tree root of the genesis block.

type Link interface {
	serde.Message
	serde.Fingerprinter

	// GetHash returns the digest of the forward link that is signed with the
	// prepare signature.
	GetHash() Digest

	// GetFrom returns the digest of the previous block.
	GetFrom() Digest

	// GetTo returns the digest of the block the link is pointing at.
	GetTo() Digest

	// GetPrepareSignature returns the signature that proves the integrity of
	// the link.
	GetPrepareSignature() crypto.Signature

	// GetCommitSignature returns the signature that proves the block has been
	// committed.
	GetCommitSignature() crypto.Signature

	// GetChangeSet returns the roster change set for this link.
	GetChangeSet() authority.ChangeSet
}

Link is the interface of a link between two blocks.

func NewForwardLink(from, to Digest, opts ...LinkOption) (Link, error)

NewForwardLink creates a new forward link between the two block digests.

type LinkFactory

type LinkFactory interface {
	serde.Factory

	LinkOf(serde.Context, []byte) (Link, error)

	BlockLinkOf(serde.Context, []byte) (BlockLink, error)
}

LinkFactory is the interface of the block link factory.

func NewLinkFactory

func NewLinkFactory(
	blockFac serde.Factory,
	sigFac crypto.SignatureFactory, csFac authority.ChangeSetFactory,
) LinkFactory

NewLinkFactory creates a new block link factory.

type LinkKey

type LinkKey struct{}

LinkKey is the key of the link factory.

type LinkOption

type LinkOption func(*linkTemplate)

LinkOption is the type of option to set some optional fields of the link.

func WithChangeSet

func WithChangeSet(cs authority.ChangeSet) LinkOption

WithChangeSet is the option to set the change set of the roster for this link.

func WithLinkHashFactory

func WithLinkHashFactory(fac crypto.HashFactory) LinkOption

WithLinkHashFactory is the option to set the hash factory for the link.

func WithSignatures

func WithSignatures(prep, commit crypto.Signature) LinkOption

WithSignatures is the option to set the signatures of the link.

type MessageFactory

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

MessageFactory is the factory to deserialize messages.

- implements serde.Factory

func NewMessageFactory

func NewMessageFactory(gf, bf serde.Factory, addrFac mino.AddressFactory,
	aggFac crypto.SignatureFactory, csf authority.ChangeSetFactory) MessageFactory

NewMessageFactory creates a new message factory.

func (MessageFactory) Deserialize

func (f MessageFactory) Deserialize(ctx serde.Context, data []byte) (serde.Message, error)

Deserialize implements serde.Factory. It populates the message if appropriate, otherwise it returns an error.

type RosterKey

type RosterKey struct{}

RosterKey is the key of the roster factory.

type SignatureKey

type SignatureKey struct{}

SignatureKey is the key of the view signature factory.

type ViewMessage

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

ViewMessage is a message to announce a view change request.

- implements serde.Message

func NewViewMessage

func NewViewMessage(id Digest, leader uint16, sig crypto.Signature) ViewMessage

NewViewMessage creates a new view message.

func (ViewMessage) GetID

func (m ViewMessage) GetID() Digest

GetID returns the digest of the latest block.

func (ViewMessage) GetLeader

func (m ViewMessage) GetLeader() uint16

GetLeader returns the leader index of the view change.

func (ViewMessage) GetSignature

func (m ViewMessage) GetSignature() crypto.Signature

GetSignature returns the signature of the view.

func (ViewMessage) Serialize

func (m ViewMessage) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data for this view message.

Jump to

Keyboard shortcuts

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