Skip to content

Add Efficient Sparse Chain Comparison to CheckPoint #2033

@evanlinjin

Description

@evanlinjin

Problem

Need to efficiently determine if two CheckPoint chains contain the same set of blocks. Currently requires O(n) traversal to compare sparse chains, even when they have the same tip.

Solution

Add a cumulative XOR field to each CheckPoint that represents the XOR of all block hashes in the sparse chain.

Why XOR Works

  • Bitcoin blocks have unique hashes (no collisions)
  • XOR is commutative: same blocks = same XOR regardless of order
  • O(1) comparison instead of O(n) traversal
  • Simple incremental computation during insert()

Testing Requirements

  • XOR correctly computed during construction
  • XOR maintained during insert() operations
  • Same sparse chains produce identical XOR
  • Different sparse chains produce different XOR
  • Edge cases: empty chain, single block, fork handling

Notes

  • 32 bytes per checkpoint overhead (acceptable for O(1) comparison benefit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Discussion

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions