Documentation ¶
Index ¶
- Constants
- Variables
- func VerifyElectionPoStVRF(ctx context.Context, worker address.Address, rand []byte, evrf []byte) error
- type BadBlockCache
- type BadBlockReason
- type SyncFunc
- type SyncManager
- type SyncManagerCtor
- type Syncer
- func (syncer *Syncer) ChainStore() *store.ChainStore
- func (syncer *Syncer) CheckBadBlockCache(blk cid.Cid) (string, bool)
- func (syncer *Syncer) FetchTipSet(ctx context.Context, p peer.ID, tsk types.TipSetKey) (*store.FullTipSet, error)
- func (syncer *Syncer) GetCheckpoint() types.TipSetKey
- func (syncer *Syncer) IncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error)
- func (syncer *Syncer) InformNewBlock(from peer.ID, blk *types.FullBlock) bool
- func (syncer *Syncer) InformNewHead(from peer.ID, fts *store.FullTipSet) bool
- func (syncer *Syncer) IsEpochBeyondCurrMax(epoch abi.ChainEpoch) bool
- func (syncer *Syncer) LocalPeer() peer.ID
- func (syncer *Syncer) MarkBad(blk cid.Cid)
- func (syncer *Syncer) SetCheckpoint(tsk types.TipSetKey) error
- func (syncer *Syncer) Start()
- func (syncer *Syncer) State() []SyncerStateSnapshot
- func (syncer *Syncer) Stop()
- func (syncer *Syncer) Sync(ctx context.Context, maybeHead *types.TipSet) error
- func (syncer *Syncer) UnmarkAllBad()
- func (syncer *Syncer) UnmarkBad(blk cid.Cid)
- func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock, useCache bool) (err error)
- func (syncer *Syncer) ValidateMsgMeta(fblk *types.FullBlock) error
- func (syncer *Syncer) ValidateTipSet(ctx context.Context, fts *store.FullTipSet, useCache bool) error
- func (syncer *Syncer) VerifyWinningPoStProof(ctx context.Context, nv network.Version, h *types.BlockHeader, ...) error
- type SyncerState
- type SyncerStateSnapshot
Constants ¶
const MaxHeightDrift = 5
Blocks that are more than MaxHeightDrift epochs above the theoretical max height based on systime are quickly rejected
Variables ¶
var ( BootstrapPeerThreshold = build.BootstrapPeerThreshold RecentSyncBufferSize = 10 MaxSyncWorkers = 5 SyncWorkerHistory = 3 InitialSyncTimeThreshold = 15 * time.Minute )
var CheckpointKey = datastore.NewKey("/chain/checks")
var ErrForkCheckpoint = fmt.Errorf("fork would require us to diverge from checkpointed block")
var ErrForkTooLong = fmt.Errorf("fork longer than threshold")
var ErrTemporal = errors.New("temporal error")
var ( // LocalIncoming is the _local_ pubsub (unrelated to libp2p pubsub) topic // where the Syncer publishes candidate chain heads to be synced. LocalIncoming = "incoming" )
Functions ¶
Types ¶
type BadBlockCache ¶
type BadBlockCache struct {
// contains filtered or unexported fields
}
func NewBadBlockCache ¶
func NewBadBlockCache() *BadBlockCache
func (*BadBlockCache) Add ¶
func (bts *BadBlockCache) Add(c cid.Cid, bbr BadBlockReason)
func (*BadBlockCache) Has ¶
func (bts *BadBlockCache) Has(c cid.Cid) (BadBlockReason, bool)
func (*BadBlockCache) Purge ¶
func (bts *BadBlockCache) Purge()
func (*BadBlockCache) Remove ¶
func (bts *BadBlockCache) Remove(c cid.Cid)
type BadBlockReason ¶
type BadBlockReason struct { Reason string TipSet []cid.Cid OriginalReason *BadBlockReason }
func NewBadBlockReason ¶
func NewBadBlockReason(cid []cid.Cid, format string, i ...interface{}) BadBlockReason
func (BadBlockReason) Linked ¶
func (bbr BadBlockReason) Linked(reason string, i ...interface{}) BadBlockReason
func (BadBlockReason) String ¶
func (bbr BadBlockReason) String() string
type SyncManager ¶
type SyncManager interface { // Start starts the SyncManager. Start() // Stop stops the SyncManager. Stop() // SetPeerHead informs the SyncManager that the supplied peer reported the // supplied tipset. SetPeerHead(ctx context.Context, p peer.ID, ts *types.TipSet) // State retrieves the state of the sync workers. State() []SyncerStateSnapshot }
SyncManager manages the chain synchronization process, both at bootstrap time and during ongoing operation.
It receives candidate chain heads in the form of tipsets from peers, and schedules them onto sync workers, deduplicating processing for already-active syncs.
type SyncManagerCtor ¶
type SyncManagerCtor func(syncFn SyncFunc) SyncManager
type Syncer ¶
type Syncer struct { // The known Genesis tipset Genesis *types.TipSet // handle to the block sync service Exchange exchange.Client // contains filtered or unexported fields }
Syncer is in charge of running the chain synchronization logic. As such, it is tasked with these functions, amongst others:
- Fast-forwards the chain as it learns of new TipSets from the network via the SyncManager.
- Applies the fork choice rule to select the correct side when confronted with a fork in the network.
- Requests block headers and messages from other peers when not available in our BlockStore.
- Tracks blocks marked as bad in a cache.
- Keeps the BlockStore and ChainStore consistent with our view of the world, the latter of which in turn informs other components when a reorg has been committed.
The Syncer does not run workers itself. It's mainly concerned with ensuring a consistent state of chain consensus. The reactive and network- interfacing processes are part of other components, such as the SyncManager (which owns the sync scheduler and sync workers), ChainExchange, the HELLO protocol, and the gossipsub block propagation layer.
{hint/concept} The fork-choice rule as it currently stands is: "pick the chain with the heaviest weight, so long as it hasn’t deviated one finality threshold from our head (900 epochs, parameter determined by spec-actors)".
func NewSyncer ¶
func NewSyncer(ds dtypes.MetadataDS, sm *stmgr.StateManager, exchange exchange.Client, syncMgrCtor SyncManagerCtor, connmgr connmgr.ConnManager, self peer.ID, beacon beacon.Schedule, verifier ffiwrapper.Verifier) (*Syncer, error)
NewSyncer creates a new Syncer object.
func (*Syncer) ChainStore ¶
func (syncer *Syncer) ChainStore() *store.ChainStore
func (*Syncer) CheckBadBlockCache ¶
func (*Syncer) FetchTipSet ¶
func (syncer *Syncer) FetchTipSet(ctx context.Context, p peer.ID, tsk types.TipSetKey) (*store.FullTipSet, error)
FetchTipSet tries to load the provided tipset from the store, and falls back to the network (client) by querying the supplied peer if not found locally.
{hint/usage} This is used from the HELLO protocol, to fetch the greeting peer's heaviest tipset if we don't have it.
func (*Syncer) GetCheckpoint ¶
func (*Syncer) IncomingBlocks ¶
IncomingBlocks spawns a goroutine that subscribes to the local eventbus to receive new block headers as they arrive from the network, and sends them to the returned channel.
These blocks have not necessarily been incorporated to our view of the chain.
func (*Syncer) InformNewBlock ¶
func (*Syncer) InformNewHead ¶
InformNewHead informs the syncer about a new potential tipset This should be called when connecting to new peers, and additionally when receiving new blocks from the network
func (*Syncer) IsEpochBeyondCurrMax ¶
func (syncer *Syncer) IsEpochBeyondCurrMax(epoch abi.ChainEpoch) bool
func (*Syncer) MarkBad ¶
func (syncer *Syncer) MarkBad(blk cid.Cid)
MarkBad manually adds a block to the "bad blocks" cache.
func (*Syncer) State ¶
func (syncer *Syncer) State() []SyncerStateSnapshot
func (*Syncer) Sync ¶
Sync tries to advance our view of the chain to `maybeHead`. It does nothing if our current head is heavier than the requested tipset, or if we're already at the requested head, or if the head is the genesis.
Most of the heavy-lifting logic happens in syncer#collectChain. Refer to the godocs on that method for a more detailed view.
func (*Syncer) UnmarkAllBad ¶
func (syncer *Syncer) UnmarkAllBad()
func (*Syncer) UnmarkBad ¶
func (syncer *Syncer) UnmarkBad(blk cid.Cid)
UnmarkBad manually adds a block to the "bad blocks" cache.
func (*Syncer) ValidateBlock ¶
func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock, useCache bool) (err error)
ValidateBlock should match up with 'Semantical Validation' in validation.md in the spec
func (*Syncer) ValidateMsgMeta ¶
ValidateMsgMeta performs structural and content hash validation of the messages within this block. If validation passes, it stores the messages in the underlying IPLD block store.
func (*Syncer) ValidateTipSet ¶
func (*Syncer) VerifyWinningPoStProof ¶
func (syncer *Syncer) VerifyWinningPoStProof(ctx context.Context, nv network.Version, h *types.BlockHeader, prevBeacon types.BeaconEntry, lbst cid.Cid, waddr address.Address) error
type SyncerState ¶
type SyncerState struct {
// contains filtered or unexported fields
}
func (*SyncerState) Error ¶
func (ss *SyncerState) Error(err error)
func (*SyncerState) Init ¶
func (ss *SyncerState) Init(base, target *types.TipSet)
func (*SyncerState) SetHeight ¶
func (ss *SyncerState) SetHeight(h abi.ChainEpoch)
func (*SyncerState) SetStage ¶
func (ss *SyncerState) SetStage(v api.SyncStateStage)
func (*SyncerState) Snapshot ¶
func (ss *SyncerState) Snapshot() SyncerStateSnapshot
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package exchange contains the ChainExchange server and client components.
|
Package exchange contains the ChainExchange server and client components. |