Documentation ¶
Overview ¶
Package blockchain defines the life-cycle and status of the beacon chain as well as the Ethereum Serenity beacon chain fork-choice rule based on Casper Proof of Stake finality.
Index ¶
- func BlockAncestor(block *pb.BeaconBlock, slot uint64, beaconDB *db.BeaconDB) (*pb.BeaconBlock, error)
- func LMDGhost(block *pb.BeaconBlock, voteTargets map[[32]byte]*pb.BeaconBlock, ...) (*pb.BeaconBlock, error)
- func VoteCount(block *pb.BeaconBlock, targets map[[32]byte]*pb.BeaconBlock, ...) (int, error)
- type ChainService
- func (c *ChainService) ApplyForkChoiceRule(block *pb.BeaconBlock, computedState *pb.BeaconState) error
- func (c *ChainService) CanonicalBlockFeed() *event.Feed
- func (c *ChainService) CanonicalStateFeed() *event.Feed
- func (c *ChainService) IncomingBlockFeed() *event.Feed
- func (c *ChainService) ReceiveBlock(block *pb.BeaconBlock, beaconState *pb.BeaconState) (*pb.BeaconState, error)
- func (c *ChainService) Start()
- func (c *ChainService) Status() error
- func (c *ChainService) Stop() error
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockAncestor ¶
func BlockAncestor(block *pb.BeaconBlock, slot uint64, beaconDB *db.BeaconDB) (*pb.BeaconBlock, error)
BlockAncestor obtains the ancestor at of a block at a certain slot.
Spec pseudocode definition:
Let get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock be the ancestor of block with slot number slot. The get_ancestor function can be defined recursively as def get_ancestor(store: Store, block: BeaconBlock, slot: SlotNumber) -> BeaconBlock: return block if block.slot == slot else get_ancestor(store, store.get_parent(block), slot)
func LMDGhost ¶
func LMDGhost( block *pb.BeaconBlock, voteTargets map[[32]byte]*pb.BeaconBlock, observedBlocks []*pb.BeaconBlock, beaconDB *db.BeaconDB, ) (*pb.BeaconBlock, error)
LMDGhost applies the Latest Message Driven, Greediest Heaviest Observed Sub-Tree fork-choice rule defined in the Ethereum Serenity specification for the beacon chain.
Spec pseudocode definition:
head = start_block while 1: children = get_children(store, head) if len(children) == 0: return head head = max(children, key=get_vote_count)
func VoteCount ¶
func VoteCount(block *pb.BeaconBlock, targets map[[32]byte]*pb.BeaconBlock, beaconDB *db.BeaconDB) (int, error)
VoteCount determines the number of votes on a beacon block by counting the number of target blocks that have such beacon block as a common ancestor.
Spec pseudocode definition:
def get_vote_count(block: BeaconBlock) -> int: return len([target for target in attestation_targets if get_ancestor(store, target, block.slot) == block])
Types ¶
type ChainService ¶
type ChainService struct {
// contains filtered or unexported fields
}
ChainService represents a service that handles the internal logic of managing the full PoS beacon chain.
func NewChainService ¶
func NewChainService(ctx context.Context, cfg *Config) (*ChainService, error)
NewChainService instantiates a new service instance that will be registered into a running beacon node.
func (*ChainService) ApplyForkChoiceRule ¶
func (c *ChainService) ApplyForkChoiceRule(block *pb.BeaconBlock, computedState *pb.BeaconState) error
ApplyForkChoiceRule determines the current beacon chain head using LMD GHOST as a block-vote weighted function to select a canonical head in Ethereum Serenity.
func (*ChainService) CanonicalBlockFeed ¶
func (c *ChainService) CanonicalBlockFeed() *event.Feed
CanonicalBlockFeed returns a channel that is written to whenever a new block is determined to be canonical in the chain.
func (*ChainService) CanonicalStateFeed ¶
func (c *ChainService) CanonicalStateFeed() *event.Feed
CanonicalStateFeed returns a feed that is written to whenever a new state is determined to be canonical in the chain.
func (*ChainService) IncomingBlockFeed ¶
func (c *ChainService) IncomingBlockFeed() *event.Feed
IncomingBlockFeed returns a feed that any service can send incoming p2p blocks into. The chain service will subscribe to this feed in order to process incoming blocks.
func (*ChainService) ReceiveBlock ¶
func (c *ChainService) ReceiveBlock(block *pb.BeaconBlock, beaconState *pb.BeaconState) (*pb.BeaconState, error)
ReceiveBlock is a function that defines the operations that are preformed on any block that is received from p2p layer or rpc. It checks the block to see if it passes the pre-processing conditions, if it does then the per slot state transition function is carried out on the block. spec:
def process_block(block): if not block_pre_processing_conditions(block): return nil, error # process skipped slots while (state.slot < block.slot - 1): state = slot_state_transition(state, block=None) # process slot with block state = slot_state_transition(state, block) # check state root if block.state_root == hash(state): return state, error else: return nil, error # or throw or whatever
func (*ChainService) Start ¶
func (c *ChainService) Start()
Start a blockchain service's main event loop.
func (*ChainService) Status ¶
func (c *ChainService) Status() error
Status always returns nil. TODO(1202): Add service health checks.
func (*ChainService) Stop ¶
func (c *ChainService) Stop() error
Stop the blockchain service's main event loop and associated goroutines.