Skip to content

dash-spv: peers sending invalid headers or CFHeaders are never banned #1290

Open

Description

@xdustinface

Problem

A peer that sends block headers failing proof-of-work or difficulty validation, or filter headers that do not chain, is never banned or penalized. The client logs the failure and asks again, possibly from the same peer.

Evidence (on dev)

  • Block headers: BlockHeadersManager::handle_headers_pipeline (dash-spv/src/sync/block_headers/manager.rs) bans the peer only when HeadersPipeline::receive_headers errors. That covers a checkpoint hash mismatch only. Continuity, PoW and difficulty are checked later, in store_headers via BlockHeaderValidator::validate, when a completed segment is stored from store_ready_batches. By then the segment no longer records which peer sent its headers. The error goes up to the sync loop in dash-spv/src/sync/sync_manager.rs, which only logs it and emits SyncEvent::ManagerError, and nothing bans a peer for it.
  • Filter headers: in FilterHeadersManager::handle_message (dash-spv/src/sync/filter_headers/sync_manager.rs), a SyncError::Validation from process_cfheaders logs Rejected CFHeaders batch at …, requesting it again and calls pipeline.requeue_rejected. The peer argument is unused (_peer), so the sender is never banned.

A peer serving bad data therefore costs us a full re-download each time, and nothing stops the broker from routing the retry back to it.

Fix

Record the sending peer with the headers a segment buffers, and with each CFHeaders response. Then call network.ban_peer(peer) when BlockHeaderValidator::validate fails or process_cfheaders returns SyncError::Validation. Only ban for failures that prove the data itself is bad: PoW, difficulty, broken continuity, and a filter header chain that doesn't match the stored one. Don't ban for failures that could come from our own state.

Spotted while reviewing #921. Its backfill paths inherit the same behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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