@aztec/epoch-cache 0.0.1-commit.ee80a48 → 0.0.1-commit.f103f88
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 +78 -17
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +234 -71
- 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 +60 -12
- package/package.json +5 -6
- package/src/config.ts +9 -3
- package/src/epoch_cache.ts +287 -62
- package/src/test/test_epoch_cache.ts +85 -12
|
@@ -3,7 +3,13 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
4
|
import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
type EpochAndSlot,
|
|
8
|
+
type EpochCacheInterface,
|
|
9
|
+
type EpochCommitteeInfo,
|
|
10
|
+
PROPOSER_PIPELINING_SLOT_OFFSET,
|
|
11
|
+
type SlotTag,
|
|
12
|
+
} from '../epoch_cache.js';
|
|
7
13
|
|
|
8
14
|
/** Default L1 constants for testing. */
|
|
9
15
|
const DEFAULT_L1_CONSTANTS: L1RollupConstants = {
|
|
@@ -13,6 +19,8 @@ const DEFAULT_L1_CONSTANTS: L1RollupConstants = {
|
|
|
13
19
|
epochDuration: 16,
|
|
14
20
|
ethereumSlotDuration: 12,
|
|
15
21
|
proofSubmissionEpochs: 2,
|
|
22
|
+
targetCommitteeSize: 48,
|
|
23
|
+
rollupManaLimit: Number.MAX_SAFE_INTEGER,
|
|
16
24
|
};
|
|
17
25
|
|
|
18
26
|
/**
|
|
@@ -30,6 +38,7 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
30
38
|
private seed: bigint = 0n;
|
|
31
39
|
private registeredValidators: EthAddress[] = [];
|
|
32
40
|
private l1Constants: L1RollupConstants;
|
|
41
|
+
private proposerPipeliningEnabled = false;
|
|
33
42
|
|
|
34
43
|
constructor(l1Constants: Partial<L1RollupConstants> = {}) {
|
|
35
44
|
this.l1Constants = { ...DEFAULT_L1_CONSTANTS, ...l1Constants };
|
|
@@ -102,6 +111,10 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
102
111
|
return this.l1Constants;
|
|
103
112
|
}
|
|
104
113
|
|
|
114
|
+
setProposerPipeliningEnabled(enabled: boolean): void {
|
|
115
|
+
this.proposerPipeliningEnabled = enabled;
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo> {
|
|
106
119
|
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
107
120
|
return Promise.resolve({
|
|
@@ -112,19 +125,62 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
112
125
|
});
|
|
113
126
|
}
|
|
114
127
|
|
|
128
|
+
getSlotNow(): SlotNumber {
|
|
129
|
+
return this.currentSlot;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getTargetSlot(): SlotNumber {
|
|
133
|
+
return this.proposerPipeliningEnabled
|
|
134
|
+
? SlotNumber(this.currentSlot + PROPOSER_PIPELINING_SLOT_OFFSET)
|
|
135
|
+
: this.currentSlot;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getEpochNow(): EpochNumber {
|
|
139
|
+
return getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getTargetEpoch(): EpochNumber {
|
|
143
|
+
return getEpochAtSlot(this.getTargetSlot(), this.l1Constants);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
isProposerPipeliningEnabled(): boolean {
|
|
147
|
+
return this.proposerPipeliningEnabled;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
pipeliningOffset(): number {
|
|
151
|
+
return this.proposerPipeliningEnabled ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
115
154
|
getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
|
|
116
|
-
const
|
|
117
|
-
const ts = getTimestampRangeForEpoch(
|
|
118
|
-
return {
|
|
155
|
+
const epochNow = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
156
|
+
const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
|
|
157
|
+
return {
|
|
158
|
+
epoch: epochNow,
|
|
159
|
+
slot: this.currentSlot,
|
|
160
|
+
ts,
|
|
161
|
+
nowMs: ts * 1000n,
|
|
162
|
+
};
|
|
119
163
|
}
|
|
120
164
|
|
|
121
|
-
getEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
122
|
-
const
|
|
123
|
-
const nextSlotTs =
|
|
165
|
+
getEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
|
|
166
|
+
const nowTs = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
|
|
167
|
+
const nextSlotTs = nowTs + BigInt(this.l1Constants.ethereumSlotDuration);
|
|
124
168
|
const nextSlot = getSlotAtTimestamp(nextSlotTs, this.l1Constants);
|
|
125
|
-
const
|
|
126
|
-
const ts = getTimestampRangeForEpoch(
|
|
127
|
-
return {
|
|
169
|
+
const epochNow = getEpochAtSlot(nextSlot, this.l1Constants);
|
|
170
|
+
const ts = getTimestampRangeForEpoch(epochNow, this.l1Constants)[0];
|
|
171
|
+
return {
|
|
172
|
+
epoch: epochNow,
|
|
173
|
+
slot: nextSlot,
|
|
174
|
+
ts,
|
|
175
|
+
nowSeconds: nowTs,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getTargetEpochAndSlotInNextL1Slot(): EpochAndSlot & { nowSeconds: bigint } {
|
|
180
|
+
const result = this.getEpochAndSlotInNextL1Slot();
|
|
181
|
+
const offset = this.isProposerPipeliningEnabled() ? PROPOSER_PIPELINING_SLOT_OFFSET : 0;
|
|
182
|
+
const targetSlot = SlotNumber(result.slot + offset);
|
|
183
|
+
return { ...result, slot: targetSlot, epoch: getEpochAtSlot(targetSlot, this.l1Constants) };
|
|
128
184
|
}
|
|
129
185
|
|
|
130
186
|
getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}` {
|
|
@@ -140,9 +196,22 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
140
196
|
}
|
|
141
197
|
|
|
142
198
|
getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
199
|
+
const currentSlot = this.getSlotNow();
|
|
200
|
+
const next = this.getEpochAndSlotInNextL1Slot();
|
|
201
|
+
|
|
143
202
|
return {
|
|
144
|
-
currentSlot
|
|
145
|
-
nextSlot:
|
|
203
|
+
currentSlot,
|
|
204
|
+
nextSlot: next.slot,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
getTargetAndNextSlot(): { targetSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
209
|
+
const targetSlot = this.getTargetSlot();
|
|
210
|
+
const next = this.getTargetEpochAndSlotInNextL1Slot();
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
targetSlot,
|
|
214
|
+
nextSlot: next.slot,
|
|
146
215
|
};
|
|
147
216
|
}
|
|
148
217
|
|
|
@@ -163,6 +232,10 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
163
232
|
return Promise.resolve(validators.filter(v => committeeSet.has(v.toString())));
|
|
164
233
|
}
|
|
165
234
|
|
|
235
|
+
isEscapeHatchOpen(_epoch: EpochNumber): Promise<boolean> {
|
|
236
|
+
return Promise.resolve(this.escapeHatchOpen);
|
|
237
|
+
}
|
|
238
|
+
|
|
166
239
|
isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean> {
|
|
167
240
|
return Promise.resolve(this.escapeHatchOpen);
|
|
168
241
|
}
|