sync

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 20 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OpVerify = "verify"
	OpStore  = "store"
	OpFetch  = "fetch"

	// Wait ops time how long a finished block waits before the next stage takes it.
	// Blocks leave each stage in order, so a block waits for all blocks before it,
	// and for free space in the queue of the next stage.
	OpFetchWait  = "fetchWait"
	OpVerifyWait = "verifyWait"

	// Reorg-check ops, one per exit level of isReverting: resolved from the
	// local height alone, after fetching the remote head, or only after also
	// reading the local header for a hash comparison.
	OpReorgCheckFast   = "reorgCheckFast"
	OpReorgCheckRemote = "reorgCheckRemote"
	OpReorgCheckLocal  = "reorgCheckLocal"
)

Variables

This section is empty.

Functions

func MissingClassHashes added in v0.17.1

func MissingClassHashes(
	chain *blockchain.Blockchain,
	stateDiff *core.StateDiff,
) ([]*felt.ClassHash, error)

Types

type CommittedBlock added in v0.15.0

type CommittedBlock struct {
	Block       *core.Block
	StateUpdate *core.StateUpdate
	NewClasses  map[felt.ClassHash]core.ClassDefinition
	Persisted   chan error // This is used to signal whether the block was persisted successfully
}

type DataSource added in v0.15.0

type DataSource interface {
	BlockByNumber(ctx context.Context, blockNumber uint64) (CommittedBlock, error)
	BlockHeaderLatest(ctx context.Context) (*core.Header, error)
}

func NewFeederGatewayDataSource added in v0.15.0

func NewFeederGatewayDataSource(
	blockchain *blockchain.Blockchain,
	feeder *adaptfeeder.Feeder,
	opts ...DataSourceOption,
) DataSource

type DataSourceOption added in v0.17.1

type DataSourceOption func(*feederGatewayDataSource)

DataSourceOption configures the feeder gateway DataSource.

func WithOnClassesFetched added in v0.17.1

func WithOnClassesFetched(
	onClassesFetched func(blockNum uint64, count int, took time.Duration),
) DataSourceOption

WithOnClassesFetched sets a callback that gets the number of new classes of each fetched block and the time to download them.

type EventListener added in v0.7.0

type EventListener interface {
	OnSyncStepDone(op string, blockNum uint64, took time.Duration)
	OnReorg(blockNum uint64)
	// OnFetchStarted and OnFetchDone mark the start and end of each block fetch.
	OnFetchStarted()
	OnFetchDone()
	// OnBlockStored reports a block that sync stored, with its transaction count.
	OnBlockStored(blockNum uint64, txCount int)
}

type NewHeadSubscription added in v0.13.2

type NewHeadSubscription struct {
	*feed.Subscription[*core.WithBloom[*core.Block]]
}

This is a work-around. mockgen chokes when the instantiated generic type is in the interface.

type NoopSynchronizer added in v0.10.0

type NoopSynchronizer struct{}

This is temporary and will be removed once the p2p synchronizer implements this interface.

func (*NoopSynchronizer) HighestBlockHeader added in v0.10.0

func (n *NoopSynchronizer) HighestBlockHeader() *core.Header

func (*NoopSynchronizer) ReadPreConfirmedChain added in v0.17.0

func (n *NoopSynchronizer) ReadPreConfirmedChain() (preconfirmed.ChainReader, error)

func (*NoopSynchronizer) RequestPreConfirmedChain added in v0.17.0

func (n *NoopSynchronizer) RequestPreConfirmedChain() (preconfirmed.ChainReader, error)

func (*NoopSynchronizer) StartingBlockHeader added in v0.16.6

func (n *NoopSynchronizer) StartingBlockHeader() (*core.Header, error)

func (*NoopSynchronizer) SubscribeNewHeads added in v0.10.0

func (n *NoopSynchronizer) SubscribeNewHeads() NewHeadSubscription

func (*NoopSynchronizer) SubscribePreConfirmed added in v0.16.0

func (n *NoopSynchronizer) SubscribePreConfirmed() preconfirmed.Subscription

func (*NoopSynchronizer) SubscribeReorg added in v0.13.0

func (n *NoopSynchronizer) SubscribeReorg() ReorgSubscription

type Option added in v0.16.7

type Option func(*options)

Option is a functional option for configuring a Synchronizer.

func WithPreConfirmed added in v0.17.0

func WithPreConfirmed(opts ...preconfirmed.Option) Option

WithPreConfirmed configures the pre-confirmed poller; see preconfirmed.Option. Repeated calls accumulate, with later options winning over earlier ones.

func WithReadOnlyBlockchain added in v0.16.7

func WithReadOnlyBlockchain(readOnly bool) Option

WithReadOnlyBlockchain stops the synchronizer from writing to the blockchain.

type Reader added in v0.6.2

type Reader interface {
	StartingBlockHeader() (*core.Header, error)
	HighestBlockHeader() *core.Header
	SubscribeNewHeads() NewHeadSubscription
	SubscribeReorg() ReorgSubscription
	SubscribePreConfirmed() preconfirmed.Subscription
	// ReadPreConfirmedChain returns the stored pre-confirmed chain
	ReadPreConfirmedChain() (preconfirmed.ChainReader, error)
	// RequestPreConfirmedChain returns the pre-confirmed chain, polling for fresher data if
	// the stored one is stale. It can block for a while doing so.
	RequestPreConfirmedChain() (preconfirmed.ChainReader, error)
}

Todo: Since this is also going to be implemented by p2p package we should move this interface to node package

type ReorgBlockRange added in v0.13.0

type ReorgBlockRange struct {
	// StartBlockHash is the hash of the first known block of the orphaned chain
	StartBlockHash *felt.Felt
	// StartBlockNum is the number of the first known block of the orphaned chain
	StartBlockNum uint64
	// The last known block of the orphaned chain
	EndBlockHash *felt.Felt
	// Number of the last known block of the orphaned chain
	EndBlockNum uint64
}

ReorgBlockRange represents data about reorganised blocks, starting and ending block number and hash

type ReorgSubscription added in v0.13.0

type ReorgSubscription struct {
	*feed.Subscription[*ReorgBlockRange]
}

type SelectiveListener added in v0.7.0

type SelectiveListener struct {
	OnSyncStepDoneCb func(op string, blockNum uint64, took time.Duration)
	OnReorgCb        func(blockNum uint64)
	OnFetchStartedCb func()
	OnFetchDoneCb    func()
	OnBlockStoredCb  func(blockNum uint64, txCount int)
}

func (*SelectiveListener) OnBlockStored added in v0.17.1

func (l *SelectiveListener) OnBlockStored(blockNum uint64, txCount int)

func (*SelectiveListener) OnFetchDone added in v0.17.1

func (l *SelectiveListener) OnFetchDone()

func (*SelectiveListener) OnFetchStarted added in v0.17.1

func (l *SelectiveListener) OnFetchStarted()

func (*SelectiveListener) OnReorg added in v0.7.0

func (l *SelectiveListener) OnReorg(blockNum uint64)

func (*SelectiveListener) OnSyncStepDone added in v0.7.0

func (l *SelectiveListener) OnSyncStepDone(op string, blockNum uint64, took time.Duration)

type Synchronizer

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

Synchronizer fetches blocks from its DataSource and stores them in the blockchain

func New added in v0.2.1

func New(
	blockchain *blockchain.Blockchain,
	dataSource DataSource,
	preConfirmedSource preconfirmed.DataSource,
	logger log.StructuredLogger,
	opts ...Option,
) *Synchronizer

func (*Synchronizer) HighestBlockHeader added in v0.3.0

func (s *Synchronizer) HighestBlockHeader() *core.Header

func (*Synchronizer) ReadPreConfirmedChain added in v0.17.0

func (s *Synchronizer) ReadPreConfirmedChain() (preconfirmed.ChainReader, error)

func (*Synchronizer) RequestPreConfirmedChain added in v0.17.0

func (s *Synchronizer) RequestPreConfirmedChain() (preconfirmed.ChainReader, error)

func (*Synchronizer) Run

func (s *Synchronizer) Run(ctx context.Context) error

Run starts the Synchronizer, returns an error if the loop is already running

func (*Synchronizer) StartingBlockHeader added in v0.16.6

func (s *Synchronizer) StartingBlockHeader() (*core.Header, error)

func (*Synchronizer) SubscribeNewHeads added in v0.7.4

func (s *Synchronizer) SubscribeNewHeads() NewHeadSubscription

func (*Synchronizer) SubscribePreConfirmed added in v0.16.0

func (s *Synchronizer) SubscribePreConfirmed() preconfirmed.Subscription

func (*Synchronizer) SubscribeReorg added in v0.13.0

func (s *Synchronizer) SubscribeReorg() ReorgSubscription

func (*Synchronizer) WithListener added in v0.7.0

func (s *Synchronizer) WithListener(listener EventListener) *Synchronizer

WithListener registers an EventListener

func (*Synchronizer) WithPlugin added in v0.12.3

func (s *Synchronizer) WithPlugin(plugin junoplugin.JunoPlugin) *Synchronizer

WithPlugin registers an plugin

Directories

Path Synopsis
Package rpcsource lives outside package sync because rpc/v10, whose types it decodes, imports sync.
Package rpcsource lives outside package sync because rpc/v10, whose types it decodes, imports sync.

Jump to

Keyboard shortcuts

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