@aztec/epoch-cache 0.87.2 → 0.87.3-nightly.20250529
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 +5 -3
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +21 -5
- package/package.json +5 -5
- package/src/epoch_cache.ts +28 -7
package/dest/epoch_cache.d.ts
CHANGED
|
@@ -52,8 +52,9 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
52
52
|
getEpochAndSlotNow(): EpochAndSlot;
|
|
53
53
|
private nowInSeconds;
|
|
54
54
|
private getEpochAndSlotAtSlot;
|
|
55
|
-
|
|
55
|
+
getEpochAndSlotInNextSlot(): EpochAndSlot;
|
|
56
56
|
private getEpochAndSlotAtTimestamp;
|
|
57
|
+
getCommitteeForEpoch(epoch: bigint): Promise<EpochCommitteeInfo>;
|
|
57
58
|
/**
|
|
58
59
|
* Get the current validator set
|
|
59
60
|
* @param nextSlot - If true, get the validator set for the next slot.
|
|
@@ -74,11 +75,12 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
74
75
|
* can be the next slot. If this is the case, then it will send proposals early.
|
|
75
76
|
*/
|
|
76
77
|
getProposerInCurrentOrNextSlot(): Promise<{
|
|
77
|
-
currentProposer: EthAddress;
|
|
78
|
-
nextProposer: EthAddress;
|
|
79
78
|
currentSlot: bigint;
|
|
80
79
|
nextSlot: bigint;
|
|
80
|
+
currentProposer: EthAddress;
|
|
81
|
+
nextProposer: EthAddress;
|
|
81
82
|
}>;
|
|
83
|
+
getProposerInNextSlot(): Promise<EthAddress>;
|
|
82
84
|
private getProposerAt;
|
|
83
85
|
/**
|
|
84
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,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,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,8BAA8B,IAAI,OAAO,CAAC;QAC9C,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,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"}
|
package/dest/epoch_cache.js
CHANGED
|
@@ -2,7 +2,7 @@ import { RollupContract, createEthereumChain } from '@aztec/ethereum';
|
|
|
2
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import { EmptyL1RollupConstants, getEpochAtSlot, getEpochNumberAtTimestamp, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
5
|
+
import { EmptyL1RollupConstants, getEpochAtSlot, getEpochNumberAtTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
6
6
|
import { createPublicClient, encodeAbiParameters, fallback, http, keccak256 } from 'viem';
|
|
7
7
|
import { getEpochCacheConfigEnvVars } from './config.js';
|
|
8
8
|
/**
|
|
@@ -86,7 +86,7 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
getEpochAndSlotInNextSlot() {
|
|
89
|
-
const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.
|
|
89
|
+
const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.ethereumSlotDuration);
|
|
90
90
|
return this.getEpochAndSlotAtTimestamp(nextSlotTs);
|
|
91
91
|
}
|
|
92
92
|
getEpochAndSlotAtTimestamp(ts) {
|
|
@@ -96,6 +96,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
96
96
|
ts
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
+
getCommitteeForEpoch(epoch) {
|
|
100
|
+
const [startSlot] = getSlotRangeForEpoch(epoch, this.l1constants);
|
|
101
|
+
return this.getCommittee(startSlot);
|
|
102
|
+
}
|
|
99
103
|
/**
|
|
100
104
|
* Get the current validator set
|
|
101
105
|
* @param nextSlot - If true, get the validator set for the next slot.
|
|
@@ -109,6 +113,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
109
113
|
epoch,
|
|
110
114
|
ts
|
|
111
115
|
});
|
|
116
|
+
// If the committe size is 0, then do not cache
|
|
117
|
+
if (epochData.committee.length == 0) {
|
|
118
|
+
return epochData;
|
|
119
|
+
}
|
|
112
120
|
this.cache.set(epoch, epochData);
|
|
113
121
|
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
114
122
|
toPurge.forEach((key)=>this.cache.delete(key));
|
|
@@ -159,6 +167,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
159
167
|
]);
|
|
160
168
|
}
|
|
161
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
|
+
}
|
|
162
174
|
return BigInt(keccak256(this.getProposerIndexEncoding(epoch, slot, seed))) % size;
|
|
163
175
|
}
|
|
164
176
|
/**
|
|
@@ -170,12 +182,16 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
170
182
|
const current = this.getEpochAndSlotNow();
|
|
171
183
|
const next = this.getEpochAndSlotInNextSlot();
|
|
172
184
|
return {
|
|
173
|
-
currentProposer: await this.getProposerAt(current),
|
|
174
|
-
nextProposer: await this.getProposerAt(next),
|
|
175
185
|
currentSlot: current.slot,
|
|
176
|
-
nextSlot: next.slot
|
|
186
|
+
nextSlot: next.slot,
|
|
187
|
+
currentProposer: await this.getProposerAt(current),
|
|
188
|
+
nextProposer: await this.getProposerAt(next)
|
|
177
189
|
};
|
|
178
190
|
}
|
|
191
|
+
getProposerInNextSlot() {
|
|
192
|
+
const epochAndSlot = this.getEpochAndSlotInNextSlot();
|
|
193
|
+
return this.getProposerAt(epochAndSlot);
|
|
194
|
+
}
|
|
179
195
|
async getProposerAt(when) {
|
|
180
196
|
const { epoch, slot } = when;
|
|
181
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.
|
|
3
|
+
"version": "0.87.3-nightly.20250529",
|
|
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.
|
|
30
|
-
"@aztec/foundation": "0.87.
|
|
31
|
-
"@aztec/l1-artifacts": "0.87.
|
|
32
|
-
"@aztec/stdlib": "0.87.
|
|
29
|
+
"@aztec/ethereum": "0.87.3-nightly.20250529",
|
|
30
|
+
"@aztec/foundation": "0.87.3-nightly.20250529",
|
|
31
|
+
"@aztec/l1-artifacts": "0.87.3-nightly.20250529",
|
|
32
|
+
"@aztec/stdlib": "0.87.3-nightly.20250529",
|
|
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
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getEpochAtSlot,
|
|
9
9
|
getEpochNumberAtTimestamp,
|
|
10
10
|
getSlotAtTimestamp,
|
|
11
|
+
getSlotRangeForEpoch,
|
|
11
12
|
getTimestampRangeForEpoch,
|
|
12
13
|
} from '@aztec/stdlib/epoch-helpers';
|
|
13
14
|
|
|
@@ -132,8 +133,8 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
132
133
|
return { epoch, ts, slot };
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.
|
|
136
|
+
public getEpochAndSlotInNextSlot(): EpochAndSlot {
|
|
137
|
+
const nextSlotTs = this.nowInSeconds() + BigInt(this.l1constants.ethereumSlotDuration);
|
|
137
138
|
return this.getEpochAndSlotAtTimestamp(nextSlotTs);
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -145,6 +146,11 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
public getCommitteeForEpoch(epoch: bigint): Promise<EpochCommitteeInfo> {
|
|
150
|
+
const [startSlot] = getSlotRangeForEpoch(epoch, this.l1constants);
|
|
151
|
+
return this.getCommittee(startSlot);
|
|
152
|
+
}
|
|
153
|
+
|
|
148
154
|
/**
|
|
149
155
|
* Get the current validator set
|
|
150
156
|
* @param nextSlot - If true, get the validator set for the next slot.
|
|
@@ -158,6 +164,10 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
158
164
|
}
|
|
159
165
|
|
|
160
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
|
+
}
|
|
161
171
|
this.cache.set(epoch, epochData);
|
|
162
172
|
|
|
163
173
|
const toPurge = Array.from(this.cache.keys())
|
|
@@ -200,6 +210,10 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
200
210
|
}
|
|
201
211
|
|
|
202
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
|
+
}
|
|
203
217
|
return BigInt(keccak256(this.getProposerIndexEncoding(epoch, slot, seed))) % size;
|
|
204
218
|
}
|
|
205
219
|
|
|
@@ -210,25 +224,32 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
210
224
|
* can be the next slot. If this is the case, then it will send proposals early.
|
|
211
225
|
*/
|
|
212
226
|
async getProposerInCurrentOrNextSlot(): Promise<{
|
|
213
|
-
currentProposer: EthAddress;
|
|
214
|
-
nextProposer: EthAddress;
|
|
215
227
|
currentSlot: bigint;
|
|
216
228
|
nextSlot: bigint;
|
|
229
|
+
currentProposer: EthAddress;
|
|
230
|
+
nextProposer: EthAddress;
|
|
217
231
|
}> {
|
|
218
232
|
const current = this.getEpochAndSlotNow();
|
|
219
233
|
const next = this.getEpochAndSlotInNextSlot();
|
|
220
234
|
|
|
221
235
|
return {
|
|
222
|
-
currentProposer: await this.getProposerAt(current),
|
|
223
|
-
nextProposer: await this.getProposerAt(next),
|
|
224
236
|
currentSlot: current.slot,
|
|
225
237
|
nextSlot: next.slot,
|
|
238
|
+
currentProposer: await this.getProposerAt(current),
|
|
239
|
+
nextProposer: await this.getProposerAt(next),
|
|
226
240
|
};
|
|
227
241
|
}
|
|
228
242
|
|
|
229
|
-
|
|
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> {
|
|
230
250
|
const { epoch, slot } = when;
|
|
231
251
|
const { seed, committee } = await this.getCommittee(slot);
|
|
252
|
+
|
|
232
253
|
const proposerIndex = this.computeProposerIndex(slot, epoch, seed, BigInt(committee.length));
|
|
233
254
|
return committee[Number(proposerIndex)];
|
|
234
255
|
}
|