statesync

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0, LGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMainTrieTask

func NewMainTrieTask(sync *stateSync) syncTask

func NewStorageTrieTask

func NewStorageTrieTask(sync *stateSync, root common.Hash, accounts []common.Hash) syncTask

func NewSyncer

func NewSyncer(client syncclient.Client, db ethdb.Database, root common.Hash, codeQueue *CodeQueue, leafsRequestSize uint16, opts ...SyncerOption) (syncpkg.Syncer, error)

func NewTrieQueue

func NewTrieQueue(db ethdb.Database) *trieQueue

func NewTrieToSync

func NewTrieToSync(sync *stateSync, root common.Hash, account common.Hash, syncTask syncTask) (*trieToSync, error)

NewTrieToSync initializes a trieToSync and restores any previously started segments.

Types

type CodeQueue

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

CodeQueue implements the producer side of code fetching. It accepts code hashes, persists durable "to-fetch" markers (idempotent per hash), and enqueues the hashes as-is onto an internal channel consumed by the code syncer. The queue does not perform in-memory deduplication or local-code checks - that is the responsibility of the consumer.

func NewCodeQueue

func NewCodeQueue(db ethdb.Database, quit <-chan struct{}, opts ...CodeQueueOption) (*CodeQueue, error)

NewCodeQueue creates a new code queue applying optional functional options. The `quit` channel, if non-nil, MUST eventually be closed to avoid leaking a goroutine.

func (*CodeQueue) AddCode

func (q *CodeQueue) AddCode(ctx context.Context, codeHashes []common.Hash) error

AddCode persists and enqueues new code hashes. Persists idempotent "to-fetch" markers for all inputs and enqueues them as-is. Returns errAddCodeAfterFinalize after a clean finalize and errFailedToAddCodeHashesToQueue on early quit.

func (*CodeQueue) CodeHashes

func (q *CodeQueue) CodeHashes() <-chan common.Hash

CodeHashes returns the receive-only channel of code hashes to consume.

func (*CodeQueue) Finalize

func (q *CodeQueue) Finalize() error

Finalize signals that no further code hashes will be added. Waits for in-flight enqueues to complete, then closes the output channel. If the queue was already closed due to early quit, returns errFailedToFinalizeCodeQueue.

type CodeQueueOption

type CodeQueueOption = options.Option[CodeQueue]

func WithCapacity

func WithCapacity(n int) CodeQueueOption

WithCapacity overrides the queue buffer capacity.

type CodeSyncer

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

CodeSyncer syncs code bytes from the network in a separate thread. It consumes code hashes from a queue and persists code into the DB. Outstanding requests are tracked via durable "to-fetch" markers in the DB for recovery. The syncer performs in-flight deduplication and skips locally-present code before issuing requests.

func NewCodeSyncer

func NewCodeSyncer(client statesyncclient.Client, db ethdb.Database, codeHashes <-chan common.Hash, opts ...CodeSyncerOption) (*CodeSyncer, error)

NewCodeSyncer allows external packages (e.g., registry wiring) to create a code syncer that consumes hashes from a provided fetcher queue.

func (*CodeSyncer) ID

func (*CodeSyncer) ID() string

ID returns the stable identifier for this sync task.

func (*CodeSyncer) Name

func (*CodeSyncer) Name() string

Name returns the human-readable name for this sync task.

func (*CodeSyncer) Sync

func (c *CodeSyncer) Sync(ctx context.Context) error

Sync starts the worker thread and populates the code hashes queue with active work. Blocks until all outstanding code requests from a previous sync have been fetched and the code channel has been closed, or the context is cancelled.

type CodeSyncerOption

type CodeSyncerOption = options.Option[codeSyncerConfig]

CodeSyncerOption configures CodeSyncer at construction time.

func WithCodeHashesPerRequest

func WithCodeHashesPerRequest(n int) CodeSyncerOption

WithCodeHashesPerRequest sets the best-effort target batch size per request. The final batch may contain fewer than the configured number if insufficient hashes remain when the channel is closed.

func WithNumWorkers

func WithNumWorkers(n int) CodeSyncerOption

WithNumWorkers overrides the number of concurrent workers.

type SyncerOption

type SyncerOption = options.Option[stateSync]

SyncerOption configures the state syncer via functional options.

func WithBatchSize

func WithBatchSize(n uint) SyncerOption

WithBatchSize sets the database batch size for writes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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