Skip to content

Commit c190141

Browse files
committed
f - replace FilteredBlock with HeaderOnly
1 parent a4af6d0 commit c190141

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

lightning-block-sync/src/lib.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ mod utils;
4646
use crate::poll::{ChainTip, Poll, ValidatedBlockHeader};
4747

4848
use bitcoin::blockdata::block::{Block, BlockHeader};
49-
use bitcoin::blockdata::transaction::Transaction;
5049
use bitcoin::hash_types::BlockHash;
5150
use bitcoin::util::uint::Uint256;
5251

@@ -153,22 +152,18 @@ pub struct BlockHeaderData {
153152
pub chainwork: Uint256,
154153
}
155154

156-
/// A block containing either all or only pertinent transactions.
155+
/// A block including either all its transactions or only the block header.
157156
///
158-
/// See [`chain::Filter`] for when a [`BlockSource`] should be implemented to filter only pertinent
159-
/// transactions.
157+
/// [`BlockSource`] may be implemented to either always return full blocks or, in the case of
158+
/// compact block filters (BIP 157/158), return header-only blocks when no pertinent transactions
159+
/// match. See [`chain::Filter`] for details on how to notify a source of such transactions.
160160
pub enum BlockData {
161161
/// A block containing all its transactions.
162162
FullBlock(Block),
163-
/// A block that has been filtered for only pertinent transactions.
164-
FilteredBlock(BlockHeader, OwnedTransactionData),
163+
/// A block header for when the block does not contain any pertinent transactions.
164+
HeaderOnly(BlockHeader),
165165
}
166166

167-
/// Similar to [`TransactionData`] only for [`Transaction`] data owned outside of a block.
168-
///
169-
/// [`TransactionData`]: chain::transaction::TransactionData
170-
pub type OwnedTransactionData = Vec<(usize, Transaction)>;
171-
172167
/// A lightweight client for keeping a listener in sync with the chain, allowing for Simplified
173168
/// Payment Verification (SPV).
174169
///
@@ -423,9 +418,8 @@ impl<'a, C: Cache, L: Deref> ChainNotifier<'a, C, L> where L::Target: chain::Lis
423418
BlockData::FullBlock(block) => {
424419
self.chain_listener.block_connected(&block, height);
425420
},
426-
BlockData::FilteredBlock(header, txdata) => {
427-
let txdata: Vec<_> = txdata.iter().map(|(idx, tx)| (*idx, tx)).collect();
428-
self.chain_listener.filtered_block_connected(&header, &txdata, height);
421+
BlockData::HeaderOnly(header) => {
422+
self.chain_listener.filtered_block_connected(&header, &[], height);
429423
},
430424
}
431425

lightning-block-sync/src/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl Validate for BlockData {
7676
fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
7777
let header = match &self {
7878
BlockData::FullBlock(block) => &block.header,
79-
BlockData::FilteredBlock(header, _) => header,
79+
BlockData::HeaderOnly(header) => header,
8080
};
8181

8282
let pow_valid_block_hash = header

lightning-block-sync/src/test_utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ impl BlockSource for Blockchain {
162162
}
163163

164164
if self.filtered_blocks {
165-
let header = block.header.clone();
166-
let txdata = block.txdata.clone().into_iter().enumerate().collect();
167-
return Ok(BlockData::FilteredBlock(header, txdata));
165+
return Ok(BlockData::HeaderOnly(block.header.clone()));
168166
} else {
169167
return Ok(BlockData::FullBlock(block.clone()));
170168
}

0 commit comments

Comments
 (0)