Skip to content

Commit 2c877e5

Browse files
committed
starting to get there
1 parent e2ded3c commit 2c877e5

File tree

12 files changed

+139
-61
lines changed

12 files changed

+139
-61
lines changed

k8s/local/aztec-listener/sp_testnet/deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ spec:
5454
valueFrom:
5555
secretKeyRef:
5656
name: global
57-
key: SP_TESTNET_OBSCURA_L2_RPC_1
57+
#key: SP_TESTNET_OBSCURA_L2_RPC_1
5858
#key: SP_TESTNET_OBSCURA_L2_RPC_2
59-
#key: SP_TESTNET_AZTEC_L2_BOOTNODE_RPC
59+
key: SP_TESTNET_AZTEC_L2_BOOTNODE_RPC
6060
status: {}

k8s/local/ethereum-listener/remote_devnet/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
- image: ethereum-listener:latest
2121
resources:
2222
limits:
23-
memory: 150Mi
23+
memory: 300Mi
2424
cpu: 500m
2525
name: ethereum-listener
2626
env:

k8s/local/ethereum-listener/sandbox/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
- image: ethereum-listener:latest
3333
resources:
3434
limits:
35-
memory: 150Mi
35+
memory: 300Mi
3636
cpu: 500m
3737
name: ethereum-listener
3838
envFrom:

k8s/local/ethereum-listener/sp_testnet/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
- image: ethereum-listener:latest
3333
resources:
3434
limits:
35-
memory: 150Mi
35+
memory: 300Mi
3636
cpu: 500m
3737
name: ethereum-listener
3838
envFrom:

k8s/production/ethereum-listener/devnet/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
name: ethereum-listener
2424
resources:
2525
limits:
26-
memory: 150Mi
26+
memory: 300Mi
2727
cpu: 500m
2828
env:
2929
- name: NODE_ENV

k8s/production/ethereum-listener/sp_testnet/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
name: ethereum-listener
2424
resources:
2525
limits:
26-
memory: 150Mi
26+
memory: 300Mi
2727
cpu: 500m
2828
env:
2929
- name: NODE_ENV

services/ethereum-listener/src/network-client/client.ts

+41-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import {
66
chicmozL1L2ValidatorSchema,
77
getL1NetworkId,
88
} from "@chicmoz-pkg/types";
9-
import { PublicClient, createPublicClient, defineChain, webSocket } from "viem";
9+
import {
10+
PublicClient,
11+
createPublicClient,
12+
defineChain,
13+
http,
14+
webSocket,
15+
} from "viem";
1016
import { foundry, mainnet, sepolia } from "viem/chains";
1117
import {
1218
ETHEREUM_HTTP_RPC_URL,
@@ -18,11 +24,21 @@ import { logger } from "../logger.js";
1824
import { getL1Contracts } from "./contracts/index.js";
1925
export { startContractWatchers as watchContractsEvents } from "./contracts/index.js";
2026

21-
let publicClient: PublicClient | undefined = undefined;
27+
let publicWsClient: PublicClient | undefined = undefined;
28+
let publicHttpClient: PublicClient | undefined = undefined;
2229

23-
export const getPublicClient = () => {
24-
if (!publicClient) throw new Error("Client not initialized");
25-
return publicClient;
30+
export const getPublicWsClient = () => {
31+
if (!publicWsClient) {
32+
throw new Error("Client not initialized");
33+
}
34+
return publicWsClient;
35+
};
36+
37+
export const getPublicHttpClient = () => {
38+
if (!publicHttpClient) {
39+
throw new Error("Client not initialized");
40+
}
41+
return publicHttpClient;
2642
};
2743

2844
export const initClient = () => {
@@ -46,18 +62,19 @@ export const initClient = () => {
4662
},
4763
},
4864
});
49-
publicClient = createPublicClient({
65+
publicWsClient = createPublicClient({
5066
chain,
5167
transport: webSocket(),
5268
});
69+
publicHttpClient = createPublicClient({ chain, transport: http() });
5370
};
5471

5572
export const getLatestHeight = async () => {
56-
return await getPublicClient().getBlockNumber();
73+
return await getPublicHttpClient().getBlockNumber();
5774
};
5875

5976
export const getBlock = async (blockNumber: number) => {
60-
return await getPublicClient().getBlock({
77+
return await getPublicHttpClient().getBlock({
6178
blockNumber: BigInt(blockNumber),
6279
});
6380
};
@@ -67,21 +84,23 @@ const json = (param: unknown): string => {
6784
param,
6885
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
6986
(_key, value) => (typeof value === "bigint" ? value.toString() : value),
70-
2
87+
2,
7188
);
7289
};
7390

7491
export const emitRandomizedChangeWithinRandomizedTime = async (
7592
depth: number,
76-
oldValues: ChicmozL1L2Validator
93+
oldValues: ChicmozL1L2Validator,
7794
) => {
78-
if (depth === 0) return;
95+
if (depth === 0) {
96+
return;
97+
}
7998
const rand = Math.random();
8099
const sleepTime = 30000;
81100
logger.info(
82101
`ATTESTER ${oldValues.attester} - DEPTH ${depth} - SLEEP ${
83102
sleepTime / 1000
84-
}s`
103+
}s`,
85104
);
86105
await new Promise((resolve) => setTimeout(resolve, sleepTime));
87106
let newValues = oldValues;
@@ -129,8 +148,10 @@ export const emitRandomizedChangeWithinRandomizedTime = async (
129148
export const queryStakingStateAndEmitUpdates = async () => {
130149
// TODO: this entire function should be replaced with a watch on the contract (and some initial state query)
131150
const l1Contracts = await getL1Contracts();
132-
if (!l1Contracts) throw new Error("Contracts not initialized");
133-
const attesterCount = await getPublicClient().readContract({
151+
if (!l1Contracts) {
152+
throw new Error("Contracts not initialized");
153+
}
154+
const attesterCount = await getPublicHttpClient().readContract({
134155
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
135156
address: l1Contracts.rollup.address as `0x${string}`,
136157
abi: RollupAbi,
@@ -139,14 +160,14 @@ export const queryStakingStateAndEmitUpdates = async () => {
139160
logger.info(`Active attester count: ${attesterCount.toString()}`);
140161
if (attesterCount > 0) {
141162
for (let i = 0; i < attesterCount; i++) {
142-
const attester = await getPublicClient().readContract({
163+
const attester = await getPublicHttpClient().readContract({
143164
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
144165
address: l1Contracts.rollup.address as `0x${string}`,
145166
abi: RollupAbi,
146167
functionName: "getAttesterAtIndex",
147168
args: [BigInt(i)],
148169
});
149-
const attesterInfo = await getPublicClient().readContract({
170+
const attesterInfo = await getPublicHttpClient().readContract({
150171
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
151172
address: l1Contracts.rollup.address as `0x${string}`,
152173
abi: RollupAbi,
@@ -158,7 +179,7 @@ export const queryStakingStateAndEmitUpdates = async () => {
158179
chicmozL1L2ValidatorSchema.parse({
159180
...attesterInfo,
160181
attester,
161-
})
182+
}),
162183
);
163184
}
164185
} else {
@@ -186,16 +207,16 @@ export const queryStakingStateAndEmitUpdates = async () => {
186207
chicmozL1L2ValidatorSchema.parse({
187208
...attesterInfo,
188209
attester: attesterInfo.attester,
189-
})
210+
}),
190211
);
191212
}
192213
for (const attesterInfo of mockedAttesters) {
193214
await emitRandomizedChangeWithinRandomizedTime(
194215
100,
195-
chicmozL1L2ValidatorSchema.parse(attesterInfo)
216+
chicmozL1L2ValidatorSchema.parse(attesterInfo),
196217
).catch((e) => {
197218
logger.error(
198-
`Randomized change emission failed: ${(e as Error).stack}`
219+
`Randomized change emission failed: ${(e as Error).stack}`,
199220
);
200221
});
201222
}

services/ethereum-listener/src/network-client/contracts/get-events.ts

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PublicClient } from "viem";
22
import { controllers as dbControllers } from "../../svcs/database/index.js";
3-
import { getPublicClient } from "../client.js";
3+
import { getPublicHttpClient } from "../client.js";
44
import {
55
l2BlockProposedEventCallbacks,
66
l2ProofVerifiedEventCallbacks,
@@ -13,20 +13,23 @@ const getRollupL2BlockProposedLogs = async ({
1313
client,
1414
contracts,
1515
toBlock,
16+
latestHeight,
1617
}: {
1718
client: PublicClient;
1819
contracts: AztecContracts;
1920
toBlock: "finalized";
21+
latestHeight: bigint;
2022
}) => {
2123
const { fromBlock, updateHeight, storeHeight } =
2224
await dbControllers.inMemoryHeightTracker({
2325
contractName: "rollup",
2426
contractAddress: contracts.rollup.address,
2527
eventName: "L2BlockProposed",
2628
isFinalized: GET_EVENETS_DEFAULT_IS_FINALIZED,
29+
latestHeight,
2730
});
2831
const rollupL2BlockProposedLogs = await client.getContractEvents({
29-
fromBlock,
32+
fromBlock: fromBlock === 1n ? "finalized" : fromBlock,
3033
toBlock,
3134
eventName: "L2BlockProposed",
3235
address: contracts.rollup.address,
@@ -43,20 +46,23 @@ const getRollupL2ProofVerifiedLogs = async ({
4346
client,
4447
contracts,
4548
toBlock,
49+
latestHeight,
4650
}: {
4751
client: PublicClient;
4852
contracts: AztecContracts;
4953
toBlock: "finalized";
54+
latestHeight: bigint;
5055
}) => {
5156
const { fromBlock, updateHeight, storeHeight } =
5257
await dbControllers.inMemoryHeightTracker({
5358
contractName: "rollup",
5459
contractAddress: contracts.rollup.address,
5560
eventName: "L2ProofVerified",
5661
isFinalized: GET_EVENETS_DEFAULT_IS_FINALIZED,
62+
latestHeight,
5763
});
5864
const rollupL2ProofVerifiedLogs = await client.getContractEvents({
59-
fromBlock,
65+
fromBlock: fromBlock === 1n ? "finalized" : fromBlock,
6066
toBlock,
6167
eventName: "L2ProofVerified",
6268
address: contracts.rollup.address,
@@ -72,11 +78,24 @@ const getRollupL2ProofVerifiedLogs = async ({
7278
export const getAllContractsEvents = async ({
7379
contracts,
7480
toBlock,
81+
latestHeight,
7582
}: {
7683
contracts: AztecContracts;
7784
toBlock: "finalized";
85+
latestHeight: bigint;
7886
}) => {
79-
const client = getPublicClient();
80-
await getRollupL2BlockProposedLogs({ client, contracts, toBlock });
81-
await getRollupL2ProofVerifiedLogs({ client, contracts, toBlock });
87+
const client = getPublicHttpClient();
88+
// TODO: batch-query if genesis-catcup
89+
await getRollupL2BlockProposedLogs({
90+
client,
91+
contracts,
92+
toBlock,
93+
latestHeight,
94+
});
95+
await getRollupL2ProofVerifiedLogs({
96+
client,
97+
contracts,
98+
toBlock,
99+
latestHeight,
100+
});
82101
};

services/ethereum-listener/src/network-client/contracts/index.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,55 @@ import {
66
RollupAbi,
77
} from "@aztec/l1-artifacts";
88
import { controllers as dbControllers } from "../../svcs/database/index.js";
9-
import { getPublicClient } from "../client.js";
9+
import { getLatestHeight, getPublicHttpClient } from "../client.js";
1010
import { getAllContractsEvents } from "./get-events.js";
1111
import { AztecContracts, UnwatchCallback, getTypedContract } from "./utils.js";
1212
import { watchAllContractsEvents } from "./watch-events.js";
1313

1414
export const getL1Contracts = async (): Promise<AztecContracts> => {
1515
const dbContracts = await dbControllers.getL1Contracts();
16-
const publicClient = getPublicClient();
16+
const publicClient = getPublicHttpClient();
1717
return {
1818
rollup: getTypedContract(
1919
RollupAbi,
2020
dbContracts.rollupAddress as `0x${string}`,
21-
publicClient
21+
publicClient,
2222
),
2323
registry: getTypedContract(
2424
RegistryAbi,
2525
dbContracts.registryAddress as `0x${string}`,
26-
publicClient
26+
publicClient,
2727
),
2828
inbox: getTypedContract(
2929
InboxAbi,
3030
dbContracts.inboxAddress as `0x${string}`,
31-
publicClient
31+
publicClient,
3232
),
3333
outbox: getTypedContract(
3434
OutboxAbi,
3535
dbContracts.outboxAddress as `0x${string}`,
36-
publicClient
36+
publicClient,
3737
),
3838
feeJuicePortal: getTypedContract(
3939
FeeJuicePortalAbi,
4040
dbContracts.feeJuiceAddress as `0x${string}`,
41-
publicClient
41+
publicClient,
4242
),
4343
};
4444
};
4545

4646
export const startContractWatchers = async (): Promise<UnwatchCallback> => {
4747
const contracts = await getL1Contracts();
48-
return watchAllContractsEvents({ contracts });
48+
const latestHeight = await getLatestHeight();
49+
return watchAllContractsEvents({ contracts, latestHeight });
4950
};
5051

5152
export const getFinalizedContractEvents = async () => {
5253
const contracts = await getL1Contracts();
53-
return getAllContractsEvents({ contracts, toBlock: "finalized" });
54+
const latestHeight = await getLatestHeight();
55+
return getAllContractsEvents({
56+
contracts,
57+
latestHeight,
58+
toBlock: "finalized",
59+
});
5460
};

0 commit comments

Comments
 (0)