@aztec/epoch-cache 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7

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.
@@ -1,6 +1,7 @@
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 { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
5
6
  import { EthAddress } from '@aztec/foundation/eth-address';
6
7
  import { type Logger, createLogger } from '@aztec/foundation/log';
@@ -10,8 +11,10 @@ import {
10
11
  getEpochAtSlot,
11
12
  getEpochNumberAtTimestamp,
12
13
  getNextL1SlotTimestamp,
14
+ getSlotAtNextL1Block,
13
15
  getSlotAtTimestamp,
14
16
  getSlotRangeForEpoch,
17
+ getStartTimestampForEpoch,
15
18
  getTimestampForSlot,
16
19
  } from '@aztec/stdlib/epoch-helpers';
17
20
 
@@ -19,7 +22,7 @@ import { createPublicClient, encodeAbiParameters, keccak256 } from 'viem';
19
22
 
20
23
  import { type EpochCacheConfig, getEpochCacheConfigEnvVars } from './config.js';
21
24
 
22
- /** When proposer pipelining is enabled, the proposer builds one slot ahead. */
25
+ /** The proposer pipelines by building one slot ahead. */
23
26
  export const PROPOSER_PIPELINING_SLOT_OFFSET = 1;
24
27
 
25
28
  /** Flat return type for compound epoch/slot getters. */
@@ -39,6 +42,22 @@ export type EpochCommitteeInfo = {
39
42
 
40
43
  export type SlotTag = 'now' | 'next' | SlotNumber;
41
44
 
45
+ /** Minimal L1 block info used for cache provenance. */
46
+ type L1BlockInfo = { number: bigint; hash: `0x${string}`; timestamp: bigint };
47
+
48
+ /** Resolved cache entry with L1 provenance metadata. */
49
+ type CachedEpochEntry = {
50
+ data: EpochCommitteeInfo;
51
+ /** L1 block number at which the committee data was originally queried. */
52
+ lastQueryL1BlockNumber: bigint;
53
+ /** L1 block hash at which the committee data was originally queried. Used to detect reorgs. */
54
+ lastQueryL1BlockHash: `0x${string}`;
55
+ /** Latest L1 block timestamp at the time of the most recent refresh (full fetch or lightweight check). */
56
+ lastRefreshL1Timestamp: bigint;
57
+ /** Whether the epoch's sampling data falls within finalized L1 history. */
58
+ finalized: boolean;
59
+ };
60
+
42
61
  export interface EpochCacheInterface {
43
62
  getCommittee(slot: SlotTag | undefined): Promise<EpochCommitteeInfo>;
44
63
  getSlotNow(): SlotNumber;
@@ -49,7 +68,6 @@ export interface EpochCacheInterface {
49
68
  getEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint };
50
69
  /** Returns epoch/slot info for the next L1 slot with pipeline offset applied. */
51
70
  getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint };
52
- isProposerPipeliningEnabled(): boolean;
53
71
  isEscapeHatchOpen(epoch: EpochNumber): Promise<boolean>;
54
72
  isEscapeHatchOpenAtSlot(slot: SlotTag): Promise<boolean>;
55
73
  getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}`;
@@ -61,6 +79,7 @@ export interface EpochCacheInterface {
61
79
  isInCommittee(slot: SlotTag, validator: EthAddress): Promise<boolean>;
62
80
  filterInCommittee(slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
63
81
  getL1Constants(): L1RollupConstants;
82
+ getLagInEpochsForValidatorSet(): number;
64
83
  }
65
84
 
66
85
  /**
@@ -73,14 +92,15 @@ export interface EpochCacheInterface {
73
92
  * Note: This class is very dependent on the system clock being in sync.
74
93
  */
75
94
  export class EpochCache implements EpochCacheInterface {
76
- // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
77
- protected cache: Map<EpochNumber, EpochCommitteeInfo> = new Map();
95
+ /**
96
+ * Single map holding both resolved entries and in-flight promises.
97
+ * A `Promise` value means a fetch is in progress; concurrent callers await it.
98
+ */
99
+ protected cache: Map<EpochNumber, CachedEpochEntry | Promise<CachedEpochEntry>> = new Map();
78
100
  private allValidators: Set<string> = new Set();
79
101
  private lastValidatorRefresh = 0;
80
102
  private readonly log: Logger = createLogger('epoch-cache');
81
103
 
82
- protected enableProposerPipelining: boolean;
83
-
84
104
  constructor(
85
105
  private rollup: RollupContract,
86
106
  private readonly l1constants: L1RollupConstants & {
@@ -88,12 +108,10 @@ export class EpochCache implements EpochCacheInterface {
88
108
  lagInEpochsForRandao: number;
89
109
  },
90
110
  private readonly dateProvider: DateProvider = new DateProvider(),
91
- protected readonly config = { cacheSize: 12, validatorRefreshIntervalSeconds: 60, enableProposerPipelining: false },
111
+ protected readonly config = { cacheSize: 12, validatorRefreshIntervalSeconds: 60 },
92
112
  ) {
93
- this.enableProposerPipelining = this.config.enableProposerPipelining;
94
113
  this.log.debug(`Initialized EpochCache`, {
95
114
  l1constants,
96
- enableProposerPipelining: this.enableProposerPipelining,
97
115
  });
98
116
  }
99
117
 
@@ -156,7 +174,6 @@ export class EpochCache implements EpochCacheInterface {
156
174
  return new EpochCache(rollup, l1RollupConstants, deps.dateProvider, {
157
175
  cacheSize: 12,
158
176
  validatorRefreshIntervalSeconds: 60,
159
- enableProposerPipelining: config.enableProposerPipelining,
160
177
  });
161
178
  }
162
179
 
@@ -164,8 +181,14 @@ export class EpochCache implements EpochCacheInterface {
164
181
  return this.l1constants;
165
182
  }
166
183
 
167
- public isProposerPipeliningEnabled(): boolean {
168
- return this.enableProposerPipelining;
184
+ /**
185
+ * The number of epochs by which validator-set sampling lags. The committee for epoch `E` samples the
186
+ * validator set as of `lagInEpochsForValidatorSet` epochs before `E` (see
187
+ * `ValidatorSelectionLib.stableEpochToValidatorSetSampleTime` on L1), so a newly staked validator only
188
+ * becomes eligible for a committee this many epochs after staking.
189
+ */
190
+ public getLagInEpochsForValidatorSet(): number {
191
+ return this.l1constants.lagInEpochsForValidatorSet;
169
192
  }
170
193
 
171
194
  public getSlotNow(): SlotNumber {
@@ -174,7 +197,7 @@ export class EpochCache implements EpochCacheInterface {
174
197
 
175
198
  public getTargetSlot(): SlotNumber {
176
199
  const slotNow = this.getSlotNow();
177
- const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
200
+ const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
178
201
  return SlotNumber(slotNow + offset);
179
202
  }
180
203
 
@@ -203,10 +226,6 @@ export class EpochCache implements EpochCacheInterface {
203
226
  }
204
227
 
205
228
  public getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
206
- if (!this.isProposerPipeliningEnabled()) {
207
- return this.getEpochAndSlotInNextL1Slot();
208
- }
209
-
210
229
  const result = this.getEpochAndSlotInNextL1Slot();
211
230
  const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
212
231
  const targetSlot = SlotNumber(result.slot + offset);
@@ -228,17 +247,8 @@ export class EpochCache implements EpochCacheInterface {
228
247
  return this.getCommittee(startSlot);
229
248
  }
230
249
 
231
- /**
232
- * Returns whether the escape hatch is open for the given epoch.
233
- *
234
- * Uses the already-cached EpochCommitteeInfo when available. If not cached, it will fetch
235
- * the epoch committee info (which includes the escape hatch flag) and return it.
236
- */
250
+ /** Returns whether the escape hatch is open for the given epoch. */
237
251
  public async isEscapeHatchOpen(epoch: EpochNumber): Promise<boolean> {
238
- const cached = this.cache.get(epoch);
239
- if (cached) {
240
- return cached.isEscapeHatchOpen;
241
- }
242
252
  const info = await this.getCommitteeForEpoch(epoch);
243
253
  return info.isEscapeHatchOpen;
244
254
  }
@@ -261,30 +271,49 @@ export class EpochCache implements EpochCacheInterface {
261
271
  }
262
272
 
263
273
  /**
264
- * Get the current validator set
265
- * @param nextSlot - If true, get the validator set for the next slot.
266
- * @returns The current validator set.
274
+ * Get the current validator set.
275
+ *
276
+ * Returns cached data if the entry is finalized or still fresh (queried less than one
277
+ * Ethereum slot ago). Stale non-finalized entries are re-queried, and concurrent callers
278
+ * coalesce on the same in-flight promise so the L1 query happens only once.
267
279
  */
268
280
  public async getCommittee(slot: SlotTag = 'now'): Promise<EpochCommitteeInfo> {
269
281
  const { epoch, ts } = this.getEpochAndTimestamp(slot);
270
282
 
271
- if (this.cache.has(epoch)) {
272
- return this.cache.get(epoch)!;
283
+ const cached = this.cache.get(epoch);
284
+
285
+ // In-flight promise: another caller is already fetching this epoch — just await it.
286
+ if (cached instanceof Promise) {
287
+ return (await cached).data;
273
288
  }
274
289
 
275
- const epochData = await this.computeCommittee({ epoch, ts });
276
- // If the committee size is 0 or undefined, then do not cache
277
- if (!epochData.committee || epochData.committee.length === 0) {
278
- return epochData;
290
+ // Resolved entry: return it if finalized or still fresh.
291
+ if (cached && (cached.finalized || !this.isStale(cached))) {
292
+ return cached.data;
279
293
  }
280
- this.cache.set(epoch, epochData);
281
294
 
282
- const toPurge = Array.from(this.cache.keys())
283
- .sort((a, b) => Number(b - a))
284
- .slice(this.config.cacheSize);
285
- toPurge.forEach(key => this.cache.delete(key));
295
+ // Stale non-finalized entry: do a lightweight refresh first (check block hash + finalized ts).
296
+ // Only fall back to a full re-fetch if the L1 block was reorged.
297
+ if (cached) {
298
+ const promise = this.refreshStaleEntry(cached, epoch, ts);
299
+ this.cache.set(epoch, promise);
300
+ try {
301
+ return (await promise).data;
302
+ } catch (err) {
303
+ this.cache.set(epoch, cached);
304
+ throw err;
305
+ }
306
+ }
286
307
 
287
- return epochData;
308
+ // No entry at all: full fetch.
309
+ const promise = this.fetchAndCache(epoch, ts);
310
+ this.cache.set(epoch, promise);
311
+ try {
312
+ return (await promise).data;
313
+ } catch (err) {
314
+ this.cache.delete(epoch);
315
+ throw err;
316
+ }
288
317
  }
289
318
 
290
319
  private getEpochAndTimestamp(slot: SlotTag = 'now'): { epoch: EpochNumber; ts: bigint } {
@@ -297,22 +326,140 @@ export class EpochCache implements EpochCacheInterface {
297
326
  }
298
327
  }
299
328
 
300
- private async computeCommittee(when: { epoch: EpochNumber; ts: bigint }): Promise<EpochCommitteeInfo> {
301
- const { ts, epoch } = when;
302
- const [committee, seedBuffer, l1Timestamp, isEscapeHatchOpen] = await Promise.all([
329
+ /** Evicts oldest cache entries (resolved or in-flight) beyond cacheSize. */
330
+ private purgeCache(): void {
331
+ if (this.cache.size <= this.config.cacheSize) {
332
+ return;
333
+ }
334
+ const toPurge = Array.from(this.cache.keys())
335
+ .sort((a, b) => Number(b - a))
336
+ .slice(this.config.cacheSize);
337
+ toPurge.forEach(key => this.cache.delete(key));
338
+ }
339
+
340
+ /** Returns true if a non-finalized cache entry is older than one Ethereum slot. */
341
+ private isStale(entry: CachedEpochEntry): boolean {
342
+ const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
343
+ return nowSeconds - entry.lastRefreshL1Timestamp >= BigInt(this.l1constants.ethereumSlotDuration);
344
+ }
345
+
346
+ /** Whether a cached epoch entry has been marked as finalized. Returns undefined if not cached or still in-flight. */
347
+ public isFinalized(epoch: EpochNumber): boolean | undefined {
348
+ const entry = this.cache.get(epoch);
349
+ if (!entry || entry instanceof Promise) {
350
+ return undefined;
351
+ }
352
+ return entry.finalized;
353
+ }
354
+
355
+ /** Returns the latest L1 timestamp stored in the cached entry. Undefined if not cached or in-flight. */
356
+ public getCachedLastRefreshL1Timestamp(epoch: EpochNumber): bigint | undefined {
357
+ const entry = this.cache.get(epoch);
358
+ if (!entry || entry instanceof Promise) {
359
+ return undefined;
360
+ }
361
+ return entry.lastRefreshL1Timestamp;
362
+ }
363
+
364
+ /** Computes the sampling timestamp for an epoch's committee data. */
365
+ private getSamplingTimestamp(epoch: EpochNumber): bigint {
366
+ const { lagInEpochsForRandao, epochDuration, slotDuration } = this.l1constants;
367
+ const epochStartTs = getStartTimestampForEpoch(epoch, this.l1constants);
368
+ return epochStartTs - BigInt(lagInEpochsForRandao) * BigInt(epochDuration) * BigInt(slotDuration);
369
+ }
370
+
371
+ /**
372
+ * Lightweight refresh for a stale non-finalized entry. Queries only the block hash at
373
+ * the original block number and the finalized block timestamp — avoids the expensive
374
+ * getCommitteeAt and getSampleSeedAt calls on the rollup contract.
375
+ *
376
+ * If the block hash still matches (no L1 reorg), we keep the existing data and just
377
+ * update the provenance timestamp. If the finalized block has caught up, we promote the
378
+ * entry to finalized. If there was a reorg (hash mismatch), we fall back to a full fetch.
379
+ */
380
+ private async refreshStaleEntry(stale: CachedEpochEntry, epoch: EpochNumber, ts: bigint): Promise<CachedEpochEntry> {
381
+ const [blockAtOriginal, l1FinalizedBlock, latestBlock] = await Promise.all([
382
+ this.rollup.client.getBlock({ blockNumber: stale.lastQueryL1BlockNumber, includeTransactions: false }),
383
+ getFinalizedL1Block(this.rollup.client),
384
+ this.rollup.client.getBlock({ includeTransactions: false }),
385
+ ]);
386
+
387
+ if (blockAtOriginal.hash === stale.lastQueryL1BlockHash) {
388
+ // No reorg: the data is still valid. Check if we can now mark it as finalized.
389
+ const samplingTs = this.getSamplingTimestamp(epoch);
390
+ const finalized =
391
+ !!(stale.data.committee && stale.data.committee.length > 0) &&
392
+ l1FinalizedBlock !== undefined &&
393
+ samplingTs <= l1FinalizedBlock.timestamp;
394
+
395
+ const refreshed: CachedEpochEntry = {
396
+ ...stale,
397
+ lastRefreshL1Timestamp: latestBlock.timestamp,
398
+ finalized,
399
+ };
400
+ this.cache.set(epoch, refreshed);
401
+ return refreshed;
402
+ }
403
+
404
+ // Reorg detected: block hash mismatch. Do a full re-fetch.
405
+ // Pass the already-fetched block timestamps to avoid redundant queries.
406
+ this.log.warn(`L1 reorg detected for epoch ${epoch}: block ${stale.lastQueryL1BlockNumber} hash changed`, {
407
+ epoch,
408
+ expectedHash: stale.lastQueryL1BlockHash,
409
+ actualHash: blockAtOriginal.hash,
410
+ });
411
+ return this.fetchAndCache(epoch, ts, { latestBlock, finalizedBlock: l1FinalizedBlock });
412
+ }
413
+
414
+ /**
415
+ * Fetches committee data from L1, determines finalization status, and stores in the cache.
416
+ *
417
+ * Uses `lagInEpochsForRandao` (the binding constraint, always <= lagInEpochsForValidatorSet)
418
+ * and computes the sampling timestamp from the epoch start to match the L1 contract's logic.
419
+ *
420
+ * When called from refreshStaleEntry after a reorg, the latest and finalized blocks are
421
+ * passed in to avoid redundant L1 queries.
422
+ */
423
+ private async fetchAndCache(
424
+ epoch: EpochNumber,
425
+ ts: bigint,
426
+ prefetched?: { latestBlock: L1BlockInfo; finalizedBlock: { timestamp: bigint } | undefined },
427
+ ): Promise<CachedEpochEntry> {
428
+ const [committee, seedBuffer, latestBlock, finalizedBlock, isEscapeHatchOpen] = await Promise.all([
303
429
  this.rollup.getCommitteeAt(ts),
304
430
  this.rollup.getSampleSeedAt(ts),
305
- this.rollup.client.getBlock({ includeTransactions: false }).then(b => b.timestamp),
431
+ prefetched?.latestBlock ?? this.rollup.client.getBlock({ includeTransactions: false }),
432
+ prefetched !== undefined ? prefetched.finalizedBlock : getFinalizedL1Block(this.rollup.client),
306
433
  this.rollup.isEscapeHatchOpen(epoch),
307
434
  ]);
308
- const { lagInEpochsForValidatorSet, epochDuration, slotDuration } = this.l1constants;
309
- const sub = BigInt(lagInEpochsForValidatorSet) * BigInt(epochDuration) * BigInt(slotDuration);
310
- if (ts - sub > l1Timestamp) {
435
+
436
+ const samplingTs = this.getSamplingTimestamp(epoch);
437
+
438
+ if (samplingTs > latestBlock.timestamp) {
311
439
  throw new Error(
312
- `Cannot query committee for future epoch ${epoch} with timestamp ${ts} (current L1 time is ${l1Timestamp}). Check your Ethereum node is synced.`,
440
+ `Cannot query committee for future epoch ${epoch}: ` +
441
+ `sampling timestamp ${samplingTs} is beyond latest L1 block at ${latestBlock.timestamp}. ` +
442
+ `Check your Ethereum node is synced.`,
313
443
  );
314
444
  }
315
- return { committee, seed: seedBuffer.toBigInt(), epoch, isEscapeHatchOpen };
445
+
446
+ // Empty committees are never marked finalized so they always get re-queried after TTL.
447
+ // If L1 has no finalized block yet (devnet startup), entries stay unfinalized.
448
+ const hasCommittee = !!(committee && committee.length > 0);
449
+ const finalized = hasCommittee && finalizedBlock !== undefined && samplingTs <= finalizedBlock.timestamp;
450
+ const data: EpochCommitteeInfo = { committee, seed: seedBuffer.toBigInt(), epoch, isEscapeHatchOpen };
451
+ const entry: CachedEpochEntry = {
452
+ data,
453
+ lastQueryL1BlockNumber: latestBlock.number!,
454
+ lastQueryL1BlockHash: latestBlock.hash!,
455
+ lastRefreshL1Timestamp: latestBlock.timestamp,
456
+ finalized,
457
+ };
458
+
459
+ this.cache.set(epoch, entry);
460
+ this.purgeCache();
461
+
462
+ return entry;
316
463
  }
317
464
 
318
465
  /**
@@ -348,15 +495,18 @@ export class EpochCache implements EpochCacheInterface {
348
495
  };
349
496
  }
350
497
 
351
- /** Returns the taget and next L2 slot in the next L1 slot */
498
+ /** Returns the target and next L2 slot in the next L1 slot. */
352
499
  public getTargetAndNextSlot(): { targetSlot: SlotNumber; nextSlot: SlotNumber } {
353
- const targetSlot = this.getTargetSlot();
354
- const next = this.getTargetEpochAndSlotInNextL1Slot();
500
+ const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
501
+ const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
355
502
 
356
- return {
357
- targetSlot,
358
- nextSlot: next.slot,
359
- };
503
+ const currentSlot = getSlotAtTimestamp(nowSeconds, this.l1constants);
504
+ const targetSlot = SlotNumber(currentSlot + offset);
505
+
506
+ const nextL2SlotOnL1 = getSlotAtNextL1Block(nowSeconds, this.l1constants);
507
+ const nextSlot = SlotNumber(nextL2SlotOnL1 + offset);
508
+
509
+ return { targetSlot, nextSlot };
360
510
  }
361
511
 
362
512
  /**
@@ -1,7 +1,12 @@
1
1
  import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
4
- import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
4
+ import {
5
+ getEpochAtSlot,
6
+ getSlotAtTimestamp,
7
+ getTimestampForSlot,
8
+ getTimestampRangeForEpoch,
9
+ } from '@aztec/stdlib/epoch-helpers';
5
10
 
6
11
  import {
7
12
  type EpochAndSlot,
@@ -38,12 +43,17 @@ export class TestEpochCache implements EpochCacheInterface {
38
43
  private seed: bigint = 0n;
39
44
  private registeredValidators: EthAddress[] = [];
40
45
  private l1Constants: L1RollupConstants;
41
- private proposerPipeliningEnabled = false;
46
+ private lagInEpochsForValidatorSet = 2;
42
47
 
43
48
  constructor(l1Constants: Partial<L1RollupConstants> = {}) {
44
49
  this.l1Constants = { ...DEFAULT_L1_CONSTANTS, ...l1Constants };
45
50
  }
46
51
 
52
+ setLagInEpochsForValidatorSet(lag: number): this {
53
+ this.lagInEpochsForValidatorSet = lag;
54
+ return this;
55
+ }
56
+
47
57
  /**
48
58
  * Sets the committee members. Used in validation and attestation flows.
49
59
  * @param committee - Array of committee member addresses.
@@ -111,8 +121,8 @@ export class TestEpochCache implements EpochCacheInterface {
111
121
  return this.l1Constants;
112
122
  }
113
123
 
114
- setProposerPipeliningEnabled(enabled: boolean): void {
115
- this.proposerPipeliningEnabled = enabled;
124
+ getLagInEpochsForValidatorSet(): number {
125
+ return this.lagInEpochsForValidatorSet;
116
126
  }
117
127
 
118
128
  getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo> {
@@ -130,9 +140,7 @@ export class TestEpochCache implements EpochCacheInterface {
130
140
  }
131
141
 
132
142
  getTargetSlot(): SlotNumber {
133
- return this.proposerPipeliningEnabled
134
- ? SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET)
135
- : this.currentSlot;
143
+ return SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET);
136
144
  }
137
145
 
138
146
  getEpochNow(): EpochNumber {
@@ -143,13 +151,12 @@ export class TestEpochCache implements EpochCacheInterface {
143
151
  return getEpochAtSlot(this.getTargetSlot(), this.l1Constants);
144
152
  }
145
153
 
146
- isProposerPipeliningEnabled(): boolean {
147
- return this.proposerPipeliningEnabled;
148
- }
149
-
150
154
  getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
155
+ // Model "now" as the start of the current slot (mirroring the real EpochCache, which derives nowMs
156
+ // from the wall clock). Using the slot start rather than the epoch start keeps nowMs consistent with
157
+ // currentSlot, which the pipelining receive-window check (clock_tolerance) relies on.
151
158
  const epochNow = getEpochAtSlot(this.currentSlot, this.l1Constants);
152
- const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
159
+ const ts = getTimestampForSlot(this.currentSlot, this.l1Constants);
153
160
  return {
154
161
  epoch: epochNow,
155
162
  slot: this.currentSlot,
@@ -174,7 +181,7 @@ export class TestEpochCache implements EpochCacheInterface {
174
181
 
175
182
  getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
176
183
  const result = this.getEpochAndSlotInNextL1Slot();
177
- const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
184
+ const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
178
185
  const targetSlot = SlotNumber(result.slot + offset);
179
186
  return { ...result, slot: targetSlot, epoch: getEpochAtSlot(targetSlot, this.l1Constants) };
180
187
  }