statesyncclient

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: GPL-3.0, LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StateSyncVersion = &version.Application{
		Major: 1,
		Minor: 7,
		Patch: 13,
	}
)

Functions

func NewClient

func NewClient(config *ClientConfig) *client

Types

type CallbackLeafSyncer

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

func NewCallbackLeafSyncer

func NewCallbackLeafSyncer(client LeafClient, tasks <-chan LeafSyncTask) *CallbackLeafSyncer

NewCallbackLeafSyncer creates a new syncer object to perform leaf sync of tries.

func (*CallbackLeafSyncer) Done

func (c *CallbackLeafSyncer) Done() <-chan error

Done returns a channel which produces any error that occurred during syncing or nil on success.

func (*CallbackLeafSyncer) Start

func (c *CallbackLeafSyncer) Start(ctx context.Context, numThreads int, onFailure func(error) error)

Start launches [numThreads] worker goroutines to process LeafSyncTasks from [c.tasks]. onFailure is called if the sync completes with an error.

type Client

type Client interface {
	// GetLeafs synchronously sends the given request, returning a parsed LeafsResponse or error
	// Note: this verifies the response including the range proofs.
	GetLeafs(ctx context.Context, request message.LeafsRequest) (message.LeafsResponse, error)

	// GetBlocks synchronously retrieves blocks starting with specified common.Hash and height up to specified parents
	// specified range from height to height-parents is inclusive
	GetBlocks(ctx context.Context, blockHash common.Hash, height uint64, parents uint16) ([]*types.Block, error)

	// GetCode synchronously retrieves code associated with the given hashes
	GetCode(ctx context.Context, hashes []common.Hash) ([][]byte, error)
}

Client synchronously fetches data from the network to fulfill state sync requests. Repeatedly requests failed requests until the context to the request is expired.

type ClientConfig

type ClientConfig struct {
	NetworkClient    peer.NetworkClient
	Codec            codec.Manager
	Stats            stats.ClientSyncerStats
	StateSyncNodeIDs []ids.NodeID
	BlockParser      EthBlockParser
}

type EthBlockParser

type EthBlockParser interface {
	ParseEthBlock(b []byte) (*types.Block, error)
}

type LeafClient

type LeafClient interface {
	// GetLeafs synchronously sends the given request, returning a parsed LeafsResponse or error
	// Note: this verifies the response including the range proofs.
	GetLeafs(context.Context, message.LeafsRequest) (message.LeafsResponse, error)
}

type LeafSyncTask

type LeafSyncTask interface {
	Root() common.Hash                 // Root of the trie to sync
	Account() common.Hash              // Account hash of the trie to sync (only applicable to storage tries)
	Start() []byte                     // Starting key to request new leaves
	End() []byte                       // End key to request new leaves
	NodeType() message.NodeType        // Specifies the message type (atomic/state trie) for the leaf syncer to send
	OnStart() (bool, error)            // Callback when tasks begins, returns true if work can be skipped
	OnLeafs(keys, vals [][]byte) error // Callback when new leaves are received from the network
	OnFinish() error                   // Callback when there are no more leaves in the trie to sync or when we reach End()
}

LeafSyncTask represents a complete task to be completed by the leaf syncer. Note: each LeafSyncTask is processed on its own goroutine and there will not be concurrent calls to the callback methods. Implementations should return the same value for Root, Account, Start, and NodeType throughout the sync. The value returned by End can change between calls to OnLeafs.

type MockClient

type MockClient struct {

	// GetLeafsIntercept is called on every GetLeafs request if set to a non-nil callback.
	// The returned response will be returned by MockClient to the caller.
	GetLeafsIntercept func(req message.LeafsRequest, res message.LeafsResponse) (message.LeafsResponse, error)
	// GetCodesIntercept is called on every GetCode request if set to a non-nil callback.
	// The returned response will be returned by MockClient to the caller.
	GetCodeIntercept func(hashes []common.Hash, codeBytes [][]byte) ([][]byte, error)
	// GetBlocksIntercept is called on every GetBlocks request if set to a non-nil callback.
	// The returned response will be returned by MockClient to the caller.
	GetBlocksIntercept func(blockReq message.BlockRequest, blocks types.Blocks) (types.Blocks, error)
	// contains filtered or unexported fields
}

TODO replace with gomock library

func NewMockClient

func NewMockClient(
	codec codec.Manager,
	leafHandler *handlers.LeafsRequestHandler,
	codesHandler *handlers.CodeRequestHandler,
	blocksHandler *handlers.BlockRequestHandler,
) *MockClient

func (*MockClient) BlocksReceived

func (ml *MockClient) BlocksReceived() int32

func (*MockClient) CodeReceived

func (ml *MockClient) CodeReceived() int32

func (*MockClient) GetBlocks

func (ml *MockClient) GetBlocks(ctx context.Context, blockHash common.Hash, height uint64, numParents uint16) ([]*types.Block, error)

func (*MockClient) GetCode

func (ml *MockClient) GetCode(ctx context.Context, hashes []common.Hash) ([][]byte, error)

func (*MockClient) GetLeafs

func (ml *MockClient) GetLeafs(ctx context.Context, request message.LeafsRequest) (message.LeafsResponse, error)

func (*MockClient) LeavesReceived

func (ml *MockClient) LeavesReceived() int32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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