statesyncclient

package
v0.8.11 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: GPL-3.0, LGPL-3.0 Imports: 27 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StateSyncVersion = version.NewDefaultApplication(constants.PlatformName, 1, 7, 12)
)

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) *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, task *LeafSyncTask, subtasks ...*LeafSyncTask)

Start begins syncing the leaves of the tries corresponding to [task] and [subtasks].

Note: a maximum of [numThreads] tasks can be executed at once, such that if all of the actively syncing tasks call addTask while the task buffer is full, there may be a deadlock. For the atomic trie, this should never happen since there is only a single root task and no subtasks. For the EVM state trie, subtasks are started before the main task. This ensures the number of in progress tasks stays less than or equal to [numThreads]. These subtasks will not add subtasks, since they have no sub-tries. Therefore, an actively syncing storage trie task never blocks. Once the number of tasks in progress is below [numThreads], the main task begins. This task adds more subtasks as storage roots are encountered during the sync. This will block when there are [numThreads-1] storage tries being synced by worker threads.

type Client

type Client interface {
	// GetLeafs synchronously sends given request, returning parsed *LeafsResponse or error
	GetLeafs(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(blockHash common.Hash, height uint64, parents uint16) ([]*types.Block, error)

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

Client is a state sync client that synchronously fetches data from the network

type ClientConfig

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

type EthBlockParser added in v0.8.11

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

type LeafClient

type LeafClient interface {
	GetLeafs(message.LeafsRequest) (message.LeafsResponse, error)
}

type LeafSyncTask

type LeafSyncTask struct {
	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
	NodeType      message.NodeType // Specifies the message type (atomic/state trie) for the leaf syncer to send
	OnStart       OnStart          // Callback when tasks begins, returns true if work can be skipped
	OnLeafs       OnLeafs          // Callback when new leaves are received from the network
	OnFinish      OnFinish         // Callback when there are no more leaves in the trie to sync
	OnSyncFailure OnSyncFailure    // Callback when the leaf syncer fails while performing the task.
}

LeafSyncTask represents a complete task to be completed by the leaf syncer.

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(blockHash common.Hash, height uint64, numParents uint16) ([]*types.Block, error)

func (*MockClient) GetCode

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

func (*MockClient) GetLeafs

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

func (*MockClient) LeavesReceived

func (ml *MockClient) LeavesReceived() int32

type OnFinish

type OnFinish func(root common.Hash) error

OnFinish is called the LeafSyncTask has completed syncing all of the leaves for the trie given by [root]. OnFinish will be called after there are no more leaves in the trie to be synced.

type OnLeafs

type OnLeafs func(root common.Hash, keys [][]byte, values [][]byte) ([]*LeafSyncTask, error)

OnLeafs is the callback used by LeafSyncTask when there are new leaves received from the network. Returns a slice of LeafSyncTasks that will be added to the tasks of the LeafSyncer.

type OnStart

type OnStart func(root common.Hash) (bool, error)

OnStart is the callback used by LeafSyncTask to determine if work can be skipped. Returns true if work should be skipped (eg, because data was available on disk)

type OnSyncFailure

type OnSyncFailure func(error) error

OnSyncFailure is notified with the error that caused the sync to halt will never be called with nil, the returned error is simply logged

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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