|
| 1 | +// This binary is used to assess the impact of accumulator designs |
| 2 | + |
| 3 | +use std::{path::PathBuf, str::FromStr, time::Instant}; |
| 4 | + |
| 5 | +use bitcoin::{consensus, OutPoint}; |
| 6 | +use kernel::{ChainType, ChainstateManager, ChainstateManagerOptions, ContextBuilder}; |
| 7 | +use node::elapsed_time; |
| 8 | + |
| 9 | +fn main() { |
| 10 | + let subscriber = tracing_subscriber::FmtSubscriber::new(); |
| 11 | + tracing::subscriber::set_global_default(subscriber).unwrap(); |
| 12 | + let home = std::env::var("HOME").unwrap(); |
| 13 | + let path_buf = PathBuf::from_str(&home).unwrap(); |
| 14 | + let bitcoin_dir = path_buf.join(".bitcoin"); |
| 15 | + let blocks_dir = bitcoin_dir.join("blocks"); |
| 16 | + let ctx = ContextBuilder::new() |
| 17 | + .chain_type(ChainType::MAINNET) |
| 18 | + .build() |
| 19 | + .unwrap(); |
| 20 | + let opts = ChainstateManagerOptions::new( |
| 21 | + &ctx, |
| 22 | + bitcoin_dir.to_str().unwrap(), |
| 23 | + blocks_dir.to_str().unwrap(), |
| 24 | + ) |
| 25 | + .unwrap(); |
| 26 | + let chainman = ChainstateManager::new(opts).unwrap(); |
| 27 | + chainman.import_blocks().unwrap(); |
| 28 | + let mut acc = accumulator::Accumulator::new(); |
| 29 | + let mut tip = chainman.block_index_tip(); |
| 30 | + tracing::info!("Starting accumulator bench"); |
| 31 | + let start = Instant::now(); |
| 32 | + while let Ok(next) = tip.prev() { |
| 33 | + tracing::info!("process block {}", next.height()); |
| 34 | + let block = chainman.read_block_data(&next).unwrap(); |
| 35 | + let (_, transactions) = consensus::deserialize::<bitcoin::Block>(&block.to_bytes()) |
| 36 | + .unwrap() |
| 37 | + .into_parts(); |
| 38 | + for tx in transactions { |
| 39 | + let txid = tx.compute_txid(); |
| 40 | + for input in tx.inputs { |
| 41 | + let outpoint = input.previous_output; |
| 42 | + acc.spend(outpoint); |
| 43 | + } |
| 44 | + for vout in 0..tx.outputs.len() { |
| 45 | + let outpoint = OutPoint { |
| 46 | + txid, |
| 47 | + vout: vout as u32, |
| 48 | + }; |
| 49 | + acc.add(outpoint); |
| 50 | + } |
| 51 | + } |
| 52 | + tip = next; |
| 53 | + } |
| 54 | + elapsed_time(start); |
| 55 | +} |
0 commit comments