@aztec-labs/epoch-cache 6.0.0-rc.2 → 6.0.0-rc.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/README.md +32 -10
- package/dest/committee_lookup.d.ts +70 -0
- package/dest/committee_lookup.d.ts.map +1 -0
- package/dest/committee_lookup.js +40 -0
- package/dest/epoch_cache.d.ts +54 -42
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +177 -115
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/lookups.d.ts +16 -0
- package/dest/test/lookups.d.ts.map +1 -0
- package/dest/test/lookups.js +37 -0
- package/dest/test/test_epoch_cache.d.ts +13 -9
- package/dest/test/test_epoch_cache.d.ts.map +1 -1
- package/dest/test/test_epoch_cache.js +39 -14
- package/package.json +6 -6
- package/src/committee_lookup.ts +84 -0
- package/src/epoch_cache.ts +218 -163
- package/src/index.ts +1 -0
- package/src/test/index.ts +1 -0
- package/src/test/lookups.ts +40 -0
- package/src/test/test_epoch_cache.ts +39 -20
|
@@ -8,10 +8,17 @@ import {
|
|
|
8
8
|
getTimestampRangeForEpoch,
|
|
9
9
|
} from '@aztec-labs/stdlib/epoch-helpers';
|
|
10
10
|
|
|
11
|
+
import {
|
|
12
|
+
type CommitteeMembershipLookup,
|
|
13
|
+
type EscapeHatchLookup,
|
|
14
|
+
type KnownCommitteeLookup,
|
|
15
|
+
type ProposerLookup,
|
|
16
|
+
toCommitteeLookup,
|
|
17
|
+
withoutMembers,
|
|
18
|
+
} from '../committee_lookup.js';
|
|
11
19
|
import {
|
|
12
20
|
type EpochAndSlot,
|
|
13
21
|
type EpochCacheInterface,
|
|
14
|
-
type EpochCommitteeInfo,
|
|
15
22
|
PROPOSER_PIPELINING_SLOT_OFFSET,
|
|
16
23
|
type SlotTag,
|
|
17
24
|
} from '../epoch_cache.js';
|
|
@@ -64,7 +71,7 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
/**
|
|
67
|
-
* Sets the proposer address returned by
|
|
74
|
+
* Sets the proposer address returned by lookupProposer.
|
|
68
75
|
* @param proposer - The address of the current proposer.
|
|
69
76
|
*/
|
|
70
77
|
setProposer(proposer: EthAddress | undefined): this {
|
|
@@ -125,14 +132,14 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
125
132
|
return this.lagInEpochsForValidatorSet;
|
|
126
133
|
}
|
|
127
134
|
|
|
128
|
-
|
|
135
|
+
/** An empty committee is `open`, as the real cache reports a target committee size of zero. */
|
|
136
|
+
getCommittee(_slot?: SlotTag): Promise<KnownCommitteeLookup> {
|
|
137
|
+
return Promise.resolve(this.getCommitteeLookup());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private getCommitteeLookup(): KnownCommitteeLookup {
|
|
129
141
|
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
130
|
-
return
|
|
131
|
-
committee: this.committee,
|
|
132
|
-
epoch,
|
|
133
|
-
seed: this.seed,
|
|
134
|
-
isEscapeHatchOpen: this.escapeHatchOpen,
|
|
135
|
-
});
|
|
142
|
+
return toCommitteeLookup(this.committee, { epoch, seed: this.seed, isEscapeHatchOpen: this.escapeHatchOpen });
|
|
136
143
|
}
|
|
137
144
|
|
|
138
145
|
getSlotNow(): SlotNumber {
|
|
@@ -218,28 +225,40 @@ export class TestEpochCache implements EpochCacheInterface {
|
|
|
218
225
|
};
|
|
219
226
|
}
|
|
220
227
|
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
/** An unset proposer is an `open` committee, independently of the committee set with {@link setCommittee}. */
|
|
229
|
+
lookupProposer(_slot: SlotNumber): Promise<ProposerLookup> {
|
|
230
|
+
return Promise.resolve(
|
|
231
|
+
this.proposerAddress === undefined ? { state: 'open' } : { state: 'members', proposer: this.proposerAddress },
|
|
232
|
+
);
|
|
223
233
|
}
|
|
224
234
|
|
|
225
235
|
getRegisteredValidators(): Promise<EthAddress[]> {
|
|
226
236
|
return Promise.resolve(this.registeredValidators);
|
|
227
237
|
}
|
|
228
238
|
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
lookupMembership(_slot: SlotTag, validator: EthAddress): Promise<CommitteeMembershipLookup<boolean>> {
|
|
240
|
+
const lookup = this.getCommitteeLookup();
|
|
241
|
+
return Promise.resolve(
|
|
242
|
+
lookup.state === 'members'
|
|
243
|
+
? { state: 'members', inCommittee: lookup.committee.some(v => v.equals(validator)) }
|
|
244
|
+
: withoutMembers(lookup),
|
|
245
|
+
);
|
|
231
246
|
}
|
|
232
247
|
|
|
233
|
-
filterInCommittee(_slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]
|
|
234
|
-
const
|
|
235
|
-
|
|
248
|
+
filterInCommittee(_slot: SlotTag, validators: EthAddress[]): Promise<CommitteeMembershipLookup<EthAddress[]>> {
|
|
249
|
+
const lookup = this.getCommitteeLookup();
|
|
250
|
+
if (lookup.state !== 'members') {
|
|
251
|
+
return Promise.resolve(withoutMembers(lookup));
|
|
252
|
+
}
|
|
253
|
+
const committeeSet = new Set(lookup.committee.map(v => v.toString()));
|
|
254
|
+
return Promise.resolve({ state: 'members', inCommittee: validators.filter(v => committeeSet.has(v.toString())) });
|
|
236
255
|
}
|
|
237
256
|
|
|
238
|
-
|
|
239
|
-
return Promise.resolve(this.escapeHatchOpen);
|
|
257
|
+
lookupEscapeHatch(_epoch: EpochNumber): Promise<EscapeHatchLookup> {
|
|
258
|
+
return Promise.resolve({ state: this.getCommitteeLookup().state, isEscapeHatchOpen: this.escapeHatchOpen });
|
|
240
259
|
}
|
|
241
260
|
|
|
242
|
-
|
|
243
|
-
return Promise.resolve(this.escapeHatchOpen);
|
|
261
|
+
lookupEscapeHatchAtSlot(_slot?: SlotTag): Promise<EscapeHatchLookup> {
|
|
262
|
+
return Promise.resolve({ state: this.getCommitteeLookup().state, isEscapeHatchOpen: this.escapeHatchOpen });
|
|
244
263
|
}
|
|
245
264
|
}
|