Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions yarn-project/archiver/src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EpochCache } from '@aztec/epoch-cache';
import { createEthereumChain } from '@aztec/ethereum/chain';
import { makeL1HttpTransport } from '@aztec/ethereum/client';
import { InboxContract, RollupContract } from '@aztec/ethereum/contracts';
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
import { BlockNumber } from '@aztec/foundation/branded-types';
Expand All @@ -18,7 +19,7 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
import { getTelemetryClient } from '@aztec/telemetry-client';

import { EventEmitter } from 'events';
import { createPublicClient, fallback, http } from 'viem';
import { createPublicClient } from 'viem';

import { Archiver, type ArchiverDeps } from './archiver.js';
import { type ArchiverConfig, mapArchiverConfig } from './config.js';
Expand Down Expand Up @@ -59,17 +60,18 @@ export async function createArchiver(

// Create Ethereum clients
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
const httpTimeout = config.l1HttpTimeoutMS;
const publicClient = createPublicClient({
chain: chain.chainInfo,
transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: httpTimeout }),
pollingInterval: config.viemPollingIntervalMS,
});

// Create debug client using debug RPC URLs if available, otherwise fall back to regular RPC URLs
const debugRpcUrls = config.l1DebugRpcUrls.length > 0 ? config.l1DebugRpcUrls : config.l1RpcUrls;
const debugClient = createPublicClient({
chain: chain.chainInfo,
transport: fallback(debugRpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(debugRpcUrls, { timeout: httpTimeout }),
pollingInterval: config.viemPollingIntervalMS,
}) as ViemPublicDebugClient;

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Blob } from '@aztec/blob-lib';
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
import { createEthereumChain } from '@aztec/ethereum/chain';
import { getPublicClient } from '@aztec/ethereum/client';
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
Expand Down Expand Up @@ -113,7 +113,7 @@ import {
} from '@aztec/validator-client';
import { createWorldStateSynchronizer } from '@aztec/world-state';

import { createPublicClient, fallback, http } from 'viem';
import { createPublicClient } from 'viem';

import { createSentinel } from '../sentinel/factory.js';
import { Sentinel } from '../sentinel/sentinel.js';
Expand Down Expand Up @@ -257,7 +257,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {

const publicClient = createPublicClient({
chain: ethereumChain.chainInfo,
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
pollingInterval: config.viemPollingIntervalMS,
});

Expand Down
9 changes: 9 additions & 0 deletions yarn-project/blob-client/src/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SecretValue,
booleanConfigHelper,
getConfigFromMappings,
optionalNumberConfigHelper,
} from '@aztec/foundation/config';

import { type BlobArchiveApiConfig, blobArchiveApiConfigMappings } from '../archive/config.js';
Expand Down Expand Up @@ -55,6 +56,9 @@ export interface BlobClientConfig extends BlobArchiveApiConfig {
* Interval in minutes for uploading healthcheck file to file store (default: 60 = 1 hour)
*/
blobHealthcheckUploadIntervalMinutes?: number;

/** Timeout for HTTP requests to the L1 RPC node in ms. */
l1HttpTimeoutMS?: number;
}

export const blobClientConfigMapping: ConfigMappingsType<BlobClientConfig> = {
Expand Down Expand Up @@ -108,6 +112,11 @@ export const blobClientConfigMapping: ConfigMappingsType<BlobClientConfig> = {
description: 'Interval in minutes for uploading healthcheck file to file store (default: 60 = 1 hour)',
parseEnv: (val: string | undefined) => (val ? +val : undefined),
},
l1HttpTimeoutMS: {
env: 'ETHEREUM_HTTP_TIMEOUT_MS',
description: 'Timeout for HTTP requests to the L1 RPC node in ms.',
...optionalNumberConfigHelper(),
},
...blobArchiveApiConfigMappings,
};

Expand Down
5 changes: 3 additions & 2 deletions yarn-project/blob-client/src/client/http.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Blob, type BlobJson, computeEthVersionedBlobHash } from '@aztec/blob-lib';
import { makeL1HttpTransport } from '@aztec/ethereum/client';
import { shuffle } from '@aztec/foundation/array';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { makeBackoff, retry } from '@aztec/foundation/retry';
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';

import { type RpcBlock, createPublicClient, fallback, http } from 'viem';
import { type RpcBlock, createPublicClient } from 'viem';

import { createBlobArchiveClient } from '../archive/factory.js';
import type { BlobArchiveClient } from '../archive/interface.js';
Expand Down Expand Up @@ -497,7 +498,7 @@ export class HttpBlobClient implements BlobClientInterface {
// Ping execution node to get the parentBeaconBlockRoot for this block
let parentBeaconBlockRoot: string | undefined;
const client = createPublicClient({
transport: fallback(l1RpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(l1RpcUrls, { timeout: this.config.l1HttpTimeoutMS }),
});
try {
const res: RpcBlock = await client.request({
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/epoch-cache/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type L1ReaderConfig, getL1ReaderConfigFromEnv } from '@aztec/ethereum/l

export type EpochCacheConfig = Pick<
L1ReaderConfig & L1ContractsConfig,
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration'
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'l1HttpTimeoutMS' | 'ethereumSlotDuration'
>;

export function getEpochCacheConfigEnvVars(): EpochCacheConfig {
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/epoch-cache/src/epoch_cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createEthereumChain } from '@aztec/ethereum/chain';
import { makeL1HttpTransport } from '@aztec/ethereum/client';
import { NoCommitteeError, RollupContract } from '@aztec/ethereum/contracts';
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
import { EthAddress } from '@aztec/foundation/eth-address';
Expand All @@ -14,7 +15,7 @@ import {
getTimestampRangeForEpoch,
} from '@aztec/stdlib/epoch-helpers';

import { createPublicClient, encodeAbiParameters, fallback, http, keccak256 } from 'viem';
import { createPublicClient, encodeAbiParameters, keccak256 } from 'viem';

import { type EpochCacheConfig, getEpochCacheConfigEnvVars } from './config.js';

Expand Down Expand Up @@ -93,7 +94,7 @@ export class EpochCache implements EpochCacheInterface {
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
const publicClient = createPublicClient({
chain: chain.chainInfo,
transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
pollingInterval: config.viemPollingIntervalMS,
});
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
Expand Down
12 changes: 10 additions & 2 deletions yarn-project/ethereum/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ type Config = {
l1ChainId: number;
/** The polling interval viem uses in ms */
viemPollingIntervalMS?: number;
/** Timeout for HTTP requests to the L1 RPC node in ms. */
l1HttpTimeoutMS?: number;
};

export type { Config as EthereumClientConfig };

/** Creates a viem fallback HTTP transport for the given L1 RPC URLs. */
export function makeL1HttpTransport(rpcUrls: string[], opts?: { timeout?: number }) {
return fallback(rpcUrls.map(url => http(url, { batch: false, timeout: opts?.timeout })));
}

// TODO: Use these methods to abstract the creation of viem clients.

/** Returns a viem public client given the L1 config. */
export function getPublicClient(config: Config): ViemPublicClient {
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
return createPublicClient({
chain: chain.chainInfo,
transport: fallback(config.l1RpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
pollingInterval: config.viemPollingIntervalMS,
});
}
Expand Down Expand Up @@ -77,6 +84,7 @@ export function createExtendedL1Client(
chain: Chain = foundry,
pollingIntervalMS?: number,
addressIndex?: number,
opts?: { httpTimeoutMS?: number },
): ExtendedViemWalletClient {
const hdAccount =
typeof mnemonicOrPrivateKeyOrHdAccount === 'string'
Expand All @@ -88,7 +96,7 @@ export function createExtendedL1Client(
const extendedClient = createWalletClient({
account: hdAccount,
chain,
transport: fallback(rpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(rpcUrls, { timeout: opts?.httpTimeoutMS }),
pollingInterval: pollingIntervalMS,
}).extend(publicActions);

Expand Down
14 changes: 13 additions & 1 deletion yarn-project/ethereum/src/l1_reader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
import {
type ConfigMappingsType,
getConfigFromMappings,
numberConfigHelper,
optionalNumberConfigHelper,
} from '@aztec/foundation/config';

import { type L1ContractAddresses, l1ContractAddressesMapping } from './l1_contract_addresses.js';

Expand All @@ -14,6 +19,8 @@ export interface L1ReaderConfig {
l1Contracts: L1ContractAddresses;
/** The polling interval viem uses in ms */
viemPollingIntervalMS: number;
/** Timeout for HTTP requests to the L1 RPC node in ms. */
l1HttpTimeoutMS?: number;
}

export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
Expand Down Expand Up @@ -43,6 +50,11 @@ export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
description: 'The polling interval viem uses in ms',
...numberConfigHelper(1_000),
},
l1HttpTimeoutMS: {
env: 'ETHEREUM_HTTP_TIMEOUT_MS',
description: 'Timeout for HTTP requests to the L1 RPC node in ms.',
...optionalNumberConfigHelper(),
},
};

export function getL1ReaderConfigFromEnv(): L1ReaderConfig {
Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type EnvVar =
| 'KEY_STORE_DIRECTORY'
| 'L1_CHAIN_ID'
| 'L1_CONSENSUS_HOST_URLS'
| 'ETHEREUM_HTTP_TIMEOUT_MS'
| 'L1_CONSENSUS_HOST_API_KEYS'
| 'L1_CONSENSUS_HOST_API_KEY_HEADERS'
| 'LOG_JSON'
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/prover-node/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { BlobClientInterface } from '@aztec/blob-client/client';
import { Blob } from '@aztec/blob-lib';
import type { EpochCacheInterface } from '@aztec/epoch-cache';
import { createEthereumChain } from '@aztec/ethereum/chain';
import { makeL1HttpTransport } from '@aztec/ethereum/client';
import { RollupContract } from '@aztec/ethereum/contracts';
import { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
import { PublisherManager } from '@aztec/ethereum/publisher-manager';
Expand All @@ -27,7 +28,7 @@ import type {
} from '@aztec/stdlib/interfaces/server';
import { L1Metrics, type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';

import { createPublicClient, fallback, http } from 'viem';
import { createPublicClient } from 'viem';

import type { SpecificProverNodeConfig } from './config.js';
import { EpochMonitor } from './monitors/epoch-monitor.js';
Expand Down Expand Up @@ -95,7 +96,7 @@ export async function createProverNode(

const publicClient = createPublicClient({
chain: chain.chainInfo,
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
pollingInterval: config.viemPollingIntervalMS,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createEthereumChain } from '@aztec/ethereum/chain';
import { makeL1HttpTransport } from '@aztec/ethereum/client';
import type { L1ContractsConfig } from '@aztec/ethereum/config';
import { RollupContract } from '@aztec/ethereum/contracts';
import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
Expand All @@ -16,7 +17,7 @@ import type {
} from '@aztec/stdlib/tx';
import { GlobalVariables } from '@aztec/stdlib/tx';

import { createPublicClient, fallback, http } from 'viem';
import { createPublicClient } from 'viem';

/**
* Simple global variables builder.
Expand Down Expand Up @@ -53,7 +54,7 @@ export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {

this.publicClient = createPublicClient({
chain: chain.chainInfo,
transport: fallback(chain.rpcUrls.map(url => http(url, { batch: false }))),
transport: makeL1HttpTransport(chain.rpcUrls, { timeout: config.l1HttpTimeoutMS }),
pollingInterval: config.viemPollingIntervalMS,
});

Expand Down
Loading