@aztec/epoch-cache 0.0.1-commit.ef17749e1 → 0.0.1-commit.f103f88

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.
@@ -3,7 +3,13 @@ import { EthAddress } from '@aztec/foundation/eth-address';
3
3
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
4
4
  import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
5
5
 
6
- import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '../epoch_cache.js';
6
+ import {
7
+ type EpochAndSlot,
8
+ type EpochCacheInterface,
9
+ type EpochCommitteeInfo,
10
+ PROPOSER_PIPELINING_SLOT_OFFSET,
11
+ type SlotTag,
12
+ } from '../epoch_cache.js';
7
13
 
8
14
  /** Default L1 constants for testing. */
9
15
  const DEFAULT_L1_CONSTANTS: L1RollupConstants = {
@@ -14,6 +20,7 @@ const DEFAULT_L1_CONSTANTS: L1RollupConstants = {
14
20
  ethereumSlotDuration: 12,
15
21
  proofSubmissionEpochs: 2,
16
22
  targetCommitteeSize: 48,
23
+ rollupManaLimit: Number.MAX_SAFE_INTEGER,
17
24
  };
18
25
 
19
26
  /**
@@ -31,6 +38,7 @@ export class TestEpochCache implements EpochCacheInterface {
31
38
  private seed: bigint = 0n;
32
39
  private registeredValidators: EthAddress[] = [];
33
40
  private l1Constants: L1RollupConstants;
41
+ private proposerPipeliningEnabled = false;
34
42
 
35
43
  constructor(l1Constants: Partial<L1RollupConstants> = {}) {
36
44
  this.l1Constants = { ...DEFAULT_L1_CONSTANTS, ...l1Constants };
@@ -103,6 +111,10 @@ export class TestEpochCache implements EpochCacheInterface {
103
111
  return this.l1Constants;
104
112
  }
105
113
 
114
+ setProposerPipeliningEnabled(enabled: boolean): void {
115
+ this.proposerPipeliningEnabled = enabled;
116
+ }
117
+
106
118
  getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo> {
107
119
  const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
108
120
  return Promise.resolve({
@@ -113,19 +125,62 @@ export class TestEpochCache implements EpochCacheInterface {
113
125
  });
114
126
  }
115
127
 
128
+ getSlotNow(): SlotNumber {
129
+ return this.currentSlot;
130
+ }
131
+
132
+ getTargetSlot(): SlotNumber {
133
+ return this.proposerPipeliningEnabled
134
+ ? SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET)
135
+ : this.currentSlot;
136
+ }
137
+
138
+ getEpochNow(): EpochNumber {
139
+ return getEpochAtSlot(this.currentSlot, this.l1Constants);
140
+ }
141
+
142
+ getTargetEpoch(): EpochNumber {
143
+ return getEpochAtSlot(this.getTargetSlot(), this.l1Constants);
144
+ }
145
+
146
+ isProposerPipeliningEnabled(): boolean {
147
+ return this.proposerPipeliningEnabled;
148
+ }
149
+
150
+ pipeliningOffset(): number {
151
+ return this.proposerPipeliningEnabled ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
152
+ }
153
+
116
154
  getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
117
- const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
118
- const ts = getTimestampRangeForEpoch(epoch, this.l1Constants)[0];
119
- return { epoch, slot: this.currentSlot, ts, nowMs: ts * 1000n };
155
+ const epochNow = getEpochAtSlot(this.currentSlot, this.l1Constants);
156
+ const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
157
+ return {
158
+ epoch: epochNow,
159
+ slot: this.currentSlot,
160
+ ts,
161
+ nowMs: ts * 1000n,
162
+ };
120
163
  }
121
164
 
122
- getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
123
- const now = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
124
- const nextSlotTs = now + BigInt(this.l1Constants.ethereumSlotDuration);
165
+ getEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
166
+ const nowTs = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
167
+ const nextSlotTs = nowTs + BigInt(this.l1Constants.ethereumSlotDuration);
125
168
  const nextSlot = getSlotAtTimestamp(nextSlotTs, this.l1Constants);
126
- const epoch = getEpochAtSlot(nextSlot, this.l1Constants);
127
- const ts = getTimestampRangeForEpoch(epoch, this.l1Constants)[0];
128
- return { epoch, slot: nextSlot, ts, now };
169
+ const epochNow = getEpochAtSlot(nextSlot, this.l1Constants);
170
+ const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
171
+ return {
172
+ epoch: epochNow,
173
+ slot: nextSlot,
174
+ ts,
175
+ nowSeconds: nowTs,
176
+ };
177
+ }
178
+
179
+ getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
180
+ const result = this.getEpochAndSlotInNextL1Slot();
181
+ const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
182
+ const targetSlot = SlotNumber(result.slot + offset);
183
+ return { ...result, slot: targetSlot, epoch: getEpochAtSlot(targetSlot, this.l1Constants) };
129
184
  }
130
185
 
131
186
  getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}` {
@@ -141,9 +196,22 @@ export class TestEpochCache implements EpochCacheInterface {
141
196
  }
142
197
 
143
198
  getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
199
+ const currentSlot = this.getSlotNow();
200
+ const next = this.getEpochAndSlotInNextL1Slot();
201
+
144
202
  return {
145
- currentSlot: this.currentSlot,
146
- nextSlot: SlotNumber(this.currentSlot + 1),
203
+ currentSlot,
204
+ nextSlot: next.slot,
205
+ };
206
+ }
207
+
208
+ getTargetAndNextSlot(): { targetSlot: SlotNumber; nextSlot: SlotNumber } {
209
+ const targetSlot = this.getTargetSlot();
210
+ const next = this.getTargetEpochAndSlotInNextL1Slot();
211
+
212
+ return {
213
+ targetSlot,
214
+ nextSlot: next.slot,
147
215
  };
148
216
  }
149
217
 
@@ -164,6 +232,10 @@ export class TestEpochCache implements EpochCacheInterface {
164
232
  return Promise.resolve(validators.filter(v => committeeSet.has(v.toString())));
165
233
  }
166
234
 
235
+ isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean> {
236
+ return Promise.resolve(this.escapeHatchOpen);
237
+ }
238
+
167
239
  isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean> {
168
240
  return Promise.resolve(this.escapeHatchOpen);
169
241
  }