Documentation
¶
Index ¶
- Constants
- func ComputeBlockHash(chainID, blockNumber uint64) []byte
- type Client
- func (c *Client) Close()
- func (c *Client) DepositToCanton(ctx context.Context, token common.Address, amount *big.Int, ...) (common.Hash, error)
- func (c *Client) GetLastScannedBlock() uint64
- func (c *Client) GetLatestBlockNumber(ctx context.Context) (uint64, error)
- func (c *Client) GetTransactor(ctx context.Context) (*bind.TransactOpts, error)
- func (c *Client) IsWithdrawalProcessed(ctx context.Context, cantonTxHash [32]byte) (bool, error)
- func (c *Client) WatchDepositEvents(ctx context.Context, fromBlock uint64, handler func(*DepositEvent) error) error
- func (c *Client) WithdrawFromCanton(ctx context.Context, token common.Address, recipient common.Address, ...) (common.Hash, error)
- type Config
- type DepositEvent
- type Metrics
- type WithdrawalEvent
Constants ¶
const ERC20ABI = `` /* 1309-byte string literal not displayed */
ERC20ABI is the standard ERC20 token interface ABI. This is the canonical definition used across the codebase.
Variables ¶
This section is empty.
Functions ¶
func ComputeBlockHash ¶
ComputeBlockHash generates a deterministic block hash from chain ID and block number. This is used for synthetic blocks in the Canton-EVM bridge.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an Ethereum client
func NewClient ¶
NewClient creates a new Ethereum client.
metrics receives Prometheus observations for every outbound RPC call and for the deposit-event poll loop. Pass NewNopMetrics() in tests where metric values aren't asserted.
func (*Client) DepositToCanton ¶
func (c *Client) DepositToCanton( ctx context.Context, token common.Address, amount *big.Int, cantonRecipient [32]byte, ) (common.Hash, error)
DepositToCanton submits a deposit transaction (for testing)
func (*Client) GetLastScannedBlock ¶
GetLastScannedBlock returns the highest block number the poller has scanned.
func (*Client) GetLatestBlockNumber ¶
GetLatestBlockNumber gets the latest block number
func (*Client) GetTransactor ¶
GetTransactor returns a transaction signer
func (*Client) IsWithdrawalProcessed ¶
IsWithdrawalProcessed checks if a Canton withdrawal has already been processed on EVM
func (*Client) WatchDepositEvents ¶
func (c *Client) WatchDepositEvents(ctx context.Context, fromBlock uint64, handler func(*DepositEvent) error) error
WatchDepositEvents polls for deposit events (uses polling for HTTP RPC compatibility).
Each tick's [currentBlock+1, latestBlock] range is walked in slices of at most config.MaxBlockRange blocks so requests stay under the provider's per-call cap. On a slice failure, currentBlock advances only through the last successful slice and the failing range is retried on the next tick.
type Config ¶
type Config struct {
RPCURL string `yaml:"rpc_url" validate:"required"`
WSUrl string `yaml:"ws_url" default:""`
ChainID int64 `yaml:"chain_id" validate:"required,gt=0"`
BridgeContract string `yaml:"bridge_contract" validate:"required"`
TokenContract string `yaml:"token_contract" default:""`
RelayerPrivateKey string `yaml:"relayer_private_key" validate:"required"`
ConfirmationBlocks int `yaml:"confirmation_blocks" default:"12"`
GasLimit uint64 `yaml:"gas_limit" validate:"required,gt=0"`
MaxGasPrice string `yaml:"max_gas_price" default:""`
PollingInterval time.Duration `yaml:"polling_interval" validate:"required,gt=0"`
StartBlock int64 `yaml:"start_block" default:"0"`
LookbackBlocks int64 `yaml:"lookback_blocks" default:"1000"`
MaxBlockRange uint64 `yaml:"max_block_range" default:"100" validate:"required,gt=0"`
}
Config contains Ethereum client settings
type DepositEvent ¶
type DepositEvent struct {
Token common.Address
Sender common.Address
CantonRecipient [32]byte
Amount *big.Int
Nonce *big.Int
BlockNumber uint64
TxHash common.Hash
LogIndex uint
}
DepositEvent represents a deposit to Canton event from Ethereum
type Metrics ¶
type Metrics struct {
// RPCCallsTotal counts outbound Ethereum RPC operations by method name and
// terminal status. method is a stable lowercase identifier (see the
// method=... call sites in client.go); status is "ok" or "error".
RPCCallsTotal *prometheus.CounterVec
// RPCDuration is the per-method latency distribution for RPC calls. Paired
// with RPCCallsTotal so dashboards can show p95 latency next to error rate
// for the same operation.
RPCDuration *prometheus.HistogramVec
// EventPollDuration is the wall-clock duration of one deposit-event poll
// cycle (one tick of WatchDepositEvents). Empty cycles still contribute.
EventPollDuration prometheus.Histogram
// EventPollFailuresTotal counts poll cycles that hit an error at a
// specific phase. reason ∈
// get_latest_block – HeaderByNumber failed at the start of the cycle
// filter_events – FilterDepositToCanton failed
// iterator – iter.Error() reported a problem while ranging
// A single cycle can contribute to more than one reason if multiple phases
// fail (rare but possible).
EventPollFailuresTotal *prometheus.CounterVec
// EventsFetchedTotal is the running count of deposit events the poll loop
// has consumed (one increment per iter.Next() returning true). Pair with
// rate() to get throughput.
EventsFetchedTotal prometheus.Counter
// LatestBlockSeen is the most recent block number the client has observed
// from HeaderByNumber. Stale = the Ethereum node is unreachable or behind.
LatestBlockSeen prometheus.Gauge
// LastScannedBlock is the highest block number the poll loop has scanned
// for deposit events. Distance from LatestBlockSeen = backlog the poller
// is working through.
LastScannedBlock prometheus.Gauge
}
Metrics holds Prometheus collectors for the Ethereum RPC client.
The collectors here cover two distinct surfaces that benefit from separate observation:
- Outbound RPC calls — every method this client invokes against the Ethereum node (eth_blockNumber, eth_gasPrice, contract calls/sends, log filtering). Latency and error rate live here.
- The deposit-event poll loop — a separate, dominant code path with its own cycle-level metrics: cycle duration, where in the cycle failures cluster, and how many events each cycle pulls in.
Both surfaces share a namespaced registerer so a deployment can scrape one /metrics endpoint and discriminate by metric name.
func NewMetrics ¶
func NewMetrics(reg sharedmetrics.NamespacedRegisterer) *Metrics
NewMetrics registers ethereum client metrics against the given registerer.
func NewNopMetrics ¶
func NewNopMetrics() *Metrics
NewNopMetrics returns a Metrics instance backed by a throwaway registry. Use in tests or contexts where metric values are not asserted.