@aztec/epoch-cache 5.0.0-private.20260319 → 5.0.0-rc.1
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/README.md +210 -0
- package/dest/config.d.ts +2 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -3
- package/dest/epoch_cache.d.ts +39 -20
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +164 -68
- package/dest/test/test_epoch_cache.d.ts +1 -4
- package/dest/test/test_epoch_cache.d.ts.map +1 -1
- package/dest/test/test_epoch_cache.js +7 -11
- package/package.json +6 -6
- package/src/config.ts +3 -9
- package/src/epoch_cache.ts +207 -70
- package/src/test/test_epoch_cache.ts +12 -15
package/dest/epoch_cache.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
2
2
|
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
3
3
|
import { NoCommitteeError, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import { getFinalizedL1Block } from '@aztec/ethereum/queries';
|
|
4
5
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
7
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
8
|
-
import { getEpochAtSlot, getEpochNumberAtTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
9
|
+
import { getEpochAtSlot, getEpochNumberAtTimestamp, getNextL1SlotTimestamp, getSlotAtNextL1Block, getSlotAtTimestamp, getSlotRangeForEpoch, getStartTimestampForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
9
10
|
import { createPublicClient, encodeAbiParameters, keccak256 } from 'viem';
|
|
10
11
|
import { getEpochCacheConfigEnvVars } from './config.js';
|
|
11
|
-
/**
|
|
12
|
+
/** The proposer pipelines by building one slot ahead. */ export const PROPOSER_PIPELINING_SLOT_OFFSET = 1;
|
|
12
13
|
/**
|
|
13
14
|
* Epoch cache
|
|
14
15
|
*
|
|
@@ -22,16 +23,16 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
22
23
|
l1constants;
|
|
23
24
|
dateProvider;
|
|
24
25
|
config;
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Single map holding both resolved entries and in-flight promises.
|
|
28
|
+
* A `Promise` value means a fetch is in progress; concurrent callers await it.
|
|
29
|
+
*/ cache;
|
|
27
30
|
allValidators;
|
|
28
31
|
lastValidatorRefresh;
|
|
29
32
|
log;
|
|
30
|
-
enableProposerPipelining;
|
|
31
33
|
constructor(rollup, l1constants, dateProvider = new DateProvider(), config = {
|
|
32
34
|
cacheSize: 12,
|
|
33
|
-
validatorRefreshIntervalSeconds: 60
|
|
34
|
-
enableProposerPipelining: false
|
|
35
|
+
validatorRefreshIntervalSeconds: 60
|
|
35
36
|
}){
|
|
36
37
|
this.rollup = rollup;
|
|
37
38
|
this.l1constants = l1constants;
|
|
@@ -41,10 +42,8 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
41
42
|
this.allValidators = new Set();
|
|
42
43
|
this.lastValidatorRefresh = 0;
|
|
43
44
|
this.log = createLogger('epoch-cache');
|
|
44
|
-
this.enableProposerPipelining = this.config.enableProposerPipelining;
|
|
45
45
|
this.log.debug(`Initialized EpochCache`, {
|
|
46
|
-
l1constants
|
|
47
|
-
enableProposerPipelining: this.enableProposerPipelining
|
|
46
|
+
l1constants
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
static async create(rollupOrAddress, config, deps = {}) {
|
|
@@ -89,22 +88,18 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
89
88
|
};
|
|
90
89
|
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider, {
|
|
91
90
|
cacheSize: 12,
|
|
92
|
-
validatorRefreshIntervalSeconds: 60
|
|
93
|
-
enableProposerPipelining: config.enableProposerPipelining
|
|
91
|
+
validatorRefreshIntervalSeconds: 60
|
|
94
92
|
});
|
|
95
93
|
}
|
|
96
94
|
getL1Constants() {
|
|
97
95
|
return this.l1constants;
|
|
98
96
|
}
|
|
99
|
-
isProposerPipeliningEnabled() {
|
|
100
|
-
return this.enableProposerPipelining;
|
|
101
|
-
}
|
|
102
97
|
getSlotNow() {
|
|
103
98
|
return this.getEpochAndSlotNow().slot;
|
|
104
99
|
}
|
|
105
100
|
getTargetSlot() {
|
|
106
101
|
const slotNow = this.getSlotNow();
|
|
107
|
-
const offset =
|
|
102
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
108
103
|
return SlotNumber(slotNow + offset);
|
|
109
104
|
}
|
|
110
105
|
getEpochNow() {
|
|
@@ -121,24 +116,18 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
121
116
|
nowMs
|
|
122
117
|
};
|
|
123
118
|
}
|
|
124
|
-
nowInSeconds() {
|
|
125
|
-
return BigInt(Math.floor(this.dateProvider.now() / 1000));
|
|
126
|
-
}
|
|
127
119
|
getEpochAndSlotAtSlot(slot) {
|
|
128
120
|
return this.getEpochAndSlotAtTimestamp(getTimestampForSlot(slot, this.l1constants));
|
|
129
121
|
}
|
|
130
122
|
getEpochAndSlotInNextL1Slot() {
|
|
131
|
-
const nowSeconds = this.nowInSeconds();
|
|
132
|
-
const nextSlotTs = nowSeconds
|
|
123
|
+
const nowSeconds = this.dateProvider.nowInSeconds();
|
|
124
|
+
const nextSlotTs = getNextL1SlotTimestamp(nowSeconds, this.l1constants);
|
|
133
125
|
return {
|
|
134
126
|
...this.getEpochAndSlotAtTimestamp(nextSlotTs),
|
|
135
|
-
nowSeconds
|
|
127
|
+
nowSeconds: BigInt(nowSeconds)
|
|
136
128
|
};
|
|
137
129
|
}
|
|
138
130
|
getTargetEpochAndSlotInNextL1Slot() {
|
|
139
|
-
if (!this.isProposerPipeliningEnabled()) {
|
|
140
|
-
return this.getEpochAndSlotInNextL1Slot();
|
|
141
|
-
}
|
|
142
131
|
const result = this.getEpochAndSlotInNextL1Slot();
|
|
143
132
|
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
144
133
|
const targetSlot = SlotNumber(result.slot + offset);
|
|
@@ -161,16 +150,7 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
161
150
|
const [startSlot] = getSlotRangeForEpoch(epoch, this.l1constants);
|
|
162
151
|
return this.getCommittee(startSlot);
|
|
163
152
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Returns whether the escape hatch is open for the given epoch.
|
|
166
|
-
*
|
|
167
|
-
* Uses the already-cached EpochCommitteeInfo when available. If not cached, it will fetch
|
|
168
|
-
* the epoch committee info (which includes the escape hatch flag) and return it.
|
|
169
|
-
*/ async isEscapeHatchOpen(epoch) {
|
|
170
|
-
const cached = this.cache.get(epoch);
|
|
171
|
-
if (cached) {
|
|
172
|
-
return cached.isEscapeHatchOpen;
|
|
173
|
-
}
|
|
153
|
+
/** Returns whether the escape hatch is open for the given epoch. */ async isEscapeHatchOpen(epoch) {
|
|
174
154
|
const info = await this.getCommitteeForEpoch(epoch);
|
|
175
155
|
return info.isEscapeHatchOpen;
|
|
176
156
|
}
|
|
@@ -184,26 +164,43 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
184
164
|
return await this.isEscapeHatchOpen(epoch);
|
|
185
165
|
}
|
|
186
166
|
/**
|
|
187
|
-
* Get the current validator set
|
|
188
|
-
*
|
|
189
|
-
*
|
|
167
|
+
* Get the current validator set.
|
|
168
|
+
*
|
|
169
|
+
* Returns cached data if the entry is finalized or still fresh (queried less than one
|
|
170
|
+
* Ethereum slot ago). Stale non-finalized entries are re-queried, and concurrent callers
|
|
171
|
+
* coalesce on the same in-flight promise so the L1 query happens only once.
|
|
190
172
|
*/ async getCommittee(slot = 'now') {
|
|
191
173
|
const { epoch, ts } = this.getEpochAndTimestamp(slot);
|
|
192
|
-
|
|
193
|
-
|
|
174
|
+
const cached = this.cache.get(epoch);
|
|
175
|
+
// In-flight promise: another caller is already fetching this epoch — just await it.
|
|
176
|
+
if (cached instanceof Promise) {
|
|
177
|
+
return (await cached).data;
|
|
194
178
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
//
|
|
200
|
-
if
|
|
201
|
-
|
|
179
|
+
// Resolved entry: return it if finalized or still fresh.
|
|
180
|
+
if (cached && (cached.finalized || !this.isStale(cached))) {
|
|
181
|
+
return cached.data;
|
|
182
|
+
}
|
|
183
|
+
// Stale non-finalized entry: do a lightweight refresh first (check block hash + finalized ts).
|
|
184
|
+
// Only fall back to a full re-fetch if the L1 block was reorged.
|
|
185
|
+
if (cached) {
|
|
186
|
+
const promise = this.refreshStaleEntry(cached, epoch, ts);
|
|
187
|
+
this.cache.set(epoch, promise);
|
|
188
|
+
try {
|
|
189
|
+
return (await promise).data;
|
|
190
|
+
} catch (err) {
|
|
191
|
+
this.cache.set(epoch, cached);
|
|
192
|
+
throw err;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// No entry at all: full fetch.
|
|
196
|
+
const promise = this.fetchAndCache(epoch, ts);
|
|
197
|
+
this.cache.set(epoch, promise);
|
|
198
|
+
try {
|
|
199
|
+
return (await promise).data;
|
|
200
|
+
} catch (err) {
|
|
201
|
+
this.cache.delete(epoch);
|
|
202
|
+
throw err;
|
|
202
203
|
}
|
|
203
|
-
this.cache.set(epoch, epochData);
|
|
204
|
-
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
205
|
-
toPurge.forEach((key)=>this.cache.delete(key));
|
|
206
|
-
return epochData;
|
|
207
204
|
}
|
|
208
205
|
getEpochAndTimestamp(slot = 'now') {
|
|
209
206
|
if (slot === 'now') {
|
|
@@ -214,27 +211,121 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
214
211
|
return this.getEpochAndSlotAtSlot(slot);
|
|
215
212
|
}
|
|
216
213
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
214
|
+
/** Evicts oldest cache entries (resolved or in-flight) beyond cacheSize. */ purgeCache() {
|
|
215
|
+
if (this.cache.size <= this.config.cacheSize) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
219
|
+
toPurge.forEach((key)=>this.cache.delete(key));
|
|
220
|
+
}
|
|
221
|
+
/** Returns true if a non-finalized cache entry is older than one Ethereum slot. */ isStale(entry) {
|
|
222
|
+
const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
|
|
223
|
+
return nowSeconds - entry.lastRefreshL1Timestamp >= BigInt(this.l1constants.ethereumSlotDuration);
|
|
224
|
+
}
|
|
225
|
+
/** Whether a cached epoch entry has been marked as finalized. Returns undefined if not cached or still in-flight. */ isFinalized(epoch) {
|
|
226
|
+
const entry = this.cache.get(epoch);
|
|
227
|
+
if (!entry || entry instanceof Promise) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
return entry.finalized;
|
|
231
|
+
}
|
|
232
|
+
/** Returns the latest L1 timestamp stored in the cached entry. Undefined if not cached or in-flight. */ getCachedLastRefreshL1Timestamp(epoch) {
|
|
233
|
+
const entry = this.cache.get(epoch);
|
|
234
|
+
if (!entry || entry instanceof Promise) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
return entry.lastRefreshL1Timestamp;
|
|
238
|
+
}
|
|
239
|
+
/** Computes the sampling timestamp for an epoch's committee data. */ getSamplingTimestamp(epoch) {
|
|
240
|
+
const { lagInEpochsForRandao, epochDuration, slotDuration } = this.l1constants;
|
|
241
|
+
const epochStartTs = getStartTimestampForEpoch(epoch, this.l1constants);
|
|
242
|
+
return epochStartTs - BigInt(lagInEpochsForRandao) * BigInt(epochDuration) * BigInt(slotDuration);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Lightweight refresh for a stale non-finalized entry. Queries only the block hash at
|
|
246
|
+
* the original block number and the finalized block timestamp — avoids the expensive
|
|
247
|
+
* getCommitteeAt and getSampleSeedAt calls on the rollup contract.
|
|
248
|
+
*
|
|
249
|
+
* If the block hash still matches (no L1 reorg), we keep the existing data and just
|
|
250
|
+
* update the provenance timestamp. If the finalized block has caught up, we promote the
|
|
251
|
+
* entry to finalized. If there was a reorg (hash mismatch), we fall back to a full fetch.
|
|
252
|
+
*/ async refreshStaleEntry(stale, epoch, ts) {
|
|
253
|
+
const [blockAtOriginal, l1FinalizedBlock, latestBlock] = await Promise.all([
|
|
254
|
+
this.rollup.client.getBlock({
|
|
255
|
+
blockNumber: stale.lastQueryL1BlockNumber,
|
|
256
|
+
includeTransactions: false
|
|
257
|
+
}),
|
|
258
|
+
getFinalizedL1Block(this.rollup.client),
|
|
259
|
+
this.rollup.client.getBlock({
|
|
260
|
+
includeTransactions: false
|
|
261
|
+
})
|
|
262
|
+
]);
|
|
263
|
+
if (blockAtOriginal.hash === stale.lastQueryL1BlockHash) {
|
|
264
|
+
// No reorg: the data is still valid. Check if we can now mark it as finalized.
|
|
265
|
+
const samplingTs = this.getSamplingTimestamp(epoch);
|
|
266
|
+
const finalized = !!(stale.data.committee && stale.data.committee.length > 0) && l1FinalizedBlock !== undefined && samplingTs <= l1FinalizedBlock.timestamp;
|
|
267
|
+
const refreshed = {
|
|
268
|
+
...stale,
|
|
269
|
+
lastRefreshL1Timestamp: latestBlock.timestamp,
|
|
270
|
+
finalized
|
|
271
|
+
};
|
|
272
|
+
this.cache.set(epoch, refreshed);
|
|
273
|
+
return refreshed;
|
|
274
|
+
}
|
|
275
|
+
// Reorg detected: block hash mismatch. Do a full re-fetch.
|
|
276
|
+
// Pass the already-fetched block timestamps to avoid redundant queries.
|
|
277
|
+
this.log.warn(`L1 reorg detected for epoch ${epoch}: block ${stale.lastQueryL1BlockNumber} hash changed`, {
|
|
278
|
+
epoch,
|
|
279
|
+
expectedHash: stale.lastQueryL1BlockHash,
|
|
280
|
+
actualHash: blockAtOriginal.hash
|
|
281
|
+
});
|
|
282
|
+
return this.fetchAndCache(epoch, ts, {
|
|
283
|
+
latestBlock,
|
|
284
|
+
finalizedBlock: l1FinalizedBlock
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Fetches committee data from L1, determines finalization status, and stores in the cache.
|
|
289
|
+
*
|
|
290
|
+
* Uses `lagInEpochsForRandao` (the binding constraint, always <= lagInEpochsForValidatorSet)
|
|
291
|
+
* and computes the sampling timestamp from the epoch start to match the L1 contract's logic.
|
|
292
|
+
*
|
|
293
|
+
* When called from refreshStaleEntry after a reorg, the latest and finalized blocks are
|
|
294
|
+
* passed in to avoid redundant L1 queries.
|
|
295
|
+
*/ async fetchAndCache(epoch, ts, prefetched) {
|
|
296
|
+
const [committee, seedBuffer, latestBlock, finalizedBlock, isEscapeHatchOpen] = await Promise.all([
|
|
220
297
|
this.rollup.getCommitteeAt(ts),
|
|
221
298
|
this.rollup.getSampleSeedAt(ts),
|
|
222
|
-
this.rollup.client.getBlock({
|
|
299
|
+
prefetched?.latestBlock ?? this.rollup.client.getBlock({
|
|
223
300
|
includeTransactions: false
|
|
224
|
-
})
|
|
301
|
+
}),
|
|
302
|
+
prefetched !== undefined ? prefetched.finalizedBlock : getFinalizedL1Block(this.rollup.client),
|
|
225
303
|
this.rollup.isEscapeHatchOpen(epoch)
|
|
226
304
|
]);
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
throw new Error(`Cannot query committee for future epoch ${epoch} with timestamp ${ts} (current L1 time is ${l1Timestamp}). Check your Ethereum node is synced.`);
|
|
305
|
+
const samplingTs = this.getSamplingTimestamp(epoch);
|
|
306
|
+
if (samplingTs > latestBlock.timestamp) {
|
|
307
|
+
throw new Error(`Cannot query committee for future epoch ${epoch}: ` + `sampling timestamp ${samplingTs} is beyond latest L1 block at ${latestBlock.timestamp}. ` + `Check your Ethereum node is synced.`);
|
|
231
308
|
}
|
|
232
|
-
|
|
309
|
+
// Empty committees are never marked finalized so they always get re-queried after TTL.
|
|
310
|
+
// If L1 has no finalized block yet (devnet startup), entries stay unfinalized.
|
|
311
|
+
const hasCommittee = !!(committee && committee.length > 0);
|
|
312
|
+
const finalized = hasCommittee && finalizedBlock !== undefined && samplingTs <= finalizedBlock.timestamp;
|
|
313
|
+
const data = {
|
|
233
314
|
committee,
|
|
234
315
|
seed: seedBuffer.toBigInt(),
|
|
235
316
|
epoch,
|
|
236
317
|
isEscapeHatchOpen
|
|
237
318
|
};
|
|
319
|
+
const entry = {
|
|
320
|
+
data,
|
|
321
|
+
lastQueryL1BlockNumber: latestBlock.number,
|
|
322
|
+
lastQueryL1BlockHash: latestBlock.hash,
|
|
323
|
+
lastRefreshL1Timestamp: latestBlock.timestamp,
|
|
324
|
+
finalized
|
|
325
|
+
};
|
|
326
|
+
this.cache.set(epoch, entry);
|
|
327
|
+
this.purgeCache();
|
|
328
|
+
return entry;
|
|
238
329
|
}
|
|
239
330
|
/**
|
|
240
331
|
* Get the ABI encoding of the proposer index - see ValidatorSelectionLib.sol computeProposerIndex
|
|
@@ -273,12 +364,16 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
273
364
|
nextSlot: next.slot
|
|
274
365
|
};
|
|
275
366
|
}
|
|
276
|
-
/** Returns the
|
|
277
|
-
const
|
|
278
|
-
const
|
|
367
|
+
/** Returns the target and next L2 slot in the next L1 slot. */ getTargetAndNextSlot() {
|
|
368
|
+
const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
|
|
369
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
370
|
+
const currentSlot = getSlotAtTimestamp(nowSeconds, this.l1constants);
|
|
371
|
+
const targetSlot = SlotNumber(currentSlot + offset);
|
|
372
|
+
const nextL2SlotOnL1 = getSlotAtNextL1Block(nowSeconds, this.l1constants);
|
|
373
|
+
const nextSlot = SlotNumber(nextL2SlotOnL1 + offset);
|
|
279
374
|
return {
|
|
280
375
|
targetSlot,
|
|
281
|
-
nextSlot
|
|
376
|
+
nextSlot
|
|
282
377
|
};
|
|
283
378
|
}
|
|
284
379
|
/**
|
|
@@ -338,10 +433,11 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
338
433
|
async getRegisteredValidators() {
|
|
339
434
|
const validatorRefreshIntervalMs = this.config.validatorRefreshIntervalSeconds * 1000;
|
|
340
435
|
const validatorRefreshTime = this.lastValidatorRefresh + validatorRefreshIntervalMs;
|
|
341
|
-
|
|
342
|
-
|
|
436
|
+
const now = this.dateProvider.now();
|
|
437
|
+
if (validatorRefreshTime < now) {
|
|
438
|
+
const currentSet = await this.rollup.getAttesters(BigInt(Math.floor(now / 1000)));
|
|
343
439
|
this.allValidators = new Set(currentSet.map((v)=>v.toString()));
|
|
344
|
-
this.lastValidatorRefresh =
|
|
440
|
+
this.lastValidatorRefresh = now;
|
|
345
441
|
}
|
|
346
442
|
return Array.from(this.allValidators.keys()).map((v)=>EthAddress.fromString(v));
|
|
347
443
|
}
|
|
@@ -17,7 +17,6 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
17
17
|
private seed;
|
|
18
18
|
private registeredValidators;
|
|
19
19
|
private l1Constants;
|
|
20
|
-
private proposerPipeliningEnabled;
|
|
21
20
|
constructor(l1Constants?: Partial<L1RollupConstants>);
|
|
22
21
|
/**
|
|
23
22
|
* Sets the committee members. Used in validation and attestation flows.
|
|
@@ -55,13 +54,11 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
55
54
|
*/
|
|
56
55
|
setL1Constants(constants: Partial<L1RollupConstants>): this;
|
|
57
56
|
getL1Constants(): L1RollupConstants;
|
|
58
|
-
setProposerPipeliningEnabled(enabled: boolean): void;
|
|
59
57
|
getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo>;
|
|
60
58
|
getSlotNow(): SlotNumber;
|
|
61
59
|
getTargetSlot(): SlotNumber;
|
|
62
60
|
getEpochNow(): EpochNumber;
|
|
63
61
|
getTargetEpoch(): EpochNumber;
|
|
64
|
-
isProposerPipeliningEnabled(): boolean;
|
|
65
62
|
getEpochAndSlotNow(): EpochAndSlot & {
|
|
66
63
|
nowMs: bigint;
|
|
67
64
|
};
|
|
@@ -88,4 +85,4 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
88
85
|
isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean>;
|
|
89
86
|
isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean>;
|
|
90
87
|
}
|
|
91
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
88
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF9lcG9jaF9jYWNoZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Rlc3QvdGVzdF9lcG9jaF9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzFFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUMzRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBUXJFLE9BQU8sRUFDTCxLQUFLLFlBQVksRUFDakIsS0FBSyxtQkFBbUIsRUFDeEIsS0FBSyxrQkFBa0IsRUFFdkIsS0FBSyxPQUFPLEVBQ2IsTUFBTSxtQkFBbUIsQ0FBQztBQWMzQjs7Ozs7O0dBTUc7QUFDSCxxQkFBYSxjQUFlLFlBQVcsbUJBQW1CO0lBQ3hELE9BQU8sQ0FBQyxTQUFTLENBQW9CO0lBQ3JDLE9BQU8sQ0FBQyxlQUFl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E9BQU8sQ0FBQyxDQUVyRTtJQUVELGlCQUFpQixDQUFDLEtBQUssRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLFVBQVUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxVQUFVLEVBQUUsQ0FBQyxDQUdqRjtJQUVELGlCQUFpQixDQUFDLE1BQU0sRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUV2RDtJQUVELHVCQUF1QixDQUFDLEtBQUssQ0FBQyxFQUFFLE9BQU8sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBRXpEO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test_epoch_cache.d.ts","sourceRoot":"","sources":["../../src/test/test_epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"test_epoch_cache.d.ts","sourceRoot":"","sources":["../../src/test/test_epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAQrE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AAc3B;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,mBAAmB;IACxD,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,eA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AG,KAAK,MAAM,EAAE,CAG1F;IAED,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/F;IAED,qBAAqB,IAAI;QAAE,WAAW,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,UAAU,CAAA;KAAE,CAQzE;IAED,oBAAoB,IAAI;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,UAAU,CAAA;KAAE,CAQvE;IAED,gCAAgC,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAEnF;IAED,uBAAuB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAE/C;IAED,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAErE;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAGjF;IAED,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAEvD;IAED,uBAAuB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAEzD;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
2
|
+
import { getEpochAtSlot, getSlotAtTimestamp, getTimestampForSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
3
3
|
import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
4
4
|
/** Default L1 constants for testing. */ const DEFAULT_L1_CONSTANTS = {
|
|
5
5
|
l1StartBlock: 0n,
|
|
@@ -25,7 +25,6 @@ import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
|
25
25
|
seed = 0n;
|
|
26
26
|
registeredValidators = [];
|
|
27
27
|
l1Constants;
|
|
28
|
-
proposerPipeliningEnabled = false;
|
|
29
28
|
constructor(l1Constants = {}){
|
|
30
29
|
this.l1Constants = {
|
|
31
30
|
...DEFAULT_L1_CONSTANTS,
|
|
@@ -87,9 +86,6 @@ import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
|
87
86
|
getL1Constants() {
|
|
88
87
|
return this.l1Constants;
|
|
89
88
|
}
|
|
90
|
-
setProposerPipeliningEnabled(enabled) {
|
|
91
|
-
this.proposerPipeliningEnabled = enabled;
|
|
92
|
-
}
|
|
93
89
|
getCommittee(_slot) {
|
|
94
90
|
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
95
91
|
return Promise.resolve({
|
|
@@ -103,7 +99,7 @@ import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
|
103
99
|
return this.currentSlot;
|
|
104
100
|
}
|
|
105
101
|
getTargetSlot() {
|
|
106
|
-
return
|
|
102
|
+
return SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
107
103
|
}
|
|
108
104
|
getEpochNow() {
|
|
109
105
|
return getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
@@ -111,12 +107,12 @@ import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
|
111
107
|
getTargetEpoch() {
|
|
112
108
|
return getEpochAtSlot(this.getTargetSlot(), this.l1Constants);
|
|
113
109
|
}
|
|
114
|
-
isProposerPipeliningEnabled() {
|
|
115
|
-
return this.proposerPipeliningEnabled;
|
|
116
|
-
}
|
|
117
110
|
getEpochAndSlotNow() {
|
|
111
|
+
// Model "now" as the start of the current slot (mirroring the real EpochCache, which derives nowMs
|
|
112
|
+
// from the wall clock). Using the slot start rather than the epoch start keeps nowMs consistent with
|
|
113
|
+
// currentSlot, which the pipelining receive-window check (clock_tolerance) relies on.
|
|
118
114
|
const epochNow = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
119
|
-
const ts =
|
|
115
|
+
const ts = getTimestampForSlot(this.currentSlot, this.l1Constants);
|
|
120
116
|
return {
|
|
121
117
|
epoch: epochNow,
|
|
122
118
|
slot: this.currentSlot,
|
|
@@ -139,7 +135,7 @@ import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
|
139
135
|
}
|
|
140
136
|
getTargetEpochAndSlotInNextL1Slot() {
|
|
141
137
|
const result = this.getEpochAndSlotInNextL1Slot();
|
|
142
|
-
const offset =
|
|
138
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
143
139
|
const targetSlot = SlotNumber(result.slot + offset);
|
|
144
140
|
return {
|
|
145
141
|
...result,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/epoch-cache",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-rc.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"../package.common.json"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aztec/ethereum": "5.0.0-
|
|
30
|
-
"@aztec/foundation": "5.0.0-
|
|
31
|
-
"@aztec/l1-artifacts": "5.0.0-
|
|
32
|
-
"@aztec/stdlib": "5.0.0-
|
|
29
|
+
"@aztec/ethereum": "5.0.0-rc.1",
|
|
30
|
+
"@aztec/foundation": "5.0.0-rc.1",
|
|
31
|
+
"@aztec/l1-artifacts": "5.0.0-rc.1",
|
|
32
|
+
"@aztec/stdlib": "5.0.0-rc.1",
|
|
33
33
|
"dotenv": "^16.0.3",
|
|
34
34
|
"get-port": "^7.1.0",
|
|
35
35
|
"jest-mock-extended": "^4.0.0",
|
|
36
36
|
"tslib": "^2.4.0",
|
|
37
37
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
38
|
-
"zod": "^
|
|
38
|
+
"zod": "^4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@jest/globals": "^30.0.0",
|
package/src/config.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { type L1ContractsConfig, getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
2
2
|
import { type L1ReaderConfig, getL1ReaderConfigFromEnv } from '@aztec/ethereum/l1-reader';
|
|
3
|
-
import { type PipelineConfig, getPipelineConfigEnvVars } from '@aztec/stdlib/config';
|
|
4
3
|
|
|
5
4
|
export type EpochCacheConfig = Pick<
|
|
6
|
-
L1ReaderConfig & L1ContractsConfig
|
|
7
|
-
| '
|
|
8
|
-
| 'l1ChainId'
|
|
9
|
-
| 'viemPollingIntervalMS'
|
|
10
|
-
| 'ethereumSlotDuration'
|
|
11
|
-
| 'l1HttpTimeoutMS'
|
|
12
|
-
| 'enableProposerPipelining'
|
|
5
|
+
L1ReaderConfig & L1ContractsConfig,
|
|
6
|
+
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration' | 'l1HttpTimeoutMS'
|
|
13
7
|
>;
|
|
14
8
|
|
|
15
9
|
export function getEpochCacheConfigEnvVars(): EpochCacheConfig {
|
|
16
|
-
return { ...getL1ReaderConfigFromEnv(), ...getL1ContractsConfigEnvVars()
|
|
10
|
+
return { ...getL1ReaderConfigFromEnv(), ...getL1ContractsConfigEnvVars() };
|
|
17
11
|
}
|