1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 01:43:29 +01:00

Add txid collision scanner (#928)

This commit is contained in:
Roman Zeyde 2023-08-28 13:55:41 +03:00 committed by GitHub
parent ff984fb967
commit 1b06226c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

31
examples/tx_collisions.rs Normal file
View File

@ -0,0 +1,31 @@
use anyhow::{Context, Result};
use electrs_rocksdb::{ColumnFamilyDescriptor, IteratorMode, Options, DB};
fn main() -> Result<()> {
let path = std::env::args().skip(1).next().context("missing DB path")?;
let cf_names = DB::list_cf(&Options::default(), &path)?;
let cfs: Vec<_> = cf_names
.iter()
.map(|name| ColumnFamilyDescriptor::new(name, Options::default()))
.collect();
let db = DB::open_cf_descriptors(&Options::default(), &path, cfs)?;
let cf = db.cf_handle("txid").context("missing column family")?;
let mut state: Option<(u64, u32)> = None;
for row in db.iterator_cf(cf, IteratorMode::Start) {
let (curr, _value) = row?;
let curr_prefix = u64::from_le_bytes(curr[..8].try_into()?);
let curr_height = u32::from_le_bytes(curr[8..].try_into()?);
if let Some((prev_prefix, prev_height)) = state {
if prev_prefix == curr_prefix {
eprintln!(
"prefix={:x} heights: {} {}",
curr_prefix, prev_height, curr_height
);
};
}
state = Some((curr_prefix, curr_height));
}
Ok(())
}