Documentation ¶
Overview ¶
Package header contains all services related to generating, requesting, syncing and storing ExtendedHeaders.
An ExtendedHeader is similar to a regular block header from celestia-core, but "extended" by adding the DataAvailabilityHeader (DAH), ValidatorSet and Commit in order to allow for light and full nodes to reconstruct block data by referencing the DAH.
ExtendedHeaders are generated by bridge nodes that listen to the celestia-core network for blocks, validate and extend the block data in order to generate the DAH, and request both the ValidatorSet and Commit for that block height from the celestia-core network. Bridge nodes then package that data up into an ExtendedHeader and broadcast it to the 'header-sub' GossipSub topic (HeaderSub). All nodes subscribed to HeaderSub will receive and validate the ExtendedHeader, and store it, making it available to all other dependent services (such as the DataAvailabilitySampler, or DASer) to access.
There are 5 main components in the header package:
- core.Listener listens for new blocks from the celestia-core network (run by bridge nodes only), extends them, generates a new ExtendedHeader, and publishes it to the HeaderSub.
- p2p.Subscriber listens for new ExtendedHeaders from the Celestia Data Availability (DA) network (via the HeaderSub)
- p2p.Exchange or core.Exchange request ExtendedHeaders from other celestia DA nodes (default for full and light nodes) or from a celestia-core node connection (bridge nodes only)
- Syncer manages syncing of past and recent ExtendedHeaders from either the DA network or a celestia-core connection (bridge nodes only).
- Store manages storing ExtendedHeaders and making them available for access by other dependent services.
For bridge nodes, the general flow of the header Service is as follows:
- core.Listener listens for new blocks from the celestia-core connection
- core.Listener validates the block and generates the ExtendedHeader, simultaneously storing the extended block shares to disk
- core.Listener publishes the new ExtendedHeader to HeaderSub, notifying all subscribed peers of the new ExtendedHeader
- Syncer is already subscribed to the HeaderSub, so it receives new ExtendedHeaders locally from the core.Listener and stores them to disk via Store. - If the celestia-core connection is started simultaneously with the bridge node, then the celestia-core connection will handle the syncing component, piping every synced block to the core.Listener - If the celestia-core connection is already synced to the network, the Syncer handles requesting past headers up to the network head from the celestia-core connection (using core.Exchange rather than p2p.Exchange).
For full and light nodes, the general flow of the header Service is as follows:
- Syncer listens for new ExtendedHeaders from HeaderSub
- If there is a gap between the local head of chain and the new, validated network head, the Syncer kicks off a sync routine to request all ExtendedHeaders between local head and network head.
- While the Syncer requests headers between the local head and network head in batches, it appends them to the subjective chain via Store with the last batched header as the new local head.
Index ¶
- Variables
- func ExtendedHeaderToProto(eh *ExtendedHeader) (*header_pb.ExtendedHeader, error)
- func MarshalExtendedHeader(in *ExtendedHeader) (_ []byte, err error)
- func MsgID(pmsg *pb.Message) string
- type ConstructFn
- type ExtendedHeader
- func (eh *ExtendedHeader) ChainID() string
- func (eh *ExtendedHeader) Equals(header *ExtendedHeader) bool
- func (eh *ExtendedHeader) Hash() libhead.Hash
- func (eh *ExtendedHeader) Height() uint64
- func (eh *ExtendedHeader) IsZero() bool
- func (eh *ExtendedHeader) LastHeader() libhead.Hash
- func (eh *ExtendedHeader) MarshalBinary() ([]byte, error)
- func (eh *ExtendedHeader) MarshalJSON() ([]byte, error)
- func (eh *ExtendedHeader) New() *ExtendedHeader
- func (eh *ExtendedHeader) Time() time.Time
- func (eh *ExtendedHeader) UnmarshalBinary(data []byte) error
- func (eh *ExtendedHeader) UnmarshalJSON(data []byte) error
- func (eh *ExtendedHeader) Validate() error
- func (eh *ExtendedHeader) Verify(untrst *ExtendedHeader) error
- type RawHeader
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ExtendedHeaderToProto ¶
func ExtendedHeaderToProto(eh *ExtendedHeader) (*header_pb.ExtendedHeader, error)
func MarshalExtendedHeader ¶
func MarshalExtendedHeader(in *ExtendedHeader) (_ []byte, err error)
MarshalExtendedHeader serializes given ExtendedHeader to bytes using protobuf. Paired with UnmarshalExtendedHeader.
Types ¶
type ConstructFn ¶
type ConstructFn = func( *core.Header, *core.Commit, *core.ValidatorSet, *rsmt2d.ExtendedDataSquare, ) (*ExtendedHeader, error)
ConstructFn aliases a function that creates an ExtendedHeader.
type ExtendedHeader ¶
type ExtendedHeader struct { RawHeader `json:"header"` Commit *core.Commit `json:"commit"` ValidatorSet *core.ValidatorSet `json:"validator_set"` DAH *share.Root `json:"dah"` }
ExtendedHeader represents a wrapped "raw" header that includes information necessary for Celestia Nodes to be notified of new block headers and perform Data Availability Sampling.
func MakeExtendedHeader ¶
func MakeExtendedHeader( h *core.Header, comm *core.Commit, vals *core.ValidatorSet, eds *rsmt2d.ExtendedDataSquare, ) (*ExtendedHeader, error)
MakeExtendedHeader assembles new ExtendedHeader.
func ProtoToExtendedHeader ¶
func ProtoToExtendedHeader(pb *header_pb.ExtendedHeader) (*ExtendedHeader, error)
func UnmarshalExtendedHeader ¶
func UnmarshalExtendedHeader(data []byte) (*ExtendedHeader, error)
UnmarshalExtendedHeader deserializes given data into a new ExtendedHeader using protobuf. Paired with MarshalExtendedHeader.
func (*ExtendedHeader) ChainID ¶ added in v0.6.3
func (eh *ExtendedHeader) ChainID() string
func (*ExtendedHeader) Equals ¶
func (eh *ExtendedHeader) Equals(header *ExtendedHeader) bool
Equals returns whether the hash and height of the given header match.
func (*ExtendedHeader) Hash ¶
func (eh *ExtendedHeader) Hash() libhead.Hash
Hash returns Hash of the wrapped RawHeader. NOTE: It purposely overrides Hash method of RawHeader to get it directly from Commit without recomputing.
func (*ExtendedHeader) Height ¶ added in v0.6.3
func (eh *ExtendedHeader) Height() uint64
func (*ExtendedHeader) IsZero ¶ added in v0.6.3
func (eh *ExtendedHeader) IsZero() bool
func (*ExtendedHeader) LastHeader ¶
func (eh *ExtendedHeader) LastHeader() libhead.Hash
LastHeader returns the Hash of the last wrapped RawHeader.
func (*ExtendedHeader) MarshalBinary ¶
func (eh *ExtendedHeader) MarshalBinary() ([]byte, error)
MarshalBinary marshals ExtendedHeader to binary.
func (*ExtendedHeader) MarshalJSON ¶ added in v0.5.0
func (eh *ExtendedHeader) MarshalJSON() ([]byte, error)
MarshalJSON marshals an ExtendedHeader to JSON. The ValidatorSet is wrapped with amino encoding, to be able to unmarshal the crypto.PubKey type back from JSON.
func (*ExtendedHeader) New ¶ added in v0.6.3
func (eh *ExtendedHeader) New() *ExtendedHeader
func (*ExtendedHeader) Time ¶ added in v0.6.3
func (eh *ExtendedHeader) Time() time.Time
func (*ExtendedHeader) UnmarshalBinary ¶
func (eh *ExtendedHeader) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshals ExtendedHeader from binary.
func (*ExtendedHeader) UnmarshalJSON ¶ added in v0.5.0
func (eh *ExtendedHeader) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals an ExtendedHeader from JSON. The ValidatorSet is wrapped with amino encoding, to be able to unmarshal the crypto.PubKey type back from JSON.
func (*ExtendedHeader) Validate ¶ added in v0.6.3
func (eh *ExtendedHeader) Validate() error
Validate performs *basic* validation to check for missed/incorrect fields.
func (*ExtendedHeader) Verify ¶ added in v0.7.0
func (eh *ExtendedHeader) Verify(untrst *ExtendedHeader) error
Verify validates given untrusted Header against trusted ExtendedHeader.