Documentation
¶
Overview ¶
Package block defines the `Block` type, and all of the related types. This package does not implement any kind of consensus logic; it is concerned with defining data types, and serialization/deserialization of those data types.
Index ¶
- Variables
- func ComputeHash(header Header, txs Txs, plan Plan, prevState State) id.Hash
- type Block
- func (block Block) Equal(other Block) bool
- func (block Block) Hash() id.Hash
- func (block Block) Header() Header
- func (block Block) Marshal(w io.Writer, m int) (int, error)
- func (block Block) MarshalJSON() ([]byte, error)
- func (block Block) Plan() Plan
- func (block Block) PreviousState() State
- func (block Block) SizeHint() int
- func (block Block) String() string
- func (block Block) Txs() Txs
- func (block *Block) Unmarshal(r io.Reader, m int) (int, error)
- func (block *Block) UnmarshalJSON(data []byte) error
- type Blocks
- type Header
- func (header Header) BaseHash() id.Hash
- func (header Header) Height() Height
- func (header Header) Kind() Kind
- func (header Header) Marshal(w io.Writer, m int) (int, error)
- func (header Header) MarshalJSON() ([]byte, error)
- func (header Header) ParentHash() id.Hash
- func (header Header) PlanRef() id.Hash
- func (header Header) PrevStateRef() id.Hash
- func (header Header) Round() Round
- func (header Header) Signatories() id.Signatories
- func (header Header) SizeHint() int
- func (header Header) String() string
- func (header Header) Timestamp() Timestamp
- func (header Header) TxsRef() id.Hash
- func (header *Header) Unmarshal(r io.Reader, m int) (int, error)
- func (header *Header) UnmarshalJSON(data []byte) error
- type Height
- type Kind
- type Plan
- type Round
- type State
- type Timestamp
- type Txs
Constants ¶
This section is empty.
Variables ¶
var ( InvalidHash = id.Hash{} InvalidSignature = id.Signature{} InvalidSignatory = id.Signatory{} InvalidHeader = Header{ // contains filtered or unexported fields } InvalidBlock = Block{ // contains filtered or unexported fields } InvalidRound = Round(-1) InvalidHeight = Height(-1) )
Define some default invalid values.
Functions ¶
func ComputeHash ¶ added in v0.2.0
ComputeHash of a block based on its header, transactions, execution plan and state before execution (i.e. state after execution of its parent). This function returns a hash that can be used when creating a block.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
A Block is the atomic unit upon which consensus is reached. Consensus guarantees a consistent ordering of blocks that is agreed upon by all members in a distributed network, even when some of the members are malicious.
func New ¶
New Block with the Header, Txs, Plan, and State of the Block parent. The Block Hash will automatically be computed and set.
func (Block) MarshalJSON ¶ added in v0.2.0
MarshalJSON is implemented because it is not uncommon that blocks and block headers need to be made available through external APIs.
func (Block) PreviousState ¶ added in v0.2.0
PreviousState embedded in the Block for application-specific state after the execution of the Block parent.
func (Block) SizeHint ¶ added in v0.4.2
SizeHint of how many bytes will be needed to represent a header in binary.
func (Block) String ¶
String implements the `fmt.Stringer` interface for the `Block` type. Two blocks must not have the same string representation, unless the blocks are equal.
func (*Block) UnmarshalJSON ¶ added in v0.2.0
UnmarshalJSON is implemented because it is not uncommon that blocks and block headers need to be made available through external APIs.
type Header ¶ added in v0.2.0
type Header struct {
// contains filtered or unexported fields
}
A Header defines properties of a block that are not application-specific. These properties are required by, or produced by, the consensus algorithm and are not subject modification by the user.
func NewHeader ¶ added in v0.2.0
func NewHeader(kind Kind, parentHash, baseHash, txsRef, planRef, prevStateRef id.Hash, height Height, round Round, timestamp Timestamp, signatories id.Signatories) Header
NewHeader with all pre-conditions and invariants checked. It will panic if a pre-condition or invariant is violated.
func (Header) MarshalJSON ¶ added in v0.2.0
MarshalJSON is implemented because it is not uncommon that blocks and block headers need to be made available through external APIs.
func (Header) ParentHash ¶ added in v0.2.0
ParentHash of the block.
func (Header) PrevStateRef ¶ added in v0.3.0
PrevStateRef of the block.
func (Header) Signatories ¶ added in v0.2.0
func (header Header) Signatories() id.Signatories
Signatories of the block.
func (Header) SizeHint ¶ added in v0.4.2
SizeHint of how many bytes will be needed to represent a header in binary.
func (Header) String ¶ added in v0.2.0
String implements the `fmt.Stringer` interface for the `Header` type. Two headers must not have the same string representation, unless the headers are equal.
func (*Header) UnmarshalJSON ¶ added in v0.2.0
UnmarshalJSON is implemented because it is not uncommon that blocks and block headers need to be made available through external APIs.
type Height ¶
type Height int64
Height of a block.
type Kind ¶ added in v0.2.0
type Kind uint8
Kind defines the different kinds of blocks that exist. This is used for differentiating between blocks that are for consensus on application-specific data, blocks that suggest changing the signatories of a shard, and blocks that change the signatories of a shard.
const ( // Invalid defines an invalid kind that must not be used. Invalid Kind = iota // Standard blocks are used when reaching consensus on the ordering of // application-specific data. Standard blocks must have nil header // signatories. This is the most common block kind. Standard // Rebase blocks are used when reaching consensus about a change to the // header signatories that oversee the consensus algorithm. Rebase blocks // must include non-empty header signatories. Rebase // Base blocks are used to finalise rebase blocks. Base blocks must come // immediately after a rebase block, must have no content, and must have the // same header signatories as their parent. Base )
func (Kind) SizeHint ¶ added in v0.4.2
SizeHint of how many bytes will be needed to represent kindedness in binary.
type Plan ¶ added in v0.3.0
type Plan []byte
Plan stores application-specific data used that is required for the execution of transactions in the block. This plan is usually pre-computed data that is needed by players in the secure multi-party computation. It is separated from transactions for clearer semantic representation (sometimes plans can be needed without transactions, and some transactions can be executed without plans).
func (Plan) SizeHint ¶ added in v0.4.2
SizeHint of how many bytes will be needed to represent a plan in binary.
type Round ¶
type Round int64
Round in which a block was proposed.
type State ¶ added in v0.2.0
type State []byte
State stores application-specific state after the execution of a block. The block at height H+1 will store the state after the execution of block H. This is required because of the nature of execution when using an interactive secure multi-party computations.
func (State) SizeHint ¶ added in v0.4.2
SizeHint of how many bytes will be needed to represent state in binary.
type Timestamp ¶ added in v0.2.0
type Timestamp uint64
Timestamp represents seconds since Unix epoch.
type Txs ¶ added in v0.3.0
type Txs []byte
Txs stores application-specific transaction data used in blocks.
func (Txs) SizeHint ¶ added in v0.4.2
SizeHint of how many bytes will be needed to represent transactions in binary.