Skip to content

Commit

Permalink
Prune producedBlobsSidecarCache
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Nov 27, 2022
1 parent ebf0eae commit ccdb9bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {IBeaconConfig} from "@lodestar/config";
import {allForks, UintNum64, Root, phase0, eip4844, Slot, RootHex, Epoch, ValidatorIndex} from "@lodestar/types";
import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {ProcessShutdownCallback} from "@lodestar/validator";
import {ILogger, toHex} from "@lodestar/utils";
import {ILogger, pruneSetToMax, toHex} from "@lodestar/utils";
import {CompositeTypeAny, fromHexString, TreeView, Type} from "@chainsafe/ssz";
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";

import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
import {IBeaconDb} from "../db/index.js";
Expand Down Expand Up @@ -65,6 +65,9 @@ import {BlobsResultType, BlockAttributes, produceBlockBody} from "./produceBlock
import {computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js";
import {BlockImport} from "./blocks/types.js";

const DEFAULT_MAX_CACHED_BLOBS_SIDECAR = 8;
const MAX_RETAINED_SLOTS_CACHED_BLOBS_SIDECAR = 8;

export class BeaconChain implements IBeaconChain {
readonly genesisTime: UintNum64;
readonly genesisValidatorsRoot: Root;
Expand Down Expand Up @@ -394,6 +397,10 @@ export class BeaconChain implements IBeaconChain {
blobs: blobs.blobs,
kzgAggregatedProof: computeAggregateKzgProof(blobs.blobs),
});
pruneSetToMax(
this.producedBlobsSidecarCache,
this.opts.maxCachedBlobsSidecar ?? DEFAULT_MAX_CACHED_BLOBS_SIDECAR
);
}

return block;
Expand Down Expand Up @@ -630,6 +637,15 @@ export class BeaconChain implements IBeaconChain {
this.logger.error("Error on exchangeTransitionConfiguration", {}, e as Error);
});
}

// Prune old blobsSidecar for block production, those are only useful on their slot
if (this.config.getForkSeq(slot) >= ForkSeq.eip4844 && this.producedBlobsSidecarCache.size > 0) {
for (const [key, blobsSidecar] of this.producedBlobsSidecarCache) {
if (slot > blobsSidecar.beaconBlockSlot + MAX_RETAINED_SLOTS_CACHED_BLOBS_SIDECAR) {
this.producedBlobsSidecarCache.delete(key);
}
}
}
}

private onClockEpoch(epoch: Epoch): void {
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/src/chain/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type IChainOptions = BlockProcessOpts &
/** Number of missed slots allowed in the faultInspectionWindow for builder circuit*/
allowedFaults?: number;
sanityCheckExecutionEngineBlocks?: boolean;
maxCachedBlobsSidecar?: number;
};

export type BlockProcessOpts = {
Expand Down

0 comments on commit ccdb9bb

Please sign in to comment.