@aztec/epoch-cache 0.0.1-commit.e558bd1c → 0.0.1-commit.e57c76e
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/README.md +210 -0
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/epoch_cache.d.ts +71 -17
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +214 -70
- package/dest/test/test_epoch_cache.d.ts +15 -3
- package/dest/test/test_epoch_cache.d.ts.map +1 -1
- package/dest/test/test_epoch_cache.js +50 -12
- package/package.json +6 -7
- package/src/config.ts +1 -1
- package/src/epoch_cache.ts +271 -62
- package/src/test/test_epoch_cache.ts +70 -12
package/dest/epoch_cache.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
2
|
+
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
2
3
|
import { NoCommitteeError, RollupContract } from '@aztec/ethereum/contracts';
|
|
4
|
+
import { getFinalizedL1Block } from '@aztec/ethereum/queries';
|
|
5
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import { getEpochAtSlot, getEpochNumberAtTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch,
|
|
7
|
-
import { createPublicClient, encodeAbiParameters,
|
|
9
|
+
import { getEpochAtSlot, getEpochNumberAtTimestamp, getNextL1SlotTimestamp, getSlotAtNextL1Block, getSlotAtTimestamp, getSlotRangeForEpoch, getStartTimestampForEpoch, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
10
|
+
import { createPublicClient, encodeAbiParameters, keccak256 } from 'viem';
|
|
8
11
|
import { getEpochCacheConfigEnvVars } from './config.js';
|
|
12
|
+
/** The proposer pipelines by building one slot ahead. */ export const PROPOSER_PIPELINING_SLOT_OFFSET = 1;
|
|
9
13
|
/**
|
|
10
14
|
* Epoch cache
|
|
11
15
|
*
|
|
@@ -19,8 +23,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
19
23
|
l1constants;
|
|
20
24
|
dateProvider;
|
|
21
25
|
config;
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Single map holding both resolved entries and in-flight promises.
|
|
28
|
+
* A `Promise` value means a fetch is in progress; concurrent callers await it.
|
|
29
|
+
*/ cache;
|
|
24
30
|
allValidators;
|
|
25
31
|
lastValidatorRefresh;
|
|
26
32
|
log;
|
|
@@ -50,21 +56,23 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
50
56
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
51
57
|
const publicClient = createPublicClient({
|
|
52
58
|
chain: chain.chainInfo,
|
|
53
|
-
transport:
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
60
|
+
timeout: config.l1HttpTimeoutMS
|
|
61
|
+
}),
|
|
56
62
|
pollingInterval: config.viemPollingIntervalMS
|
|
57
63
|
});
|
|
58
64
|
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
|
|
59
65
|
}
|
|
60
|
-
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration, lagInEpochsForValidatorSet, lagInEpochsForRandao] = await Promise.all([
|
|
66
|
+
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration, lagInEpochsForValidatorSet, lagInEpochsForRandao, targetCommitteeSize, rollupManaLimit] = await Promise.all([
|
|
61
67
|
rollup.getL1StartBlock(),
|
|
62
68
|
rollup.getL1GenesisTime(),
|
|
63
69
|
rollup.getProofSubmissionEpochs(),
|
|
64
70
|
rollup.getSlotDuration(),
|
|
65
71
|
rollup.getEpochDuration(),
|
|
66
72
|
rollup.getLagInEpochsForValidatorSet(),
|
|
67
|
-
rollup.getLagInEpochsForRandao()
|
|
73
|
+
rollup.getLagInEpochsForRandao(),
|
|
74
|
+
rollup.getTargetCommitteeSize(),
|
|
75
|
+
rollup.getManaLimit()
|
|
68
76
|
]);
|
|
69
77
|
const l1RollupConstants = {
|
|
70
78
|
l1StartBlock,
|
|
@@ -74,13 +82,32 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
74
82
|
epochDuration: Number(epochDuration),
|
|
75
83
|
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
76
84
|
lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
|
|
77
|
-
lagInEpochsForRandao: Number(lagInEpochsForRandao)
|
|
85
|
+
lagInEpochsForRandao: Number(lagInEpochsForRandao),
|
|
86
|
+
targetCommitteeSize: Number(targetCommitteeSize),
|
|
87
|
+
rollupManaLimit: Number(rollupManaLimit)
|
|
78
88
|
};
|
|
79
|
-
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider
|
|
89
|
+
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider, {
|
|
90
|
+
cacheSize: 12,
|
|
91
|
+
validatorRefreshIntervalSeconds: 60
|
|
92
|
+
});
|
|
80
93
|
}
|
|
81
94
|
getL1Constants() {
|
|
82
95
|
return this.l1constants;
|
|
83
96
|
}
|
|
97
|
+
getSlotNow() {
|
|
98
|
+
return this.getEpochAndSlotNow().slot;
|
|
99
|
+
}
|
|
100
|
+
getTargetSlot() {
|
|
101
|
+
const slotNow = this.getSlotNow();
|
|
102
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
103
|
+
return SlotNumber(slotNow + offset);
|
|
104
|
+
}
|
|
105
|
+
getEpochNow() {
|
|
106
|
+
return this.getEpochAndSlotNow().epoch;
|
|
107
|
+
}
|
|
108
|
+
getTargetEpoch() {
|
|
109
|
+
return getEpochAtSlot(this.getTargetSlot(), this.l1constants);
|
|
110
|
+
}
|
|
84
111
|
getEpochAndSlotNow() {
|
|
85
112
|
const nowMs = BigInt(this.dateProvider.now());
|
|
86
113
|
const nowSeconds = nowMs / 1000n;
|
|
@@ -89,48 +116,41 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
89
116
|
nowMs
|
|
90
117
|
};
|
|
91
118
|
}
|
|
92
|
-
nowInSeconds() {
|
|
93
|
-
return BigInt(Math.floor(this.dateProvider.now() / 1000));
|
|
94
|
-
}
|
|
95
119
|
getEpochAndSlotAtSlot(slot) {
|
|
96
|
-
|
|
97
|
-
const ts = getTimestampRangeForEpoch(epoch, this.l1constants)[0];
|
|
98
|
-
return {
|
|
99
|
-
epoch,
|
|
100
|
-
ts,
|
|
101
|
-
slot
|
|
102
|
-
};
|
|
120
|
+
return this.getEpochAndSlotAtTimestamp(getTimestampForSlot(slot, this.l1constants));
|
|
103
121
|
}
|
|
104
122
|
getEpochAndSlotInNextL1Slot() {
|
|
105
|
-
const
|
|
106
|
-
const nextSlotTs =
|
|
123
|
+
const nowSeconds = this.dateProvider.nowInSeconds();
|
|
124
|
+
const nextSlotTs = getNextL1SlotTimestamp(nowSeconds, this.l1constants);
|
|
107
125
|
return {
|
|
108
126
|
...this.getEpochAndSlotAtTimestamp(nextSlotTs),
|
|
109
|
-
|
|
127
|
+
nowSeconds: BigInt(nowSeconds)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
getTargetEpochAndSlotInNextL1Slot() {
|
|
131
|
+
const result = this.getEpochAndSlotInNextL1Slot();
|
|
132
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
133
|
+
const targetSlot = SlotNumber(result.slot + offset);
|
|
134
|
+
return {
|
|
135
|
+
...result,
|
|
136
|
+
slot: targetSlot,
|
|
137
|
+
epoch: getEpochAtSlot(targetSlot, this.l1constants)
|
|
110
138
|
};
|
|
111
139
|
}
|
|
112
140
|
getEpochAndSlotAtTimestamp(ts) {
|
|
113
141
|
const slot = getSlotAtTimestamp(ts, this.l1constants);
|
|
142
|
+
const epoch = getEpochNumberAtTimestamp(ts, this.l1constants);
|
|
114
143
|
return {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
slot
|
|
144
|
+
slot,
|
|
145
|
+
epoch,
|
|
146
|
+
ts: getTimestampForSlot(slot, this.l1constants)
|
|
118
147
|
};
|
|
119
148
|
}
|
|
120
149
|
getCommitteeForEpoch(epoch) {
|
|
121
150
|
const [startSlot] = getSlotRangeForEpoch(epoch, this.l1constants);
|
|
122
151
|
return this.getCommittee(startSlot);
|
|
123
152
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Returns whether the escape hatch is open for the given epoch.
|
|
126
|
-
*
|
|
127
|
-
* Uses the already-cached EpochCommitteeInfo when available. If not cached, it will fetch
|
|
128
|
-
* the epoch committee info (which includes the escape hatch flag) and return it.
|
|
129
|
-
*/ async isEscapeHatchOpen(epoch) {
|
|
130
|
-
const cached = this.cache.get(epoch);
|
|
131
|
-
if (cached) {
|
|
132
|
-
return cached.isEscapeHatchOpen;
|
|
133
|
-
}
|
|
153
|
+
/** Returns whether the escape hatch is open for the given epoch. */ async isEscapeHatchOpen(epoch) {
|
|
134
154
|
const info = await this.getCommitteeForEpoch(epoch);
|
|
135
155
|
return info.isEscapeHatchOpen;
|
|
136
156
|
}
|
|
@@ -140,30 +160,47 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
140
160
|
* This is a lightweight helper intended for callers that already have a slot number and only
|
|
141
161
|
* need the escape hatch flag (without pulling full committee info).
|
|
142
162
|
*/ async isEscapeHatchOpenAtSlot(slot = 'now') {
|
|
143
|
-
const epoch = slot === 'now' ? this.
|
|
163
|
+
const epoch = slot === 'now' ? this.getEpochNow() : slot === 'next' ? this.getEpochAndSlotInNextL1Slot().epoch : getEpochAtSlot(slot, this.l1constants);
|
|
144
164
|
return await this.isEscapeHatchOpen(epoch);
|
|
145
165
|
}
|
|
146
166
|
/**
|
|
147
|
-
* Get the current validator set
|
|
148
|
-
*
|
|
149
|
-
*
|
|
167
|
+
* Get the current validator set.
|
|
168
|
+
*
|
|
169
|
+
* Returns cached data if the entry is finalized or still fresh (queried less than one
|
|
170
|
+
* Ethereum slot ago). Stale non-finalized entries are re-queried, and concurrent callers
|
|
171
|
+
* coalesce on the same in-flight promise so the L1 query happens only once.
|
|
150
172
|
*/ async getCommittee(slot = 'now') {
|
|
151
173
|
const { epoch, ts } = this.getEpochAndTimestamp(slot);
|
|
152
|
-
|
|
153
|
-
|
|
174
|
+
const cached = this.cache.get(epoch);
|
|
175
|
+
// In-flight promise: another caller is already fetching this epoch — just await it.
|
|
176
|
+
if (cached instanceof Promise) {
|
|
177
|
+
return (await cached).data;
|
|
154
178
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
//
|
|
160
|
-
if
|
|
161
|
-
|
|
179
|
+
// Resolved entry: return it if finalized or still fresh.
|
|
180
|
+
if (cached && (cached.finalized || !this.isStale(cached))) {
|
|
181
|
+
return cached.data;
|
|
182
|
+
}
|
|
183
|
+
// Stale non-finalized entry: do a lightweight refresh first (check block hash + finalized ts).
|
|
184
|
+
// Only fall back to a full re-fetch if the L1 block was reorged.
|
|
185
|
+
if (cached) {
|
|
186
|
+
const promise = this.refreshStaleEntry(cached, epoch, ts);
|
|
187
|
+
this.cache.set(epoch, promise);
|
|
188
|
+
try {
|
|
189
|
+
return (await promise).data;
|
|
190
|
+
} catch (err) {
|
|
191
|
+
this.cache.set(epoch, cached);
|
|
192
|
+
throw err;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// No entry at all: full fetch.
|
|
196
|
+
const promise = this.fetchAndCache(epoch, ts);
|
|
197
|
+
this.cache.set(epoch, promise);
|
|
198
|
+
try {
|
|
199
|
+
return (await promise).data;
|
|
200
|
+
} catch (err) {
|
|
201
|
+
this.cache.delete(epoch);
|
|
202
|
+
throw err;
|
|
162
203
|
}
|
|
163
|
-
this.cache.set(epoch, epochData);
|
|
164
|
-
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
165
|
-
toPurge.forEach((key)=>this.cache.delete(key));
|
|
166
|
-
return epochData;
|
|
167
204
|
}
|
|
168
205
|
getEpochAndTimestamp(slot = 'now') {
|
|
169
206
|
if (slot === 'now') {
|
|
@@ -174,27 +211,121 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
174
211
|
return this.getEpochAndSlotAtSlot(slot);
|
|
175
212
|
}
|
|
176
213
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
214
|
+
/** Evicts oldest cache entries (resolved or in-flight) beyond cacheSize. */ purgeCache() {
|
|
215
|
+
if (this.cache.size <= this.config.cacheSize) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
219
|
+
toPurge.forEach((key)=>this.cache.delete(key));
|
|
220
|
+
}
|
|
221
|
+
/** Returns true if a non-finalized cache entry is older than one Ethereum slot. */ isStale(entry) {
|
|
222
|
+
const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
|
|
223
|
+
return nowSeconds - entry.lastRefreshL1Timestamp >= BigInt(this.l1constants.ethereumSlotDuration);
|
|
224
|
+
}
|
|
225
|
+
/** Whether a cached epoch entry has been marked as finalized. Returns undefined if not cached or still in-flight. */ isFinalized(epoch) {
|
|
226
|
+
const entry = this.cache.get(epoch);
|
|
227
|
+
if (!entry || entry instanceof Promise) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
return entry.finalized;
|
|
231
|
+
}
|
|
232
|
+
/** Returns the latest L1 timestamp stored in the cached entry. Undefined if not cached or in-flight. */ getCachedLastRefreshL1Timestamp(epoch) {
|
|
233
|
+
const entry = this.cache.get(epoch);
|
|
234
|
+
if (!entry || entry instanceof Promise) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
return entry.lastRefreshL1Timestamp;
|
|
238
|
+
}
|
|
239
|
+
/** Computes the sampling timestamp for an epoch's committee data. */ getSamplingTimestamp(epoch) {
|
|
240
|
+
const { lagInEpochsForRandao, epochDuration, slotDuration } = this.l1constants;
|
|
241
|
+
const epochStartTs = getStartTimestampForEpoch(epoch, this.l1constants);
|
|
242
|
+
return epochStartTs - BigInt(lagInEpochsForRandao) * BigInt(epochDuration) * BigInt(slotDuration);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Lightweight refresh for a stale non-finalized entry. Queries only the block hash at
|
|
246
|
+
* the original block number and the finalized block timestamp — avoids the expensive
|
|
247
|
+
* getCommitteeAt and getSampleSeedAt calls on the rollup contract.
|
|
248
|
+
*
|
|
249
|
+
* If the block hash still matches (no L1 reorg), we keep the existing data and just
|
|
250
|
+
* update the provenance timestamp. If the finalized block has caught up, we promote the
|
|
251
|
+
* entry to finalized. If there was a reorg (hash mismatch), we fall back to a full fetch.
|
|
252
|
+
*/ async refreshStaleEntry(stale, epoch, ts) {
|
|
253
|
+
const [blockAtOriginal, l1FinalizedBlock, latestBlock] = await Promise.all([
|
|
254
|
+
this.rollup.client.getBlock({
|
|
255
|
+
blockNumber: stale.lastQueryL1BlockNumber,
|
|
256
|
+
includeTransactions: false
|
|
257
|
+
}),
|
|
258
|
+
getFinalizedL1Block(this.rollup.client),
|
|
259
|
+
this.rollup.client.getBlock({
|
|
260
|
+
includeTransactions: false
|
|
261
|
+
})
|
|
262
|
+
]);
|
|
263
|
+
if (blockAtOriginal.hash === stale.lastQueryL1BlockHash) {
|
|
264
|
+
// No reorg: the data is still valid. Check if we can now mark it as finalized.
|
|
265
|
+
const samplingTs = this.getSamplingTimestamp(epoch);
|
|
266
|
+
const finalized = !!(stale.data.committee && stale.data.committee.length > 0) && l1FinalizedBlock !== undefined && samplingTs <= l1FinalizedBlock.timestamp;
|
|
267
|
+
const refreshed = {
|
|
268
|
+
...stale,
|
|
269
|
+
lastRefreshL1Timestamp: latestBlock.timestamp,
|
|
270
|
+
finalized
|
|
271
|
+
};
|
|
272
|
+
this.cache.set(epoch, refreshed);
|
|
273
|
+
return refreshed;
|
|
274
|
+
}
|
|
275
|
+
// Reorg detected: block hash mismatch. Do a full re-fetch.
|
|
276
|
+
// Pass the already-fetched block timestamps to avoid redundant queries.
|
|
277
|
+
this.log.warn(`L1 reorg detected for epoch ${epoch}: block ${stale.lastQueryL1BlockNumber} hash changed`, {
|
|
278
|
+
epoch,
|
|
279
|
+
expectedHash: stale.lastQueryL1BlockHash,
|
|
280
|
+
actualHash: blockAtOriginal.hash
|
|
281
|
+
});
|
|
282
|
+
return this.fetchAndCache(epoch, ts, {
|
|
283
|
+
latestBlock,
|
|
284
|
+
finalizedBlock: l1FinalizedBlock
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Fetches committee data from L1, determines finalization status, and stores in the cache.
|
|
289
|
+
*
|
|
290
|
+
* Uses `lagInEpochsForRandao` (the binding constraint, always <= lagInEpochsForValidatorSet)
|
|
291
|
+
* and computes the sampling timestamp from the epoch start to match the L1 contract's logic.
|
|
292
|
+
*
|
|
293
|
+
* When called from refreshStaleEntry after a reorg, the latest and finalized blocks are
|
|
294
|
+
* passed in to avoid redundant L1 queries.
|
|
295
|
+
*/ async fetchAndCache(epoch, ts, prefetched) {
|
|
296
|
+
const [committee, seedBuffer, latestBlock, finalizedBlock, isEscapeHatchOpen] = await Promise.all([
|
|
180
297
|
this.rollup.getCommitteeAt(ts),
|
|
181
298
|
this.rollup.getSampleSeedAt(ts),
|
|
182
|
-
this.rollup.client.getBlock({
|
|
299
|
+
prefetched?.latestBlock ?? this.rollup.client.getBlock({
|
|
183
300
|
includeTransactions: false
|
|
184
|
-
})
|
|
301
|
+
}),
|
|
302
|
+
prefetched !== undefined ? prefetched.finalizedBlock : getFinalizedL1Block(this.rollup.client),
|
|
185
303
|
this.rollup.isEscapeHatchOpen(epoch)
|
|
186
304
|
]);
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
throw new Error(`Cannot query committee for future epoch ${epoch} with timestamp ${ts} (current L1 time is ${l1Timestamp}). Check your Ethereum node is synced.`);
|
|
305
|
+
const samplingTs = this.getSamplingTimestamp(epoch);
|
|
306
|
+
if (samplingTs > latestBlock.timestamp) {
|
|
307
|
+
throw new Error(`Cannot query committee for future epoch ${epoch}: ` + `sampling timestamp ${samplingTs} is beyond latest L1 block at ${latestBlock.timestamp}. ` + `Check your Ethereum node is synced.`);
|
|
191
308
|
}
|
|
192
|
-
|
|
309
|
+
// Empty committees are never marked finalized so they always get re-queried after TTL.
|
|
310
|
+
// If L1 has no finalized block yet (devnet startup), entries stay unfinalized.
|
|
311
|
+
const hasCommittee = !!(committee && committee.length > 0);
|
|
312
|
+
const finalized = hasCommittee && finalizedBlock !== undefined && samplingTs <= finalizedBlock.timestamp;
|
|
313
|
+
const data = {
|
|
193
314
|
committee,
|
|
194
315
|
seed: seedBuffer.toBigInt(),
|
|
195
316
|
epoch,
|
|
196
317
|
isEscapeHatchOpen
|
|
197
318
|
};
|
|
319
|
+
const entry = {
|
|
320
|
+
data,
|
|
321
|
+
lastQueryL1BlockNumber: latestBlock.number,
|
|
322
|
+
lastQueryL1BlockHash: latestBlock.hash,
|
|
323
|
+
lastRefreshL1Timestamp: latestBlock.timestamp,
|
|
324
|
+
finalized
|
|
325
|
+
};
|
|
326
|
+
this.cache.set(epoch, entry);
|
|
327
|
+
this.purgeCache();
|
|
328
|
+
return entry;
|
|
198
329
|
}
|
|
199
330
|
/**
|
|
200
331
|
* Get the ABI encoding of the proposer index - see ValidatorSelectionLib.sol computeProposerIndex
|
|
@@ -225,14 +356,26 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
225
356
|
}
|
|
226
357
|
return BigInt(keccak256(this.getProposerIndexEncoding(epoch, slot, seed))) % size;
|
|
227
358
|
}
|
|
228
|
-
/** Returns the current and next L2 slot
|
|
229
|
-
const
|
|
359
|
+
/** Returns the current and next L2 slot in next eth L1 Slot. */ getCurrentAndNextSlot() {
|
|
360
|
+
const currentSlot = this.getSlotNow();
|
|
230
361
|
const next = this.getEpochAndSlotInNextL1Slot();
|
|
231
362
|
return {
|
|
232
|
-
currentSlot
|
|
363
|
+
currentSlot,
|
|
233
364
|
nextSlot: next.slot
|
|
234
365
|
};
|
|
235
366
|
}
|
|
367
|
+
/** Returns the target and next L2 slot in the next L1 slot. */ getTargetAndNextSlot() {
|
|
368
|
+
const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
|
|
369
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
370
|
+
const currentSlot = getSlotAtTimestamp(nowSeconds, this.l1constants);
|
|
371
|
+
const targetSlot = SlotNumber(currentSlot + offset);
|
|
372
|
+
const nextL2SlotOnL1 = getSlotAtNextL1Block(nowSeconds, this.l1constants);
|
|
373
|
+
const nextSlot = SlotNumber(nextL2SlotOnL1 + offset);
|
|
374
|
+
return {
|
|
375
|
+
targetSlot,
|
|
376
|
+
nextSlot
|
|
377
|
+
};
|
|
378
|
+
}
|
|
236
379
|
/**
|
|
237
380
|
* Get the proposer attester address in the given L2 slot
|
|
238
381
|
* @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
|
|
@@ -290,10 +433,11 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
290
433
|
async getRegisteredValidators() {
|
|
291
434
|
const validatorRefreshIntervalMs = this.config.validatorRefreshIntervalSeconds * 1000;
|
|
292
435
|
const validatorRefreshTime = this.lastValidatorRefresh + validatorRefreshIntervalMs;
|
|
293
|
-
|
|
294
|
-
|
|
436
|
+
const now = this.dateProvider.now();
|
|
437
|
+
if (validatorRefreshTime < now) {
|
|
438
|
+
const currentSet = await this.rollup.getAttesters(BigInt(Math.floor(now / 1000)));
|
|
295
439
|
this.allValidators = new Set(currentSet.map((v)=>v.toString()));
|
|
296
|
-
this.lastValidatorRefresh =
|
|
440
|
+
this.lastValidatorRefresh = now;
|
|
297
441
|
}
|
|
298
442
|
return Array.from(this.allValidators.keys()).map((v)=>EthAddress.fromString(v));
|
|
299
443
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
|
-
import type
|
|
4
|
+
import { type EpochAndSlot, type EpochCacheInterface, type EpochCommitteeInfo, type SlotTag } from '../epoch_cache.js';
|
|
5
5
|
/**
|
|
6
6
|
* A test implementation of EpochCacheInterface that allows manual configuration
|
|
7
7
|
* of committee, proposer, slot, and escape hatch state for use in tests.
|
|
@@ -55,11 +55,18 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
55
55
|
setL1Constants(constants: Partial<L1RollupConstants>): this;
|
|
56
56
|
getL1Constants(): L1RollupConstants;
|
|
57
57
|
getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo>;
|
|
58
|
+
getSlotNow(): SlotNumber;
|
|
59
|
+
getTargetSlot(): SlotNumber;
|
|
60
|
+
getEpochNow(): EpochNumber;
|
|
61
|
+
getTargetEpoch(): EpochNumber;
|
|
58
62
|
getEpochAndSlotNow(): EpochAndSlot & {
|
|
59
63
|
nowMs: bigint;
|
|
60
64
|
};
|
|
61
65
|
getEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
62
|
-
|
|
66
|
+
nowSeconds: bigint;
|
|
67
|
+
};
|
|
68
|
+
getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
69
|
+
nowSeconds: bigint;
|
|
63
70
|
};
|
|
64
71
|
getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}`;
|
|
65
72
|
computeProposerIndex(slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, size: bigint): bigint;
|
|
@@ -67,10 +74,15 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
67
74
|
currentSlot: SlotNumber;
|
|
68
75
|
nextSlot: SlotNumber;
|
|
69
76
|
};
|
|
77
|
+
getTargetAndNextSlot(): {
|
|
78
|
+
targetSlot: SlotNumber;
|
|
79
|
+
nextSlot: SlotNumber;
|
|
80
|
+
};
|
|
70
81
|
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined>;
|
|
71
82
|
getRegisteredValidators(): Promise<EthAddress[]>;
|
|
72
83
|
isInCommittee(_slot: SlotTag, validator: EthAddress): Promise<boolean>;
|
|
73
84
|
filterInCommittee(_slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
85
|
+
isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean>;
|
|
74
86
|
isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean>;
|
|
75
87
|
}
|
|
76
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
88
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF9lcG9jaF9jYWNoZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Rlc3QvdGVzdF9lcG9jaF9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzFFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUMzRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBR3JFLE9BQU8sRUFDTCxLQUFLLFlBQVksRUFDakIsS0FBSyxtQkFBbUIsRUFDeEIsS0FBSyxrQkFBa0IsRUFFdkIsS0FBSyxPQUFPLEVBQ2IsTUFBTSxtQkFBbUIsQ0FBQztBQWMzQjs7Ozs7O0dBTU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UUsQ0FBQyxDQUUvQztJQUVELGFBQWEsQ0FBQyxLQUFLLEVBQUUsT0FBTyxFQUFFLFNBQVMsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUVyRTtJQUVELGlCQUFpQixDQUFDLEtBQUssRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLFVBQVUsRUFBRSxHQUFHLE9BQU8sQ0FBQyxVQUFVLEVBQUUsQ0FBQyxDQUdqRjtJQUVELGlCQUFpQixDQUFDLE1BQU0sRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUV2RDtJQUVELHVCQUF1QixDQUFDLEtBQUssQ0FBQyxFQUFFLE9BQU8sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBRXpEO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test_epoch_cache.d.ts","sourceRoot":"","sources":["../../src/test/test_epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"test_epoch_cache.d.ts","sourceRoot":"","sources":["../../src/test/test_epoch_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AAc3B;;;;;;GAMG;AAC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YAAY,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAKzE;IAED,wBAAwB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAG1F;IAED,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/F;IAED,qBAAqB,IAAI;QAAE,WAAW,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,UAAU,CAAA;KAAE,CAQzE;IAED,oBAAoB,IAAI;QAAE,UAAU,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,UAAU,CAAA;KAAE,CAQvE;IAED,gCAAgC,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAEnF;IAED,uBAAuB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAE/C;IAED,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAErE;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAGjF;IAED,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAEvD;IAED,uBAAuB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAEzD;CACF"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
3
|
+
import { PROPOSER_PIPELINING_SLOT_OFFSET } from '../epoch_cache.js';
|
|
3
4
|
/** Default L1 constants for testing. */ const DEFAULT_L1_CONSTANTS = {
|
|
4
5
|
l1StartBlock: 0n,
|
|
5
6
|
l1GenesisTime: 0n,
|
|
6
7
|
slotDuration: 24,
|
|
7
8
|
epochDuration: 16,
|
|
8
9
|
ethereumSlotDuration: 12,
|
|
9
|
-
proofSubmissionEpochs: 2
|
|
10
|
+
proofSubmissionEpochs: 2,
|
|
11
|
+
targetCommitteeSize: 48,
|
|
12
|
+
rollupManaLimit: Number.MAX_SAFE_INTEGER
|
|
10
13
|
};
|
|
11
14
|
/**
|
|
12
15
|
* A test implementation of EpochCacheInterface that allows manual configuration
|
|
@@ -92,27 +95,49 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
92
95
|
isEscapeHatchOpen: this.escapeHatchOpen
|
|
93
96
|
});
|
|
94
97
|
}
|
|
98
|
+
getSlotNow() {
|
|
99
|
+
return this.currentSlot;
|
|
100
|
+
}
|
|
101
|
+
getTargetSlot() {
|
|
102
|
+
return SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET);
|
|
103
|
+
}
|
|
104
|
+
getEpochNow() {
|
|
105
|
+
return getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
106
|
+
}
|
|
107
|
+
getTargetEpoch() {
|
|
108
|
+
return getEpochAtSlot(this.getTargetSlot(), this.l1Constants);
|
|
109
|
+
}
|
|
95
110
|
getEpochAndSlotNow() {
|
|
96
|
-
const
|
|
97
|
-
const ts = getTimestampRangeForEpoch(
|
|
111
|
+
const epochNow = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
112
|
+
const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
|
|
98
113
|
return {
|
|
99
|
-
epoch,
|
|
114
|
+
epoch: epochNow,
|
|
100
115
|
slot: this.currentSlot,
|
|
101
116
|
ts,
|
|
102
117
|
nowMs: ts * 1000n
|
|
103
118
|
};
|
|
104
119
|
}
|
|
105
120
|
getEpochAndSlotInNextL1Slot() {
|
|
106
|
-
const
|
|
107
|
-
const nextSlotTs =
|
|
121
|
+
const nowTs = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
|
|
122
|
+
const nextSlotTs = nowTs + BigInt(this.l1Constants.ethereumSlotDuration);
|
|
108
123
|
const nextSlot = getSlotAtTimestamp(nextSlotTs, this.l1Constants);
|
|
109
|
-
const
|
|
110
|
-
const ts = getTimestampRangeForEpoch(
|
|
124
|
+
const epochNow = getEpochAtSlot(nextSlot, this.l1Constants);
|
|
125
|
+
const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
|
|
111
126
|
return {
|
|
112
|
-
epoch,
|
|
127
|
+
epoch: epochNow,
|
|
113
128
|
slot: nextSlot,
|
|
114
129
|
ts,
|
|
115
|
-
|
|
130
|
+
nowSeconds: nowTs
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
getTargetEpochAndSlotInNextL1Slot() {
|
|
134
|
+
const result = this.getEpochAndSlotInNextL1Slot();
|
|
135
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
136
|
+
const targetSlot = SlotNumber(result.slot + offset);
|
|
137
|
+
return {
|
|
138
|
+
...result,
|
|
139
|
+
slot: targetSlot,
|
|
140
|
+
epoch: getEpochAtSlot(targetSlot, this.l1Constants)
|
|
116
141
|
};
|
|
117
142
|
}
|
|
118
143
|
getProposerIndexEncoding(epoch, slot, seed) {
|
|
@@ -126,9 +151,19 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
126
151
|
return BigInt(slot) % size;
|
|
127
152
|
}
|
|
128
153
|
getCurrentAndNextSlot() {
|
|
154
|
+
const currentSlot = this.getSlotNow();
|
|
155
|
+
const next = this.getEpochAndSlotInNextL1Slot();
|
|
129
156
|
return {
|
|
130
|
-
currentSlot
|
|
131
|
-
nextSlot:
|
|
157
|
+
currentSlot,
|
|
158
|
+
nextSlot: next.slot
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
getTargetAndNextSlot() {
|
|
162
|
+
const targetSlot = this.getTargetSlot();
|
|
163
|
+
const next = this.getTargetEpochAndSlotInNextL1Slot();
|
|
164
|
+
return {
|
|
165
|
+
targetSlot,
|
|
166
|
+
nextSlot: next.slot
|
|
132
167
|
};
|
|
133
168
|
}
|
|
134
169
|
getProposerAttesterAddressInSlot(_slot) {
|
|
@@ -144,6 +179,9 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
144
179
|
const committeeSet = new Set(this.committee.map((v)=>v.toString()));
|
|
145
180
|
return Promise.resolve(validators.filter((v)=>committeeSet.has(v.toString())));
|
|
146
181
|
}
|
|
182
|
+
isEscapeHatchOpen(_epoch) {
|
|
183
|
+
return Promise.resolve(this.escapeHatchOpen);
|
|
184
|
+
}
|
|
147
185
|
isEscapeHatchOpenAtSlot(_slot) {
|
|
148
186
|
return Promise.resolve(this.escapeHatchOpen);
|
|
149
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/epoch-cache",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.e57c76e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -26,17 +26,16 @@
|
|
|
26
26
|
"../package.common.json"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
30
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
31
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
32
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
33
|
-
"@viem/anvil": "^0.0.10",
|
|
29
|
+
"@aztec/ethereum": "0.0.1-commit.e57c76e",
|
|
30
|
+
"@aztec/foundation": "0.0.1-commit.e57c76e",
|
|
31
|
+
"@aztec/l1-artifacts": "0.0.1-commit.e57c76e",
|
|
32
|
+
"@aztec/stdlib": "0.0.1-commit.e57c76e",
|
|
34
33
|
"dotenv": "^16.0.3",
|
|
35
34
|
"get-port": "^7.1.0",
|
|
36
35
|
"jest-mock-extended": "^4.0.0",
|
|
37
36
|
"tslib": "^2.4.0",
|
|
38
37
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
39
|
-
"zod": "^
|
|
38
|
+
"zod": "^4"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@jest/globals": "^30.0.0",
|
package/src/config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type L1ReaderConfig, getL1ReaderConfigFromEnv } from '@aztec/ethereum/l
|
|
|
3
3
|
|
|
4
4
|
export type EpochCacheConfig = Pick<
|
|
5
5
|
L1ReaderConfig & L1ContractsConfig,
|
|
6
|
-
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration'
|
|
6
|
+
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration' | 'l1HttpTimeoutMS'
|
|
7
7
|
>;
|
|
8
8
|
|
|
9
9
|
export function getEpochCacheConfigEnvVars(): EpochCacheConfig {
|