@aztec/epoch-cache 0.87.2-nightly.20250527 → 0.87.3-nightly.20250528

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.
@@ -52,7 +52,7 @@ export declare class EpochCache implements EpochCacheInterface {
52
52
  getEpochAndSlotNow(): EpochAndSlot;
53
53
  private nowInSeconds;
54
54
  private getEpochAndSlotAtSlot;
55
- private getEpochAndSlotInNextSlot;
55
+ getEpochAndSlotInNextSlot(): EpochAndSlot;
56
56
  private getEpochAndSlotAtTimestamp;
57
57
  getCommitteeForEpoch(epoch: bigint): Promise<EpochCommitteeInfo>;
58
58
  /**
@@ -75,11 +75,12 @@ export declare class EpochCache implements EpochCacheInterface {
75
75
  * can be the next slot. If this is the case, then it will send proposals early.
76
76
  */
77
77
  getProposerInCurrentOrNextSlot(): Promise<{
78
- currentProposer: EthAddress;
79
- nextProposer: EthAddress;
80
78
  currentSlot: bigint;
81
79
  nextSlot: bigint;
80
+ currentProposer: EthAddress;
81
+ nextProposer: EthAddress;
82
82
  }>;
83
+ getProposerInNextSlot(): Promise<EthAddress>;
83
84
  private getProposerAt;
84
85
  /**
85
86
  * Check if a validator is in the current epoch's committee
@@ -1 +1 @@
1
- {"version":3,"file":"epoch_cache.d.ts","sourceRoot":"","sources":["../src/epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAEL,KAAK,iBAAiB,EAMvB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAAE,KAAK,gBAAgB,EAA8B,MAAM,aAAa,CAAC;AAEhF,KAAK,YAAY,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ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jB,eAAe,EAAE,UAAU,CAAC;QAC5B,YAAY,EAAE,UAAU,CAAC;KAC1B,CAAC;IAYF,qBAAqB,IAAI,OAAO,CAAC,UAAU,CAAC;YAM9B,aAAa;IAQ3B;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAI7D"}
@@ -86,7 +86,7 @@ import { getEpochCacheConfigEnvVars } from './config.js';
86
86
  };
87
87
  }
88
88
  getEpochAndSlotInNextSlot() {
89
- const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.slotDuration);
89
+ const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.ethereumSlotDuration);
90
90
  return this.getEpochAndSlotAtTimestamp(nextSlotTs);
91
91
  }
92
92
  getEpochAndSlotAtTimestamp(ts) {
@@ -113,6 +113,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
113
113
  epoch,
114
114
  ts
115
115
  });
116
+ // If the committe size is 0, then do not cache
117
+ if (epochData.committee.length == 0) {
118
+ return epochData;
119
+ }
116
120
  this.cache.set(epoch, epochData);
117
121
  const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
118
122
  toPurge.forEach((key)=>this.cache.delete(key));
@@ -163,6 +167,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
163
167
  ]);
164
168
  }
165
169
  computeProposerIndex(slot, epoch, seed, size) {
170
+ // if committe size is 0, then mod 1 is 0
171
+ if (size === 0n) {
172
+ return 0n;
173
+ }
166
174
  return BigInt(keccak256(this.getProposerIndexEncoding(epoch, slot, seed))) % size;
167
175
  }
168
176
  /**
@@ -174,12 +182,16 @@ import { getEpochCacheConfigEnvVars } from './config.js';
174
182
  const current = this.getEpochAndSlotNow();
175
183
  const next = this.getEpochAndSlotInNextSlot();
176
184
  return {
177
- currentProposer: await this.getProposerAt(current),
178
- nextProposer: await this.getProposerAt(next),
179
185
  currentSlot: current.slot,
180
- nextSlot: next.slot
186
+ nextSlot: next.slot,
187
+ currentProposer: await this.getProposerAt(current),
188
+ nextProposer: await this.getProposerAt(next)
181
189
  };
182
190
  }
191
+ getProposerInNextSlot() {
192
+ const epochAndSlot = this.getEpochAndSlotInNextSlot();
193
+ return this.getProposerAt(epochAndSlot);
194
+ }
183
195
  async getProposerAt(when) {
184
196
  const { epoch, slot } = when;
185
197
  const { seed, committee } = await this.getCommittee(slot);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/epoch-cache",
3
- "version": "0.87.2-nightly.20250527",
3
+ "version": "0.87.3-nightly.20250528",
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": "0.87.2-nightly.20250527",
30
- "@aztec/foundation": "0.87.2-nightly.20250527",
31
- "@aztec/l1-artifacts": "0.87.2-nightly.20250527",
32
- "@aztec/stdlib": "0.87.2-nightly.20250527",
29
+ "@aztec/ethereum": "0.87.3-nightly.20250528",
30
+ "@aztec/foundation": "0.87.3-nightly.20250528",
31
+ "@aztec/l1-artifacts": "0.87.3-nightly.20250528",
32
+ "@aztec/stdlib": "0.87.3-nightly.20250528",
33
33
  "@viem/anvil": "^0.0.10",
34
34
  "dotenv": "^16.0.3",
35
35
  "get-port": "^7.1.0",
@@ -133,8 +133,8 @@ export class EpochCache implements EpochCacheInterface {
133
133
  return { epoch, ts, slot };
134
134
  }
135
135
 
136
- private getEpochAndSlotInNextSlot(): EpochAndSlot {
137
- const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.slotDuration);
136
+ public getEpochAndSlotInNextSlot(): EpochAndSlot {
137
+ const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.ethereumSlotDuration);
138
138
  return this.getEpochAndSlotAtTimestamp(nextSlotTs);
139
139
  }
140
140
 
@@ -164,6 +164,10 @@ export class EpochCache implements EpochCacheInterface {
164
164
  }
165
165
 
166
166
  const epochData = await this.computeCommittee({ epoch, ts });
167
+ // If the committe size is 0, then do not cache
168
+ if (epochData.committee.length == 0) {
169
+ return epochData;
170
+ }
167
171
  this.cache.set(epoch, epochData);
168
172
 
169
173
  const toPurge = Array.from(this.cache.keys())
@@ -206,6 +210,10 @@ export class EpochCache implements EpochCacheInterface {
206
210
  }
207
211
 
208
212
  computeProposerIndex(slot: bigint, epoch: bigint, seed: bigint, size: bigint): bigint {
213
+ // if committe size is 0, then mod 1 is 0
214
+ if (size === 0n) {
215
+ return 0n;
216
+ }
209
217
  return BigInt(keccak256(this.getProposerIndexEncoding(epoch, slot, seed))) % size;
210
218
  }
211
219
 
@@ -216,25 +224,32 @@ export class EpochCache implements EpochCacheInterface {
216
224
  * can be the next slot. If this is the case, then it will send proposals early.
217
225
  */
218
226
  async getProposerInCurrentOrNextSlot(): Promise<{
219
- currentProposer: EthAddress;
220
- nextProposer: EthAddress;
221
227
  currentSlot: bigint;
222
228
  nextSlot: bigint;
229
+ currentProposer: EthAddress;
230
+ nextProposer: EthAddress;
223
231
  }> {
224
232
  const current = this.getEpochAndSlotNow();
225
233
  const next = this.getEpochAndSlotInNextSlot();
226
234
 
227
235
  return {
228
- currentProposer: await this.getProposerAt(current),
229
- nextProposer: await this.getProposerAt(next),
230
236
  currentSlot: current.slot,
231
237
  nextSlot: next.slot,
238
+ currentProposer: await this.getProposerAt(current),
239
+ nextProposer: await this.getProposerAt(next),
232
240
  };
233
241
  }
234
242
 
235
- private async getProposerAt(when: EpochAndSlot) {
243
+ getProposerInNextSlot(): Promise<EthAddress> {
244
+ const epochAndSlot = this.getEpochAndSlotInNextSlot();
245
+
246
+ return this.getProposerAt(epochAndSlot);
247
+ }
248
+
249
+ private async getProposerAt(when: EpochAndSlot): Promise<EthAddress> {
236
250
  const { epoch, slot } = when;
237
251
  const { seed, committee } = await this.getCommittee(slot);
252
+
238
253
  const proposerIndex = this.computeProposerIndex(slot, epoch, seed, BigInt(committee.length));
239
254
  return committee[Number(proposerIndex)];
240
255
  }