@aztec/epoch-cache 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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 +211 -0
- package/dest/config.d.ts +3 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -1
- package/dest/epoch_cache.d.ts +77 -17
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +223 -68
- package/dest/test/test_epoch_cache.d.ts +19 -3
- package/dest/test/test_epoch_cache.d.ts.map +1 -1
- package/dest/test/test_epoch_cache.js +57 -11
- package/package.json +5 -5
- package/src/config.ts +9 -3
- package/src/epoch_cache.ts +284 -62
- package/src/test/test_epoch_cache.ts +83 -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
|
+
/** When proposer pipelining is enabled, the proposer builds one slot ahead. */ export const PROPOSER_PIPELINING_SLOT_OFFSET = 1;
|
|
9
13
|
/**
|
|
10
14
|
* Epoch cache
|
|
11
15
|
*
|
|
@@ -19,14 +23,19 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
19
23
|
l1constants;
|
|
20
24
|
dateProvider;
|
|
21
25
|
config;
|
|
22
|
-
|
|
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
|
+
*/ // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
23
30
|
cache;
|
|
24
31
|
allValidators;
|
|
25
32
|
lastValidatorRefresh;
|
|
26
33
|
log;
|
|
34
|
+
enableProposerPipelining;
|
|
27
35
|
constructor(rollup, l1constants, dateProvider = new DateProvider(), config = {
|
|
28
36
|
cacheSize: 12,
|
|
29
|
-
validatorRefreshIntervalSeconds: 60
|
|
37
|
+
validatorRefreshIntervalSeconds: 60,
|
|
38
|
+
enableProposerPipelining: false
|
|
30
39
|
}){
|
|
31
40
|
this.rollup = rollup;
|
|
32
41
|
this.l1constants = l1constants;
|
|
@@ -36,8 +45,10 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
36
45
|
this.allValidators = new Set();
|
|
37
46
|
this.lastValidatorRefresh = 0;
|
|
38
47
|
this.log = createLogger('epoch-cache');
|
|
48
|
+
this.enableProposerPipelining = this.config.enableProposerPipelining;
|
|
39
49
|
this.log.debug(`Initialized EpochCache`, {
|
|
40
|
-
l1constants
|
|
50
|
+
l1constants,
|
|
51
|
+
enableProposerPipelining: this.enableProposerPipelining
|
|
41
52
|
});
|
|
42
53
|
}
|
|
43
54
|
static async create(rollupOrAddress, config, deps = {}) {
|
|
@@ -50,9 +61,9 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
50
61
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
51
62
|
const publicClient = createPublicClient({
|
|
52
63
|
chain: chain.chainInfo,
|
|
53
|
-
transport:
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
65
|
+
timeout: config.l1HttpTimeoutMS
|
|
66
|
+
}),
|
|
56
67
|
pollingInterval: config.viemPollingIntervalMS
|
|
57
68
|
});
|
|
58
69
|
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
|
|
@@ -80,11 +91,35 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
80
91
|
targetCommitteeSize: Number(targetCommitteeSize),
|
|
81
92
|
rollupManaLimit: Number(rollupManaLimit)
|
|
82
93
|
};
|
|
83
|
-
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider
|
|
94
|
+
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider, {
|
|
95
|
+
cacheSize: 12,
|
|
96
|
+
validatorRefreshIntervalSeconds: 60,
|
|
97
|
+
enableProposerPipelining: config.enableProposerPipelining
|
|
98
|
+
});
|
|
84
99
|
}
|
|
85
100
|
getL1Constants() {
|
|
86
101
|
return this.l1constants;
|
|
87
102
|
}
|
|
103
|
+
isProposerPipeliningEnabled() {
|
|
104
|
+
return this.enableProposerPipelining;
|
|
105
|
+
}
|
|
106
|
+
pipeliningOffset() {
|
|
107
|
+
return this.enableProposerPipelining ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
108
|
+
}
|
|
109
|
+
getSlotNow() {
|
|
110
|
+
return this.getEpochAndSlotNow().slot;
|
|
111
|
+
}
|
|
112
|
+
getTargetSlot() {
|
|
113
|
+
const slotNow = this.getSlotNow();
|
|
114
|
+
const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
115
|
+
return SlotNumber(slotNow + offset);
|
|
116
|
+
}
|
|
117
|
+
getEpochNow() {
|
|
118
|
+
return this.getEpochAndSlotNow().epoch;
|
|
119
|
+
}
|
|
120
|
+
getTargetEpoch() {
|
|
121
|
+
return getEpochAtSlot(this.getTargetSlot(), this.l1constants);
|
|
122
|
+
}
|
|
88
123
|
getEpochAndSlotNow() {
|
|
89
124
|
const nowMs = BigInt(this.dateProvider.now());
|
|
90
125
|
const nowSeconds = nowMs / 1000n;
|
|
@@ -93,48 +128,44 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
93
128
|
nowMs
|
|
94
129
|
};
|
|
95
130
|
}
|
|
96
|
-
nowInSeconds() {
|
|
97
|
-
return BigInt(Math.floor(this.dateProvider.now() / 1000));
|
|
98
|
-
}
|
|
99
131
|
getEpochAndSlotAtSlot(slot) {
|
|
100
|
-
|
|
101
|
-
const ts = getTimestampRangeForEpoch(epoch, this.l1constants)[0];
|
|
102
|
-
return {
|
|
103
|
-
epoch,
|
|
104
|
-
ts,
|
|
105
|
-
slot
|
|
106
|
-
};
|
|
132
|
+
return this.getEpochAndSlotAtTimestamp(getTimestampForSlot(slot, this.l1constants));
|
|
107
133
|
}
|
|
108
134
|
getEpochAndSlotInNextL1Slot() {
|
|
109
|
-
const
|
|
110
|
-
const nextSlotTs =
|
|
135
|
+
const nowSeconds = this.dateProvider.nowInSeconds();
|
|
136
|
+
const nextSlotTs = getNextL1SlotTimestamp(nowSeconds, this.l1constants);
|
|
111
137
|
return {
|
|
112
138
|
...this.getEpochAndSlotAtTimestamp(nextSlotTs),
|
|
113
|
-
|
|
139
|
+
nowSeconds: BigInt(nowSeconds)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
getTargetEpochAndSlotInNextL1Slot() {
|
|
143
|
+
if (!this.isProposerPipeliningEnabled()) {
|
|
144
|
+
return this.getEpochAndSlotInNextL1Slot();
|
|
145
|
+
}
|
|
146
|
+
const result = this.getEpochAndSlotInNextL1Slot();
|
|
147
|
+
const offset = PROPOSER_PIPELINING_SLOT_OFFSET;
|
|
148
|
+
const targetSlot = SlotNumber(result.slot + offset);
|
|
149
|
+
return {
|
|
150
|
+
...result,
|
|
151
|
+
slot: targetSlot,
|
|
152
|
+
epoch: getEpochAtSlot(targetSlot, this.l1constants)
|
|
114
153
|
};
|
|
115
154
|
}
|
|
116
155
|
getEpochAndSlotAtTimestamp(ts) {
|
|
117
156
|
const slot = getSlotAtTimestamp(ts, this.l1constants);
|
|
157
|
+
const epoch = getEpochNumberAtTimestamp(ts, this.l1constants);
|
|
118
158
|
return {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
slot
|
|
159
|
+
slot,
|
|
160
|
+
epoch,
|
|
161
|
+
ts: getTimestampForSlot(slot, this.l1constants)
|
|
122
162
|
};
|
|
123
163
|
}
|
|
124
164
|
getCommitteeForEpoch(epoch) {
|
|
125
165
|
const [startSlot] = getSlotRangeForEpoch(epoch, this.l1constants);
|
|
126
166
|
return this.getCommittee(startSlot);
|
|
127
167
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Returns whether the escape hatch is open for the given epoch.
|
|
130
|
-
*
|
|
131
|
-
* Uses the already-cached EpochCommitteeInfo when available. If not cached, it will fetch
|
|
132
|
-
* the epoch committee info (which includes the escape hatch flag) and return it.
|
|
133
|
-
*/ async isEscapeHatchOpen(epoch) {
|
|
134
|
-
const cached = this.cache.get(epoch);
|
|
135
|
-
if (cached) {
|
|
136
|
-
return cached.isEscapeHatchOpen;
|
|
137
|
-
}
|
|
168
|
+
/** Returns whether the escape hatch is open for the given epoch. */ async isEscapeHatchOpen(epoch) {
|
|
138
169
|
const info = await this.getCommitteeForEpoch(epoch);
|
|
139
170
|
return info.isEscapeHatchOpen;
|
|
140
171
|
}
|
|
@@ -144,30 +175,47 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
144
175
|
* This is a lightweight helper intended for callers that already have a slot number and only
|
|
145
176
|
* need the escape hatch flag (without pulling full committee info).
|
|
146
177
|
*/ async isEscapeHatchOpenAtSlot(slot = 'now') {
|
|
147
|
-
const epoch = slot === 'now' ? this.
|
|
178
|
+
const epoch = slot === 'now' ? this.getEpochNow() : slot === 'next' ? this.getEpochAndSlotInNextL1Slot().epoch : getEpochAtSlot(slot, this.l1constants);
|
|
148
179
|
return await this.isEscapeHatchOpen(epoch);
|
|
149
180
|
}
|
|
150
181
|
/**
|
|
151
|
-
* Get the current validator set
|
|
152
|
-
*
|
|
153
|
-
*
|
|
182
|
+
* Get the current validator set.
|
|
183
|
+
*
|
|
184
|
+
* Returns cached data if the entry is finalized or still fresh (queried less than one
|
|
185
|
+
* Ethereum slot ago). Stale non-finalized entries are re-queried, and concurrent callers
|
|
186
|
+
* coalesce on the same in-flight promise so the L1 query happens only once.
|
|
154
187
|
*/ async getCommittee(slot = 'now') {
|
|
155
188
|
const { epoch, ts } = this.getEpochAndTimestamp(slot);
|
|
156
|
-
|
|
157
|
-
|
|
189
|
+
const cached = this.cache.get(epoch);
|
|
190
|
+
// In-flight promise: another caller is already fetching this epoch — just await it.
|
|
191
|
+
if (cached instanceof Promise) {
|
|
192
|
+
return (await cached).data;
|
|
158
193
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
//
|
|
164
|
-
if
|
|
165
|
-
|
|
194
|
+
// Resolved entry: return it if finalized or still fresh.
|
|
195
|
+
if (cached && (cached.finalized || !this.isStale(cached))) {
|
|
196
|
+
return cached.data;
|
|
197
|
+
}
|
|
198
|
+
// Stale non-finalized entry: do a lightweight refresh first (check block hash + finalized ts).
|
|
199
|
+
// Only fall back to a full re-fetch if the L1 block was reorged.
|
|
200
|
+
if (cached) {
|
|
201
|
+
const promise = this.refreshStaleEntry(cached, epoch, ts);
|
|
202
|
+
this.cache.set(epoch, promise);
|
|
203
|
+
try {
|
|
204
|
+
return (await promise).data;
|
|
205
|
+
} catch (err) {
|
|
206
|
+
this.cache.set(epoch, cached);
|
|
207
|
+
throw err;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// No entry at all: full fetch.
|
|
211
|
+
const promise = this.fetchAndCache(epoch, ts);
|
|
212
|
+
this.cache.set(epoch, promise);
|
|
213
|
+
try {
|
|
214
|
+
return (await promise).data;
|
|
215
|
+
} catch (err) {
|
|
216
|
+
this.cache.delete(epoch);
|
|
217
|
+
throw err;
|
|
166
218
|
}
|
|
167
|
-
this.cache.set(epoch, epochData);
|
|
168
|
-
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
169
|
-
toPurge.forEach((key)=>this.cache.delete(key));
|
|
170
|
-
return epochData;
|
|
171
219
|
}
|
|
172
220
|
getEpochAndTimestamp(slot = 'now') {
|
|
173
221
|
if (slot === 'now') {
|
|
@@ -178,27 +226,121 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
178
226
|
return this.getEpochAndSlotAtSlot(slot);
|
|
179
227
|
}
|
|
180
228
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
229
|
+
/** Evicts oldest cache entries (resolved or in-flight) beyond cacheSize. */ purgeCache() {
|
|
230
|
+
if (this.cache.size <= this.config.cacheSize) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const toPurge = Array.from(this.cache.keys()).sort((a, b)=>Number(b - a)).slice(this.config.cacheSize);
|
|
234
|
+
toPurge.forEach((key)=>this.cache.delete(key));
|
|
235
|
+
}
|
|
236
|
+
/** Returns true if a non-finalized cache entry is older than one Ethereum slot. */ isStale(entry) {
|
|
237
|
+
const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
|
|
238
|
+
return nowSeconds - entry.lastRefreshL1Timestamp >= BigInt(this.l1constants.ethereumSlotDuration);
|
|
239
|
+
}
|
|
240
|
+
/** Whether a cached epoch entry has been marked as finalized. Returns undefined if not cached or still in-flight. */ isFinalized(epoch) {
|
|
241
|
+
const entry = this.cache.get(epoch);
|
|
242
|
+
if (!entry || entry instanceof Promise) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
return entry.finalized;
|
|
246
|
+
}
|
|
247
|
+
/** Returns the latest L1 timestamp stored in the cached entry. Undefined if not cached or in-flight. */ getCachedLastRefreshL1Timestamp(epoch) {
|
|
248
|
+
const entry = this.cache.get(epoch);
|
|
249
|
+
if (!entry || entry instanceof Promise) {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
return entry.lastRefreshL1Timestamp;
|
|
253
|
+
}
|
|
254
|
+
/** Computes the sampling timestamp for an epoch's committee data. */ getSamplingTimestamp(epoch) {
|
|
255
|
+
const { lagInEpochsForRandao, epochDuration, slotDuration } = this.l1constants;
|
|
256
|
+
const epochStartTs = getStartTimestampForEpoch(epoch, this.l1constants);
|
|
257
|
+
return epochStartTs - BigInt(lagInEpochsForRandao) * BigInt(epochDuration) * BigInt(slotDuration);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Lightweight refresh for a stale non-finalized entry. Queries only the block hash at
|
|
261
|
+
* the original block number and the finalized block timestamp — avoids the expensive
|
|
262
|
+
* getCommitteeAt and getSampleSeedAt calls on the rollup contract.
|
|
263
|
+
*
|
|
264
|
+
* If the block hash still matches (no L1 reorg), we keep the existing data and just
|
|
265
|
+
* update the provenance timestamp. If the finalized block has caught up, we promote the
|
|
266
|
+
* entry to finalized. If there was a reorg (hash mismatch), we fall back to a full fetch.
|
|
267
|
+
*/ async refreshStaleEntry(stale, epoch, ts) {
|
|
268
|
+
const [blockAtOriginal, l1FinalizedBlock, latestBlock] = await Promise.all([
|
|
269
|
+
this.rollup.client.getBlock({
|
|
270
|
+
blockNumber: stale.lastQueryL1BlockNumber,
|
|
271
|
+
includeTransactions: false
|
|
272
|
+
}),
|
|
273
|
+
getFinalizedL1Block(this.rollup.client),
|
|
274
|
+
this.rollup.client.getBlock({
|
|
275
|
+
includeTransactions: false
|
|
276
|
+
})
|
|
277
|
+
]);
|
|
278
|
+
if (blockAtOriginal.hash === stale.lastQueryL1BlockHash) {
|
|
279
|
+
// No reorg: the data is still valid. Check if we can now mark it as finalized.
|
|
280
|
+
const samplingTs = this.getSamplingTimestamp(epoch);
|
|
281
|
+
const finalized = !!(stale.data.committee && stale.data.committee.length > 0) && l1FinalizedBlock !== undefined && samplingTs <= l1FinalizedBlock.timestamp;
|
|
282
|
+
const refreshed = {
|
|
283
|
+
...stale,
|
|
284
|
+
lastRefreshL1Timestamp: latestBlock.timestamp,
|
|
285
|
+
finalized
|
|
286
|
+
};
|
|
287
|
+
this.cache.set(epoch, refreshed);
|
|
288
|
+
return refreshed;
|
|
289
|
+
}
|
|
290
|
+
// Reorg detected: block hash mismatch. Do a full re-fetch.
|
|
291
|
+
// Pass the already-fetched block timestamps to avoid redundant queries.
|
|
292
|
+
this.log.warn(`L1 reorg detected for epoch ${epoch}: block ${stale.lastQueryL1BlockNumber} hash changed`, {
|
|
293
|
+
epoch,
|
|
294
|
+
expectedHash: stale.lastQueryL1BlockHash,
|
|
295
|
+
actualHash: blockAtOriginal.hash
|
|
296
|
+
});
|
|
297
|
+
return this.fetchAndCache(epoch, ts, {
|
|
298
|
+
latestBlock,
|
|
299
|
+
finalizedBlock: l1FinalizedBlock
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Fetches committee data from L1, determines finalization status, and stores in the cache.
|
|
304
|
+
*
|
|
305
|
+
* Uses `lagInEpochsForRandao` (the binding constraint, always <= lagInEpochsForValidatorSet)
|
|
306
|
+
* and computes the sampling timestamp from the epoch start to match the L1 contract's logic.
|
|
307
|
+
*
|
|
308
|
+
* When called from refreshStaleEntry after a reorg, the latest and finalized blocks are
|
|
309
|
+
* passed in to avoid redundant L1 queries.
|
|
310
|
+
*/ async fetchAndCache(epoch, ts, prefetched) {
|
|
311
|
+
const [committee, seedBuffer, latestBlock, finalizedBlock, isEscapeHatchOpen] = await Promise.all([
|
|
184
312
|
this.rollup.getCommitteeAt(ts),
|
|
185
313
|
this.rollup.getSampleSeedAt(ts),
|
|
186
|
-
this.rollup.client.getBlock({
|
|
314
|
+
prefetched?.latestBlock ?? this.rollup.client.getBlock({
|
|
187
315
|
includeTransactions: false
|
|
188
|
-
})
|
|
316
|
+
}),
|
|
317
|
+
prefetched !== undefined ? prefetched.finalizedBlock : getFinalizedL1Block(this.rollup.client),
|
|
189
318
|
this.rollup.isEscapeHatchOpen(epoch)
|
|
190
319
|
]);
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
throw new Error(`Cannot query committee for future epoch ${epoch} with timestamp ${ts} (current L1 time is ${l1Timestamp}). Check your Ethereum node is synced.`);
|
|
320
|
+
const samplingTs = this.getSamplingTimestamp(epoch);
|
|
321
|
+
if (samplingTs > latestBlock.timestamp) {
|
|
322
|
+
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.`);
|
|
195
323
|
}
|
|
196
|
-
|
|
324
|
+
// Empty committees are never marked finalized so they always get re-queried after TTL.
|
|
325
|
+
// If L1 has no finalized block yet (devnet startup), entries stay unfinalized.
|
|
326
|
+
const hasCommittee = !!(committee && committee.length > 0);
|
|
327
|
+
const finalized = hasCommittee && finalizedBlock !== undefined && samplingTs <= finalizedBlock.timestamp;
|
|
328
|
+
const data = {
|
|
197
329
|
committee,
|
|
198
330
|
seed: seedBuffer.toBigInt(),
|
|
199
331
|
epoch,
|
|
200
332
|
isEscapeHatchOpen
|
|
201
333
|
};
|
|
334
|
+
const entry = {
|
|
335
|
+
data,
|
|
336
|
+
lastQueryL1BlockNumber: latestBlock.number,
|
|
337
|
+
lastQueryL1BlockHash: latestBlock.hash,
|
|
338
|
+
lastRefreshL1Timestamp: latestBlock.timestamp,
|
|
339
|
+
finalized
|
|
340
|
+
};
|
|
341
|
+
this.cache.set(epoch, entry);
|
|
342
|
+
this.purgeCache();
|
|
343
|
+
return entry;
|
|
202
344
|
}
|
|
203
345
|
/**
|
|
204
346
|
* Get the ABI encoding of the proposer index - see ValidatorSelectionLib.sol computeProposerIndex
|
|
@@ -229,14 +371,26 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
229
371
|
}
|
|
230
372
|
return BigInt(keccak256(this.getProposerIndexEncoding(epoch, slot, seed))) % size;
|
|
231
373
|
}
|
|
232
|
-
/** Returns the current and next L2 slot
|
|
233
|
-
const
|
|
374
|
+
/** Returns the current and next L2 slot in next eth L1 Slot. */ getCurrentAndNextSlot() {
|
|
375
|
+
const currentSlot = this.getSlotNow();
|
|
234
376
|
const next = this.getEpochAndSlotInNextL1Slot();
|
|
235
377
|
return {
|
|
236
|
-
currentSlot
|
|
378
|
+
currentSlot,
|
|
237
379
|
nextSlot: next.slot
|
|
238
380
|
};
|
|
239
381
|
}
|
|
382
|
+
/** Returns the target and next L2 slot in the next L1 slot. */ getTargetAndNextSlot() {
|
|
383
|
+
const nowSeconds = BigInt(this.dateProvider.nowInSeconds());
|
|
384
|
+
const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
385
|
+
const currentSlot = getSlotAtTimestamp(nowSeconds, this.l1constants);
|
|
386
|
+
const targetSlot = SlotNumber(currentSlot + offset);
|
|
387
|
+
const nextL2SlotOnL1 = getSlotAtNextL1Block(nowSeconds, this.l1constants);
|
|
388
|
+
const nextSlot = SlotNumber(nextL2SlotOnL1 + offset);
|
|
389
|
+
return {
|
|
390
|
+
targetSlot,
|
|
391
|
+
nextSlot
|
|
392
|
+
};
|
|
393
|
+
}
|
|
240
394
|
/**
|
|
241
395
|
* Get the proposer attester address in the given L2 slot
|
|
242
396
|
* @returns The proposer attester address. If the committee does not exist, we throw a NoCommitteeError.
|
|
@@ -294,10 +448,11 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
294
448
|
async getRegisteredValidators() {
|
|
295
449
|
const validatorRefreshIntervalMs = this.config.validatorRefreshIntervalSeconds * 1000;
|
|
296
450
|
const validatorRefreshTime = this.lastValidatorRefresh + validatorRefreshIntervalMs;
|
|
297
|
-
|
|
298
|
-
|
|
451
|
+
const now = this.dateProvider.now();
|
|
452
|
+
if (validatorRefreshTime < now) {
|
|
453
|
+
const currentSet = await this.rollup.getAttesters(BigInt(Math.floor(now / 1000)));
|
|
299
454
|
this.allValidators = new Set(currentSet.map((v)=>v.toString()));
|
|
300
|
-
this.lastValidatorRefresh =
|
|
455
|
+
this.lastValidatorRefresh = now;
|
|
301
456
|
}
|
|
302
457
|
return Array.from(this.allValidators.keys()).map((v)=>EthAddress.fromString(v));
|
|
303
458
|
}
|
|
@@ -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.
|
|
@@ -17,6 +17,7 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
17
17
|
private seed;
|
|
18
18
|
private registeredValidators;
|
|
19
19
|
private l1Constants;
|
|
20
|
+
private proposerPipeliningEnabled;
|
|
20
21
|
constructor(l1Constants?: Partial<L1RollupConstants>);
|
|
21
22
|
/**
|
|
22
23
|
* Sets the committee members. Used in validation and attestation flows.
|
|
@@ -54,12 +55,22 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
54
55
|
*/
|
|
55
56
|
setL1Constants(constants: Partial<L1RollupConstants>): this;
|
|
56
57
|
getL1Constants(): L1RollupConstants;
|
|
58
|
+
setProposerPipeliningEnabled(enabled: boolean): void;
|
|
57
59
|
getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo>;
|
|
60
|
+
getSlotNow(): SlotNumber;
|
|
61
|
+
getTargetSlot(): SlotNumber;
|
|
62
|
+
getEpochNow(): EpochNumber;
|
|
63
|
+
getTargetEpoch(): EpochNumber;
|
|
64
|
+
isProposerPipeliningEnabled(): boolean;
|
|
65
|
+
pipeliningOffset(): number;
|
|
58
66
|
getEpochAndSlotNow(): EpochAndSlot & {
|
|
59
67
|
nowMs: bigint;
|
|
60
68
|
};
|
|
61
69
|
getEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
62
|
-
|
|
70
|
+
nowSeconds: bigint;
|
|
71
|
+
};
|
|
72
|
+
getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
73
|
+
nowSeconds: bigint;
|
|
63
74
|
};
|
|
64
75
|
getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}`;
|
|
65
76
|
computeProposerIndex(slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, size: bigint): bigint;
|
|
@@ -67,10 +78,15 @@ export declare class TestEpochCache implements EpochCacheInterface {
|
|
|
67
78
|
currentSlot: SlotNumber;
|
|
68
79
|
nextSlot: SlotNumber;
|
|
69
80
|
};
|
|
81
|
+
getTargetAndNextSlot(): {
|
|
82
|
+
targetSlot: SlotNumber;
|
|
83
|
+
nextSlot: SlotNumber;
|
|
84
|
+
};
|
|
70
85
|
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined>;
|
|
71
86
|
getRegisteredValidators(): Promise<EthAddress[]>;
|
|
72
87
|
isInCommittee(_slot: SlotTag, validator: EthAddress): Promise<boolean>;
|
|
73
88
|
filterInCommittee(_slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
89
|
+
isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean>;
|
|
74
90
|
isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean>;
|
|
75
91
|
}
|
|
76
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
92
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVz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UFFLE9BQU8sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBRXpEO0NBQ0YifQ==
|
|
@@ -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;AACH,qBAAa,cAAe,YAAW,mBAAmB;IACxD,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,yBAAyB,CAAS;IAE1C,YAAY,WAAW,GAAE,OAAO,CAAC,iBAAiB,CAAM,EAEvD;IAED;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,CAG1C;IAED;;;OAGG;IACH,WAAW,CAA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M,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,5 +1,6 @@
|
|
|
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,
|
|
@@ -24,6 +25,7 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
24
25
|
seed = 0n;
|
|
25
26
|
registeredValidators = [];
|
|
26
27
|
l1Constants;
|
|
28
|
+
proposerPipeliningEnabled = false;
|
|
27
29
|
constructor(l1Constants = {}){
|
|
28
30
|
this.l1Constants = {
|
|
29
31
|
...DEFAULT_L1_CONSTANTS,
|
|
@@ -85,6 +87,9 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
85
87
|
getL1Constants() {
|
|
86
88
|
return this.l1Constants;
|
|
87
89
|
}
|
|
90
|
+
setProposerPipeliningEnabled(enabled) {
|
|
91
|
+
this.proposerPipeliningEnabled = enabled;
|
|
92
|
+
}
|
|
88
93
|
getCommittee(_slot) {
|
|
89
94
|
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
90
95
|
return Promise.resolve({
|
|
@@ -94,27 +99,55 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
94
99
|
isEscapeHatchOpen: this.escapeHatchOpen
|
|
95
100
|
});
|
|
96
101
|
}
|
|
102
|
+
getSlotNow() {
|
|
103
|
+
return this.currentSlot;
|
|
104
|
+
}
|
|
105
|
+
getTargetSlot() {
|
|
106
|
+
return this.proposerPipeliningEnabled ? SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET) : this.currentSlot;
|
|
107
|
+
}
|
|
108
|
+
getEpochNow() {
|
|
109
|
+
return getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
110
|
+
}
|
|
111
|
+
getTargetEpoch() {
|
|
112
|
+
return getEpochAtSlot(this.getTargetSlot(), this.l1Constants);
|
|
113
|
+
}
|
|
114
|
+
isProposerPipeliningEnabled() {
|
|
115
|
+
return this.proposerPipeliningEnabled;
|
|
116
|
+
}
|
|
117
|
+
pipeliningOffset() {
|
|
118
|
+
return this.proposerPipeliningEnabled ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
119
|
+
}
|
|
97
120
|
getEpochAndSlotNow() {
|
|
98
|
-
const
|
|
99
|
-
const ts = getTimestampRangeForEpoch(
|
|
121
|
+
const epochNow = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
122
|
+
const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
|
|
100
123
|
return {
|
|
101
|
-
epoch,
|
|
124
|
+
epoch: epochNow,
|
|
102
125
|
slot: this.currentSlot,
|
|
103
126
|
ts,
|
|
104
127
|
nowMs: ts * 1000n
|
|
105
128
|
};
|
|
106
129
|
}
|
|
107
130
|
getEpochAndSlotInNextL1Slot() {
|
|
108
|
-
const
|
|
109
|
-
const nextSlotTs =
|
|
131
|
+
const nowTs = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
|
|
132
|
+
const nextSlotTs = nowTs + BigInt(this.l1Constants.ethereumSlotDuration);
|
|
110
133
|
const nextSlot = getSlotAtTimestamp(nextSlotTs, this.l1Constants);
|
|
111
|
-
const
|
|
112
|
-
const ts = getTimestampRangeForEpoch(
|
|
134
|
+
const epochNow = getEpochAtSlot(nextSlot, this.l1Constants);
|
|
135
|
+
const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
|
|
113
136
|
return {
|
|
114
|
-
epoch,
|
|
137
|
+
epoch: epochNow,
|
|
115
138
|
slot: nextSlot,
|
|
116
139
|
ts,
|
|
117
|
-
|
|
140
|
+
nowSeconds: nowTs
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
getTargetEpochAndSlotInNextL1Slot() {
|
|
144
|
+
const result = this.getEpochAndSlotInNextL1Slot();
|
|
145
|
+
const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
146
|
+
const targetSlot = SlotNumber(result.slot + offset);
|
|
147
|
+
return {
|
|
148
|
+
...result,
|
|
149
|
+
slot: targetSlot,
|
|
150
|
+
epoch: getEpochAtSlot(targetSlot, this.l1Constants)
|
|
118
151
|
};
|
|
119
152
|
}
|
|
120
153
|
getProposerIndexEncoding(epoch, slot, seed) {
|
|
@@ -128,9 +161,19 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
128
161
|
return BigInt(slot) % size;
|
|
129
162
|
}
|
|
130
163
|
getCurrentAndNextSlot() {
|
|
164
|
+
const currentSlot = this.getSlotNow();
|
|
165
|
+
const next = this.getEpochAndSlotInNextL1Slot();
|
|
131
166
|
return {
|
|
132
|
-
currentSlot
|
|
133
|
-
nextSlot:
|
|
167
|
+
currentSlot,
|
|
168
|
+
nextSlot: next.slot
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
getTargetAndNextSlot() {
|
|
172
|
+
const targetSlot = this.getTargetSlot();
|
|
173
|
+
const next = this.getTargetEpochAndSlotInNextL1Slot();
|
|
174
|
+
return {
|
|
175
|
+
targetSlot,
|
|
176
|
+
nextSlot: next.slot
|
|
134
177
|
};
|
|
135
178
|
}
|
|
136
179
|
getProposerAttesterAddressInSlot(_slot) {
|
|
@@ -146,6 +189,9 @@ import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@
|
|
|
146
189
|
const committeeSet = new Set(this.committee.map((v)=>v.toString()));
|
|
147
190
|
return Promise.resolve(validators.filter((v)=>committeeSet.has(v.toString())));
|
|
148
191
|
}
|
|
192
|
+
isEscapeHatchOpen(_epoch) {
|
|
193
|
+
return Promise.resolve(this.escapeHatchOpen);
|
|
194
|
+
}
|
|
149
195
|
isEscapeHatchOpenAtSlot(_slot) {
|
|
150
196
|
return Promise.resolve(this.escapeHatchOpen);
|
|
151
197
|
}
|
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.b2a5d0dd1",
|
|
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.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.
|
|
29
|
+
"@aztec/ethereum": "0.0.1-commit.b2a5d0dd1",
|
|
30
|
+
"@aztec/foundation": "0.0.1-commit.b2a5d0dd1",
|
|
31
|
+
"@aztec/l1-artifacts": "0.0.1-commit.b2a5d0dd1",
|
|
32
|
+
"@aztec/stdlib": "0.0.1-commit.b2a5d0dd1",
|
|
33
33
|
"dotenv": "^16.0.3",
|
|
34
34
|
"get-port": "^7.1.0",
|
|
35
35
|
"jest-mock-extended": "^4.0.0",
|
package/src/config.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { type L1ContractsConfig, getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
|
|
2
2
|
import { type L1ReaderConfig, getL1ReaderConfigFromEnv } from '@aztec/ethereum/l1-reader';
|
|
3
|
+
import { type PipelineConfig, getPipelineConfigEnvVars } from '@aztec/stdlib/config';
|
|
3
4
|
|
|
4
5
|
export type EpochCacheConfig = Pick<
|
|
5
|
-
L1ReaderConfig & L1ContractsConfig,
|
|
6
|
-
|
|
6
|
+
L1ReaderConfig & L1ContractsConfig & PipelineConfig,
|
|
7
|
+
| 'l1RpcUrls'
|
|
8
|
+
| 'l1ChainId'
|
|
9
|
+
| 'viemPollingIntervalMS'
|
|
10
|
+
| 'ethereumSlotDuration'
|
|
11
|
+
| 'l1HttpTimeoutMS'
|
|
12
|
+
| 'enableProposerPipelining'
|
|
7
13
|
>;
|
|
8
14
|
|
|
9
15
|
export function getEpochCacheConfigEnvVars(): EpochCacheConfig {
|
|
10
|
-
return { ...getL1ReaderConfigFromEnv(), ...getL1ContractsConfigEnvVars() };
|
|
16
|
+
return { ...getL1ReaderConfigFromEnv(), ...getL1ContractsConfigEnvVars(), ...getPipelineConfigEnvVars() };
|
|
11
17
|
}
|