syncer

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChainHasBadTipSet is returned when the syncer traverses a chain with a cached bad tipset.
	ErrChainHasBadTipSet = errors.New("input chain contains a cached bad tipset")
	// ErrNewChainTooLong is returned when processing a fork that split off from the main chain too many blocks ago.
	ErrNewChainTooLong = errors.New("input chain forked from best chain past finality limit")
	// ErrUnexpectedStoreState indicates that the syncer's chain bsstore is violating expected invariants.
	ErrUnexpectedStoreState = errors.New("the chain bsstore is in an unexpected state")
)
View Source
var ErrForkTooLong = fmt.Errorf("fork longer than threshold")

Functions

func RangeProcess

func RangeProcess(ts []*block.TipSet, cb func(ts []*block.TipSet) error) (err error)

Types

type BlockValidator

type BlockValidator interface {
	// ValidateHeaderSemantic validates conditions on a block header that can be
	// checked with the parent header but not parent state.
	ValidateHeaderSemantic(context.Context, *block.Block, *block.TipSet) error
	// ValidateMessagesSemantic validates a block's messages against parent state without applying the messages
	ValidateMessagesSemantic(context.Context, *block.Block, *block.TipSet) error
}

BlockValidator does semanitc validation on headers

type ChainReaderWriter

type ChainReaderWriter interface {
	GetHead() *block.TipSet
	GetTipSet(block.TipSetKey) (*block.TipSet, error)
	GetTipSetStateRoot(*block.TipSet) (cid.Cid, error)
	GetTipSetReceiptsRoot(*block.TipSet) (cid.Cid, error)
	HasTipSetAndState(context.Context, *block.TipSet) bool
	PutTipSetMetadata(context.Context, *chain.TipSetMetadata) error
	SetHead(context.Context, *block.TipSet) error
	HasSiblingState(*block.TipSet) bool
	GetSiblingState(*block.TipSet) ([]*chain.TipSetMetadata, error)
	GetLatestBeaconEntry(*block.TipSet) (*block.BeaconEntry, error)
	GetGenesisBlock(context.Context) (*block.Block, error)
}

ChainReaderWriter reads and writes the chain bsstore.

type ChainSelector

type ChainSelector interface {
	// IsHeavier returns true if tipset a is heavier than tipset b and false if
	// tipset b is heavier than tipset a.
	IsHeavier(ctx context.Context, a, b *block.TipSet) (bool, error)
	// Weight returns the weight of a tipset after the upgrade to version 1
	Weight(ctx context.Context, ts *block.TipSet) (big.Int, error)
}

ChainSelector chooses the heaviest between chains.

type Fetcher

type Fetcher interface {
	// FetchTipSets will only fetch TipSets that evaluate to `false` when passed to `done`,
	// this includes the provided `ts`. The TipSet that evaluates to true when
	// passed to `done` will be in the returned slice. The returns slice of TipSets is in Traversal order.
	FetchTipSets(context.Context, block.TipSetKey, peer.ID, func(*block.TipSet) (bool, error)) ([]*block.TipSet, error)

	// FetchTipSetHeaders will fetch only the headers of tipset blocks.
	// Returned slice in reversal order
	FetchTipSetHeaders(context.Context, block.TipSetKey, peer.ID, func(*block.TipSet) (bool, error)) ([]*block.TipSet, error)
}

Fetcher defines an interface that may be used to fetch data from the network.

type FullBlockValidator

type FullBlockValidator interface {
	// RunStateTransition returns the state root CID resulting from applying the input ts to the
	// prior `stateRoot`.  It returns an error if the transition is invalid.
	RunStateTransition(ctx context.Context, ts *block.TipSet, parentStateRoot cid.Cid) (root cid.Cid, receipts []types.MessageReceipt, err error)
	// Todo add by force
	ValidateMining(ctx context.Context, parent, ts *block.TipSet, parentWeight big.Int, parentReceiptRoot cid.Cid) error
}

FullBlockValidator does semantic validation on fullblocks.

type Syncer

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

func NewSyncer

func NewSyncer(fv FullBlockValidator,
	hv BlockValidator,
	cs ChainSelector,
	s ChainReaderWriter,
	m messageStore,
	bsstore blockstore.Blockstore,
	f Fetcher,
	exchangeClient exchange.Client,
	c clock.Clock,
	fd faultDetector,
	fork fork.IFork) (*Syncer, error)

NewSyncer constructs a Syncer ready for use. The chain reader must have a head tipset to initialize the staging field.

func (*Syncer) HandleNewTipSet

func (syncer *Syncer) HandleNewTipSet(ctx context.Context, target *syncTypes.Target) (err error)

HandleNewTipSet validates and syncs the chain rooted at the provided tipset to a chain bsstore. Iff catchup is false then the syncer will set the head.

func (*Syncer) InitStaged

func (syncer *Syncer) InitStaged() error

InitStaged reads the head from the syncer's chain bsstore and sets the syncer's staged field. Used for initializing syncer.

func (*Syncer) SetStagedHead

func (syncer *Syncer) SetStagedHead(ctx context.Context) error

SetStagedHead sets the syncer's internal staged tipset to the chain's head.

func (*Syncer) Staged

func (syncer *Syncer) Staged() *block.TipSet

Jump to

Keyboard shortcuts

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