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