@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
36 lines • 1.19 kB
JavaScript
import { MapDef } from "@lodestar/utils";
/**
* SyncCommittee signatures are only useful during a single slot according to our peer's clocks
*/
const MAX_SLOTS_IN_CACHE = 3;
/**
* Cache seen SyncCommitteeMessage by slot + validator index.
*/
export class SeenSyncCommitteeMessages {
constructor() {
this.seenCacheBySlot = new MapDef(() => new Map());
}
/**
* based on slot + validator index
*/
get(slot, subnet, validatorIndex) {
const root = this.seenCacheBySlot.getOrDefault(slot).get(seenCacheKey(subnet, validatorIndex));
return root ?? null;
}
/** Register item as seen in the cache */
add(slot, subnet, validatorIndex, root) {
this.seenCacheBySlot.getOrDefault(slot).set(seenCacheKey(subnet, validatorIndex), root);
}
/** Prune per clock slot */
prune(clockSlot) {
for (const slot of this.seenCacheBySlot.keys()) {
if (slot < clockSlot - MAX_SLOTS_IN_CACHE) {
this.seenCacheBySlot.delete(slot);
}
}
}
}
function seenCacheKey(subnet, validatorIndex) {
return `${subnet}-${validatorIndex}`;
}
//# sourceMappingURL=seenCommittee.js.map