statesync

package
v0.35.5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SnapshotChannel exchanges snapshot metadata
	SnapshotChannel = p2p.ChannelID(0x60)

	// ChunkChannel exchanges chunk contents
	ChunkChannel = p2p.ChannelID(0x61)

	// LightBlockChannel exchanges light blocks
	LightBlockChannel = p2p.ChannelID(0x62)

	// ParamsChannel exchanges consensus params
	ParamsChannel = p2p.ChannelID(0x63)
)
View Source
const (
	// MetricsSubsystem is a subsystem shared by all metrics exposed by this package.
	MetricsSubsystem = "statesync"
)

Variables

View Source
var (

	// ChannelShims contains a map of ChannelDescriptorShim objects, where each
	// object wraps a reference to a legacy p2p ChannelDescriptor and the corresponding
	// p2p proto.Message the new p2p Channel is responsible for handling.
	//
	//
	// TODO: Remove once p2p refactor is complete.
	// ref: https://github.com/tendermint/tendermint/issues/5670
	ChannelShims = map[p2p.ChannelID]*p2p.ChannelDescriptorShim{
		SnapshotChannel: {
			MsgType: new(ssproto.Message),
			Descriptor: &p2p.ChannelDescriptor{
				ID:                  byte(SnapshotChannel),
				Priority:            6,
				SendQueueCapacity:   10,
				RecvMessageCapacity: snapshotMsgSize,
				RecvBufferCapacity:  128,
				MaxSendBytes:        400,
			},
		},
		ChunkChannel: {
			MsgType: new(ssproto.Message),
			Descriptor: &p2p.ChannelDescriptor{
				ID:                  byte(ChunkChannel),
				Priority:            3,
				SendQueueCapacity:   4,
				RecvMessageCapacity: chunkMsgSize,
				RecvBufferCapacity:  128,
				MaxSendBytes:        400,
			},
		},
		LightBlockChannel: {
			MsgType: new(ssproto.Message),
			Descriptor: &p2p.ChannelDescriptor{
				ID:                  byte(LightBlockChannel),
				Priority:            5,
				SendQueueCapacity:   10,
				RecvMessageCapacity: lightBlockMsgSize,
				RecvBufferCapacity:  128,
				MaxSendBytes:        400,
			},
		},
		ParamsChannel: {
			MsgType: new(ssproto.Message),
			Descriptor: &p2p.ChannelDescriptor{
				ID:                  byte(ParamsChannel),
				Priority:            2,
				SendQueueCapacity:   10,
				RecvMessageCapacity: paramMsgSize,
				RecvBufferCapacity:  128,
				MaxSendBytes:        400,
			},
		},
	}
)

Functions

This section is empty.

Types

type BlockProvider

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

BlockProvider is a p2p based light provider which uses a dispatcher connected to the state sync reactor to serve light blocks to the light client

TODO: This should probably be moved over to the light package but as we're not yet officially supporting p2p light clients we'll leave this here for now.

NOTE: BlockProvider will return an error with concurrent calls. However, we don't need a mutex because a light client (and the backfill process) will never call a method more than once at the same time

func NewBlockProvider

func NewBlockProvider(peer types.NodeID, chainID string, dispatcher *Dispatcher) *BlockProvider

Creates a block provider which implements the light client Provider interface.

func (*BlockProvider) LightBlock

func (p *BlockProvider) LightBlock(ctx context.Context, height int64) (*types.LightBlock, error)

LightBlock fetches a light block from the peer at a specified height returning either a light block or an appropriate error.

func (*BlockProvider) ReportEvidence

func (p *BlockProvider) ReportEvidence(ctx context.Context, ev types.Evidence) error

ReportEvidence should allow for the light client to report any light client attacks. This is a no op as there currently isn't a way to wire this up to the evidence reactor (we should endeavor to do this in the future but for now it's not critical for backwards verification)

func (*BlockProvider) String

func (p *BlockProvider) String() string

String implements stringer interface

type Dispatcher

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

A Dispatcher multiplexes concurrent requests by multiple peers for light blocks. Only one request per peer can be sent at a time. Subsequent concurrent requests will report an error from the LightBlock method. NOTE: It is not the responsibility of the dispatcher to verify the light blocks.

func NewDispatcher

func NewDispatcher(requestCh chan<- p2p.Envelope) *Dispatcher

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close shuts down the dispatcher and cancels any pending calls awaiting responses. Peers awaiting responses that have not arrived are delivered a nil block.

func (*Dispatcher) Done

func (d *Dispatcher) Done() <-chan struct{}

func (*Dispatcher) LightBlock

func (d *Dispatcher) LightBlock(ctx context.Context, height int64, peer types.NodeID) (*types.LightBlock, error)

LightBlock uses the request channel to fetch a light block from a given peer tracking, the call and waiting for the reactor to pass back the response. A nil LightBlock response is used to signal that the peer doesn't have the requested LightBlock.

func (*Dispatcher) Respond

func (d *Dispatcher) Respond(lb *tmproto.LightBlock, peer types.NodeID) error

Respond allows the underlying process which receives requests on the requestCh to respond with the respective light block. A nil response is used to represent that the receiver of the request does not have a light block at that height.

type Metricer

type Metricer interface {
	TotalSnapshots() int64
	ChunkProcessAvgTime() time.Duration
	SnapshotHeight() int64
	SnapshotChunksCount() int64
	SnapshotChunksTotal() int64
	BackFilledBlocks() int64
	BackFillBlocksTotal() int64
}

Metricer defines an interface used for the rpc sync info query, please see statesync.metrics for the details.

type Metrics

type Metrics struct {
	TotalSnapshots      metrics.Counter
	ChunkProcessAvgTime metrics.Gauge
	SnapshotHeight      metrics.Gauge
	SnapshotChunk       metrics.Counter
	SnapshotChunkTotal  metrics.Gauge
	BackFilledBlocks    metrics.Counter
	BackFillBlocksTotal metrics.Gauge
}

Metrics contains metrics exposed by this package.

func NopMetrics

func NopMetrics() *Metrics

NopMetrics returns no-op Metrics.

func PrometheusMetrics

func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics

PrometheusMetrics returns Metrics build using Prometheus client library. Optionally, labels can be provided along with their values ("foo", "fooValue").

type Reactor

type Reactor struct {
	service.BaseService
	// contains filtered or unexported fields
}

Reactor handles state sync, both restoring snapshots for the local node and serving snapshots for other nodes.

func NewReactor

func NewReactor(
	chainID string,
	initialHeight int64,
	cfg config.StateSyncConfig,
	logger log.Logger,
	conn proxy.AppConnSnapshot,
	connQuery proxy.AppConnQuery,
	snapshotCh, chunkCh, blockCh, paramsCh *p2p.Channel,
	peerUpdates *p2p.PeerUpdates,
	stateStore sm.Store,
	blockStore *store.BlockStore,
	tempDir string,
	ssMetrics *Metrics,
) *Reactor

NewReactor returns a reference to a new state sync reactor, which implements the service.Service interface. It accepts a logger, connections for snapshots and querying, references to p2p Channels and a channel to listen for peer updates on. Note, the reactor will close all p2p Channels when stopping.

func (*Reactor) BackFillBlocksTotal

func (r *Reactor) BackFillBlocksTotal() int64

func (*Reactor) BackFilledBlocks

func (r *Reactor) BackFilledBlocks() int64

func (*Reactor) Backfill

func (r *Reactor) Backfill(ctx context.Context, state sm.State) error

Backfill sequentially fetches, verifies and stores light blocks in reverse order. It does not stop verifying blocks until reaching a block with a height and time that is less or equal to the stopHeight and stopTime. The trustedBlockID should be of the header at startHeight.

func (*Reactor) ChunkProcessAvgTime

func (r *Reactor) ChunkProcessAvgTime() time.Duration

func (*Reactor) OnStart

func (r *Reactor) OnStart() error

OnStart starts separate go routines for each p2p Channel and listens for envelopes on each. In addition, it also listens for peer updates and handles messages on that p2p channel accordingly. Note, we do not launch a go-routine to handle individual envelopes as to not have to deal with bounding workers or pools. The caller must be sure to execute OnStop to ensure the outbound p2p Channels are closed. No error is returned.

func (*Reactor) OnStop

func (r *Reactor) OnStop()

OnStop stops the reactor by signaling to all spawned goroutines to exit and blocking until they all exit.

func (*Reactor) SnapshotChunksCount

func (r *Reactor) SnapshotChunksCount() int64

func (*Reactor) SnapshotChunksTotal

func (r *Reactor) SnapshotChunksTotal() int64

func (*Reactor) SnapshotHeight

func (r *Reactor) SnapshotHeight() int64

func (*Reactor) Sync

func (r *Reactor) Sync(ctx context.Context) (sm.State, error)

Sync runs a state sync, fetching snapshots and providing chunks to the application. At the close of the operation, Sync will bootstrap the state store and persist the commit at that height so that either consensus or blocksync can commence. It will then proceed to backfill the necessary amount of historical blocks before participating in consensus

func (*Reactor) TotalSnapshots

func (r *Reactor) TotalSnapshots() int64

type StateProvider

type StateProvider interface {
	// AppHash returns the app hash after the given height has been committed.
	AppHash(ctx context.Context, height uint64) ([]byte, error)
	// Commit returns the commit at the given height.
	Commit(ctx context.Context, height uint64) (*types.Commit, error)
	// State returns a state object at the given height.
	State(ctx context.Context, height uint64) (sm.State, error)
}

StateProvider is a provider of trusted state data for bootstrapping a node. This refers to the state.State object, not the state machine. There are two implementations. One uses the P2P layer and the other uses the RPC layer. Both use light client verification.

func NewP2PStateProvider

func NewP2PStateProvider(
	ctx context.Context,
	chainID string,
	initialHeight int64,
	providers []lightprovider.Provider,
	trustOptions light.TrustOptions,
	paramsSendCh chan<- p2p.Envelope,
	logger log.Logger,
) (StateProvider, error)

NewP2PStateProvider creates a light client state provider but uses a dispatcher connected to the P2P layer

func NewRPCStateProvider

func NewRPCStateProvider(
	ctx context.Context,
	chainID string,
	initialHeight int64,
	servers []string,
	trustOptions light.TrustOptions,
	logger log.Logger,
) (StateProvider, error)

NewRPCStateProvider creates a new StateProvider using a light client and RPC clients.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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