sync

package
v0.0.8-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainServiceProtocol        = "/chainservice/"
	ChainServiceProtocolVersion = "1.0.0"
)

Variables

View Source
var ErrNotCurrent = errors.New("peer not current")
View Source
var ErrNotFound = errors.New("not found")

Functions

func UseLogger

func UseLogger(logger *logger.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type ChainService

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

func NewChainService

func NewChainService(ctx context.Context, fetchBlock FetchBlockFunc, chain *blockchain.Blockchain, network *net.Network, params *params.NetworkParams) (*ChainService, error)

func (*ChainService) GetBest

func (cs *ChainService) GetBest(p peer.ID) (types.ID, uint32, error)

func (*ChainService) GetBlock

func (cs *ChainService) GetBlock(p peer.ID, blockID types.ID) (*blocks.Block, error)

func (*ChainService) GetBlockID

func (cs *ChainService) GetBlockID(p peer.ID, height uint32) (types.ID, error)

func (*ChainService) GetBlockTxids

func (cs *ChainService) GetBlockTxids(p peer.ID, blockID types.ID) ([]types.ID, error)

func (*ChainService) GetBlockTxs

func (cs *ChainService) GetBlockTxs(p peer.ID, blockID types.ID, txIndexes []uint32) ([]*transactions.Transaction, error)

func (*ChainService) GetBlockTxsStream

func (cs *ChainService) GetBlockTxsStream(p peer.ID, startHeight uint32) (<-chan *blocks.BlockTxs, error)

func (*ChainService) GetHeadersStream

func (cs *ChainService) GetHeadersStream(p peer.ID, startHeight uint32) (<-chan *blocks.BlockHeader, error)

func (*ChainService) HandleNewStream

func (cs *ChainService) HandleNewStream(s inet.Stream)

type ConsensusChooser

type ConsensusChooser func([]*blocks.Block) (types.ID, error)

ConsensusChooser is an interface function which polls the consensus engine to determine the best block at the height.

type FetchBlockFunc

type FetchBlockFunc func(blockID types.ID) (*blocks.Block, error)

type SyncManager

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

SyncManager is responsible for trustlessly syncing the blockchain to the tip of the chain.

func NewSyncManager

func NewSyncManager(cfg *SyncManagerConfig) *SyncManager

NewSyncManager returns a new initialized SyncManager

func (*SyncManager) Close

func (sm *SyncManager) Close()

Close stops the sync and resets the SyncManager. It can be restarted after this point.

func (*SyncManager) IsCurrent

func (sm *SyncManager) IsCurrent() bool

IsCurrent returns whether the SyncManager believes it is synced to the tip of the chain.

func (*SyncManager) SetCurrent

func (sm *SyncManager) SetCurrent()

SetCurrent sets the sync manager to current. This will stop the sync.

func (*SyncManager) Start

func (sm *SyncManager) Start()

Start begins the process of syncing to the tip of the chain

type SyncManagerConfig

type SyncManagerConfig struct {
	Ctx               context.Context
	Chain             *blockchain.Blockchain
	Network           *net.Network
	Params            *params.NetworkParams
	CS                *ChainService
	Chooser           ConsensusChooser
	ProofCache        *blockchain.ProofCache
	SigCache          *blockchain.SigCache
	Verifier          zk.Verifier
	IsCurrentCallback func()
}

SyncManagerConfig holds the configuration options for the SyncManager

Jump to

Keyboard shortcuts

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