Documentation
¶
Index ¶
Constants ¶
const MaxTransactions = 8
MaxTransactions defines the maximum number of transactions allowed in a block.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
Time time.Time
Height Height
Header sig.Hash
ParentHeader sig.Hash
TxHeader sig.Hash
Txs tx.Transactions
}
A Block is the data structure on which consensus must be reached. The Height of a Block should be unique to that Block, otherwise the consensus mechanism is faulty. A Block stores an ordered list of Transactions that will be executed when consensus has been reached on the Block.
func New ¶
New Block with the transaction header, and header, automatically computed and stored in the returned Block.
func (Block) Sign ¶
func (block Block) Sign(signer sig.Signer) (SignedBlock, error)
Sign the header of the Block.
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
func NewBlockchain ¶
func NewBlockchain(store Store) Blockchain
func (*Blockchain) Blocks ¶
func (blockchain *Blockchain) Blocks(begin, end Height) []Commit
func (*Blockchain) Extend ¶
func (blockchain *Blockchain) Extend(commitToNextBlock Commit) error
func (*Blockchain) Head ¶
func (blockchain *Blockchain) Head() (Commit, bool)
func (*Blockchain) Height ¶
func (blockchain *Blockchain) Height() Height
type Commit ¶
type Commit struct {
Polka Polka
Signatures sig.Signatures
Signatories sig.Signatories
}
type CommitBuilder ¶
type CommitBuilder map[Height]map[Round]map[sig.Signatory]SignedPreCommit
CommitBuilder is used to build up collections of SignedPreCommits at different Heights and Rounds and then build Commits wherever there are enough SignedPreCommits to do so.
func NewCommitBuilder ¶
func NewCommitBuilder() CommitBuilder
func (CommitBuilder) Commit ¶
func (builder CommitBuilder) Commit(height Height, consensusThreshold int) (*Commit, *Round)
Commit returns a Commit and the latest Round for which there are 2/3rd+ pre-commits. The Commit will be nil unless there is 2/3rds+ pre-commits for nil or a specific SignedBlock. The Round will be nil unless there are 2/3rds+ pre-commits for a specific Round. If a Commit is returned, the Round will match the Commit.
func (CommitBuilder) Drop ¶
func (builder CommitBuilder) Drop(fromHeight Height)
func (CommitBuilder) Insert ¶
func (builder CommitBuilder) Insert(preCommit SignedPreCommit) bool
Insert a SignedPreCommit into the CommitBuilder. This will include the SignedPreCommit in all attempts to build a Commit for the respective Height.
type Polka ¶
type Polka struct {
Block *SignedBlock
Round Round
Height Height
Signatures sig.Signatures
Signatories sig.Signatories
}
Polka is created when 2/3 of the nodes have all PreVoted for a given block. The Signatures are expected to be ordered to match the order of the Signatories.
type PolkaBuilder ¶
type PolkaBuilder map[Height]map[Round]map[sig.Signatory]SignedPreVote
PolkaBuilder is used to build up collections of SignedPreVotes at different Heights and Rounds and then build Polkas wherever there are enough SignedPreVotes to do so.
func NewPolkaBuilder ¶
func NewPolkaBuilder() PolkaBuilder
func (PolkaBuilder) Drop ¶
func (builder PolkaBuilder) Drop(dropHeight Height)
Drop removes all SignedPreVotes below the given Height.
func (PolkaBuilder) Insert ¶
func (builder PolkaBuilder) Insert(preVote SignedPreVote) bool
Insert a SignedPreVote into the PolkaBuilder. This will include the SignedPreVote in all attempts to build a Polka for the respective Height.
func (PolkaBuilder) Polka ¶
func (builder PolkaBuilder) Polka(height Height, consensusThreshold int) (*Polka, *Round)
Polka returns a Polka and the latest Round for which there are 2/3rd+ pre-votes. The Polka will be nil unless there is 2/3rds+ pre-votes for nil or a specific SignedBlock. The Round will be nil unless there are 2/3rds+ pre-votes for a specific Round. If a Polka is returned, the Round will match the Polka.
type PreCommit ¶
type PreCommit struct {
Polka Polka
}
type PreVote ¶
type PreVote struct {
Block *SignedBlock
Round Round
Height Height
}
PreVote is you voting for the encapsulated block to be added during this round at this height. It is a PreVoteNil when the block is nil.
func NewPreVote ¶
func NewPreVote(block *SignedBlock, round Round, height Height) PreVote
NewPreVote creates a PreVote
type Propose ¶
type Propose struct {
Block SignedBlock
Round Round
ValidRound Round // TODO: (Review) This name comes from the pseudocode in (https://arxiv.org/pdf/1807.04938.pdf). Should this be renamed to something more appropriate?
LastCommit *Commit
}
type SignedBlock ¶
A SignedBlock is a Block associated with a Signature and a Signatory. The Signature is generated by signing the Block header.
func Genesis ¶
func Genesis() SignedBlock
Genesis returns the genesis SignedBlock. The Signature and Signatory is empty, and all other values are non-nil zero values.
func (SignedBlock) String ¶
func (signedBlock SignedBlock) String() string
String implements the Stringer interface for the SignedBlock type.
type SignedPreCommit ¶
func (SignedPreCommit) String ¶
func (signedPreCommit SignedPreCommit) String() string
type SignedPreVote ¶
SignedPreVote is the signed version of a PreVote
func (SignedPreVote) String ¶
func (signedPreVote SignedPreVote) String() string
type SignedPropose ¶
type Store ¶
type Store interface {
// InsertBlock stores a committed SignedBlock to persistent storage.
InsertBlock(commit Commit) error
// Block returns a committed SignedBlock from persistent storage. An error
// is returned when there is no SignedBlock committed at the given Height.
Block(height Height) (Commit, error)
// Height returns the latest Height that has been seen when inserting a
// Block. An error is returned when there is no Height.
Height() (Height, error)
}