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 ¶
- func RegisterBlockFormat(f serde.Format, e serde.FormatEngine)
- func RegisterChainFormat(f serde.Format, e serde.FormatEngine)
- func RegisterGenesisFormat(f serde.Format, e serde.FormatEngine)
- func RegisterLinkFormat(f serde.Format, e serde.FormatEngine)
- func RegisterMessageFormat(f serde.Format, e serde.FormatEngine)
- type AddressKey
- type AggregateKey
- type Block
- func (b Block) Fingerprint(w io.Writer) error
- func (b Block) GetData() validation.Result
- func (b Block) GetHash() Digest
- func (b Block) GetIndex() uint64
- func (b Block) GetTransactions() []txn.Transaction
- func (b Block) GetTreeRoot() Digest
- func (b Block) Serialize(ctx serde.Context) ([]byte, error)
- type BlockFactory
- type BlockKey
- type BlockLink
- type BlockMessage
- type BlockOption
- type Chain
- type ChainFactory
- type ChangeSetKey
- type CommitMessage
- type DataKey
- type Digest
- type DoneMessage
- type Genesis
- type GenesisFactory
- type GenesisKey
- type GenesisMessage
- type GenesisOption
- type Link
- type LinkFactory
- type LinkKey
- type LinkOption
- type MessageFactory
- type RosterKey
- type SignatureKey
- type ViewMessage
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 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 ¶
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) GetTransactions ¶
func (b Block) GetTransactions() []txn.Transaction
GetTransactions is a helper to extract the transactions from the validation result.
func (Block) GetTreeRoot ¶
GetTreeRoot returns the tree root 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 ¶
Deserialize implements serde.Factory. It populates the block from the data if appropriate, otherwise it returns an error.
type BlockLink ¶
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 ¶
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.
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.
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 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.
type Digest ¶
type Digest [32]byte
Digest defines the result of a fingerprint. It expects a digest of 256 bits.
- implements fmt.Stringer
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.
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 ¶
Fingerprint implements serde.Fingerprinter. It deterministically writes a binary representation of the genesis block into the writer.
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 ¶
Deserialize implements serde.Factory. It populates the genesis block if appropriate, otherwise it returns an error.
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.
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 ¶
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 ¶
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 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 ¶
Deserialize implements serde.Factory. It populates the message if appropriate, otherwise it returns an error.
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.