Skip to content

Commit c7f3e8d

Browse files
authored
fix: do not create default cache entry for unknown proposers (#8532)
**Motivation** If we don't have the proposer index in cache when having to build a block, we create a default entry [here](https://github.com/ChainSafe/lodestar/blob/d9cc6b90f70c4740e9d28b50f01d90d1a25b620e/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts#L196). This shouldn't happen in normal circumstances as proposers are registered beforehand, however if you produce a block each slot for testing purposes this affects the custody of the node as it will have up to 32 validators in proposer cache (assuming a block each slot) and since we never reduce the cgc it will stay at that value. Logs from Ethpandaops from a node without attached validators but that's producing a block each slot ``` Oct-14 09:12:00.005[chain] verbose: Updated target custody group count finalizedEpoch=272653, validatorCount=32, targetCustodyGroupCount=33 ``` ``` Oct-14 09:12:00.008[network] debug: Updated cgc field in ENR custodyGroupCount=33 ``` **Description** Do not create default cache entry for unknown proposers by using normal `Map` and just fall back to `suggestedFeeRecipient` if there isn't any value. The behavior from a caller perspective stays the same but we no longer create a proposer cache entry for unknown proposers.
1 parent d9cc6b9 commit c7f3e8d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

packages/beacon-node/src/chain/beaconProposerCache.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import {routes} from "@lodestar/api";
22
import {Epoch} from "@lodestar/types";
3-
import {MapDef} from "@lodestar/utils";
43

54
const PROPOSER_PRESERVE_EPOCHS = 2;
65

76
export type ProposerPreparationData = routes.validator.ProposerPreparationData;
87

98
export class BeaconProposerCache {
10-
private readonly feeRecipientByValidatorIndex: MapDef<number, {epoch: Epoch; feeRecipient: string}>;
11-
constructor(opts: {suggestedFeeRecipient: string}) {
12-
this.feeRecipientByValidatorIndex = new MapDef(() => ({
13-
epoch: 0,
14-
feeRecipient: opts.suggestedFeeRecipient,
15-
}));
9+
private readonly feeRecipientByValidatorIndex: Map<number, {epoch: Epoch; feeRecipient: string}>;
10+
constructor(readonly opts: {suggestedFeeRecipient: string}) {
11+
this.feeRecipientByValidatorIndex = new Map();
1612
}
1713

1814
add(epoch: Epoch, {validatorIndex, feeRecipient}: ProposerPreparationData): void {
@@ -30,7 +26,7 @@ export class BeaconProposerCache {
3026
}
3127

3228
getOrDefault(proposerIndex: number): string {
33-
return this.feeRecipientByValidatorIndex.getOrDefault(proposerIndex).feeRecipient;
29+
return this.feeRecipientByValidatorIndex.get(proposerIndex)?.feeRecipient ?? this.opts.suggestedFeeRecipient;
3430
}
3531

3632
get(proposerIndex: number): string | undefined {

0 commit comments

Comments
 (0)