block

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

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

func ComputeHash(header Header, txs Txs, plan Plan, prevState State) id.Hash

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

func New(header Header, txs Txs, plan Plan, prevState State) Block

New Block with the Header, Txs, Plan, and State of the Block parent. The Block Hash will automatically be computed and set.

func (Block) Equal

func (block Block) Equal(other Block) bool

Equal compares one block with another.

func (Block) Hash added in v0.2.0

func (block Block) Hash() id.Hash

Hash returns the 256-bit SHA2 Hash of the Header and Data.

func (Block) Header

func (block Block) Header() Header

Header of the Block.

func (Block) Marshal added in v0.4.2

func (block Block) Marshal(w io.Writer, m int) (int, error)

Marshal this block into binary.

func (Block) MarshalJSON added in v0.2.0

func (block Block) MarshalJSON() ([]byte, error)

MarshalJSON is implemented because it is not uncommon that blocks and block headers need to be made available through external APIs.

func (Block) Plan added in v0.3.0

func (block Block) Plan() Plan

Plan embedded in the Block for application-specific purposes.

func (Block) PreviousState added in v0.2.0

func (block Block) PreviousState() State

PreviousState embedded in the Block for application-specific state after the execution of the Block parent.

func (Block) SizeHint added in v0.4.2

func (block Block) SizeHint() int

SizeHint of how many bytes will be needed to represent a header in binary.

func (Block) String

func (block Block) String() 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) Txs

func (block Block) Txs() Txs

Txs embedded in the Block for application-specific purposes.

func (*Block) Unmarshal added in v0.4.2

func (block *Block) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal into this block from binary.

func (*Block) UnmarshalJSON added in v0.2.0

func (block *Block) UnmarshalJSON(data []byte) error

UnmarshalJSON is implemented because it is not uncommon that blocks and block headers need to be made available through external APIs.

type Blocks added in v0.2.0

type Blocks []Block

Blocks is a wrapper around the `[]Block` type.

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) BaseHash added in v0.2.0

func (header Header) BaseHash() id.Hash

BaseHash of the block.

func (Header) Height added in v0.2.0

func (header Header) Height() Height

Height of the block.

func (Header) Kind added in v0.2.0

func (header Header) Kind() Kind

Kind of the block.

func (Header) Marshal added in v0.4.2

func (header Header) Marshal(w io.Writer, m int) (int, error)

Marshal this header into binary.

func (Header) MarshalJSON added in v0.2.0

func (header Header) MarshalJSON() ([]byte, error)

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

func (header Header) ParentHash() id.Hash

ParentHash of the block.

func (Header) PlanRef added in v0.3.0

func (header Header) PlanRef() id.Hash

PlanRef of the block.

func (Header) PrevStateRef added in v0.3.0

func (header Header) PrevStateRef() id.Hash

PrevStateRef of the block.

func (Header) Round added in v0.2.0

func (header Header) Round() Round

Round 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

func (header Header) SizeHint() int

SizeHint of how many bytes will be needed to represent a header in binary.

func (Header) String added in v0.2.0

func (header Header) String() string

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) Timestamp added in v0.2.0

func (header Header) Timestamp() Timestamp

Timestamp of the block in seconds since Unix epoch.

func (Header) TxsRef added in v0.3.0

func (header Header) TxsRef() id.Hash

TxsRef of the block.

func (*Header) Unmarshal added in v0.4.2

func (header *Header) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal into this header from binary.

func (*Header) UnmarshalJSON added in v0.2.0

func (header *Header) UnmarshalJSON(data []byte) error

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.

func (Height) Marshal added in v0.4.2

func (h Height) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (Height) SizeHint added in v0.4.2

func (h Height) SizeHint() int

SizeHint of how many bytes will be needed to represent height in binary.

func (*Height) Unmarshal added in v0.4.2

func (h *Height) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from binary.

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) Marshal added in v0.4.2

func (kind Kind) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (Kind) SizeHint added in v0.4.2

func (kind Kind) SizeHint() int

SizeHint of how many bytes will be needed to represent kindedness in binary.

func (Kind) String added in v0.2.0

func (kind Kind) String() string

String implements the `fmt.Stringer` interface for the `Kind` type.

func (*Kind) Unmarshal added in v0.4.2

func (kind *Kind) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from 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) Hash added in v0.3.0

func (plan Plan) Hash() id.Hash

Hash the plan using SHA256.

func (Plan) Marshal added in v0.4.2

func (plan Plan) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (Plan) SizeHint added in v0.4.2

func (plan Plan) SizeHint() int

SizeHint of how many bytes will be needed to represent a plan in binary.

func (Plan) String added in v0.3.0

func (plan Plan) String() string

String implements the `fmt.Stringer` interface for the `Plan` type.

func (*Plan) Unmarshal added in v0.4.2

func (plan *Plan) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from binary.

type Round

type Round int64

Round in which a block was proposed.

func (Round) Marshal added in v0.4.2

func (round Round) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (Round) SizeHint added in v0.4.2

func (round Round) SizeHint() int

SizeHint of how many bytes will be needed to represent time in binary.

func (*Round) Unmarshal added in v0.4.2

func (round *Round) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from binary.

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) Hash added in v0.3.0

func (state State) Hash() id.Hash

Hash the state using SHA256.

func (State) Marshal added in v0.4.2

func (state State) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (State) SizeHint added in v0.4.2

func (state State) SizeHint() int

SizeHint of how many bytes will be needed to represent state in binary.

func (State) String added in v0.2.0

func (state State) String() string

String implements the `fmt.Stringer` interface for the `State` type.

func (*State) Unmarshal added in v0.4.2

func (state *State) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from binary.

type Timestamp added in v0.2.0

type Timestamp uint64

Timestamp represents seconds since Unix epoch.

func (Timestamp) Marshal added in v0.4.2

func (t Timestamp) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (Timestamp) SizeHint added in v0.4.2

func (t Timestamp) SizeHint() int

SizeHint of how many bytes will be needed to represent time in binary.

func (*Timestamp) Unmarshal added in v0.4.2

func (t *Timestamp) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from binary.

type Txs added in v0.3.0

type Txs []byte

Txs stores application-specific transaction data used in blocks.

func (Txs) Hash added in v0.3.0

func (txs Txs) Hash() id.Hash

Hash the transactions using SHA256.

func (Txs) Marshal added in v0.4.2

func (txs Txs) Marshal(w io.Writer, m int) (int, error)

Marshal to binary.

func (Txs) SizeHint added in v0.4.2

func (txs Txs) SizeHint() int

SizeHint of how many bytes will be needed to represent transactions in binary.

func (Txs) String added in v0.3.0

func (txs Txs) String() string

String implements the `fmt.Stringer` interface for the `Txs` type.

func (*Txs) Unmarshal added in v0.4.2

func (txs *Txs) Unmarshal(r io.Reader, m int) (int, error)

Unmarshal from binary.

Jump to

Keyboard shortcuts

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