syncer

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: Apache-2.0, MIT Imports: 18 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 store is violating expected invariants.
	ErrUnexpectedStoreState = errors.New("the chain store is in an unexpected state")
)

Functions

This section is empty.

Types

type BadTipSetCache

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

BadTipSetCache keeps track of bad tipsets that the syncer should not try to download. Readers and writers grab a lock. The purpose of this cache is to prevent a node from having to repeatedly invalidate a block (and its children) in the event that the tipset does not conform to the rules of consensus. Note that the cache is only in-memory, so it is reset whenever the node is restarted. TODO: this needs to be limited.

func (*BadTipSetCache) Add

func (cache *BadTipSetCache) Add(tsKey string)

Add adds a single tipset key to the BadTipSetCache.

func (*BadTipSetCache) AddChain

func (cache *BadTipSetCache) AddChain(chain []block.TipSet)

AddChain adds the chain of tipsets to the BadTipSetCache. For now it just does the simplest thing and adds all blocks of the chain to the cache. TODO: might want to cache a random subset once cache size is limited.

func (*BadTipSetCache) Has

func (cache *BadTipSetCache) Has(tsKey string) bool

Has checks for membership in the BadTipSetCache.

type ChainReaderWriter

type ChainReaderWriter interface {
	GetHead() block.TipSetKey
	GetTipSet(tsKey block.TipSetKey) (block.TipSet, error)
	GetTipSetStateRoot(tsKey block.TipSetKey) (cid.Cid, error)
	GetTipSetReceiptsRoot(tsKey block.TipSetKey) (cid.Cid, error)
	HasTipSetAndState(ctx context.Context, tsKey block.TipSetKey) bool
	PutTipSetMetadata(ctx context.Context, tsas *chain.TipSetMetadata) error
	SetHead(ctx context.Context, ts block.TipSet) error
	HasTipSetAndStatesWithParentsAndHeight(pTsKey block.TipSetKey, h abi.ChainEpoch) bool
	GetTipSetAndStatesByParentsAndHeight(pTsKey block.TipSetKey, h abi.ChainEpoch) ([]*chain.TipSetMetadata, error)
}

ChainReaderWriter reads and writes the chain store.

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, aStateID, bStateID cid.Cid) (bool, error)
	// Weight returns the weight of a tipset after the upgrade to version 1
	Weight(ctx context.Context, ts block.TipSet, stRoot cid.Cid) (fbig.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, blsMessages [][]*types.UnsignedMessage, secpMessages [][]*types.SignedMessage, parentWeight fbig.Int, stateID cid.Cid, receiptRoot cid.Cid) (cid.Cid, []vm.MessageReceipt, error)
}

FullBlockValidator does semantic validation on fullblocks.

type HeaderValidator

type HeaderValidator interface {
	// ValidateSemantic validates conditions on a block header that can be
	// checked with the parent header but not parent state.
	ValidateSemantic(ctx context.Context, header *block.Block, parents block.TipSet) error
}

HeaderValidator does semanitc validation on headers

type Syncer

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

Syncer updates its chain.Store according to the methods of its consensus.Protocol. It uses a bad tipset cache and a limit on new blocks to traverse during chain collection. The Syncer can query the network for blocks. The Syncer maintains the following invariant on its store: all tipsets that pass the syncer's validity checks are added to the chain store along with their state root CID.

Ideally the code that syncs the chain according to consensus rules should be independent of any particular implementation of consensus. Currently the Syncer is coupled to details of Expected Consensus. This dependence exists in the widen function, the fact that widen is called on only one tipset in the incoming chain, and assumptions regarding the existence of grandparent state in the store.

func NewSyncer

func NewSyncer(fv FullBlockValidator, hv HeaderValidator, cs ChainSelector, s ChainReaderWriter, m messageStore, f Fetcher, sr status.Reporter, c clock.Clock, fd faultDetector) (*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, ci *block.ChainInfo, catchup bool) error

HandleNewTipSet validates and syncs the chain rooted at the provided tipset to a chain store. 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 store 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) Status

func (syncer *Syncer) Status() status.Status

Status returns the current syncer status.

Jump to

Keyboard shortcuts

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