sync

package
v0.15.16 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrMustSwitchPollingPreConfirmed = errors.New(
		"reached starknet 0.14.0. node requires switching from pending to polling pre_confirmed blocks",
	)
)

Functions

This section is empty.

Types

type CommittedBlock added in v0.15.0

type CommittedBlock struct {
	Block       *core.Block
	StateUpdate *core.StateUpdate
	NewClasses  map[felt.Felt]core.ClassDefinition
	Persisted   chan struct{} // This is used to signal that the block has been persisted
}

type DataSource added in v0.15.0

type DataSource interface {
	BlockByNumber(ctx context.Context, blockNumber uint64) (CommittedBlock, error)
	BlockLatest(ctx context.Context) (*core.Block, error)
	BlockPending(ctx context.Context) (core.Pending, error)
	PreConfirmedBlockByNumber(ctx context.Context, blockNumber uint64) (core.PreConfirmed, error)
}

func NewFeederGatewayDataSource added in v0.15.0

func NewFeederGatewayDataSource(blockchain *blockchain.Blockchain, starknetData starknetdata.StarknetData) DataSource

type EventListener added in v0.7.0

type EventListener interface {
	OnSyncStepDone(op string, blockNum uint64, took time.Duration)
	OnReorg(blockNum uint64)
}

type NewHeadSubscription added in v0.13.2

type NewHeadSubscription struct {
	*feed.Subscription[*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) PendingBlock added in v0.13.0

func (n *NoopSynchronizer) PendingBlock() *core.Block

func (*NoopSynchronizer) PendingData added in v0.15.0

func (n *NoopSynchronizer) PendingData() (core.PendingData, error)

func (*NoopSynchronizer) PendingState added in v0.13.0

func (n *NoopSynchronizer) PendingState() (core.StateReader, func() error, error)

func (*NoopSynchronizer) StartingBlockNumber added in v0.10.0

func (n *NoopSynchronizer) StartingBlockNumber() (uint64, error)

func (*NoopSynchronizer) SubscribeNewHeads added in v0.10.0

func (n *NoopSynchronizer) SubscribeNewHeads() NewHeadSubscription

func (*NoopSynchronizer) SubscribePendingData added in v0.15.0

func (n *NoopSynchronizer) SubscribePendingData() PendingDataSubscription

func (*NoopSynchronizer) SubscribePreLatest added in v0.15.9

func (n *NoopSynchronizer) SubscribePreLatest() PreLatestDataSubscription

func (*NoopSynchronizer) SubscribeReorg added in v0.13.0

func (n *NoopSynchronizer) SubscribeReorg() ReorgSubscription

type PendingDataSubscription added in v0.15.0

type PendingDataSubscription struct {
	*feed.Subscription[core.PendingData]
}

type PendingTxSubscription added in v0.13.0

type PendingTxSubscription struct {
	*feed.Subscription[[]core.Transaction]
}

type PreLatestDataSubscription added in v0.15.9

type PreLatestDataSubscription struct {
	*feed.Subscription[*core.PreLatest]
}

type Reader added in v0.6.2

type Reader interface {
	StartingBlockNumber() (uint64, error)
	HighestBlockHeader() *core.Header
	SubscribeNewHeads() NewHeadSubscription
	SubscribeReorg() ReorgSubscription
	SubscribePendingData() PendingDataSubscription
	SubscribePreLatest() PreLatestDataSubscription

	PendingData() (core.PendingData, error)
	PendingBlock() *core.Block
}

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)
}

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 manages a list of StarknetData to fetch the latest blockchain updates

func New added in v0.2.1

func New(
	bc *blockchain.Blockchain,
	dataSource DataSource,
	log utils.SimpleLogger,
	pendingPollInterval, preConfirmedPollInterval time.Duration,
	readOnlyBlockchain bool,
	database db.KeyValueStore,
) *Synchronizer

func (*Synchronizer) HighestBlockHeader added in v0.3.0

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

func (*Synchronizer) PendingBlock added in v0.13.0

func (s *Synchronizer) PendingBlock() *core.Block

func (*Synchronizer) PendingData added in v0.15.0

func (s *Synchronizer) PendingData() (core.PendingData, 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) StartingBlockNumber added in v0.3.0

func (s *Synchronizer) StartingBlockNumber() (uint64, error)

func (*Synchronizer) StorePending added in v0.13.0

func (s *Synchronizer) StorePending(p *core.Pending) (bool, error)

StorePending stores a pending block given that it is for the next height

func (*Synchronizer) StorePreConfirmed added in v0.15.0

func (s *Synchronizer) StorePreConfirmed(p *core.PreConfirmed) (bool, error)

StorePreConfirmed stores a pre_confirmed block given that it is for the next height. If an equal-number block with >= txCount already exists, we do not overwrite it, but we allow updating the PreLatest attachment in-place via a CAS swap.

func (*Synchronizer) SubscribeNewHeads added in v0.7.4

func (s *Synchronizer) SubscribeNewHeads() NewHeadSubscription

func (*Synchronizer) SubscribePendingData added in v0.15.0

func (s *Synchronizer) SubscribePendingData() PendingDataSubscription

func (*Synchronizer) SubscribePreLatest added in v0.15.9

func (s *Synchronizer) SubscribePreLatest() PreLatestDataSubscription

func (*Synchronizer) SubscribeReorg added in v0.13.0

func (s *Synchronizer) SubscribeReorg() ReorgSubscription

func (*Synchronizer) UpdatePreLatestAttachment added in v0.15.6

func (s *Synchronizer) UpdatePreLatestAttachment(blockNumber uint64, preLatest *core.PreLatest) bool

UpdatePreLatestAttachment updates (or clears) the PreLatest attachment of the currently stored pre_confirmed at the given blockNumber by atomically swapping the stored pointer. Returns true if the store was updated, false if no matching pre_confirmed is stored or the attachment was already equal.

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

Jump to

Keyboard shortcuts

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