block

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

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

Blocks (e)

View Source
var EmptyTSK = TipSetKey{}
View Source
var MaxWinCount = 3 * int64(BlocksPerEpoch)
View Source
var UndefTipSet = &TipSet{}

UndefTipSet is a singleton representing a nil or undefined tipset.

Functions

func CidArrsContains

func CidArrsContains(a []cid.Cid, b cid.Cid) bool

func CidArrsEqual

func CidArrsEqual(a, b []cid.Cid) bool

func CidArrsSubset

func CidArrsSubset(a, b []cid.Cid) bool

func ReverseFullBlock

func ReverseFullBlock(chain []*FullTipSet)

Reverse reverses the order of the slice `chain`.

Types

type BeaconEntry

type BeaconEntry struct {
	Round uint64
	Data  []byte
}

func (*BeaconEntry) MarshalCBOR

func (t *BeaconEntry) MarshalCBOR(w io.Writer) error

func (*BeaconEntry) UnmarshalCBOR

func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error

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 *ElectionProof `json:"electionProof"`

	// BeaconEntries contain the verifiable oracle randomness used to elect
	// this block's author leader
	BeaconEntries []*BeaconEntry `json:"beaconEntries"`

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

	// 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"`

	// ParentStateRoot 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.
	ParentStateRoot cid.Cid `json:"parentStateRoot,omitempty"`

	// ParentMessageReceipts 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 ParentStateRoot).
	ParentMessageReceipts cid.Cid `json:"parentMessageReceipts,omitempty"`

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

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

	// 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 `json:"forkSignaling"`

	ParentBaseFee abi.TokenAmount `json:"parentBaseFee"`
	// 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) LastTicket

func (b *Block) LastTicket() *Ticket

func (*Block) MarshalCBOR

func (t *Block) MarshalCBOR(w io.Writer) error

func (*Block) Serialize

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

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.

func (*Block) ToStorageBlock

func (b *Block) ToStorageBlock() (blocks.Block, error)

func (*Block) UnmarshalCBOR

func (t *Block) UnmarshalCBOR(r io.Reader) error

type BlockMessagesInfo

type BlockMessagesInfo struct {
	BlsMessages   []types.ChainMsg
	SecpkMessages []types.ChainMsg
	Block         *Block
}

BlockMessagesInfo contains messages for one block in a tipset.

type BlockMsg

type BlockMsg struct {
	Header        *Block
	BlsMessages   []cid.Cid
	SecpkMessages []cid.Cid
}

func (*BlockMsg) Cid

func (bm *BlockMsg) Cid() cid.Cid

func (*BlockMsg) MarshalCBOR

func (t *BlockMsg) MarshalCBOR(w io.Writer) error

func (*BlockMsg) Serialize

func (bm *BlockMsg) Serialize() ([]byte, error)

func (*BlockMsg) UnmarshalCBOR

func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error

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   *TipSet
}

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

func NewChainInfo

func NewChainInfo(source peer.ID, sender peer.ID, head *TipSet) *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 ElectionProof

type ElectionProof struct {
	WinCount int64

	// A proof output by running a VRF on the VRFProof of the parent ticket
	VRFProof VRFPi
}

func (*ElectionProof) ComputeWinCount

func (ep *ElectionProof) ComputeWinCount(power abi.StoragePower, totalPower abi.StoragePower) int64

ComputeWinCount uses VRFProof to compute number of wins The algorithm is based on Algorand's Sortition with Binomial distribution replaced by Poisson distribution.

func (*ElectionProof) MarshalCBOR

func (t *ElectionProof) MarshalCBOR(w io.Writer) error

func (*ElectionProof) UnmarshalCBOR

func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error

type FullBlock

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

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

func (*FullBlock) Cid

func (fb *FullBlock) Cid() cid.Cid

Cid returns the FullBlock's header's Cid

type FullTipSet

type FullTipSet struct {
	Blocks []*FullBlock
	// contains filtered or unexported fields
}

FullTipSet is an expanded version of the TipSet that contains all the blocks and messages

func NewFullTipSet

func NewFullTipSet(blks []*FullBlock) *FullTipSet

func (*FullTipSet) Cids

func (fts *FullTipSet) Cids() []cid.Cid

func (*FullTipSet) TipSet

func (fts *FullTipSet) TipSet() *TipSet

TipSet returns a narrower view of this FullTipSet elliding the block messages.

type MiningBaseInfo

type MiningBaseInfo struct {
	MinerPower        abi.StoragePower
	NetworkPower      abi.StoragePower
	Sectors           []builtin.SectorInfo
	WorkerKey         address.Address
	SectorSize        abi.SectorSize
	PrevBeaconEntry   BeaconEntry
	BeaconEntries     []BeaconEntry
	EligibleForMining bool
}

type PoStProof

type PoStProof struct {
	PoStProof  abi.RegisteredPoStProof
	ProofBytes []byte
}

func FromAbiProof

func FromAbiProof(abiProof builtin.PoStProof) PoStProof

func FromAbiProofArr

func FromAbiProofArr(abiProof []builtin.PoStProof) []PoStProof

func (PoStProof) AsAbiProof

func (p PoStProof) AsAbiProof() builtin.PoStProof

func (*PoStProof) MarshalCBOR

func (t *PoStProof) MarshalCBOR(w io.Writer) error

func (*PoStProof) UnmarshalCBOR

func (t *PoStProof) UnmarshalCBOR(r io.Reader) error

type Ticket

type Ticket struct {
	// A proof output by running a VRF on the VRFProof of the parent ticket
	VRFProof VRFPi
}

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

func (t *Ticket) Less(o *Ticket) bool

func (*Ticket) MarshalCBOR

func (t *Ticket) MarshalCBOR(w io.Writer) error

func (*Ticket) Quality

func (t *Ticket) Quality() float64

func (Ticket) String

func (t Ticket) String() string

String returns the string representation of the VRFProof of the ticket

func (*Ticket) UnmarshalCBOR

func (t *Ticket) UnmarshalCBOR(r io.Reader) error

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

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

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

func (ts *TipSet) EnsureHeight() abi.ChainEpoch

Height returns the height of a tipset.

func (*TipSet) EnsureParents

func (ts *TipSet) EnsureParents() TipSetKey

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

func (ts *TipSet) IsChildOf(parent *TipSet) bool

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

func (ts *TipSet) MarshalJSON() ([]byte, error)

func (*TipSet) MinTicket

func (ts *TipSet) MinTicket() Ticket

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

func (*TipSet) MinTicketBlock

func (ts *TipSet) MinTicketBlock() *Block

func (*TipSet) MinTimestamp

func (ts *TipSet) MinTimestamp() uint64

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.

func (*TipSet) UnmarshalJSON

func (ts *TipSet) UnmarshalJSON(b []byte) error

type TipSetKey

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

A TipSetKey is an immutable collection of CIDs forming a unique key for a tipset. The CIDs are assumed to be distinct and in canonical order. Two keys with the same CIDs in a different order are not considered equal. TipSetKey is a lightweight value type, and may be compared for equality with ==.

func NewTipSetKey

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

NewTipSetKey builds a new key from a slice of CIDs. The CIDs are assumed to be ordered correctly.

func TipSetKeyFromBytes

func TipSetKeyFromBytes(encoded []byte) (TipSetKey, error)

TipSetKeyFromBytes wraps an encoded key, validating correct decoding.

func (TipSetKey) Bytes

func (tipsetKey TipSetKey) Bytes() []byte

Bytes() returns a binary representation of the key.

func (TipSetKey) Cids

func (tipsetKey TipSetKey) Cids() []cid.Cid

Cids returns a slice of the CIDs comprising this key.

func (TipSetKey) ContainsAll

func (tipsetKey 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) Equals

func (tipsetKey TipSetKey) Equals(other TipSetKey) bool

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

func (TipSetKey) Has

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

Has checks whether the set contains `id`.

func (TipSetKey) IsEmpty

func (tipsetKey TipSetKey) IsEmpty() bool

func (TipSetKey) MarshalCBOR

func (tipsetKey TipSetKey) MarshalCBOR(w io.Writer) error

func (TipSetKey) MarshalJSON

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

func (TipSetKey) String

func (tipsetKey TipSetKey) String() string

String() returns a human-readable representation of the key.

func (*TipSetKey) UnmarshalCBOR

func (tipsetKey *TipSetKey) UnmarshalCBOR(r io.Reader) error

func (*TipSetKey) UnmarshalJSON

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

type VRFPi

type VRFPi []byte

VRFPi is the proof output from running a VRF.

func (VRFPi) Digest

func (p VRFPi) Digest() [32]byte

Digest returns the digest (hash) of a proof, for use generating challenges etc.

Jump to

Keyboard shortcuts

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