block

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

func New(height Height, parentHeader sig.Hash, txs tx.Transactions) Block

New Block with the transaction header, and header, automatically computed and stored in the returned Block.

func (Block) Equal

func (block Block) Equal(other Block) bool

Equal checks for equality between the heights, headers, and parent headers.

func (*Block) Read

func (block *Block) Read(r io.Reader) error

func (Block) Sign

func (block Block) Sign(signer sig.Signer) (SignedBlock, error)

Sign the header of the Block.

func (Block) String

func (block Block) String() string

String implements the Stringer interface for the Block type.

func (Block) Write

func (block Block) Write(w io.Writer) error

type Blockchain

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

func NewBlockchain

func NewBlockchain(store Store) Blockchain

func (*Blockchain) Block

func (blockchain *Blockchain) Block(height Height) (Commit, bool)

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
}

func (*Commit) Read

func (commit *Commit) Read(r io.Reader) error

func (Commit) String

func (commit Commit) String() string

func (Commit) Write

func (commit Commit) Write(w io.Writer) error

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 Height

type Height int64

The Height at which a `Block` was proposed.

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.

func (Polka) Equal

func (polka Polka) Equal(other *Polka) bool

Equal checks that two Polka are functionally equivalent

func (*Polka) Read

func (polka *Polka) Read(r io.Reader) error

func (Polka) String

func (polka Polka) String() string

func (Polka) Write

func (polka Polka) Write(w io.Writer) error

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
}

func (*PreCommit) Read

func (preCommit *PreCommit) Read(r io.Reader) error

func (PreCommit) Sign

func (preCommit PreCommit) Sign(signer sig.Signer) (SignedPreCommit, error)

Sign a PreCommit with your private key

func (PreCommit) String

func (preCommit PreCommit) String() string

func (PreCommit) Write

func (preCommit PreCommit) Write(w io.Writer) error

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

func (*PreVote) Read

func (preVote *PreVote) Read(r io.Reader) error

func (PreVote) Sign

func (preVote PreVote) Sign(signer sig.Signer) (SignedPreVote, error)

Sign is indented to be the way you sign your PreVote with your private key

func (PreVote) String

func (preVote PreVote) String() string

func (PreVote) Write

func (preVote PreVote) Write(w io.Writer) error

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
}

func (*Propose) Read

func (propose *Propose) Read(r io.Reader) error

func (Propose) Sign

func (propose Propose) Sign(signer sig.Signer) (SignedPropose, error)

Sign a Propose with your private key

func (Propose) String

func (propose Propose) String() string

func (Propose) Write

func (propose Propose) Write(w io.Writer) error

type Round

type Round int64

The Round in which a `Block` was proposed.

type SignedBlock

type SignedBlock struct {
	Block

	Signature sig.Signature
	Signatory sig.Signatory
}

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) Read

func (signedBlock *SignedBlock) Read(r io.Reader) error

func (SignedBlock) String

func (signedBlock SignedBlock) String() string

String implements the Stringer interface for the SignedBlock type.

func (SignedBlock) Write

func (signedBlock SignedBlock) Write(w io.Writer) error

type SignedPreCommit

type SignedPreCommit struct {
	PreCommit
	Signature sig.Signature
	Signatory sig.Signatory
}

func (*SignedPreCommit) Read

func (signedPreCommit *SignedPreCommit) Read(r io.Reader) error

func (SignedPreCommit) String

func (signedPreCommit SignedPreCommit) String() string

func (SignedPreCommit) Write

func (signedPreCommit SignedPreCommit) Write(w io.Writer) error

type SignedPreVote

type SignedPreVote struct {
	PreVote
	Signature sig.Signature
	Signatory sig.Signatory
}

SignedPreVote is the signed version of a PreVote

func (*SignedPreVote) Read

func (signedPreVote *SignedPreVote) Read(r io.Reader) error

func (SignedPreVote) String

func (signedPreVote SignedPreVote) String() string

func (SignedPreVote) Write

func (signedPreVote SignedPreVote) Write(w io.Writer) error

type SignedPropose

type SignedPropose struct {
	Propose

	Signature sig.Signature
	Signatory sig.Signatory
}

func (*SignedPropose) Read

func (signedPropose *SignedPropose) Read(r io.Reader) error

func (SignedPropose) Write

func (signedPropose SignedPropose) Write(w io.Writer) error

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)
}

Jump to

Keyboard shortcuts

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