chainsync

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package chainsync implements the Ouroboros chain-sync protocol

Index

Constants

View Source
const (
	MessageTypeRequestNext       = 0
	MessageTypeAwaitReply        = 1
	MessageTypeRollForward       = 2
	MessageTypeRollBackward      = 3
	MessageTypeFindIntersect     = 4
	MessageTypeIntersectFound    = 5
	MessageTypeIntersectNotFound = 6
	MessageTypeDone              = 7
)

Message types

Variables

View Source
var StateMap = protocol.StateMap{
	// contains filtered or unexported fields
}

ChainSync protocol state machine

Functions

func NewMsgFromCbor added in v0.10.0

func NewMsgFromCbor(protoMode protocol.ProtocolMode, msgType uint, data []byte) (protocol.Message, error)

NewMsgFromCbor parses a ChainSync message from CBOR

func NewMsgFromCborNtC added in v0.10.0

func NewMsgFromCborNtC(msgType uint, data []byte) (protocol.Message, error)

NewMsgFromCborNtC parses a NtC ChainSync message from CBOR

func NewMsgFromCborNtN added in v0.10.0

func NewMsgFromCborNtN(msgType uint, data []byte) (protocol.Message, error)

NewMsgFromCborNtN parses a NtC ChainSync message from CBOR

Types

type ChainSync

type ChainSync struct {
	Client *Client
	Server *Server
}

ChainSync is a wrapper object that holds the client and server instances

func New

func New(protoOptions protocol.ProtocolOptions, cfg *Config) *ChainSync

New returns a new ChainSync object

type ChainSyncOptionFunc added in v0.25.0

type ChainSyncOptionFunc func(*Config)

ChainSyncOptionFunc represents a function used to modify the ChainSync protocol config

func WithBlockTimeout added in v0.25.0

func WithBlockTimeout(timeout time.Duration) ChainSyncOptionFunc

WithBlockTimeout specifies the timeout for block fetch operations

func WithIntersectTimeout added in v0.25.0

func WithIntersectTimeout(timeout time.Duration) ChainSyncOptionFunc

WithIntersectTimeout specifies the timeout for intersect operations

func WithRollBackwardFunc added in v0.25.0

func WithRollBackwardFunc(rollBackwardFunc RollBackwardFunc) ChainSyncOptionFunc

WithRollBackwardFunc specifies the RollBackward callback function

func WithRollForwardFunc added in v0.25.0

func WithRollForwardFunc(rollForwardFunc RollForwardFunc) ChainSyncOptionFunc

WithRollForwardFunc specifies the RollForward callback function

type Client added in v0.19.0

type Client struct {
	*protocol.Protocol
	// contains filtered or unexported fields
}

Client implements the ChainSync client

func NewClient added in v0.19.0

func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client

NewClient returns a new ChainSync client object

func (*Client) GetCurrentTip added in v0.22.0

func (c *Client) GetCurrentTip() (*Tip, error)

GetCurrentTip returns the current chain tip

func (*Client) Stop added in v0.21.0

func (c *Client) Stop() error

Stop transitions the protocol to the Done state. No more protocol operations will be possible afterward

func (*Client) Sync added in v0.21.0

func (c *Client) Sync(intersectPoints []common.Point) error

Sync begins a chain-sync operation using the provided intersect point(s). Incoming blocks will be delivered via the RollForward callback function specified in the protocol config

type Config added in v0.18.0

type Config struct {
	RollBackwardFunc RollBackwardFunc
	RollForwardFunc  RollForwardFunc
	IntersectTimeout time.Duration
	BlockTimeout     time.Duration
}

Config is used to configure the ChainSync protocol instance

func NewConfig added in v0.25.0

func NewConfig(options ...ChainSyncOptionFunc) Config

NewConfig returns a new ChainSync config object with the provided options

type IntersectNotFoundError added in v0.21.0

type IntersectNotFoundError struct {
}

IntersectNotFoundError represents a failure to find a chain intersection

func (IntersectNotFoundError) Error added in v0.21.0

func (e IntersectNotFoundError) Error() string

type MsgAwaitReply added in v0.10.0

type MsgAwaitReply struct {
	protocol.MessageBase
}

func NewMsgAwaitReply added in v0.12.1

func NewMsgAwaitReply() *MsgAwaitReply

type MsgDone added in v0.10.0

type MsgDone struct {
	protocol.MessageBase
}

func NewMsgDone added in v0.12.1

func NewMsgDone() *MsgDone

type MsgFindIntersect added in v0.10.0

type MsgFindIntersect struct {
	protocol.MessageBase
	Points []common.Point
}

func NewMsgFindIntersect added in v0.10.0

func NewMsgFindIntersect(points []common.Point) *MsgFindIntersect

type MsgIntersectFound added in v0.10.0

type MsgIntersectFound struct {
	protocol.MessageBase
	Point common.Point
	Tip   Tip
}

func NewMsgIntersectFound added in v0.12.1

func NewMsgIntersectFound(point common.Point, tip Tip) *MsgIntersectFound

type MsgIntersectNotFound added in v0.10.0

type MsgIntersectNotFound struct {
	protocol.MessageBase
	Tip Tip
}

func NewMsgIntersectNotFound added in v0.12.1

func NewMsgIntersectNotFound(tip Tip) *MsgIntersectNotFound

type MsgRequestNext added in v0.10.0

type MsgRequestNext struct {
	protocol.MessageBase
}

func NewMsgRequestNext added in v0.10.0

func NewMsgRequestNext() *MsgRequestNext

type MsgRollBackward added in v0.10.0

type MsgRollBackward struct {
	protocol.MessageBase
	Point common.Point
	Tip   Tip
}

func NewMsgRollBackward added in v0.12.1

func NewMsgRollBackward(point common.Point, tip Tip) *MsgRollBackward

type MsgRollForwardNtC added in v0.10.0

type MsgRollForwardNtC struct {
	protocol.MessageBase
	WrappedBlock cbor.Tag
	Tip          Tip
	// contains filtered or unexported fields
}

MsgRollForwardNtC is the NtC version of the RollForward message

func NewMsgRollForwardNtC added in v0.12.1

func NewMsgRollForwardNtC(blockType uint, blockCbor []byte, tip Tip) *MsgRollForwardNtC

NewMsgRollForwardNtC returns a MsgRollForwardNtC with the provided parameters

func (*MsgRollForwardNtC) BlockCbor added in v0.13.1

func (m *MsgRollForwardNtC) BlockCbor() []byte

BlockCbor returns the block CBOR

func (*MsgRollForwardNtC) BlockType added in v0.13.1

func (m *MsgRollForwardNtC) BlockType() uint

BlockType returns the block type

type MsgRollForwardNtN added in v0.10.0

type MsgRollForwardNtN struct {
	protocol.MessageBase
	WrappedHeader WrappedHeader
	Tip           Tip
}

MsgRollForwardNtN is the NtN version of the RollForward message

func NewMsgRollForwardNtN added in v0.12.1

func NewMsgRollForwardNtN(era uint, byronType uint, blockCbor []byte, tip Tip) *MsgRollForwardNtN

NewMsgRollForwardNtN returns a MsgRollForwardNtN with the provided parameters

type RollBackwardFunc added in v0.18.0

type RollBackwardFunc func(common.Point, Tip) error

Callback function types

type RollForwardFunc added in v0.18.0

type RollForwardFunc func(uint, interface{}, Tip) error

type Server added in v0.19.0

type Server struct {
	*protocol.Protocol
	// contains filtered or unexported fields
}

Server implements the ChainSync server

func NewServer added in v0.19.0

func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server

NewServer returns a new ChainSync server object

type Tip added in v0.10.0

type Tip struct {
	Point       common.Point
	BlockNumber uint64
	// contains filtered or unexported fields
}

type WrappedBlock added in v0.10.0

type WrappedBlock struct {
	BlockType uint
	BlockCbor cbor.RawMessage
	// contains filtered or unexported fields
}

WrappedBlock represents a block returned via a NtC RollForward message

func NewWrappedBlock added in v0.13.1

func NewWrappedBlock(blockType uint, blockCbor []byte) *WrappedBlock

NewWrappedBlock returns a new WrappedBlock

type WrappedHeader added in v0.10.0

type WrappedHeader struct {
	Era        uint
	RawMessage cbor.RawMessage
	// contains filtered or unexported fields
}

WrappedHeader represents a block header returned via NtN RollForward message

func NewWrappedHeader added in v0.13.1

func NewWrappedHeader(era uint, byronType uint, blockCbor []byte) *WrappedHeader

NewWrappedHeader returns a new WrappedHeader

func (*WrappedHeader) ByronType added in v0.13.1

func (w *WrappedHeader) ByronType() uint

ByronType returns the block type for Byron blocks

func (*WrappedHeader) HeaderCbor added in v0.13.1

func (w *WrappedHeader) HeaderCbor() []byte

HeaderCbor returns the header CBOR

func (*WrappedHeader) MarshalCBOR added in v0.13.1

func (w *WrappedHeader) MarshalCBOR() ([]byte, error)

func (*WrappedHeader) UnmarshalCBOR added in v0.13.1

func (w *WrappedHeader) UnmarshalCBOR(data []byte) error

Jump to

Keyboard shortcuts

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