Documentation
¶
Overview ¶
Package hotstuff defines the core types and interfaces that implement the HotStuff protocol. These interfaces allow us to split the implementations into different modules, and each module can have multiple can have multiple implementations.
The following diagram illustrates the relationships between these interfaces:
OnDeliver()------------------------+
| +--------------+
OnPropose()---------------------+ | +--Accept()--->| Acceptor |
| | | +--------------+
OnVote()---------------------+ | | |
| | | | +--------------+
OnNewView()---------------+ | | | | +--Exec()-->| Executor |
| | | | | | +--------------+
v v v v | |
+--------------+ +-------------------------+ +------------------+
| | | |<--Propose()------| |
| |<--------Sign()--------| | | |
| Signer | | |<--NewView()------| |
| |<--CreateQuorumCert()--| | | |
| | | |---OnPropose()--->| ViewSynchronizer |
+--------------+ | | | |
| Consensus |---OnNewView()--->| |
+--------------+ | | | |
| | | |---OnFinishQC()-->| |
| |<--VerifyQuorumCert()--| | +------------------+
| Verifier | | | |
| |<-VerifyPartialCert()--| | |
| | | |-------GetLeader()------------+
+--------------+ +-------------------------+ |
| | | | | | v
+----------------+ | | | | | | +----------------+
| |<----Propose()---------+ | | | | | | LeaderRotation |
| | | | | | | +----------------+
| |<----Vote()---------------+ | | | |
| Config/Replica | | | | | +----------------+
| |<----NewView()---------------+ | | +-Store()---->| |
| | | | | BlockChain |
| |<----Fetch()--------------------+ +----Get()------>| |
+----------------+ +----------------+
The `Consensus` interface is the "core" of the system, and it is the part that implements the consensus algorithm. The `OnDeliver()`, `OnPropose()`, `OnVote()`, and `OnNewView()` methods should be called by some backend service to deliver messages to the Consensus algorithm. The `Server` struct in the `backend/gorums` package is an example of such a service.
Index ¶
- type Acceptor
- type Block
- type BlockChain
- type Command
- type CommandQueue
- type Config
- type Consensus
- type Credentials
- type Executor
- type Hash
- type ID
- type LeaderRotation
- type NewView
- type PartialCert
- type PrivateKey
- type PublicKey
- type QuorumCert
- type Replica
- type Signature
- type Signer
- type ToBytes
- type Verifier
- type View
- type ViewSynchronizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶ added in v0.2.0
type Acceptor interface {
// Accept returns true if the replica should accept the command, false otherwise
Accept(Command) bool
}
Acceptor is the mechanism that decides wether a command should be accepted by the replica
type Block ¶ added in v0.2.0
type Block struct {
// contains filtered or unexported fields
}
func GetGenesis ¶ added in v0.2.0
func GetGenesis() *Block
Genesis returns a pointer to the genesis block, the starting point for the hotstuff blockchain
func (*Block) QuorumCert ¶ added in v0.2.0
func (b *Block) QuorumCert() QuorumCert
Certificate returns the certificate that this Block references
type BlockChain ¶ added in v0.2.0
type BlockChain interface {
// Store stores a block in the blockchain
Store(*Block)
// Get retrieves a block given its hash
Get(Hash) (*Block, bool)
}
BlockChain is a datastructure that stores a chain of blocks
type Command ¶ added in v0.2.0
type Command string
Command is a client request to be executed by the consensus protocol
type CommandQueue ¶ added in v0.2.0
type CommandQueue interface {
// GetCommand returns the next command to be proposed.
GetCommand() *Command
}
CommandQueue is a queue of commands to be proposed
type Config ¶ added in v0.2.0
type Config interface {
// ID returns the id of this replica
ID() ID
// PrivateKey returns the id of this replica
PrivateKey() PrivateKey
// Replicas returns all of the replicas in the configuration
Replicas() map[ID]Replica
// Replica returns a replica if present in the configuration
Replica(ID) (replica Replica, ok bool)
// Len returns the number of replicas in the configuration
Len() int
// QuorumSize returns the size of a quorum
QuorumSize() int
// Propose sends the block to all replicas in the configuration
Propose(block *Block)
// Fetch requests a block from all the replicas in the configuration
Fetch(ctx context.Context, hash Hash)
}
Config holds information about Replicas and provides methods to send messages to the replicas
type Consensus ¶ added in v0.2.0
type Consensus interface {
// Config returns the configuration of this replica
Config() Config
// LastVote returns the view in which the replica last voted
LastVote() View
// HighQC returns the highest QC known to the replica
HighQC() QuorumCert
// Leaf returns the last proposed block
Leaf() *Block
// BlockChain returns the datastructure containing the blocks known to the replica
BlockChain() BlockChain
// CreateDummy inserts a dummy block at View+1.
// This is useful when a view must be skipped.
CreateDummy()
// Propose starts a new proposal
Propose()
// NewView sends a NewView message to the next leader
NewView()
// OnPropose handles an incoming proposal
OnPropose(block *Block)
// OnVote handles an incoming vote
OnVote(cert PartialCert)
// OnNewView handles an incoming NewView
OnNewView(msg NewView)
// OnDeliver handles an incoming block
OnDeliver(block *Block)
}
Consensus implements a consensus protocol
type Credentials ¶ added in v0.2.0
type Credentials interface{}
Credentials are used to authenticate communication between replicas
type Executor ¶ added in v0.2.0
type Executor interface {
// Exec executes the given command
Exec(Command)
}
Executor executes a command
type LeaderRotation ¶ added in v0.2.0
type LeaderRotation interface {
// GetLeader returns the id of the leader in the given view
GetLeader(View) ID
}
LeaderRotation implements a leader rotation scheme
type NewView ¶ added in v0.2.0
type NewView struct {
// The ID of the replica who sent the message
ID ID
// The view that the replica wants to enter
View View
// The quorum certificate
QC QuorumCert
}
NewView represents a new-view message
type PartialCert ¶ added in v0.2.0
type PartialCert interface {
ToBytes
// Signature returns the signature
Signature() Signature
// BlockHash returns the hash of the block that was signed
BlockHash() Hash
}
PartialCert is a certificate for a block created by a single replica
type PrivateKey ¶ added in v0.2.0
type PrivateKey interface {
// PublicKey returns the public key associated with this private key
PublicKey() PublicKey
}
PrivateKey is the private part of a replica's key pair
type PublicKey ¶ added in v0.2.0
type PublicKey interface{}
PublicKey is the public part of a replica's key pair
type QuorumCert ¶ added in v0.2.0
type QuorumCert interface {
ToBytes
// BlockHash returns the hash of the block for which the certificate was created
BlockHash() Hash
}
QuorumCert is a certificate for a Block created by a quorum of replicas
type Replica ¶ added in v0.2.0
type Replica interface {
// ID returns the replica's id
ID() ID
// PublicKey returns the replica's public key
PublicKey() PublicKey
// Vote sends the partial certificate to the other replica
Vote(cert PartialCert)
// NewView sends the quorum certificate to the other replica
NewView(msg NewView)
// Deliver sends the block to the other replica
Deliver(block *Block)
}
Replica implements the methods that communicate with another replica
type Signature ¶ added in v0.2.0
type Signature interface {
ToBytes
// Signer returns the ID of the replica that generated the signature.
Signer() ID
}
Signature is a signature of a block
type Signer ¶ added in v0.2.0
type Signer interface {
// Sign signs a single block and returns the signature
Sign(block *Block) (cert PartialCert, err error)
// CreateQuourmCert creates a from a list of partial certificates
CreateQuorumCert(block *Block, signatures []PartialCert) (cert QuorumCert, err error)
}
Signer implements the methods requried to create signatures and certificates
type ToBytes ¶ added in v0.2.0
type ToBytes interface {
// ToBytes returns the object as bytes
ToBytes() []byte
}
ToBytes is an object that can be converted into bytes for the purposes of hashing, etc.
type Verifier ¶ added in v0.2.0
type Verifier interface {
// VerifyPartialCert verifies a single partial certificate
VerifyPartialCert(cert PartialCert) bool
// VerifyQuorumCert verifies a quorum certificate
VerifyQuorumCert(qc QuorumCert) bool
}
Verifier implements the methods required to verify partial and quorum certificates
type ViewSynchronizer ¶ added in v0.2.0
type ViewSynchronizer interface {
LeaderRotation
// OnPropose should be called when a replica has received a new valid proposal.
OnPropose()
// OnFinishQC should be called when a replica has created a new qc
OnFinishQC()
// OnNewView should be called when a replica receives a valid NewView message
OnNewView()
// Init gives the synchronizer a consensus instance to synchronize
Init(Consensus)
// Start starts the synchronizer
Start()
// Stop stops the synchronizer
Stop()
}
ViewSynchronizer synchronizes replicas to the same view
Directories
¶
| Path | Synopsis |
|---|---|
|
backend
|
|
|
cmd
|
|
|
hotstuffclient
command
|
|
|
hotstuffkeygen
command
|
|
|
hotstuffserver
command
|
|
|
consensus
|
|
|
internal
|
|
|
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |