Documentation
¶
Index ¶
- type Client
- type EventListener
- type GethL1StateProvider
- func (s *GethL1StateProvider) ChainID(ctx context.Context) (*big.Int, error)
- func (s *GethL1StateProvider) Close()
- func (s *GethL1StateProvider) FilterStateUpdate(ctx context.Context, from, to uint64) ([]*StateUpdate, error)
- func (s *GethL1StateProvider) FinalisedHeight(ctx context.Context) (uint64, error)
- func (s *GethL1StateProvider) LatestHeight(ctx context.Context) (uint64, error)
- func (s *GethL1StateProvider) TransactionReceipt(ctx context.Context, txHash eth.Hash) (eth.Receipt, error)
- func (s *GethL1StateProvider) WatchStateUpdate(ctx context.Context, updatesCh chan<- *StateUpdate) (Subscription, error)
- type GethL1StateProviderOption
- type L1StateProvider
- type Option
- type SelectiveListener
- type StateUpdate
- type Subscription
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
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.
type EventListener ¶ added in v0.7.5
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
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
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
WithPollFinalisedInterval sets the time to wait before checking for an update to the finalised L1 block.
func WithResubscribeDelay ¶ added in v0.16.1
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.