@aztec/epoch-cache 3.0.0-nightly.20251105 → 3.0.0-nightly.20251106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/epoch_cache.d.ts +3 -1
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +17 -7
- package/package.json +5 -5
- package/src/epoch_cache.ts +25 -12
package/dest/epoch_cache.d.ts
CHANGED
|
@@ -53,7 +53,9 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
53
53
|
private allValidators;
|
|
54
54
|
private lastValidatorRefresh;
|
|
55
55
|
private readonly log;
|
|
56
|
-
constructor(rollup: RollupContract, l1constants
|
|
56
|
+
constructor(rollup: RollupContract, l1constants: L1RollupConstants & {
|
|
57
|
+
lagInEpochs: number;
|
|
58
|
+
}, dateProvider?: DateProvider, config?: {
|
|
57
59
|
cacheSize: number;
|
|
58
60
|
validatorRefreshIntervalSeconds: number;
|
|
59
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epoch_cache.d.ts","sourceRoot":"","sources":["../src/epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"epoch_cache.d.ts","sourceRoot":"","sources":["../src/epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,KAAK,iBAAiB,EAOvB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAAE,KAAK,gBAAgB,EAA8B,M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EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE;IAW3E,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAQ5F;;;;;OAKG;IACU,6CAA6C,IAAI,OAAO,CAAC;QACpE,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,eAAe,EAAE,UAAU,GAAG,SAAS,CAAC;QACxC,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC;KACtC,CAAC;IAYF;;;;OAIG;IACI,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAKtF;;;;OAIG;IACI,oCAAoC,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAK9E;;;;;OAKG;YACW,4BAA4B;IAanC,6BAA6B,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAclH,4DAA4D;IACtD,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ3E,+FAA+F;IACzF,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IASjF,uBAAuB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;CAUvD"}
|
package/dest/epoch_cache.js
CHANGED
|
@@ -2,7 +2,7 @@ import { NoCommitteeError, RollupContract, createEthereumChain } from '@aztec/et
|
|
|
2
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import {
|
|
5
|
+
import { getEpochAtSlot, getEpochNumberAtTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch, getTimestampForSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
6
6
|
import { createPublicClient, encodeAbiParameters, fallback, http, keccak256 } from 'viem';
|
|
7
7
|
import { getEpochCacheConfigEnvVars } from './config.js';
|
|
8
8
|
/**
|
|
@@ -22,7 +22,7 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
22
22
|
allValidators;
|
|
23
23
|
lastValidatorRefresh;
|
|
24
24
|
log;
|
|
25
|
-
constructor(rollup, l1constants
|
|
25
|
+
constructor(rollup, l1constants, dateProvider = new DateProvider(), config = {
|
|
26
26
|
cacheSize: 12,
|
|
27
27
|
validatorRefreshIntervalSeconds: 60
|
|
28
28
|
}){
|
|
@@ -53,12 +53,13 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
53
53
|
});
|
|
54
54
|
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
|
|
55
55
|
}
|
|
56
|
-
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration] = await Promise.all([
|
|
56
|
+
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration, lagInEpochs] = await Promise.all([
|
|
57
57
|
rollup.getL1StartBlock(),
|
|
58
58
|
rollup.getL1GenesisTime(),
|
|
59
59
|
rollup.getProofSubmissionEpochs(),
|
|
60
60
|
rollup.getSlotDuration(),
|
|
61
|
-
rollup.getEpochDuration()
|
|
61
|
+
rollup.getEpochDuration(),
|
|
62
|
+
rollup.getLagInEpochs()
|
|
62
63
|
]);
|
|
63
64
|
const l1RollupConstants = {
|
|
64
65
|
l1StartBlock,
|
|
@@ -66,7 +67,8 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
66
67
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
67
68
|
slotDuration: Number(slotDuration),
|
|
68
69
|
epochDuration: Number(epochDuration),
|
|
69
|
-
ethereumSlotDuration: config.ethereumSlotDuration
|
|
70
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
71
|
+
lagInEpochs: Number(lagInEpochs)
|
|
70
72
|
};
|
|
71
73
|
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider);
|
|
72
74
|
}
|
|
@@ -145,10 +147,18 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
145
147
|
}
|
|
146
148
|
async computeCommittee(when) {
|
|
147
149
|
const { ts, epoch } = when;
|
|
148
|
-
const [committeeHex, seed] = await Promise.all([
|
|
150
|
+
const [committeeHex, seed, l1Timestamp] = await Promise.all([
|
|
149
151
|
this.rollup.getCommitteeAt(ts),
|
|
150
|
-
this.rollup.getSampleSeedAt(ts)
|
|
152
|
+
this.rollup.getSampleSeedAt(ts),
|
|
153
|
+
this.rollup.client.getBlock({
|
|
154
|
+
includeTransactions: false
|
|
155
|
+
}).then((b)=>b.timestamp)
|
|
151
156
|
]);
|
|
157
|
+
const { lagInEpochs, epochDuration, slotDuration } = this.l1constants;
|
|
158
|
+
const sub = BigInt(lagInEpochs) * BigInt(epochDuration) * BigInt(slotDuration);
|
|
159
|
+
if (ts - sub > l1Timestamp) {
|
|
160
|
+
throw new Error(`Cannot query committee for future epoch ${epoch} with timestamp ${ts} (current L1 time is ${l1Timestamp})`);
|
|
161
|
+
}
|
|
152
162
|
const committee = committeeHex?.map((v)=>EthAddress.fromString(v));
|
|
153
163
|
return {
|
|
154
164
|
committee,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/epoch-cache",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.20251106",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"../package.common.json"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
30
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
31
|
-
"@aztec/l1-artifacts": "3.0.0-nightly.
|
|
32
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
29
|
+
"@aztec/ethereum": "3.0.0-nightly.20251106",
|
|
30
|
+
"@aztec/foundation": "3.0.0-nightly.20251106",
|
|
31
|
+
"@aztec/l1-artifacts": "3.0.0-nightly.20251106",
|
|
32
|
+
"@aztec/stdlib": "3.0.0-nightly.20251106",
|
|
33
33
|
"@viem/anvil": "^0.0.10",
|
|
34
34
|
"dotenv": "^16.0.3",
|
|
35
35
|
"get-port": "^7.1.0",
|
package/src/epoch_cache.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
5
|
import {
|
|
6
|
-
EmptyL1RollupConstants,
|
|
7
6
|
type L1RollupConstants,
|
|
8
7
|
getEpochAtSlot,
|
|
9
8
|
getEpochNumberAtTimestamp,
|
|
@@ -65,7 +64,7 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
65
64
|
|
|
66
65
|
constructor(
|
|
67
66
|
private rollup: RollupContract,
|
|
68
|
-
private readonly l1constants: L1RollupConstants
|
|
67
|
+
private readonly l1constants: L1RollupConstants & { lagInEpochs: number },
|
|
69
68
|
private readonly dateProvider: DateProvider = new DateProvider(),
|
|
70
69
|
protected readonly config = { cacheSize: 12, validatorRefreshIntervalSeconds: 60 },
|
|
71
70
|
) {
|
|
@@ -95,21 +94,24 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
95
94
|
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration] =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
97
|
+
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration, lagInEpochs] =
|
|
98
|
+
await Promise.all([
|
|
99
|
+
rollup.getL1StartBlock(),
|
|
100
|
+
rollup.getL1GenesisTime(),
|
|
101
|
+
rollup.getProofSubmissionEpochs(),
|
|
102
|
+
rollup.getSlotDuration(),
|
|
103
|
+
rollup.getEpochDuration(),
|
|
104
|
+
rollup.getLagInEpochs(),
|
|
105
|
+
] as const);
|
|
106
|
+
|
|
107
|
+
const l1RollupConstants = {
|
|
107
108
|
l1StartBlock,
|
|
108
109
|
l1GenesisTime,
|
|
109
110
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
110
111
|
slotDuration: Number(slotDuration),
|
|
111
112
|
epochDuration: Number(epochDuration),
|
|
112
113
|
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
114
|
+
lagInEpochs: Number(lagInEpochs),
|
|
113
115
|
};
|
|
114
116
|
|
|
115
117
|
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider);
|
|
@@ -193,7 +195,18 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
193
195
|
|
|
194
196
|
private async computeCommittee(when: { epoch: bigint; ts: bigint }): Promise<EpochCommitteeInfo> {
|
|
195
197
|
const { ts, epoch } = when;
|
|
196
|
-
const [committeeHex, seed] = await Promise.all([
|
|
198
|
+
const [committeeHex, seed, l1Timestamp] = await Promise.all([
|
|
199
|
+
this.rollup.getCommitteeAt(ts),
|
|
200
|
+
this.rollup.getSampleSeedAt(ts),
|
|
201
|
+
this.rollup.client.getBlock({ includeTransactions: false }).then(b => b.timestamp),
|
|
202
|
+
]);
|
|
203
|
+
const { lagInEpochs, epochDuration, slotDuration } = this.l1constants;
|
|
204
|
+
const sub = BigInt(lagInEpochs) * BigInt(epochDuration) * BigInt(slotDuration);
|
|
205
|
+
if (ts - sub > l1Timestamp) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Cannot query committee for future epoch ${epoch} with timestamp ${ts} (current L1 time is ${l1Timestamp})`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
197
210
|
const committee = committeeHex?.map((v: `0x${string}`) => EthAddress.fromString(v));
|
|
198
211
|
return { committee, seed, epoch };
|
|
199
212
|
}
|