Skip to content

bug: channel log scan drops blocks when RPC triggers range halving #412

@skyc1e

Description

@skyc1e

Summary

When discover_channels_on_network encounters an RPC error that triggers range halving (e.g. "query returned more than N results"), the upper half of the original block range is silently dropped and never re-queried. This can cause opened channels to be missed during discovery.

Location

crates/tempo-common/src/payment/session/channel.rs, around line 284

Details

The scanning loop iterates backward from latest to earliest in chunks. When get_logs returns an error matching should_halve_range, the code halves the range:

let halved = (chunk_end - chunk_start) / 2;
chunk_end = chunk_start + halved;
continue;

After the halved query succeeds, the normal end-of-loop logic advances to the chunk below chunk_start:

chunk_end = chunk_start.saturating_sub(1);

The blocks from chunk_start + halved + 1 to the original chunk_end are never queried.

Example

  1. Loop queries blocks [80, 100] - RPC error triggers halving
  2. halved = (100 - 80) / 2 = 10, chunk_end = 80 + 10 = 90
  3. Retries [80, 90] - succeeds
  4. Normal advance: chunk_end = 79, next query [59, 79]
  5. Blocks 91-100 are never scanned

Impact

Channels opened in the dropped block range will not be discovered by tempo wallet sessions sync or cooperative close flows. The user would need to manually find and force-close these channels on-chain.

Suggested fix

After successfully querying the first half, save the original chunk_end and resume from there after completing the lower half, so the upper portion is retried instead of dropped.

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