block

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: Apache-2.0, MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BlockMessageLimit = 512

BlockMessageLimit is the maximum number of messages in a block

View Source
const IndexMessagesField = 10

IndexMessagesField is the message field position in the encoded block

View Source
const IndexParentsField = 5

IndexParentsField is the parents field position in the encoded block

Variables

View Source
var UndefTipSet = TipSet{}

UndefTipSet is a singleton representing a nil or undefined tipset.

Functions

func AsSet

func AsSet(cids []cid.Cid) map[cid.Cid]struct{}

Types

type Block

type Block struct {

	// Miner is the address of the miner actor that mined this block.
	Miner address.Address `json:"miner"`

	// Ticket is the ticket submitted with this block.
	Ticket Ticket `json:"ticket"`

	// ElectionProof is the vrf proof giving this block's miner authoring rights
	ElectionProof *crypto.ElectionProof

	// BeaconEntries contain the verifiable oracle randomness used to elect
	// this block's author leader
	BeaconEntries []*drand.Entry

	// PoStProofs are the winning post proofs
	PoStProofs []PoStProof `json:"PoStProofs"`

	// Parents is the set of parents this block was based on. Typically one,
	// but can be several in the case where there were multiple winning ticket-
	// holders for an epoch.
	Parents TipSetKey `json:"parents"`

	// ParentWeight is the aggregate chain weight of the parent set.
	ParentWeight fbig.Int `json:"parentWeight"`

	// Height is the chain height of this block.
	Height abi.ChainEpoch `json:"height"`

	// StateRoot is the CID of the root of the state tree after application of the messages in the parent tipset
	// to the parent tipset's state root.
	StateRoot e.Cid `json:"stateRoot,omitempty"`

	// MessageReceipts is a list of receipts corresponding to the application of the messages in the parent tipset
	// to the parent tipset's state root (corresponding to this block's StateRoot).
	MessageReceipts e.Cid `json:"messageReceipts,omitempty"`

	// Messages is the set of messages included in this block
	Messages e.Cid `json:"messages,omitempty"`

	// The aggregate signature of all BLS signed messages in the block
	BLSAggregateSig *crypto.Signature `json:"blsAggregateSig"`

	// The timestamp, in seconds since the Unix epoch, at which this block was created.
	Timestamp uint64 `json:"timestamp"`

	// The signature of the miner's worker key over the block
	BlockSig *crypto.Signature `json:"blocksig"`

	// ForkSignaling is extra data used by miners to communicate
	ForkSignaling uint64
	// contains filtered or unexported fields
}

Block is a block in the blockchain.

func DecodeBlock

func DecodeBlock(b []byte) (*Block, error)

DecodeBlock decodes raw cbor bytes into a Block.

func (*Block) Cid

func (b *Block) Cid() cid.Cid

Cid returns the content id of this block.

func (*Block) Equals

func (b *Block) Equals(other *Block) bool

Equals returns true if the Block is equal to other.

func (*Block) SignatureData

func (b *Block) SignatureData() []byte

SignatureData returns the block's bytes with a null signature field for signature creation and verification

func (*Block) String

func (b *Block) String() string

func (*Block) ToNode

func (b *Block) ToNode() node.Node

ToNode converts the Block to an IPLD node.

type CISlice

type CISlice []*ChainInfo

CISlice is for sorting chain infos

func (CISlice) Len

func (cis CISlice) Len() int

Len returns the number of chain infos in the slice.

func (CISlice) Less

func (cis CISlice) Less(i, j int) bool

Less compares chain infos on peer ID. There should only ever be one chain info per peer in a CISlice.

func (CISlice) Swap

func (cis CISlice) Swap(i, j int)

Swap swaps chain infos.

type ChainInfo

type ChainInfo struct {
	// The originator of the TipSetKey propagation wave.
	Source peer.ID
	// The peer that sent us the TipSetKey message.
	Sender peer.ID
	Head   TipSetKey
	Height abi.ChainEpoch
}

ChainInfo is used to track metadata about a peer and its chain.

func NewChainInfo

func NewChainInfo(source peer.ID, sender peer.ID, head TipSetKey, height abi.ChainEpoch) *ChainInfo

NewChainInfo creates a chain info from a peer id a head tipset key and a chain height.

func (*ChainInfo) String

func (i *ChainInfo) String() string

Returns a human-readable string representation of a chain info

type FullBlock

type FullBlock struct {
	Header       *Block
	SECPMessages []*types.SignedMessage
	BLSMessages  []*types.UnsignedMessage
}

FullBlock carries a block header and the message and receipt collections referenced from the header.

func NewFullBlock

func NewFullBlock(header *Block, secp []*types.SignedMessage, bls []*types.UnsignedMessage) *FullBlock

NewFullBlock constructs a new full block.

type PoStProof

type PoStProof struct {
	RegisteredProof abi.RegisteredProof
	ProofBytes      []byte
	// contains filtered or unexported fields
}

PoStProof is a winning post proof included in a block header

func FromABIPoStProofs

func FromABIPoStProofs(postProofs ...abi.PoStProof) []PoStProof

FromABIPoStProofs converts the abi post proof type to a local type for serialization purposes

func NewPoStProof

func NewPoStProof(rpp abi.RegisteredProof, bs []byte) PoStProof

NewPoStProof constructs an epost proof from registered proof and bytes

type Ticket

type Ticket struct {

	// A proof output by running a VRF on the VRFProof of the parent ticket
	VRFProof crypto.VRFPi
	// contains filtered or unexported fields
}

A Ticket is a marker of a tick of the blockchain's clock. It is the source of randomness for proofs of storage and leader election. It is generated by the miner of a block using a VRF.

func (*Ticket) Compare

func (t *Ticket) Compare(o *Ticket) int

func (Ticket) String

func (t Ticket) String() string

String returns the string representation of the VRFProof of the ticket

type TipSet

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

TipSet is a non-empty, immutable set of blocks at the same height with the same parent set. Blocks in a tipset are canonically ordered by ticket. Blocks may be iterated either via ToSlice() (which involves a shallow copy) or efficiently by index with At(). TipSet is a lightweight value type; passing by pointer is usually unnecessary.

Canonical tipset block ordering does not match the order of CIDs in a TipSetKey used as a tipset "key".

func NewTipSet

func NewTipSet(blocks ...*Block) (TipSet, error)

NewTipSet builds a new TipSet from a collection of blocks. The blocks must be distinct (different CIDs), have the same height, and same parent set.

func RequireNewTipSet

func RequireNewTipSet(t *testing.T, blks ...*Block) TipSet

RequireNewTipSet instantiates and returns a new tipset of the given blocks and requires that the setup validation succeed.

func (TipSet) At

func (ts TipSet) At(i int) *Block

At returns the i'th block in the tipset. An index outside the half-open range [0, Len()) will panic.

func (TipSet) Defined

func (ts TipSet) Defined() bool

Defined checks whether the tipset is defined. Invoking any other methods on an undefined tipset will result in undefined behaviour (c.f. cid.Undef)

func (TipSet) Equals

func (ts TipSet) Equals(ts2 TipSet) bool

Equals tests whether the tipset contains the same blocks as another. Equality is not tested deeply: two tipsets are considered equal if their keys (ordered block CIDs) are equal.

func (TipSet) Height

func (ts TipSet) Height() (abi.ChainEpoch, error)

Height returns the height of a tipset.

func (TipSet) Key

func (ts TipSet) Key() TipSetKey

Key returns a key for the tipset.

func (TipSet) Len

func (ts TipSet) Len() int

Len returns the number of blocks in the tipset.

func (TipSet) MinTicket

func (ts TipSet) MinTicket() (Ticket, error)

MinTicket returns the smallest ticket of all blocks in the tipset.

func (TipSet) ParentWeight

func (ts TipSet) ParentWeight() (fbig.Int, error)

ParentWeight returns the tipset's ParentWeight in fixed point form.

func (TipSet) Parents

func (ts TipSet) Parents() (TipSetKey, error)

Parents returns the CIDs of the parents of the blocks in the tipset.

func (TipSet) String

func (ts TipSet) String() string

String returns a formatted string of the CIDs in the TipSet. "{ <cid1> <cid2> <cid3> }" Note: existing callers use this as a unique key for the tipset. We should change them to use the TipSetKey explicitly

func (TipSet) ToSlice

func (ts TipSet) ToSlice() []*Block

ToSlice returns an ordered slice of pointers to the tipset's blocks.

type TipSetKey

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

TipSetKey is an immutable set of CIDs forming a unique key for a TipSet. Equal keys will have equivalent iteration order. CIDs are maintained in the same order as the canonical iteration order of blocks in a tipset (which is by ticket). This convention is maintained by the caller. The order of input cids to the constructor must be the same as this canonical order. It is the caller's responsibility to not construct a key with duplicate ids TipSetKey is a lightweight value type; passing by pointer is usually unnecessary.

func NewTipSetKey

func NewTipSetKey(ids ...cid.Cid) TipSetKey

NewTipSetKey initialises a new TipSetKey. Duplicate CIDs are silently ignored.

func NewTipSetKeyFromUnique

func NewTipSetKeyFromUnique(ids ...cid.Cid) (TipSetKey, error)

NewTipSetKeyFromUnique initialises a set with CIDs that are expected to be unique.

func (*TipSetKey) ContainsAll

func (s *TipSetKey) ContainsAll(other TipSetKey) bool

ContainsAll checks if another set is a subset of this one. We can assume that the relative order of members of one key is maintained in the other since we assume that all ids are sorted by corresponding block ticket value.

func (TipSetKey) Empty

func (s TipSetKey) Empty() bool

Empty checks whether the set is empty.

func (TipSetKey) Equals

func (s TipSetKey) Equals(other TipSetKey) bool

Equals checks whether the set contains exactly the same CIDs as another.

func (TipSetKey) Has

func (s TipSetKey) Has(id cid.Cid) bool

Has checks whether the set contains `id`.

func (TipSetKey) Iter

func (s TipSetKey) Iter() TipSetKeyIterator

Iter returns an iterator that allows the caller to iterate the set in its sort order.

func (TipSetKey) Len

func (s TipSetKey) Len() int

Len returns the number of items in the set.

func (TipSetKey) MarshalCBOR

func (s TipSetKey) MarshalCBOR() ([]byte, error)

MarshalCBOR marshals the tipset key as an array of cids

func (TipSetKey) MarshalJSON

func (s TipSetKey) MarshalJSON() ([]byte, error)

MarshalJSON serializes the key to JSON.

func (TipSetKey) String

func (s TipSetKey) String() string

String returns a string listing the cids in the set.

func (TipSetKey) ToSlice

func (s TipSetKey) ToSlice() []cid.Cid

ToSlice returns a slice listing the cids in the set.

func (*TipSetKey) UnmarshalCBOR

func (s *TipSetKey) UnmarshalCBOR(data []byte) error

UnmarshalCBOR unmarshals a cbor array of cids to a tipset key

func (*TipSetKey) UnmarshalJSON

func (s *TipSetKey) UnmarshalJSON(b []byte) error

UnmarshalJSON parses JSON into the key. Note that this pattern technically violates the immutability.

type TipSetKeyIterator

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

TipSetKeyIterator is a iterator over a sorted collection of CIDs.

func (*TipSetKeyIterator) Complete

func (si *TipSetKeyIterator) Complete() bool

Complete returns true if the iterator has reached the end of the set.

func (*TipSetKeyIterator) Next

func (si *TipSetKeyIterator) Next() bool

Next advances the iterator to the next item and returns true if there is such an item.

func (TipSetKeyIterator) Value

func (si TipSetKeyIterator) Value() cid.Cid

Value returns the current item for the iterator

Jump to

Keyboard shortcuts

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