Documentation ¶
Index ¶
- Variables
- func NewClient(config *ClientConfig) *client
- type CallbackLeafSyncer
- type Client
- type ClientConfig
- type EthBlockParser
- type LeafClient
- type LeafSyncTask
- type MockClient
- func (ml *MockClient) BlocksReceived() int32
- func (ml *MockClient) CodeReceived() int32
- func (ml *MockClient) GetBlocks(ctx context.Context, blockHash common.Hash, height uint64, numParents uint16) ([]*types.Block, error)
- func (ml *MockClient) GetCode(ctx context.Context, hashes []common.Hash) ([][]byte, error)
- func (ml *MockClient) GetLeafs(ctx context.Context, request message.LeafsRequest) (message.LeafsResponse, error)
- func (ml *MockClient) LeavesReceived() int32
- type OnFinish
- type OnLeafs
- type OnStart
- type OnSyncFailure
Constants ¶
This section is empty.
Variables ¶
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) *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 // 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 ¶ added in v0.8.11
type LeafClient ¶
type LeafClient interface {
GetLeafs(context.Context, 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) GetLeafs ¶
func (ml *MockClient) GetLeafs(ctx context.Context, request message.LeafsRequest) (message.LeafsResponse, error)
func (*MockClient) LeavesReceived ¶
func (ml *MockClient) LeavesReceived() int32
type OnFinish ¶
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 ¶
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 ¶
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 ¶
OnSyncFailure is notified with the error that caused the sync to halt will never be called with nil, the returned error is simply logged