@aztec/epoch-cache 1.0.0-nightly.20250708 → 1.0.0-staging.0
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 +10 -13
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +6 -4
- package/package.json +5 -5
- package/src/epoch_cache.ts +12 -15
package/dest/epoch_cache.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
4
|
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
5
5
|
import { type EpochCacheConfig } from './config.js';
|
|
6
|
-
|
|
6
|
+
type EpochAndSlot = {
|
|
7
7
|
epoch: bigint;
|
|
8
8
|
slot: bigint;
|
|
9
9
|
ts: bigint;
|
|
@@ -13,13 +13,9 @@ export type EpochCommitteeInfo = {
|
|
|
13
13
|
seed: bigint;
|
|
14
14
|
epoch: bigint;
|
|
15
15
|
};
|
|
16
|
-
export type SlotTag = 'now' | 'next' | bigint;
|
|
17
16
|
export interface EpochCacheInterface {
|
|
18
|
-
getCommittee(slot:
|
|
17
|
+
getCommittee(slot: 'now' | 'next' | bigint | undefined): Promise<EpochCommitteeInfo>;
|
|
19
18
|
getEpochAndSlotNow(): EpochAndSlot;
|
|
20
|
-
getEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
21
|
-
now: bigint;
|
|
22
|
-
};
|
|
23
19
|
getProposerIndexEncoding(epoch: bigint, slot: bigint, seed: bigint): `0x${string}`;
|
|
24
20
|
computeProposerIndex(slot: bigint, epoch: bigint, seed: bigint, size: bigint): bigint;
|
|
25
21
|
getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
|
|
@@ -28,8 +24,7 @@ export interface EpochCacheInterface {
|
|
|
28
24
|
currentSlot: bigint;
|
|
29
25
|
nextSlot: bigint;
|
|
30
26
|
}>;
|
|
31
|
-
isInCommittee(
|
|
32
|
-
filterInCommittee(slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
27
|
+
isInCommittee(validator: EthAddress): Promise<boolean>;
|
|
33
28
|
}
|
|
34
29
|
/**
|
|
35
30
|
* Epoch cache
|
|
@@ -69,7 +64,7 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
69
64
|
* @param nextSlot - If true, get the validator set for the next slot.
|
|
70
65
|
* @returns The current validator set.
|
|
71
66
|
*/
|
|
72
|
-
getCommittee(slot?:
|
|
67
|
+
getCommittee(slot?: 'now' | 'next' | bigint): Promise<EpochCommitteeInfo>;
|
|
73
68
|
private getEpochAndTimestamp;
|
|
74
69
|
private computeCommittee;
|
|
75
70
|
/**
|
|
@@ -102,9 +97,11 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
102
97
|
* If the committee is empty (i.e. target committee size is 0, and anyone can propose), we return undefined.
|
|
103
98
|
*/
|
|
104
99
|
private getProposerAttesterAddressAt;
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Check if a validator is in the current epoch's committee
|
|
102
|
+
*/
|
|
103
|
+
isInCommittee(validator: EthAddress): Promise<boolean>;
|
|
104
|
+
filterInCommittee(validators: EthAddress[]): Promise<EthAddress[]>;
|
|
109
105
|
}
|
|
106
|
+
export {};
|
|
110
107
|
//# sourceMappingURL=epoch_cache.d.ts.map
|
|
@@ -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,EAEL,KAAK,iBAAiB,EAOvB,MAAM,6BAA6B,CA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9B;;OAEG;IACH,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE;IAWlF,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAQrF;;;;;OAKG;IACG,6CAA6C,IAAI,OAAO,CAAC;QAC7D,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;IACH,oCAAoC,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAMvE;;;;;OAKG;YACW,4BAA4B;IAa1C;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAQtD,iBAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAQzE"}
|
package/dest/epoch_cache.js
CHANGED
|
@@ -222,15 +222,17 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
222
222
|
const proposerIndex = this.computeProposerIndex(slot, epoch, seed, BigInt(committee.length));
|
|
223
223
|
return committee[Number(proposerIndex)];
|
|
224
224
|
}
|
|
225
|
-
/**
|
|
226
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Check if a validator is in the current epoch's committee
|
|
227
|
+
*/ async isInCommittee(validator) {
|
|
228
|
+
const { committee } = await this.getCommittee();
|
|
227
229
|
if (!committee) {
|
|
228
230
|
return false;
|
|
229
231
|
}
|
|
230
232
|
return committee.some((v)=>v.equals(validator));
|
|
231
233
|
}
|
|
232
|
-
|
|
233
|
-
const { committee } = await this.getCommittee(
|
|
234
|
+
async filterInCommittee(validators) {
|
|
235
|
+
const { committee } = await this.getCommittee();
|
|
234
236
|
if (!committee) {
|
|
235
237
|
return [];
|
|
236
238
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/epoch-cache",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-staging.0",
|
|
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": "1.0.0-
|
|
30
|
-
"@aztec/foundation": "1.0.0-
|
|
31
|
-
"@aztec/l1-artifacts": "1.0.0-
|
|
32
|
-
"@aztec/stdlib": "1.0.0-
|
|
29
|
+
"@aztec/ethereum": "1.0.0-staging.0",
|
|
30
|
+
"@aztec/foundation": "1.0.0-staging.0",
|
|
31
|
+
"@aztec/l1-artifacts": "1.0.0-staging.0",
|
|
32
|
+
"@aztec/stdlib": "1.0.0-staging.0",
|
|
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
|
@@ -17,7 +17,7 @@ import { createPublicClient, encodeAbiParameters, fallback, http, keccak256 } fr
|
|
|
17
17
|
|
|
18
18
|
import { type EpochCacheConfig, getEpochCacheConfigEnvVars } from './config.js';
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
type EpochAndSlot = {
|
|
21
21
|
epoch: bigint;
|
|
22
22
|
slot: bigint;
|
|
23
23
|
ts: bigint;
|
|
@@ -29,12 +29,9 @@ export type EpochCommitteeInfo = {
|
|
|
29
29
|
epoch: bigint;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export type SlotTag = 'now' | 'next' | bigint;
|
|
33
|
-
|
|
34
32
|
export interface EpochCacheInterface {
|
|
35
|
-
getCommittee(slot:
|
|
33
|
+
getCommittee(slot: 'now' | 'next' | bigint | undefined): Promise<EpochCommitteeInfo>;
|
|
36
34
|
getEpochAndSlotNow(): EpochAndSlot;
|
|
37
|
-
getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint };
|
|
38
35
|
getProposerIndexEncoding(epoch: bigint, slot: bigint, seed: bigint): `0x${string}`;
|
|
39
36
|
computeProposerIndex(slot: bigint, epoch: bigint, seed: bigint, size: bigint): bigint;
|
|
40
37
|
getProposerAttesterAddressInCurrentOrNextSlot(): Promise<{
|
|
@@ -43,8 +40,7 @@ export interface EpochCacheInterface {
|
|
|
43
40
|
currentSlot: bigint;
|
|
44
41
|
nextSlot: bigint;
|
|
45
42
|
}>;
|
|
46
|
-
isInCommittee(
|
|
47
|
-
filterInCommittee(slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
43
|
+
isInCommittee(validator: EthAddress): Promise<boolean>;
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
/**
|
|
@@ -166,7 +162,7 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
166
162
|
* @param nextSlot - If true, get the validator set for the next slot.
|
|
167
163
|
* @returns The current validator set.
|
|
168
164
|
*/
|
|
169
|
-
public async getCommittee(slot:
|
|
165
|
+
public async getCommittee(slot: 'now' | 'next' | bigint = 'now'): Promise<EpochCommitteeInfo> {
|
|
170
166
|
const { epoch, ts } = this.getEpochAndTimestamp(slot);
|
|
171
167
|
|
|
172
168
|
if (this.cache.has(epoch)) {
|
|
@@ -188,7 +184,7 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
188
184
|
return epochData;
|
|
189
185
|
}
|
|
190
186
|
|
|
191
|
-
private getEpochAndTimestamp(slot:
|
|
187
|
+
private getEpochAndTimestamp(slot: 'now' | 'next' | bigint = 'now') {
|
|
192
188
|
if (slot === 'now') {
|
|
193
189
|
return this.getEpochAndSlotNow();
|
|
194
190
|
} else if (slot === 'next') {
|
|
@@ -280,18 +276,19 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
280
276
|
return committee[Number(proposerIndex)];
|
|
281
277
|
}
|
|
282
278
|
|
|
283
|
-
/**
|
|
284
|
-
|
|
285
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Check if a validator is in the current epoch's committee
|
|
281
|
+
*/
|
|
282
|
+
async isInCommittee(validator: EthAddress): Promise<boolean> {
|
|
283
|
+
const { committee } = await this.getCommittee();
|
|
286
284
|
if (!committee) {
|
|
287
285
|
return false;
|
|
288
286
|
}
|
|
289
287
|
return committee.some(v => v.equals(validator));
|
|
290
288
|
}
|
|
291
289
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const { committee } = await this.getCommittee(slot);
|
|
290
|
+
async filterInCommittee(validators: EthAddress[]): Promise<EthAddress[]> {
|
|
291
|
+
const { committee } = await this.getCommittee();
|
|
295
292
|
if (!committee) {
|
|
296
293
|
return [];
|
|
297
294
|
}
|