Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions src/chain/cfheader_batch.rs

This file was deleted.

5 changes: 2 additions & 3 deletions src/chain/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use bitcoin::{
use tokio::sync::Mutex;

use super::{
cfheader_batch::CFHeaderBatch,
error::{CFHeaderSyncError, CFilterSyncError, HeaderSyncError},
graph::{AcceptHeaderChanges, BlockTree, HeaderRejection},
CFHeaderChanges, ChainState, Filter, FilterCheck, FilterHeaderRequest, FilterRequest,
FilterRequestState, HeaderValidationExt, HeightMonitor, PeerId,
CFHeaderBatch, CFHeaderChanges, ChainState, Filter, FilterCheck, FilterHeaderRequest,
FilterRequest, FilterRequestState, HeaderValidationExt, HeightMonitor, PeerId,
};
use crate::IndexedFilter;
use crate::{chain::BlockHeaderChanges, messages::Event, Dialog, Info, Progress};
Expand Down
56 changes: 51 additions & 5 deletions src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! Notably, [`checkpoints`] contains known Bitcoin block hashes and heights with significant work, so Kyoto nodes do not have to sync from genesis.
pub(crate) mod block_queue;
mod cfheader_batch;
#[allow(clippy::module_inception)]
pub(crate) mod chain;
/// Expected block header checkpoints and corresponding structure.
Expand All @@ -18,15 +17,13 @@ use bitcoin::constants::SUBSIDY_HALVING_INTERVAL;
use bitcoin::hashes::{sha256d, Hash};
use bitcoin::Amount;
use bitcoin::{
bip158::BlockFilter, block::Header, params::Params, BlockHash, FilterHash, FilterHeader,
ScriptBuf, Target, Work,
bip158::BlockFilter, block::Header, p2p::message_filter::CFHeaders, params::Params, BlockHash,
FilterHash, FilterHeader, ScriptBuf, Target, Work,
};

use crate::network::PeerId;
use crate::HeaderCheckpoint;

use cfheader_batch::CFHeaderBatch;

type Height = u32;

/// A block header with associated height.
Expand Down Expand Up @@ -170,6 +167,55 @@ pub(crate) enum CFHeaderChanges {
Conflict,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct CFHeaderBatch {
inner: Vec<FilterCommitment>,
prev_filter_header: FilterHeader,
stop_hash: BlockHash,
}

impl CFHeaderBatch {
pub(crate) fn new(batch: CFHeaders) -> Self {
let mut headers: Vec<FilterCommitment> = vec![];
let mut prev_header = batch.previous_filter_header;
for hash in batch.filter_hashes {
let next_header = hash.filter_header(&prev_header);
headers.push(FilterCommitment {
header: next_header,
filter_hash: hash,
});
prev_header = next_header;
}
Self {
inner: headers,
prev_filter_header: batch.previous_filter_header,
stop_hash: batch.stop_hash,
}
}

fn prev_header(&self) -> &FilterHeader {
&self.prev_filter_header
}

fn stop_hash(&self) -> BlockHash {
self.stop_hash
}

fn len(&self) -> u32 {
self.inner.len() as u32
}

fn take_inner(&mut self) -> Vec<FilterCommitment> {
core::mem::take(&mut self.inner)
}
}

impl From<CFHeaders> for CFHeaderBatch {
fn from(val: CFHeaders) -> Self {
CFHeaderBatch::new(val)
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct FilterCheck {
// This filter was for the `stop_hash`
Expand Down