chain

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockService

type BlockService struct {
	KnownLeaves     map[crypto.Hash]jamtime.Timeslot // Maps leaf block hashes to their timeslots
	LatestFinalized LatestFinalized                  // Tracks the most recently finalized block
	Store           *store.Chain                     // Persistent block storage
	// contains filtered or unexported fields
}

BlockService manages the node's view of the blockchain state, including: - Known leaf blocks (blocks with no known children) - Latest finalized block - Block storage and retrieval

It handles block announcements according to UP 0 protocol specification, maintaining the set of leaf blocks and tracking finalization status.

func NewBlockService

func NewBlockService(kvStore *pebble.KVStore) (*BlockService, error)

NewBlockService initializes a new BlockService with: - Empty leaf block set - Persistent block storage using PebbleDB - Genesis block as the latest finalized block

func (*BlockService) AddLeaf

func (bs *BlockService) AddLeaf(hash crypto.Hash, slot jamtime.Timeslot)

AddLeaf adds a block to the set of known leaves.

func (*BlockService) HandleNewHeader

func (bs *BlockService) HandleNewHeader(header *block.Header) error

HandleNewHeader processes a new block header announcement by: 1. Storing the header in persistent storage 2. Updating the leaf block set (removing parent, adding new block) 3. Checking if the parent block can now be finalized

This implements the core block processing logic required by UP 0 protocol, maintaining the node's view of chain tips and finalization status.

func (*BlockService) IsDescendantOfFinalized

func (bs *BlockService) IsDescendantOfFinalized(header *block.Header) (bool, error)

IsDescendantOfFinalized checks if a block is a descendant of the latest finalized block by walking back through its ancestors until we either: - Find the latest finalized block (true) - Find a different block at the same height as latest finalized (false) - Can't find a parent (error)

func (*BlockService) RemoveLeaf

func (bs *BlockService) RemoveLeaf(hash crypto.Hash)

RemoveLeaf removes a block from the set of known leaves.

func (*BlockService) UpdateLatestFinalized

func (bs *BlockService) UpdateLatestFinalized(hash crypto.Hash, slot jamtime.Timeslot)

UpdateLatestFinalized updates the latest finalized block pointer.

type LatestFinalized

type LatestFinalized struct {
	Hash          crypto.Hash      // Hash of the finalized block
	TimeSlotIndex jamtime.Timeslot // Timeslot of the finalized block
}

LatestFinalized represents the latest finalized block in the chain. A block is considered finalized when it has a chain of 5 descendant blocks built on top of it according to the finalization rules.

type Leaf

type Leaf struct {
	Hash          crypto.Hash      // Hash of the leaf block
	TimeSlotIndex jamtime.Timeslot // Timeslot of the leaf block
}

Leaf represents a block with no known children (a tip of the chain). The BlockService tracks all known leaves to implement the UP 0 protocol's requirement of announcing all leaves in handshake messages.

Jump to

Keyboard shortcuts

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