l1

package
v0.16.6-rc.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(
	provider L1StateProvider,
	chain *blockchain.Blockchain,
	logger log.StructuredLogger,
	opts ...Option,
) *Client

func (*Client) CatchUpL1Head added in v0.16.1

func (c *Client) CatchUpL1Head(ctx context.Context) error

CatchUpL1Head fetches and writes the latest L1 head to the database. Contrary to Client.Run it doesn't track live updates and finishes on the spot. The client must not be re-used after.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run fetches and writes the latest L1 head to the database. Then, it tracks live updates until context is cancelled.

type EventListener added in v0.7.5

type EventListener interface {
	OnNewL1Head(head *core.L1Head)
	OnL1Call(method string, took time.Duration)
}

type GethL1StateProvider added in v0.16.6

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

GethL1StateProvider is the go-ethereum-backed L1StateProvider, wrapping ethclient plus the abigen StarknetFilterer to talk to the Starknet core L1 bridge. It also satisfies rpccore.L1Client (via TransactionReceipt), so node.go hands one instance to both the L1 sync loop and the RPC handlers.

WS connection drops are recovered below this layer: rpc.Client reconnects unary calls, and subscription drops surface on Err() for l1.Client.watchL1StateUpdates to resubscribe.

func NewGethL1StateProvider added in v0.16.6

func NewGethL1StateProvider(
	ctx context.Context,
	rawURL string,
	contractAddress eth.Address,
	opts ...GethL1StateProviderOption,
) (*GethL1StateProvider, error)

NewGethL1StateProvider dials the Ethereum endpoint at url and returns a ready-to-use L1StateProvider bound to contractAddress (the Starknet core L1 bridge). The transport is selected by URL scheme; ws/wss is required so log subscriptions work.

func (*GethL1StateProvider) ChainID added in v0.16.6

func (s *GethL1StateProvider) ChainID(ctx context.Context) (*big.Int, error)

ChainID returns the Ethereum chain id (eth_chainId).

func (*GethL1StateProvider) Close added in v0.16.6

func (s *GethL1StateProvider) Close()

Close releases the underlying RPC client.

func (*GethL1StateProvider) FilterStateUpdate added in v0.16.6

func (s *GethL1StateProvider) FilterStateUpdate(
	ctx context.Context,
	from, to uint64,
) ([]*StateUpdate, error)

FilterStateUpdate decodes every LogStateUpdate in [from, to] into the StateUpdate shape.

func (*GethL1StateProvider) FinalisedHeight added in v0.16.6

func (s *GethL1StateProvider) FinalisedHeight(ctx context.Context) (uint64, error)

FinalisedHeight returns the latest finalised L1 block number. A missing finalised header is reported as eth.ErrNotFound so callers can distinguish "node hasn't seen finality yet" from a transport failure.

func (*GethL1StateProvider) LatestHeight added in v0.16.6

func (s *GethL1StateProvider) LatestHeight(ctx context.Context) (uint64, error)

LatestHeight returns the latest known L1 block number (eth_blockNumber).

func (*GethL1StateProvider) TransactionReceipt added in v0.16.6

func (s *GethL1StateProvider) TransactionReceipt(
	ctx context.Context,
	txHash eth.Hash,
) (eth.Receipt, error)

TransactionReceipt fetches an L1 transaction receipt by hash. Used by the RPC handlers for starknet_getMessageStatus.

func (*GethL1StateProvider) WatchStateUpdate added in v0.16.6

func (s *GethL1StateProvider) WatchStateUpdate(
	ctx context.Context,
	updatesCh chan<- *StateUpdate,
) (Subscription, error)

WatchStateUpdate subscribes to live LogStateUpdate events and forwards each one (decoded into StateUpdate, with felt conversion already applied) on updatesCh. Requires a ws/wss endpoint.

Caller contract: updatesCh MUST be drained promptly. A channel that stalls back-pressures the abigen subscription channel and eventually the underlying ws connection.

type GethL1StateProviderOption added in v0.16.6

type GethL1StateProviderOption func(*gethL1StateProviderOptions)

GethL1StateProviderOption configures a GethL1StateProvider at construction time.

func WithL1StateProviderListener added in v0.16.6

func WithL1StateProviderListener(l EventListener) GethL1StateProviderOption

type L1StateProvider added in v0.16.6

type L1StateProvider interface {
	ChainID(ctx context.Context) (*big.Int, error)
	FinalisedHeight(ctx context.Context) (uint64, error)
	LatestHeight(ctx context.Context) (uint64, error)
	WatchStateUpdate(ctx context.Context, updatesCh chan<- *StateUpdate) (Subscription, error)
	FilterStateUpdate(ctx context.Context, from, to uint64) ([]*StateUpdate, error)
	Close()
}

L1StateProvider is how l1.Client follows the Ethereum L1 chain Starknet settles to: heights, LogStateUpdate events, and chain id.

type Option added in v0.16.1

type Option func(*options)

Option is a functional option for configuring l1 client options.

func WithCatchUpChunkSize added in v0.16.1

func WithCatchUpChunkSize(size uint64) Option

WithCatchUpChunkSize sets the L1 block range per backward eth_getLogs request during the startup catch-up scan.

func WithEventListener added in v0.16.1

func WithEventListener(l EventListener) Option

func WithPollFinalisedInterval added in v0.16.1

func WithPollFinalisedInterval(d time.Duration) Option

WithPollFinalisedInterval sets the time to wait before checking for an update to the finalised L1 block.

func WithResubscribeDelay added in v0.16.1

func WithResubscribeDelay(d time.Duration) Option

type SelectiveListener added in v0.7.5

type SelectiveListener struct {
	OnNewL1HeadCb func(head *core.L1Head)
	OnL1CallCb    func(method string, took time.Duration)
}

func (SelectiveListener) OnL1Call added in v0.12.3

func (l SelectiveListener) OnL1Call(method string, took time.Duration)

func (SelectiveListener) OnNewL1Head added in v0.7.5

func (l SelectiveListener) OnNewL1Head(head *core.L1Head)

type StateUpdate added in v0.16.6

type StateUpdate struct {
	// L2BlockNumber is the Starknet block number being committed.
	L2BlockNumber uint64
	// L2BlockHash is the Starknet block hash for that block.
	L2BlockHash felt.Felt
	// StateRoot is the Starknet global state root after the block
	// (the "globalRoot" field in the on-chain event).
	StateRoot felt.Felt
	// L1RefHeight is the L1 block number where the commit was observed.
	// Used by the L1 sync loop to gate writes on L1 finality.
	L1RefHeight uint64
	// Removed is set when L1 signals that the log was rolled back by a
	// reorg.
	Removed bool
}

StateUpdate is the decoded form of the Starknet core contract's LogStateUpdate event in juno's own types

type Subscription added in v0.16.6

type Subscription interface {
	Err() <-chan error
	Unsubscribe()
}

Subscription mirrors go-ethereum's event.Subscription surface as consumed by l1.Client: a channel signalling failure, and an Unsubscribe method to release resources.

Directories

Path Synopsis
eth
abi
Package abi decodes the non-indexed data section of specific Ethereum event logs the juno node consumes.
Package abi decodes the non-indexed data section of specific Ethereum event logs the juno node consumes.
geth

Jump to

Keyboard shortcuts

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