UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

22 lines 860 B
import { toPubkeyHex } from "@lodestar/utils"; const REGISTRATION_PRESERVE_EPOCHS = 2; export class ValidatorRegistrationCache { constructor() { this.registrationByValidatorPubkey = new Map(); } add(epoch, { pubkey, gasLimit }) { this.registrationByValidatorPubkey.set(toPubkeyHex(pubkey), { epoch, gasLimit }); } prune(epoch) { for (const [pubkeyHex, registration] of this.registrationByValidatorPubkey.entries()) { // We only retain an registrations for REGISTRATION_PRESERVE_EPOCHS epochs if (registration.epoch + REGISTRATION_PRESERVE_EPOCHS < epoch) { this.registrationByValidatorPubkey.delete(pubkeyHex); } } } get(pubkey) { return this.registrationByValidatorPubkey.get(toPubkeyHex(pubkey)); } } //# sourceMappingURL=cache.js.map