@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
29 lines • 1.2 kB
JavaScript
import { MapDef } from "@lodestar/utils";
const PROPOSER_PRESERVE_EPOCHS = 2;
export class BeaconProposerCache {
constructor(opts) {
this.feeRecipientByValidatorIndex = new MapDef(() => ({
epoch: 0,
feeRecipient: opts.suggestedFeeRecipient,
}));
}
add(epoch, { validatorIndex, feeRecipient }) {
this.feeRecipientByValidatorIndex.set(validatorIndex, { epoch, feeRecipient });
}
prune(epoch) {
// This is not so optimized function, but could maintain a 2d array may be?
for (const [validatorIndex, feeRecipientEntry] of this.feeRecipientByValidatorIndex.entries()) {
// We only retain an entry for PROPOSER_PRESERVE_EPOCHS epochs
if (feeRecipientEntry.epoch + PROPOSER_PRESERVE_EPOCHS < epoch) {
this.feeRecipientByValidatorIndex.delete(validatorIndex);
}
}
}
getOrDefault(proposerIndex) {
return this.feeRecipientByValidatorIndex.getOrDefault(proposerIndex).feeRecipient;
}
get(proposerIndex) {
return this.feeRecipientByValidatorIndex.get(proposerIndex)?.feeRecipient;
}
}
//# sourceMappingURL=beaconProposerCache.js.map