@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
31 lines • 1.26 kB
JavaScript
const PROPOSER_PRESERVE_EPOCHS = 2;
export class BeaconProposerCache {
opts;
feeRecipientByValidatorIndex;
constructor(opts) {
this.opts = opts;
this.feeRecipientByValidatorIndex = new Map();
}
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.get(proposerIndex)?.feeRecipient ?? this.opts.suggestedFeeRecipient;
}
get(proposerIndex) {
return this.feeRecipientByValidatorIndex.get(proposerIndex)?.feeRecipient;
}
getValidatorIndices() {
return Array.from(this.feeRecipientByValidatorIndex.keys());
}
}
//# sourceMappingURL=beaconProposerCache.js.map