From f4cbc4920f578a31e6d338e68a25455884c1d6f5 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Thu, 14 Aug 2025 10:05:12 +0100 Subject: [PATCH 1/2] Naively write every outpoint --- hintfile/src/bin/construct.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/hintfile/src/bin/construct.rs b/hintfile/src/bin/construct.rs index dbf7d5e..bf32faa 100644 --- a/hintfile/src/bin/construct.rs +++ b/hintfile/src/bin/construct.rs @@ -1,6 +1,7 @@ -use std::{fs::File, sync::Arc}; +use std::{fs::File, io::Write, sync::Arc}; -use bitcoin::consensus; +use bitcoin::{consensus, OutPoint}; +use hintfile::write_compact_size; use kernel::{ChainType, ChainstateManager, ChainstateManagerOptions, ContextBuilder, KernelError}; fn main() { @@ -21,6 +22,8 @@ fn main() { let chainman = ChainstateManager::new(options, context).unwrap(); println!("Chain state initialized"); let genesis = chainman.get_block_index_genesis(); + let tip = chainman.get_block_index_tip().block_hash().hash; + file.write_all(&tip).unwrap(); let mut current = chainman.get_next_block_index(genesis).unwrap(); loop { let block = chainman.read_block_data(¤t).unwrap(); @@ -30,7 +33,25 @@ fn main() { println!("On block {}", current.height()); let mut delta: u64 = 0; let mut block_offsets: Vec = Vec::new(); - for tx in transactions {} + for tx in transactions { + let txid = tx.compute_txid(); + for (index, _txout) in tx.outputs.iter().enumerate() { + let _outpoint = OutPoint { + txid, + vout: index as u32, + }; + // if true + block_offsets.push(delta); + delta = 0; + } + } + // Overflows 32 bit machines + let len_encode = block_offsets.len() as u64; + println!("Writing block offsets"); + write_compact_size(len_encode, &mut file).expect("unexpected EOF"); + for offset in block_offsets { + write_compact_size(offset, &mut file).expect("unexpected EOF"); + } match chainman.get_next_block_index(current) { Ok(next) => current = next, Err(KernelError::OutOfBounds) => break, From 3aa7effead041dafbd90b3a1e82159a5d1adc41d Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Thu, 14 Aug 2025 16:31:05 +0100 Subject: [PATCH 2/2] Make `Hints` immutable In practice, many threads will probably be grabbing this. --- hintfile/src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hintfile/src/lib.rs b/hintfile/src/lib.rs index 92451ea..6015460 100644 --- a/hintfile/src/lib.rs +++ b/hintfile/src/lib.rs @@ -72,8 +72,11 @@ impl Hints { /// /// If there are no offset present at that height, aka an overflow, or the entry has already /// been fetched. - pub fn take_block_offsets(&mut self, height: BlockHeight) -> Vec { - self.map.remove(&height).expect("block height overflow") + pub fn get_block_offsets(&self, height: BlockHeight) -> Vec { + self.map + .get(&height) + .cloned() + .expect("block height overflow") } }