import { toPubkeyHex } from "@lodestar/utils";
const REGISTRATION_PRESERVE_EPOCHS = 2;
export class ValidatorRegistrationCache {
    /**
     * Map to track registrations by validator pubkey which is used here instead of
     * validator index as `bellatrix.ValidatorRegistrationV1` does not contain the index
     * and builder flow in general prefers to use pubkey over index.
     */
    registrationByValidatorPubkey;
    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