Skip to content

Commit 78042a2

Browse files
authored
Merge pull request #63 from rustaceanrob/26-1-15-elias-fano-hints
Switch to hintsfile crate
2 parents 8ed944b + 8b700c1 commit 78042a2

File tree

8 files changed

+20
-175
lines changed

8 files changed

+20
-175
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[workspace]
2-
members = ["accumulator", "hintfile", "node"]
2+
members = ["accumulator", "node"]
33
default-members = ["accumulator"]
44
resolver = "2"
55

66
[workspace.dependencies]
77
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", default-features = false, rev = "16cc257c3695dea0e7301a5fa9cab44b8ed60598" }
8+
hintsfile = { version = "0.1.0" }
89
kernel = { package = "bitcoinkernel", git = "https://github.com/alexanderwiederin/rust-bitcoinkernel.git", rev = "353533221e3ba91d672418eab1ae7b83a61214f9" }
910
p2p = { package = "bitcoin-p2p", git = "https://github.com/2140-dev/bitcoin-p2p.git", rev = "a8b3af8dfc32a06eadb867b07afd537ebf347104" }

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
This repository is a collection of crates related to a SwiftSync node implementation. Some crates will be SwiftSync-specific, while others may have broader use cases.
66

77
- `accumulator`: A hash-based SwiftSync accumulator used to add and subtrack elements from a set.
8-
- `hintfile`: Read a hints file from a server.
98
- `node`: Perform fast IBD using a SwiftSync hints file.

hintfile/Cargo.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

hintfile/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

hintfile/src/lib.rs

Lines changed: 0 additions & 152 deletions
This file was deleted.

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build = "build.rs"
88
accumulator = { path = "../accumulator/" }
99
bitcoin = { workspace = true }
1010
kernel = { workspace = true }
11-
hintfile = { path = "../hintfile/" }
11+
hintsfile = { workspace = true }
1212
p2p = { workspace = true }
1313

1414
configure_me = "0.4.0"

node/src/bin/ibd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use bitcoin::Network;
9-
use hintfile::Hints;
9+
use hintsfile::Hintsfile;
1010
use kernel::{ChainstateManager, ChainstateManagerOptions, ContextBuilder};
1111

1212
use node::{
@@ -41,8 +41,8 @@ fn main() {
4141
tracing::subscriber::set_global_default(subscriber).unwrap();
4242
let hintfile_start_time = Instant::now();
4343
tracing::info!("Reading in {hint_path}");
44-
let hintfile = File::open(hint_path).expect("invalid hintfile path");
45-
let hints = Hints::from_file(hintfile);
44+
let mut hintfile = File::open(hint_path).expect("invalid hintfile path");
45+
let hints = Hintsfile::from_reader(&mut hintfile).unwrap();
4646
let stop_height = hints.stop_height();
4747
elapsed_time(hintfile_start_time);
4848
tracing::info!("Syncing to height {}", hints.stop_height());

node/src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bitcoin::{
1919
transaction::TransactionExt,
2020
BlockHash, Network, OutPoint,
2121
};
22-
use hintfile::Hints;
22+
use hintsfile::Hintsfile;
2323
use kernel::{ChainType, ChainstateManager};
2424
use p2p::{
2525
dns::DnsQueryExt,
@@ -177,7 +177,7 @@ pub fn get_blocks_for_range(
177177
network: Network,
178178
block_dir: Option<PathBuf>,
179179
chain: Arc<ChainstateManager>,
180-
hints: Arc<Mutex<Hints>>,
180+
hints: Arc<Mutex<Hintsfile>>,
181181
peers: Arc<Mutex<Vec<SocketAddr>>>,
182182
updater: Sender<AccumulatorUpdate>,
183183
hashes: Arc<Mutex<Vec<Vec<BlockHash>>>>,
@@ -234,9 +234,13 @@ pub fn get_blocks_for_range(
234234
.block_index_by_hash(kernal_hash)
235235
.expect("header is in best chain.");
236236
let block_height = block_index.height().unsigned_abs();
237-
let unspent_indexes: HashSet<u64> = {
238-
let mut hint_ref = hints.lock().unwrap();
239-
hint_ref.get_indexes(block_height).into_iter().collect()
237+
let unspent_indexes: HashSet<u32> = {
238+
let hint_ref = hints.lock().unwrap();
239+
hint_ref
240+
.indices_at_height(block_height)
241+
.expect("hints should exist")
242+
.into_iter()
243+
.collect()
240244
};
241245
if let Some(block_dir) = block_dir.as_ref() {
242246
let file_path = block_dir.join(format!("{hash}.block"));
@@ -268,10 +272,12 @@ pub fn get_blocks_for_range(
268272
}
269273
}
270274
for (vout, txout) in transaction.outputs.iter().enumerate() {
271-
if !txout.script_pubkey.is_op_return()
272-
&& !txout.script_pubkey.len() > 10_000
273-
&& !unspent_indexes.contains(&output_index)
275+
if txout.script_pubkey.is_op_return()
276+
|| txout.script_pubkey.len() > 10_000
274277
{
278+
continue;
279+
}
280+
if !unspent_indexes.contains(&output_index) {
275281
let outpoint = OutPoint {
276282
txid: tx_hash,
277283
vout: vout as u32,

0 commit comments

Comments
 (0)