statesync

package
v0.34.11 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: Apache-2.0 Imports: 37 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)
)

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/providenetwork/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:            2,
				SendQueueCapacity:   10,
				RecvMessageCapacity: lightBlockMsgSize,
				RecvBufferCapacity:  128,
				MaxSendBytes:        400,
			},
		},
	}
)

Functions

This section is empty.

Types

type MockSyncReactor

type MockSyncReactor struct {
	mock.Mock
}

MockSyncReactor is an autogenerated mock type for the SyncReactor type. Because of the stateprovider uses in Sync(), we use package statesync instead of mocks.

func (*MockSyncReactor) Backfill

func (_m *MockSyncReactor) Backfill(_a0 state.State) error

Backfill provides a mock function with given fields: _a0

func (*MockSyncReactor) Sync

Sync provides a mock function with given fields: _a0, _a1, _a2

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(
	cfg config.StateSyncConfig,
	logger log.Logger,
	conn proxy.AppConnSnapshot,
	connQuery proxy.AppConnQuery,
	snapshotCh, chunkCh, blockCh *p2p.Channel,
	peerUpdates *p2p.PeerUpdates,
	stateStore sm.Store,
	blockStore *store.BlockStore,
	tempDir string,
) *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) Backfill

func (r *Reactor) Backfill(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) Dispatcher

func (r *Reactor) Dispatcher() *dispatcher

Dispatcher exposes the dispatcher so that a state provider can use it for light client verification

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. 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) Sync

func (r *Reactor) Sync(
	ctx context.Context,
	stateProvider StateProvider,
	discoveryTime time.Duration,
) (sm.State, error)

Sync runs a state sync, fetching snapshots and providing chunks to the application. It also saves tendermint state and runs a backfill process to retrieve the necessary amount of headers, commits and validators sets to be able to process evidence and participate in consensus.

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.

func NewLightClientStateProvider

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

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

func NewLightClientStateProviderFromDispatcher

func NewLightClientStateProviderFromDispatcher(
	ctx context.Context,
	chainID string,
	version sm.Version,
	initialHeight int64,
	dispatcher *dispatcher,
	trustOptions light.TrustOptions,
	logger log.Logger,
) (StateProvider, error)

NewLightClientStateProviderFromDispatcher creates a light client state provider but uses a p2p connected dispatched instead of RPC endpoints

type SyncReactor

type SyncReactor interface {
	Sync(context.Context, StateProvider, time.Duration) (sm.State, error)
	Backfill(sm.State) error
}

SyncReactor defines an interface used for testing abilities of node.startStateSync.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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