chain

package
v0.2.4-0...-f8342f3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnknownRootErr = errors.New("unknown root")

Functions

This section is empty.

Types

type BlockSink

type BlockSink interface {
	// Sink handles blocks that come from the Hot part, and may be finalized or not
	Sink(entry *HotEntry, canonical bool) error
}

type BlockSinkFn

type BlockSinkFn func(entry *HotEntry, canonical bool) error

func (BlockSinkFn) Sink

func (fn BlockSinkFn) Sink(entry *HotEntry, canonical bool) error

type BlockSlotKey

type BlockSlotKey [32 + 8]byte

func NewBlockSlotKey

func NewBlockSlotKey(block Root, slot Slot) (out BlockSlotKey)

func (*BlockSlotKey) Root

func (key *BlockSlotKey) Root() (out Root)

func (*BlockSlotKey) Slot

func (key *BlockSlotKey) Slot() Slot

type Chain

type Chain interface {
	ByStateRoot(root Root) (ChainEntry, error)
	ByBlockRoot(root Root) (ChainEntry, error)
	ClosestFrom(fromBlockRoot Root, toSlot Slot) (ChainEntry, error)
	BySlot(slot Slot) (ChainEntry, error)
	Iter() (ChainIter, error)
}

type ChainEntry

type ChainEntry interface {
	// Slot of this entry
	Slot() Slot
	// BlockRoot returns the last block root, replicating the previous block root if the current slot has none.
	BlockRoot() (root Root)
	// The parent block root. If this is an empty slot, it will just be previous block root. Can also be zeroed if unknown.
	ParentRoot() (root Root)
	// If this is an empty slot, i.e. no block
	IsEmpty() bool
	// State root (of the post-state of this entry). Should match state-root in the block at the same slot (if any)
	StateRoot() Root
	// The context of this chain entry (shuffling, proposers, etc.)
	EpochsContext(ctx context.Context) (*beacon.EpochsContext, error)
	// State of the entry, a data-sharing view. Call .Copy() before modifying this to preserve validity.
	State(ctx context.Context) (*beacon.BeaconStateView, error)
}

type ChainID

type ChainID string

type ChainIter

type ChainIter interface {
	// Start is the minimum slot to reach to, inclusive.
	Start() Slot
	// End is the maximum slot to reach to, exclusive.
	End() Slot
	// Entry fetches the chain entry at the given slot.
	// If it does not exist, entry=nil, err=nil.
	// If the request is out of bounds or fails, an error may be returned.
	Entry(slot Slot) (entry ChainEntry, err error)
}

type Chains

type Chains interface {
	Find(id ChainID) (pi FullChain, ok bool)
	Create(id ChainID, anchor *HotEntry, spec *beacon.Spec) (pi FullChain, err error)
	Remove(id ChainID) (existed bool)
	List() []ChainID
}

type ChainsMap

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

func (*ChainsMap) Create

func (cs *ChainsMap) Create(id ChainID, anchor *HotEntry, spec *beacon.Spec) (pi FullChain, err error)

func (*ChainsMap) Find

func (cs *ChainsMap) Find(id ChainID) (pi FullChain, ok bool)

func (*ChainsMap) List

func (cs *ChainsMap) List() (out []ChainID)

func (*ChainsMap) Remove

func (cs *ChainsMap) Remove(id ChainID) (existed bool)

type Checkpoint

type Checkpoint = beacon.Checkpoint

type ColdChain

type ColdChain interface {
	Start() Slot
	End() Slot
	OnFinalizedEntry(entry *HotEntry) error
	Chain
}

type ColdChainIter

type ColdChainIter struct {
	Chain              Chain
	StartSlot, EndSlot Slot
}

func (*ColdChainIter) End

func (fi *ColdChainIter) End() Slot

func (*ColdChainIter) Entry

func (fi *ColdChainIter) Entry(slot Slot) (entry ChainEntry, err error)

func (*ColdChainIter) Start

func (fi *ColdChainIter) Start() Slot

type Epoch

type Epoch = beacon.Epoch

type FinalizedChain

type FinalizedChain struct {
	// Cache of pubkeys, may contain pubkeys that are not finalized,
	// but finalized state will not be in conflict with this cache.
	PubkeyCache *beacon.PubkeyCache
	// Start of the historical data
	AnchorSlot Slot

	// Block roots, starting at AnchorSlot
	// A blockRoot can be a copy of the previous root if current entry is empty
	BlockRoots []Root

	// State roots, starting at AnchorSlot
	StateRoots []Root

	// BlockRoots maps the canonical chain block roots to the block slot
	SlotsByBlockRoot map[Root]Slot
	// BlockRoots maps the canonical chain state roots to the state slot
	SlotsByStateRoot map[Root]Slot

	// Spec is holds configuration information for the parameters and types of the chain
	Spec *beacon.Spec
}

func NewFinalizedChain

func NewFinalizedChain(anchorSlot Slot, spec *beacon.Spec) *FinalizedChain

func (*FinalizedChain) ByBlockRoot

func (f *FinalizedChain) ByBlockRoot(root Root) (ChainEntry, error)

func (*FinalizedChain) BySlot

func (f *FinalizedChain) BySlot(slot Slot) (ChainEntry, error)

func (*FinalizedChain) ByStateRoot

func (f *FinalizedChain) ByStateRoot(root Root) (ChainEntry, error)

func (*FinalizedChain) ClosestFrom

func (f *FinalizedChain) ClosestFrom(fromBlockRoot Root, toSlot Slot) (ChainEntry, error)

func (*FinalizedChain) End

func (f *FinalizedChain) End() Slot

func (*FinalizedChain) Iter

func (f *FinalizedChain) Iter() (ChainIter, error)

func (*FinalizedChain) OnFinalizedEntry

func (f *FinalizedChain) OnFinalizedEntry(entry *HotEntry) error

func (*FinalizedChain) Start

func (f *FinalizedChain) Start() Slot

type FinalizedEntryView

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

func (*FinalizedEntryView) BlockRoot

func (e *FinalizedEntryView) BlockRoot() (root Root)

func (*FinalizedEntryView) EpochsContext

func (e *FinalizedEntryView) EpochsContext(ctx context.Context) (*beacon.EpochsContext, error)

func (*FinalizedEntryView) IsEmpty

func (e *FinalizedEntryView) IsEmpty() bool

func (*FinalizedEntryView) ParentRoot

func (e *FinalizedEntryView) ParentRoot() (root Root)

func (*FinalizedEntryView) Slot

func (e *FinalizedEntryView) Slot() Slot

func (*FinalizedEntryView) State

func (*FinalizedEntryView) StateRoot

func (e *FinalizedEntryView) StateRoot() Root

type FullChain

type FullChain interface {
	Chain

	Justified() Checkpoint
	Finalized() Checkpoint
	Head() (ChainEntry, error)
	AddBlock(ctx context.Context, signedBlock *beacon.SignedBeaconBlock) error
	AddAttestation(att *beacon.Attestation) error

	Start() Slot
	End() Slot
	OnFinalizedEntry(entry *HotEntry) error
}

TODO: in Go 1.15 this can be overlapping embedded interfaces

type FullChainIter

type FullChainIter struct {
	HotIter  ChainIter
	ColdIter ChainIter
}

func (*FullChainIter) End

func (fi *FullChainIter) End() Slot

func (*FullChainIter) Entry

func (fi *FullChainIter) Entry(slot Slot) (entry ChainEntry, err error)

func (*FullChainIter) Start

func (fi *FullChainIter) Start() Slot

type Gwei

type Gwei = beacon.Gwei

type HotChain

type HotChain interface {
	Chain
	Justified() Checkpoint
	Finalized() Checkpoint
	Head() (ChainEntry, error)
	// Process a block. If there is an error, the chain is not mutated, and can be continued to use.
	AddBlock(ctx context.Context, signedBlock *beacon.SignedBeaconBlock) error
	// Process an attestation. If there is an error, the chain is not mutated, and can be continued to use.
	AddAttestation(att *beacon.Attestation) error
}

type HotChainIter

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

func (*HotChainIter) End

func (fi *HotChainIter) End() Slot

func (*HotChainIter) Entry

func (fi *HotChainIter) Entry(slot Slot) (entry ChainEntry, err error)

func (*HotChainIter) Start

func (fi *HotChainIter) Start() Slot

type HotColdChain

type HotColdChain struct {
	HotChain
	ColdChain
	Spec *beacon.Spec
}

func (*HotColdChain) ByBlockRoot

func (hc *HotColdChain) ByBlockRoot(root Root) (ChainEntry, error)

func (*HotColdChain) BySlot

func (hc *HotColdChain) BySlot(slot Slot) (ChainEntry, error)

func (*HotColdChain) ByStateRoot

func (hc *HotColdChain) ByStateRoot(root Root) (ChainEntry, error)

func (*HotColdChain) ClosestFrom

func (hc *HotColdChain) ClosestFrom(fromBlockRoot Root, toSlot Slot) (ChainEntry, error)

func (*HotColdChain) Iter

func (hc *HotColdChain) Iter() (ChainIter, error)

type HotEntry

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

func NewHotEntry

func NewHotEntry(
	slot Slot, blockRoot Root, parentRoot Root,
	state *beacon.BeaconStateView, epc *beacon.EpochsContext) *HotEntry

func (*HotEntry) BlockRoot

func (e *HotEntry) BlockRoot() (root Root)

func (*HotEntry) EpochsContext

func (e *HotEntry) EpochsContext(ctx context.Context) (*beacon.EpochsContext, error)

func (*HotEntry) IsEmpty

func (e *HotEntry) IsEmpty() bool

func (*HotEntry) ParentRoot

func (e *HotEntry) ParentRoot() (root Root)

func (*HotEntry) Slot

func (e *HotEntry) Slot() Slot

func (*HotEntry) State

func (e *HotEntry) State(ctx context.Context) (*beacon.BeaconStateView, error)

func (*HotEntry) StateRoot

func (e *HotEntry) StateRoot() Root

type Root

type Root = beacon.Root

type Slot

type Slot = beacon.Slot

type UnfinalizedChain

type UnfinalizedChain struct {
	ForkChoice *forkchoice.ForkChoice

	AnchorSlot Slot

	// block++slot -> Entry
	Entries map[BlockSlotKey]*HotEntry
	// state root -> block+slot key
	State2Key map[Root]BlockSlotKey

	// BlockSink takes pruned entries and their canon status, and processes them.
	// Empty-slot entries will only occur for canonical chain,
	// non-canonical empty entries are ignored, as there can theoretically be an unlimited number of.
	// Non-canonical non-empty entries are still available, to track what is getting abandoned by the chain
	BlockSink BlockSink

	// Spec is holds configuration information for the parameters and types of the chain
	Spec *beacon.Spec
}

func NewUnfinalizedChain

func NewUnfinalizedChain(finalizedBlock *HotEntry, sink BlockSink, spec *beacon.Spec) (*UnfinalizedChain, error)

func (*UnfinalizedChain) AddAttestation

func (uc *UnfinalizedChain) AddAttestation(att *beacon.Attestation) error

func (*UnfinalizedChain) AddBlock

func (uc *UnfinalizedChain) AddBlock(ctx context.Context, signedBlock *beacon.SignedBeaconBlock) error

func (*UnfinalizedChain) ByBlockRoot

func (uc *UnfinalizedChain) ByBlockRoot(root Root) (ChainEntry, error)

func (*UnfinalizedChain) ByBlockSlot

func (uc *UnfinalizedChain) ByBlockSlot(key BlockSlotKey) (ChainEntry, error)

func (*UnfinalizedChain) BySlot

func (uc *UnfinalizedChain) BySlot(slot Slot) (ChainEntry, error)

func (*UnfinalizedChain) ByStateRoot

func (uc *UnfinalizedChain) ByStateRoot(root Root) (ChainEntry, error)

func (*UnfinalizedChain) ClosestFrom

func (uc *UnfinalizedChain) ClosestFrom(fromBlockRoot Root, toSlot Slot) (ChainEntry, error)

func (*UnfinalizedChain) Finalized

func (uc *UnfinalizedChain) Finalized() Checkpoint

func (*UnfinalizedChain) Head

func (uc *UnfinalizedChain) Head() (ChainEntry, error)

func (*UnfinalizedChain) Iter

func (uc *UnfinalizedChain) Iter() (ChainIter, error)

func (*UnfinalizedChain) Justified

func (uc *UnfinalizedChain) Justified() Checkpoint

func (*UnfinalizedChain) OnPrunedBlock

func (uc *UnfinalizedChain) OnPrunedBlock(node *forkchoice.ProtoNode, canonical bool) error

type ValidatorIndex

type ValidatorIndex = beacon.ValidatorIndex

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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