
The current implementation of pruneBelowParent is inefficient and contains a logging bug:
- Efficiency: It performs a full chain walk back to the finalized checkpoint (
getAllAncestorBlocks) every slot. Since SeenPayloadEnvelopeInput is a small cache (typically ~2 entries), it is much more efficient to iterate over the cache entries and check if they are ancestors of the current head using isDescendant. This avoids creating large arrays and performing long walks every slot.
- Logging Bug: The debug log at line 146 is inside the loop but outside the
if (input) check. This will cause the node to emit a debug log for every block in the ancestor chain (potentially hundreds) every single slot, even if no entry was deleted. This can lead to log flooding and performance degradation.
- Consistency: The suggested implementation follows the same logging pattern as
pruneFinalized, providing a summary of deleted entries.
pruneBelowParent(parentBlock: ProtoBlock): void {
let deletedCount = 0;
for (const input of this.payloadInputs.values()) {
if (input.slot < parentBlock.slot) {
// Check if the cached FULL variant is an ancestor of the current parent block
if (this.forkChoice.isDescendant(input.blockRootHex, PayloadStatus.FULL, parentBlock.blockRoot, parentBlock.payloadStatus)) {
this.evictPayloadInput(input);
deletedCount++;
}
}
}
if (deletedCount > 0) {
this.logger?.debug("SeenPayloadEnvelopeInput.pruneBelowParent deleted entries", {
parentSlot: parentBlock.slot,
parentRoot: parentBlock.blockRoot,
deletedCount,
});
}
}
Originally posted by @gemini-code-assist[bot] in #9317 (comment)
The current implementation of
pruneBelowParentis inefficient and contains a logging bug:getAllAncestorBlocks) every slot. SinceSeenPayloadEnvelopeInputis a small cache (typically ~2 entries), it is much more efficient to iterate over the cache entries and check if they are ancestors of the current head usingisDescendant. This avoids creating large arrays and performing long walks every slot.if (input)check. This will cause the node to emit a debug log for every block in the ancestor chain (potentially hundreds) every single slot, even if no entry was deleted. This can lead to log flooding and performance degradation.pruneFinalized, providing a summary of deleted entries.Originally posted by @gemini-code-assist[bot] in #9317 (comment)