Skip to content

Find better way to prune PayloadEnvelopeInput #9318

@twoeths

Description

@twoeths

high

The current implementation of pruneBelowParent is inefficient and contains a logging bug:

  1. 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.
  2. 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.
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions