vecs: part 9

This commit is contained in:
nym21
2025-07-24 17:19:05 +02:00
parent cf1fb483b3
commit 3f237689da
15 changed files with 359 additions and 328 deletions

2
Cargo.lock generated
View File

@@ -609,7 +609,7 @@ dependencies = [
"brk_logger", "brk_logger",
"brk_parser", "brk_parser",
"brk_store", "brk_store",
"brk_vec", "brk_vecs",
"color-eyre", "color-eyre",
"fjall", "fjall",
"libc", "libc",

View File

@@ -15,7 +15,7 @@ brk_exit = { workspace = true }
brk_logger = { workspace = true } brk_logger = { workspace = true }
brk_parser = { workspace = true } brk_parser = { workspace = true }
brk_store = { workspace = true } brk_store = { workspace = true }
brk_vec = { workspace = true } brk_vecs = { workspace = true }
color-eyre = { workspace = true } color-eyre = { workspace = true }
fjall = { workspace = true } fjall = { workspace = true }
libc = { workspace = true } libc = { workspace = true }

View File

@@ -6,7 +6,7 @@ use brk_core::{
Result, TxIndex, TypeIndex, UnknownOutputIndex, Result, TxIndex, TypeIndex, UnknownOutputIndex,
}; };
use brk_parser::NUMBER_OF_UNSAFE_BLOCKS; use brk_parser::NUMBER_OF_UNSAFE_BLOCKS;
use brk_vec::{AnyIndexedVec, AnyIterableVec, AnyVec, IndexedVec, StoredIndex, StoredType}; use brk_vecs::{AnyIterableVec, AnyStampedVec, AnyVec, StampedVec, StoredIndex, StoredType};
use color_eyre::eyre::ContextCompat; use color_eyre::eyre::ContextCompat;
use crate::{Stores, Vecs}; use crate::{Stores, Vecs};
@@ -208,18 +208,18 @@ impl TryFrom<(&mut Vecs, &Stores, &Client)> for Indexes {
} }
pub fn starting_index<I, T>( pub fn starting_index<I, T>(
height_to_index: &IndexedVec<Height, I>, height_to_index: &StampedVec<Height, I>,
index_to_else: &IndexedVec<I, T>, index_to_else: &StampedVec<I, T>,
starting_height: Height, starting_height: Height,
) -> Option<I> ) -> Option<I>
where where
I: StoredType + StoredIndex + From<usize>, I: StoredType + StoredIndex + From<usize>,
T: StoredType, T: StoredType,
{ {
let h = height_to_index.height(); let h = Height::from(u64::from(height_to_index.stamp()));
if h.is_zero() { if h.is_zero() {
None None
} else if height_to_index.height() + 1_u32 == starting_height { } else if h + 1_u32 == starting_height {
Some(I::from(index_to_else.len())) Some(I::from(index_to_else.len()))
} else { } else {
height_to_index.iter().get_inner(starting_height) height_to_index.iter().get_inner(starting_height)

View File

@@ -1,21 +1,20 @@
#![doc = include_str!("../README.md")] #![doc = include_str!("../README.md")]
#![doc = "\n## Example\n\n```rust"] #![doc = "\n## Example\n\n```rust"]
#![doc = include_str!("../examples/main.rs")] #![doc = include_str!("../examples/indexer.rs")]
#![doc = "```"] #![doc = "```"]
use std::{collections::BTreeMap, path::Path, str::FromStr, thread}; use std::{collections::BTreeMap, path::Path, str::FromStr, sync::Arc, thread};
use bitcoin::{Transaction, TxIn, TxOut};
use brk_core::{ use brk_core::{
AddressBytes, AddressBytesHash, BlockHash, BlockHashPrefix, Height, InputIndex, OutputIndex, AddressBytes, AddressBytesHash, BlockHash, BlockHashPrefix, Height, InputIndex, OutputIndex,
OutputType, Sats, Timestamp, TxIndex, Txid, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, OutputType, Sats, Timestamp, TxIndex, Txid, TxidPrefix, TypeIndex, TypeIndexWithOutputindex,
Unit, Version, Vin, Vout, setrlimit, Unit, Version, Vin, Vout, setrlimit,
}; };
use bitcoin::{Transaction, TxIn, TxOut};
use brk_exit::Exit; use brk_exit::Exit;
use brk_parser::Parser; use brk_parser::Parser;
use brk_store::AnyStore; use brk_store::AnyStore;
use brk_vec::{AnyVec, Mmap, VecIterator}; use brk_vecs::{AnyVec, File, Reader, VecIterator};
use color_eyre::eyre::{ContextCompat, eyre}; use color_eyre::eyre::{ContextCompat, eyre};
use log::{error, info}; use log::{error, info};
use rayon::prelude::*; use rayon::prelude::*;
@@ -33,6 +32,7 @@ const VERSION: Version = Version::ONE;
#[derive(Clone)] #[derive(Clone)]
pub struct Indexer { pub struct Indexer {
pub file: Arc<File>,
pub vecs: Vecs, pub vecs: Vecs,
pub stores: Stores, pub stores: Stores,
} }
@@ -41,9 +41,12 @@ impl Indexer {
pub fn forced_import(outputs_dir: &Path) -> color_eyre::Result<Self> { pub fn forced_import(outputs_dir: &Path) -> color_eyre::Result<Self> {
setrlimit()?; setrlimit()?;
let file = Arc::new(File::open(&outputs_dir.join("vecs"))?);
Ok(Self { Ok(Self {
vecs: Vecs::forced_import(&outputs_dir.join("vecs/indexed"), VERSION + Version::ZERO)?, vecs: Vecs::forced_import(&file, VERSION + Version::ZERO)?,
stores: Stores::forced_import(&outputs_dir.join("stores"), VERSION + Version::ZERO)?, stores: Stores::forced_import(&outputs_dir.join("stores"), VERSION + Version::ZERO)?,
file,
}) })
} }
@@ -101,67 +104,64 @@ impl Indexer {
Ok(true) Ok(true)
}; };
let mut txindex_to_first_outputindex_mmap_opt = None; let mut txindex_to_first_outputindex_reader_opt = None;
let mut p2pk65addressindex_to_p2pk65bytes_mmap_opt = None; let mut p2pk65addressindex_to_p2pk65bytes_reader_opt = None;
let mut p2pk33addressindex_to_p2pk33bytes_mmap_opt = None; let mut p2pk33addressindex_to_p2pk33bytes_reader_opt = None;
let mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt = None; let mut p2pkhaddressindex_to_p2pkhbytes_reader_opt = None;
let mut p2shaddressindex_to_p2shbytes_mmap_opt = None; let mut p2shaddressindex_to_p2shbytes_reader_opt = None;
let mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt = None; let mut p2wpkhaddressindex_to_p2wpkhbytes_reader_opt = None;
let mut p2wshaddressindex_to_p2wshbytes_mmap_opt = None; let mut p2wshaddressindex_to_p2wshbytes_reader_opt = None;
let mut p2traddressindex_to_p2trbytes_mmap_opt = None; let mut p2traddressindex_to_p2trbytes_reader_opt = None;
let mut p2aaddressindex_to_p2abytes_mmap_opt = None; let mut p2aaddressindex_to_p2abytes_reader_opt = None;
let reset_mmaps_options = let reset_mmaps_options =
|vecs: &mut Vecs, |vecs: &mut Vecs,
txindex_to_first_outputindex_mmap_opt: &mut Option<Mmap>, txindex_to_first_outputindex_reader_opt: &mut Option<Reader<'static>>,
p2pk65addressindex_to_p2pk65bytes_mmap_opt: &mut Option<Mmap>, p2pk65addressindex_to_p2pk65bytes_reader_opt: &mut Option<Reader<'static>>,
p2pk33addressindex_to_p2pk33bytes_mmap_opt: &mut Option<Mmap>, p2pk33addressindex_to_p2pk33bytes_reader_opt: &mut Option<Reader<'static>>,
p2pkhaddressindex_to_p2pkhbytes_mmap_opt: &mut Option<Mmap>, p2pkhaddressindex_to_p2pkhbytes_reader_opt: &mut Option<Reader<'static>>,
p2shaddressindex_to_p2shbytes_mmap_opt: &mut Option<Mmap>, p2shaddressindex_to_p2shbytes_reader_opt: &mut Option<Reader<'static>>,
p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt: &mut Option<Mmap>, p2wpkhaddressindex_to_p2wpkhbytes_reader_opt: &mut Option<Reader<'static>>,
p2wshaddressindex_to_p2wshbytes_mmap_opt: &mut Option<Mmap>, p2wshaddressindex_to_p2wshbytes_reader_opt: &mut Option<Reader<'static>>,
p2traddressindex_to_p2trbytes_mmap_opt: &mut Option<Mmap>, p2traddressindex_to_p2trbytes_reader_opt: &mut Option<Reader<'static>>,
p2aaddressindex_to_p2abytes_mmap_opt: &mut Option<Mmap>| { p2aaddressindex_to_p2abytes_reader_opt: &mut Option<Reader<'static>>| {
txindex_to_first_outputindex_mmap_opt txindex_to_first_outputindex_reader_opt
.replace(vecs.txindex_to_first_outputindex.create_mmap().unwrap()); .replace(vecs.txindex_to_first_outputindex.create_static_reader());
p2pk65addressindex_to_p2pk65bytes_mmap_opt.replace( p2pk65addressindex_to_p2pk65bytes_reader_opt.replace(
vecs.p2pk65addressindex_to_p2pk65bytes vecs.p2pk65addressindex_to_p2pk65bytes
.create_mmap() .create_static_reader(),
.unwrap(),
); );
p2pk33addressindex_to_p2pk33bytes_mmap_opt.replace( p2pk33addressindex_to_p2pk33bytes_reader_opt.replace(
vecs.p2pk33addressindex_to_p2pk33bytes vecs.p2pk33addressindex_to_p2pk33bytes
.create_mmap() .create_static_reader(),
.unwrap(),
); );
p2pkhaddressindex_to_p2pkhbytes_mmap_opt p2pkhaddressindex_to_p2pkhbytes_reader_opt
.replace(vecs.p2pkhaddressindex_to_p2pkhbytes.create_mmap().unwrap()); .replace(vecs.p2pkhaddressindex_to_p2pkhbytes.create_static_reader());
p2shaddressindex_to_p2shbytes_mmap_opt p2shaddressindex_to_p2shbytes_reader_opt
.replace(vecs.p2shaddressindex_to_p2shbytes.create_mmap().unwrap()); .replace(vecs.p2shaddressindex_to_p2shbytes.create_static_reader());
p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt.replace( p2wpkhaddressindex_to_p2wpkhbytes_reader_opt.replace(
vecs.p2wpkhaddressindex_to_p2wpkhbytes vecs.p2wpkhaddressindex_to_p2wpkhbytes
.create_mmap() .create_static_reader(),
.unwrap(),
); );
p2wshaddressindex_to_p2wshbytes_mmap_opt p2wshaddressindex_to_p2wshbytes_reader_opt
.replace(vecs.p2wshaddressindex_to_p2wshbytes.create_mmap().unwrap()); .replace(vecs.p2wshaddressindex_to_p2wshbytes.create_static_reader());
p2traddressindex_to_p2trbytes_mmap_opt p2traddressindex_to_p2trbytes_reader_opt
.replace(vecs.p2traddressindex_to_p2trbytes.create_mmap().unwrap()); .replace(vecs.p2traddressindex_to_p2trbytes.create_static_reader());
p2aaddressindex_to_p2abytes_mmap_opt p2aaddressindex_to_p2abytes_reader_opt
.replace(vecs.p2aaddressindex_to_p2abytes.create_mmap().unwrap()); .replace(vecs.p2aaddressindex_to_p2abytes.create_static_reader());
}; };
reset_mmaps_options( reset_mmaps_options(
vecs, vecs,
&mut txindex_to_first_outputindex_mmap_opt, &mut txindex_to_first_outputindex_reader_opt,
&mut p2pk65addressindex_to_p2pk65bytes_mmap_opt, &mut p2pk65addressindex_to_p2pk65bytes_reader_opt,
&mut p2pk33addressindex_to_p2pk33bytes_mmap_opt, &mut p2pk33addressindex_to_p2pk33bytes_reader_opt,
&mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt, &mut p2pkhaddressindex_to_p2pkhbytes_reader_opt,
&mut p2shaddressindex_to_p2shbytes_mmap_opt, &mut p2shaddressindex_to_p2shbytes_reader_opt,
&mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt, &mut p2wpkhaddressindex_to_p2wpkhbytes_reader_opt,
&mut p2wshaddressindex_to_p2wshbytes_mmap_opt, &mut p2wshaddressindex_to_p2wshbytes_reader_opt,
&mut p2traddressindex_to_p2trbytes_mmap_opt, &mut p2traddressindex_to_p2trbytes_reader_opt,
&mut p2aaddressindex_to_p2abytes_mmap_opt, &mut p2aaddressindex_to_p2abytes_reader_opt,
); );
parser.parse(start, end).iter().try_for_each( parser.parse(start, end).iter().try_for_each(
@@ -170,15 +170,15 @@ impl Indexer {
idxs.height = height; idxs.height = height;
let txindex_to_first_outputindex_mmap = txindex_to_first_outputindex_mmap_opt.as_ref().unwrap(); let txindex_to_first_outputindex_mmap = txindex_to_first_outputindex_reader_opt.as_ref().unwrap();
let p2pk65addressindex_to_p2pk65bytes_mmap = p2pk65addressindex_to_p2pk65bytes_mmap_opt.as_ref().unwrap(); let p2pk65addressindex_to_p2pk65bytes_mmap = p2pk65addressindex_to_p2pk65bytes_reader_opt.as_ref().unwrap();
let p2pk33addressindex_to_p2pk33bytes_mmap = p2pk33addressindex_to_p2pk33bytes_mmap_opt.as_ref().unwrap(); let p2pk33addressindex_to_p2pk33bytes_mmap = p2pk33addressindex_to_p2pk33bytes_reader_opt.as_ref().unwrap();
let p2pkhaddressindex_to_p2pkhbytes_mmap = p2pkhaddressindex_to_p2pkhbytes_mmap_opt.as_ref().unwrap(); let p2pkhaddressindex_to_p2pkhbytes_mmap = p2pkhaddressindex_to_p2pkhbytes_reader_opt.as_ref().unwrap();
let p2shaddressindex_to_p2shbytes_mmap = p2shaddressindex_to_p2shbytes_mmap_opt.as_ref().unwrap(); let p2shaddressindex_to_p2shbytes_mmap = p2shaddressindex_to_p2shbytes_reader_opt.as_ref().unwrap();
let p2wpkhaddressindex_to_p2wpkhbytes_mmap = p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt.as_ref().unwrap(); let p2wpkhaddressindex_to_p2wpkhbytes_mmap = p2wpkhaddressindex_to_p2wpkhbytes_reader_opt.as_ref().unwrap();
let p2wshaddressindex_to_p2wshbytes_mmap = p2wshaddressindex_to_p2wshbytes_mmap_opt.as_ref().unwrap(); let p2wshaddressindex_to_p2wshbytes_mmap = p2wshaddressindex_to_p2wshbytes_reader_opt.as_ref().unwrap();
let p2traddressindex_to_p2trbytes_mmap = p2traddressindex_to_p2trbytes_mmap_opt.as_ref().unwrap(); let p2traddressindex_to_p2trbytes_mmap = p2traddressindex_to_p2trbytes_reader_opt.as_ref().unwrap();
let p2aaddressindex_to_p2abytes_mmap = p2aaddressindex_to_p2abytes_mmap_opt.as_ref().unwrap(); let p2aaddressindex_to_p2abytes_mmap = p2aaddressindex_to_p2abytes_reader_opt.as_ref().unwrap();
// Used to check rapidhash collisions // Used to check rapidhash collisions
let check_collisions = check_collisions && height > Height::new(COLLISIONS_CHECKED_UP_TO); let check_collisions = check_collisions && height > Height::new(COLLISIONS_CHECKED_UP_TO);
@@ -721,6 +721,8 @@ impl Indexer {
}, },
)?; )?;
drop(txindex_to_txid_iter);
txindex_to_tx_and_txid txindex_to_tx_and_txid
.into_iter() .into_iter()
.try_for_each(|(txindex, (tx, txid))| -> color_eyre::Result<()> { .try_for_each(|(txindex, (tx, txid))| -> color_eyre::Result<()> {
@@ -737,20 +739,30 @@ impl Indexer {
idxs.inputindex += InputIndex::from(inputs_len); idxs.inputindex += InputIndex::from(inputs_len);
idxs.outputindex += OutputIndex::from(outputs_len); idxs.outputindex += OutputIndex::from(outputs_len);
txindex_to_first_outputindex_reader_opt.take();
p2pk65addressindex_to_p2pk65bytes_reader_opt.take();
p2pk33addressindex_to_p2pk33bytes_reader_opt.take();
p2pkhaddressindex_to_p2pkhbytes_reader_opt.take();
p2shaddressindex_to_p2shbytes_reader_opt.take();
p2wpkhaddressindex_to_p2wpkhbytes_reader_opt.take();
p2wshaddressindex_to_p2wshbytes_reader_opt.take();
p2traddressindex_to_p2trbytes_reader_opt.take();
p2aaddressindex_to_p2abytes_reader_opt.take();
let exported = export_if_needed(stores, vecs, height, false, exit)?; let exported = export_if_needed(stores, vecs, height, false, exit)?;
if exported { if exported {
reset_mmaps_options( reset_mmaps_options(
vecs, vecs,
&mut txindex_to_first_outputindex_mmap_opt, &mut txindex_to_first_outputindex_reader_opt,
&mut p2pk65addressindex_to_p2pk65bytes_mmap_opt, &mut p2pk65addressindex_to_p2pk65bytes_reader_opt,
&mut p2pk33addressindex_to_p2pk33bytes_mmap_opt, &mut p2pk33addressindex_to_p2pk33bytes_reader_opt,
&mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt, &mut p2pkhaddressindex_to_p2pkhbytes_reader_opt,
&mut p2shaddressindex_to_p2shbytes_mmap_opt, &mut p2shaddressindex_to_p2shbytes_reader_opt,
&mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt, &mut p2wpkhaddressindex_to_p2wpkhbytes_reader_opt,
&mut p2wshaddressindex_to_p2wshbytes_mmap_opt, &mut p2wshaddressindex_to_p2wshbytes_reader_opt,
&mut p2traddressindex_to_p2trbytes_mmap_opt, &mut p2traddressindex_to_p2trbytes_reader_opt,
&mut p2aaddressindex_to_p2abytes_mmap_opt, &mut p2aaddressindex_to_p2abytes_reader_opt,
); );
} }

View File

@@ -5,7 +5,7 @@ use brk_core::{
OutputType, Result, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit, Version, OutputType, Result, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit, Version,
}; };
use brk_store::{AnyStore, Store}; use brk_store::{AnyStore, Store};
use brk_vec::{AnyIterableVec, VecIterator}; use brk_vecs::{AnyIterableVec, VecIterator};
use fjall::{PersistMode, TransactionalKeyspace}; use fjall::{PersistMode, TransactionalKeyspace};
use rayon::prelude::*; use rayon::prelude::*;

View File

@@ -1,4 +1,4 @@
use std::path::Path; use std::sync::Arc;
use brk_core::{ use brk_core::{
AddressBytes, BlockHash, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex, AddressBytes, BlockHash, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex,
@@ -8,7 +8,7 @@ use brk_core::{
RawLockTime, Result, Sats, StoredF64, StoredU32, StoredUsize, Timestamp, TxIndex, TxVersion, RawLockTime, Result, Sats, StoredF64, StoredU32, StoredUsize, Timestamp, TxIndex, TxVersion,
Txid, TypeIndex, UnknownOutputIndex, Version, Weight, Txid, TypeIndex, UnknownOutputIndex, Version, Weight,
}; };
use brk_vec::{AnyCollectableVec, AnyIndexedVec, Format, IndexedVec}; use brk_vecs::{AnyCollectableVec, AnyStampedVec, File, Format, StampedVec};
use rayon::prelude::*; use rayon::prelude::*;
use crate::Indexes; use crate::Indexes;
@@ -17,317 +17,317 @@ const VERSION: Version = Version::ZERO;
#[derive(Clone)] #[derive(Clone)]
pub struct Vecs { pub struct Vecs {
pub emptyoutputindex_to_txindex: IndexedVec<EmptyOutputIndex, TxIndex>, pub emptyoutputindex_to_txindex: StampedVec<EmptyOutputIndex, TxIndex>,
pub height_to_blockhash: IndexedVec<Height, BlockHash>, pub height_to_blockhash: StampedVec<Height, BlockHash>,
pub height_to_difficulty: IndexedVec<Height, StoredF64>, pub height_to_difficulty: StampedVec<Height, StoredF64>,
pub height_to_first_emptyoutputindex: IndexedVec<Height, EmptyOutputIndex>, pub height_to_first_emptyoutputindex: StampedVec<Height, EmptyOutputIndex>,
pub height_to_first_inputindex: IndexedVec<Height, InputIndex>, pub height_to_first_inputindex: StampedVec<Height, InputIndex>,
pub height_to_first_opreturnindex: IndexedVec<Height, OpReturnIndex>, pub height_to_first_opreturnindex: StampedVec<Height, OpReturnIndex>,
pub height_to_first_outputindex: IndexedVec<Height, OutputIndex>, pub height_to_first_outputindex: StampedVec<Height, OutputIndex>,
pub height_to_first_p2aaddressindex: IndexedVec<Height, P2AAddressIndex>, pub height_to_first_p2aaddressindex: StampedVec<Height, P2AAddressIndex>,
pub height_to_first_p2msoutputindex: IndexedVec<Height, P2MSOutputIndex>, pub height_to_first_p2msoutputindex: StampedVec<Height, P2MSOutputIndex>,
pub height_to_first_p2pk33addressindex: IndexedVec<Height, P2PK33AddressIndex>, pub height_to_first_p2pk33addressindex: StampedVec<Height, P2PK33AddressIndex>,
pub height_to_first_p2pk65addressindex: IndexedVec<Height, P2PK65AddressIndex>, pub height_to_first_p2pk65addressindex: StampedVec<Height, P2PK65AddressIndex>,
pub height_to_first_p2pkhaddressindex: IndexedVec<Height, P2PKHAddressIndex>, pub height_to_first_p2pkhaddressindex: StampedVec<Height, P2PKHAddressIndex>,
pub height_to_first_p2shaddressindex: IndexedVec<Height, P2SHAddressIndex>, pub height_to_first_p2shaddressindex: StampedVec<Height, P2SHAddressIndex>,
pub height_to_first_p2traddressindex: IndexedVec<Height, P2TRAddressIndex>, pub height_to_first_p2traddressindex: StampedVec<Height, P2TRAddressIndex>,
pub height_to_first_p2wpkhaddressindex: IndexedVec<Height, P2WPKHAddressIndex>, pub height_to_first_p2wpkhaddressindex: StampedVec<Height, P2WPKHAddressIndex>,
pub height_to_first_p2wshaddressindex: IndexedVec<Height, P2WSHAddressIndex>, pub height_to_first_p2wshaddressindex: StampedVec<Height, P2WSHAddressIndex>,
pub height_to_first_txindex: IndexedVec<Height, TxIndex>, pub height_to_first_txindex: StampedVec<Height, TxIndex>,
pub height_to_first_unknownoutputindex: IndexedVec<Height, UnknownOutputIndex>, pub height_to_first_unknownoutputindex: StampedVec<Height, UnknownOutputIndex>,
/// Doesn't guarantee continuity due to possible reorgs /// Doesn't guarantee continuity due to possible reorgs
pub height_to_timestamp: IndexedVec<Height, Timestamp>, pub height_to_timestamp: StampedVec<Height, Timestamp>,
pub height_to_total_size: IndexedVec<Height, StoredUsize>, pub height_to_total_size: StampedVec<Height, StoredUsize>,
pub height_to_weight: IndexedVec<Height, Weight>, pub height_to_weight: StampedVec<Height, Weight>,
/// If outputindex == Outputindex::MAX then it's coinbase /// If outputindex == Outputindex::MAX then it's coinbase
pub inputindex_to_outputindex: IndexedVec<InputIndex, OutputIndex>, pub inputindex_to_outputindex: StampedVec<InputIndex, OutputIndex>,
pub opreturnindex_to_txindex: IndexedVec<OpReturnIndex, TxIndex>, pub opreturnindex_to_txindex: StampedVec<OpReturnIndex, TxIndex>,
pub outputindex_to_outputtype: IndexedVec<OutputIndex, OutputType>, pub outputindex_to_outputtype: StampedVec<OutputIndex, OutputType>,
pub outputindex_to_typeindex: IndexedVec<OutputIndex, TypeIndex>, pub outputindex_to_typeindex: StampedVec<OutputIndex, TypeIndex>,
pub outputindex_to_value: IndexedVec<OutputIndex, Sats>, pub outputindex_to_value: StampedVec<OutputIndex, Sats>,
pub p2aaddressindex_to_p2abytes: IndexedVec<P2AAddressIndex, P2ABytes>, pub p2aaddressindex_to_p2abytes: StampedVec<P2AAddressIndex, P2ABytes>,
pub p2msoutputindex_to_txindex: IndexedVec<P2MSOutputIndex, TxIndex>, pub p2msoutputindex_to_txindex: StampedVec<P2MSOutputIndex, TxIndex>,
pub p2pk33addressindex_to_p2pk33bytes: IndexedVec<P2PK33AddressIndex, P2PK33Bytes>, pub p2pk33addressindex_to_p2pk33bytes: StampedVec<P2PK33AddressIndex, P2PK33Bytes>,
pub p2pk65addressindex_to_p2pk65bytes: IndexedVec<P2PK65AddressIndex, P2PK65Bytes>, pub p2pk65addressindex_to_p2pk65bytes: StampedVec<P2PK65AddressIndex, P2PK65Bytes>,
pub p2pkhaddressindex_to_p2pkhbytes: IndexedVec<P2PKHAddressIndex, P2PKHBytes>, pub p2pkhaddressindex_to_p2pkhbytes: StampedVec<P2PKHAddressIndex, P2PKHBytes>,
pub p2shaddressindex_to_p2shbytes: IndexedVec<P2SHAddressIndex, P2SHBytes>, pub p2shaddressindex_to_p2shbytes: StampedVec<P2SHAddressIndex, P2SHBytes>,
pub p2traddressindex_to_p2trbytes: IndexedVec<P2TRAddressIndex, P2TRBytes>, pub p2traddressindex_to_p2trbytes: StampedVec<P2TRAddressIndex, P2TRBytes>,
pub p2wpkhaddressindex_to_p2wpkhbytes: IndexedVec<P2WPKHAddressIndex, P2WPKHBytes>, pub p2wpkhaddressindex_to_p2wpkhbytes: StampedVec<P2WPKHAddressIndex, P2WPKHBytes>,
pub p2wshaddressindex_to_p2wshbytes: IndexedVec<P2WSHAddressIndex, P2WSHBytes>, pub p2wshaddressindex_to_p2wshbytes: StampedVec<P2WSHAddressIndex, P2WSHBytes>,
pub txindex_to_base_size: IndexedVec<TxIndex, StoredU32>, pub txindex_to_base_size: StampedVec<TxIndex, StoredU32>,
pub txindex_to_first_inputindex: IndexedVec<TxIndex, InputIndex>, pub txindex_to_first_inputindex: StampedVec<TxIndex, InputIndex>,
pub txindex_to_first_outputindex: IndexedVec<TxIndex, OutputIndex>, pub txindex_to_first_outputindex: StampedVec<TxIndex, OutputIndex>,
pub txindex_to_is_explicitly_rbf: IndexedVec<TxIndex, bool>, pub txindex_to_is_explicitly_rbf: StampedVec<TxIndex, bool>,
pub txindex_to_rawlocktime: IndexedVec<TxIndex, RawLockTime>, pub txindex_to_rawlocktime: StampedVec<TxIndex, RawLockTime>,
pub txindex_to_total_size: IndexedVec<TxIndex, StoredU32>, pub txindex_to_total_size: StampedVec<TxIndex, StoredU32>,
pub txindex_to_txid: IndexedVec<TxIndex, Txid>, pub txindex_to_txid: StampedVec<TxIndex, Txid>,
pub txindex_to_txversion: IndexedVec<TxIndex, TxVersion>, pub txindex_to_txversion: StampedVec<TxIndex, TxVersion>,
pub unknownoutputindex_to_txindex: IndexedVec<UnknownOutputIndex, TxIndex>, pub unknownoutputindex_to_txindex: StampedVec<UnknownOutputIndex, TxIndex>,
} }
impl Vecs { impl Vecs {
pub fn forced_import(path: &Path, version: Version) -> color_eyre::Result<Self> { pub fn forced_import(file: &Arc<File>, version: Version) -> color_eyre::Result<Self> {
Ok(Self { Ok(Self {
emptyoutputindex_to_txindex: IndexedVec::forced_import( emptyoutputindex_to_txindex: StampedVec::forced_import(
path, file,
"txindex", "txindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_blockhash: IndexedVec::forced_import( height_to_blockhash: StampedVec::forced_import(
path, file,
"blockhash", "blockhash",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_difficulty: IndexedVec::forced_import( height_to_difficulty: StampedVec::forced_import(
path, file,
"difficulty", "difficulty",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_emptyoutputindex: IndexedVec::forced_import( height_to_first_emptyoutputindex: StampedVec::forced_import(
path, file,
"first_emptyoutputindex", "first_emptyoutputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_inputindex: IndexedVec::forced_import( height_to_first_inputindex: StampedVec::forced_import(
path, file,
"first_inputindex", "first_inputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_opreturnindex: IndexedVec::forced_import( height_to_first_opreturnindex: StampedVec::forced_import(
path, file,
"first_opreturnindex", "first_opreturnindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_outputindex: IndexedVec::forced_import( height_to_first_outputindex: StampedVec::forced_import(
path, file,
"first_outputindex", "first_outputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2aaddressindex: IndexedVec::forced_import( height_to_first_p2aaddressindex: StampedVec::forced_import(
path, file,
"first_p2aaddressindex", "first_p2aaddressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2msoutputindex: IndexedVec::forced_import( height_to_first_p2msoutputindex: StampedVec::forced_import(
path, file,
"first_p2msoutputindex", "first_p2msoutputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2pk33addressindex: IndexedVec::forced_import( height_to_first_p2pk33addressindex: StampedVec::forced_import(
path, file,
"first_p2pk33addressindex", "first_p2pk33addressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2pk65addressindex: IndexedVec::forced_import( height_to_first_p2pk65addressindex: StampedVec::forced_import(
path, file,
"first_p2pk65addressindex", "first_p2pk65addressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2pkhaddressindex: IndexedVec::forced_import( height_to_first_p2pkhaddressindex: StampedVec::forced_import(
path, file,
"first_p2pkhaddressindex", "first_p2pkhaddressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2shaddressindex: IndexedVec::forced_import( height_to_first_p2shaddressindex: StampedVec::forced_import(
path, file,
"first_p2shaddressindex", "first_p2shaddressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2traddressindex: IndexedVec::forced_import( height_to_first_p2traddressindex: StampedVec::forced_import(
path, file,
"first_p2traddressindex", "first_p2traddressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2wpkhaddressindex: IndexedVec::forced_import( height_to_first_p2wpkhaddressindex: StampedVec::forced_import(
path, file,
"first_p2wpkhaddressindex", "first_p2wpkhaddressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_p2wshaddressindex: IndexedVec::forced_import( height_to_first_p2wshaddressindex: StampedVec::forced_import(
path, file,
"first_p2wshaddressindex", "first_p2wshaddressindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_txindex: IndexedVec::forced_import( height_to_first_txindex: StampedVec::forced_import(
path, file,
"first_txindex", "first_txindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_first_unknownoutputindex: IndexedVec::forced_import( height_to_first_unknownoutputindex: StampedVec::forced_import(
path, file,
"first_unknownoutputindex", "first_unknownoutputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_timestamp: IndexedVec::forced_import( height_to_timestamp: StampedVec::forced_import(
path, file,
"timestamp", "timestamp",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_total_size: IndexedVec::forced_import( height_to_total_size: StampedVec::forced_import(
path, file,
"total_size", "total_size",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
height_to_weight: IndexedVec::forced_import( height_to_weight: StampedVec::forced_import(
path, file,
"weight", "weight",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
inputindex_to_outputindex: IndexedVec::forced_import( inputindex_to_outputindex: StampedVec::forced_import(
path, file,
"outputindex", "outputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
opreturnindex_to_txindex: IndexedVec::forced_import( opreturnindex_to_txindex: StampedVec::forced_import(
path, file,
"txindex", "txindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
outputindex_to_outputtype: IndexedVec::forced_import( outputindex_to_outputtype: StampedVec::forced_import(
path, file,
"outputtype", "outputtype",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
outputindex_to_typeindex: IndexedVec::forced_import( outputindex_to_typeindex: StampedVec::forced_import(
path, file,
"typeindex", "typeindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
outputindex_to_value: IndexedVec::forced_import( outputindex_to_value: StampedVec::forced_import(
path, file,
"value", "value",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2aaddressindex_to_p2abytes: IndexedVec::forced_import( p2aaddressindex_to_p2abytes: StampedVec::forced_import(
path, file,
"p2abytes", "p2abytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2msoutputindex_to_txindex: IndexedVec::forced_import( p2msoutputindex_to_txindex: StampedVec::forced_import(
path, file,
"txindex", "txindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2pk33addressindex_to_p2pk33bytes: IndexedVec::forced_import( p2pk33addressindex_to_p2pk33bytes: StampedVec::forced_import(
path, file,
"p2pk33bytes", "p2pk33bytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2pk65addressindex_to_p2pk65bytes: IndexedVec::forced_import( p2pk65addressindex_to_p2pk65bytes: StampedVec::forced_import(
path, file,
"p2pk65bytes", "p2pk65bytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2pkhaddressindex_to_p2pkhbytes: IndexedVec::forced_import( p2pkhaddressindex_to_p2pkhbytes: StampedVec::forced_import(
path, file,
"p2pkhbytes", "p2pkhbytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2shaddressindex_to_p2shbytes: IndexedVec::forced_import( p2shaddressindex_to_p2shbytes: StampedVec::forced_import(
path, file,
"p2shbytes", "p2shbytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2traddressindex_to_p2trbytes: IndexedVec::forced_import( p2traddressindex_to_p2trbytes: StampedVec::forced_import(
path, file,
"p2trbytes", "p2trbytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2wpkhaddressindex_to_p2wpkhbytes: IndexedVec::forced_import( p2wpkhaddressindex_to_p2wpkhbytes: StampedVec::forced_import(
path, file,
"p2wpkhbytes", "p2wpkhbytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
p2wshaddressindex_to_p2wshbytes: IndexedVec::forced_import( p2wshaddressindex_to_p2wshbytes: StampedVec::forced_import(
path, file,
"p2wshbytes", "p2wshbytes",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_base_size: IndexedVec::forced_import( txindex_to_base_size: StampedVec::forced_import(
path, file,
"base_size", "base_size",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_first_inputindex: IndexedVec::forced_import( txindex_to_first_inputindex: StampedVec::forced_import(
path, file,
"first_inputindex", "first_inputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_first_outputindex: IndexedVec::forced_import( txindex_to_first_outputindex: StampedVec::forced_import(
path, file,
"first_outputindex", "first_outputindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_is_explicitly_rbf: IndexedVec::forced_import( txindex_to_is_explicitly_rbf: StampedVec::forced_import(
path, file,
"is_explicitly_rbf", "is_explicitly_rbf",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_rawlocktime: IndexedVec::forced_import( txindex_to_rawlocktime: StampedVec::forced_import(
path, file,
"rawlocktime", "rawlocktime",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_total_size: IndexedVec::forced_import( txindex_to_total_size: StampedVec::forced_import(
path, file,
"total_size", "total_size",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_txid: IndexedVec::forced_import( txindex_to_txid: StampedVec::forced_import(
path, file,
"txid", "txid",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
txindex_to_txversion: IndexedVec::forced_import( txindex_to_txversion: StampedVec::forced_import(
path, file,
"txversion", "txversion",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
)?, )?,
unknownoutputindex_to_txindex: IndexedVec::forced_import( unknownoutputindex_to_txindex: StampedVec::forced_import(
path, file,
"txindex", "txindex",
version + VERSION + Version::ZERO, version + VERSION + Version::ZERO,
Format::Raw, Format::Raw,
@@ -357,94 +357,92 @@ impl Vecs {
unknownoutputindex, unknownoutputindex,
} = starting_indexes; } = starting_indexes;
let stamp = u64::from(saved_height).into();
self.emptyoutputindex_to_txindex self.emptyoutputindex_to_txindex
.truncate_if_needed(emptyoutputindex, saved_height)?; .truncate_if_needed(emptyoutputindex, stamp)?;
self.height_to_blockhash self.height_to_blockhash.truncate_if_needed(height, stamp)?;
.truncate_if_needed(height, saved_height)?;
self.height_to_difficulty self.height_to_difficulty
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_emptyoutputindex self.height_to_first_emptyoutputindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_inputindex self.height_to_first_inputindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_opreturnindex self.height_to_first_opreturnindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_outputindex self.height_to_first_outputindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2aaddressindex self.height_to_first_p2aaddressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2msoutputindex self.height_to_first_p2msoutputindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2pk33addressindex self.height_to_first_p2pk33addressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2pk65addressindex self.height_to_first_p2pk65addressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2pkhaddressindex self.height_to_first_p2pkhaddressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2shaddressindex self.height_to_first_p2shaddressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2traddressindex self.height_to_first_p2traddressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2wpkhaddressindex self.height_to_first_p2wpkhaddressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_p2wshaddressindex self.height_to_first_p2wshaddressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_txindex self.height_to_first_txindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_first_unknownoutputindex self.height_to_first_unknownoutputindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_timestamp self.height_to_timestamp.truncate_if_needed(height, stamp)?;
.truncate_if_needed(height, saved_height)?;
self.height_to_total_size self.height_to_total_size
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, stamp)?;
self.height_to_weight self.height_to_weight.truncate_if_needed(height, stamp)?;
.truncate_if_needed(height, saved_height)?;
self.inputindex_to_outputindex self.inputindex_to_outputindex
.truncate_if_needed(inputindex, saved_height)?; .truncate_if_needed(inputindex, stamp)?;
self.opreturnindex_to_txindex self.opreturnindex_to_txindex
.truncate_if_needed(opreturnindex, saved_height)?; .truncate_if_needed(opreturnindex, stamp)?;
self.outputindex_to_outputtype self.outputindex_to_outputtype
.truncate_if_needed(outputindex, saved_height)?; .truncate_if_needed(outputindex, stamp)?;
self.outputindex_to_typeindex self.outputindex_to_typeindex
.truncate_if_needed(outputindex, saved_height)?; .truncate_if_needed(outputindex, stamp)?;
self.outputindex_to_value self.outputindex_to_value
.truncate_if_needed(outputindex, saved_height)?; .truncate_if_needed(outputindex, stamp)?;
self.p2aaddressindex_to_p2abytes self.p2aaddressindex_to_p2abytes
.truncate_if_needed(p2aaddressindex, saved_height)?; .truncate_if_needed(p2aaddressindex, stamp)?;
self.p2msoutputindex_to_txindex self.p2msoutputindex_to_txindex
.truncate_if_needed(p2msoutputindex, saved_height)?; .truncate_if_needed(p2msoutputindex, stamp)?;
self.p2pk33addressindex_to_p2pk33bytes self.p2pk33addressindex_to_p2pk33bytes
.truncate_if_needed(p2pk33addressindex, saved_height)?; .truncate_if_needed(p2pk33addressindex, stamp)?;
self.p2pk65addressindex_to_p2pk65bytes self.p2pk65addressindex_to_p2pk65bytes
.truncate_if_needed(p2pk65addressindex, saved_height)?; .truncate_if_needed(p2pk65addressindex, stamp)?;
self.p2pkhaddressindex_to_p2pkhbytes self.p2pkhaddressindex_to_p2pkhbytes
.truncate_if_needed(p2pkhaddressindex, saved_height)?; .truncate_if_needed(p2pkhaddressindex, stamp)?;
self.p2shaddressindex_to_p2shbytes self.p2shaddressindex_to_p2shbytes
.truncate_if_needed(p2shaddressindex, saved_height)?; .truncate_if_needed(p2shaddressindex, stamp)?;
self.p2traddressindex_to_p2trbytes self.p2traddressindex_to_p2trbytes
.truncate_if_needed(p2traddressindex, saved_height)?; .truncate_if_needed(p2traddressindex, stamp)?;
self.p2wpkhaddressindex_to_p2wpkhbytes self.p2wpkhaddressindex_to_p2wpkhbytes
.truncate_if_needed(p2wpkhaddressindex, saved_height)?; .truncate_if_needed(p2wpkhaddressindex, stamp)?;
self.p2wshaddressindex_to_p2wshbytes self.p2wshaddressindex_to_p2wshbytes
.truncate_if_needed(p2wshaddressindex, saved_height)?; .truncate_if_needed(p2wshaddressindex, stamp)?;
self.txindex_to_base_size self.txindex_to_base_size
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.txindex_to_first_inputindex self.txindex_to_first_inputindex
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.txindex_to_first_outputindex self.txindex_to_first_outputindex
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.txindex_to_is_explicitly_rbf self.txindex_to_is_explicitly_rbf
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.txindex_to_rawlocktime self.txindex_to_rawlocktime
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.txindex_to_total_size self.txindex_to_total_size
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.txindex_to_txid self.txindex_to_txid.truncate_if_needed(txindex, stamp)?;
.truncate_if_needed(txindex, saved_height)?;
self.txindex_to_txversion self.txindex_to_txversion
.truncate_if_needed(txindex, saved_height)?; .truncate_if_needed(txindex, stamp)?;
self.unknownoutputindex_to_txindex self.unknownoutputindex_to_txindex
.truncate_if_needed(unknownoutputindex, saved_height)?; .truncate_if_needed(unknownoutputindex, stamp)?;
Ok(()) Ok(())
} }
@@ -481,14 +479,14 @@ impl Vecs {
pub fn flush(&mut self, height: Height) -> Result<()> { pub fn flush(&mut self, height: Height) -> Result<()> {
self.mut_vecs() self.mut_vecs()
.into_par_iter() .into_par_iter()
.try_for_each(|vec| vec.flush(height)) .try_for_each(|vec| vec.flush(u64::from(height).into()))
} }
pub fn starting_height(&mut self) -> Height { pub fn starting_height(&mut self) -> Height {
self.mut_vecs() self.mut_vecs()
.into_iter() .into_iter()
.map(|vec| { .map(|vec| {
let h = vec.height(); let h = Height::from(u64::from(vec.stamp()));
if h > Height::ZERO { h.incremented() } else { h } if h > Height::ZERO { h.incremented() } else { h }
}) })
.min() .min()
@@ -544,7 +542,7 @@ impl Vecs {
] ]
} }
fn mut_vecs(&mut self) -> Vec<&mut dyn AnyIndexedVec> { fn mut_vecs(&mut self) -> Vec<&mut dyn AnyStampedVec> {
vec![ vec![
&mut self.emptyoutputindex_to_txindex, &mut self.emptyoutputindex_to_txindex,
&mut self.height_to_blockhash, &mut self.height_to_blockhash,

View File

@@ -2,9 +2,8 @@ mod file;
mod traits; mod traits;
mod variants; mod variants;
use file::*;
use variants::*; use variants::*;
pub use file::{File, PAGE_SIZE}; pub use file::{File, PAGE_SIZE, Reader};
pub use traits::*; pub use traits::*;
pub use variants::{RawVec, Stamp, StampedVec}; pub use variants::{AnyStampedVec, Format, RawVec, Stamp, StampedVec};

View File

@@ -1,5 +1,7 @@
use brk_core::{Height, Version}; use brk_core::{Height, Version};
use crate::{File, Reader};
use super::{BoxedVecIterator, StoredIndex, StoredType}; use super::{BoxedVecIterator, StoredIndex, StoredType};
pub fn i64_to_usize(i: i64, len: usize) -> usize { pub fn i64_to_usize(i: i64, len: usize) -> usize {
@@ -37,6 +39,30 @@ pub trait AnyVec: Send + Sync {
) )
} }
fn file(&self) -> &File;
fn region_index(&self) -> usize;
/// Be careful with deadlocks
///
/// You'll want to drop the reader before mutable ops
fn create_reader(&self) -> Reader<'_> {
self.create_static_reader()
}
/// Be careful with deadlocks
///
/// You'll want to drop the reader before mutable ops
fn create_static_reader(&self) -> Reader<'static> {
unsafe {
std::mem::transmute(
self.file()
.create_region_reader(self.region_index().into())
.unwrap(),
)
}
}
#[inline] #[inline]
fn i64_to_usize(&self, i: i64) -> usize { fn i64_to_usize(&self, i: i64) -> usize {
let len = self.len(); let len = self.len();

View File

@@ -6,7 +6,7 @@ use std::{
use brk_core::{Error, Result}; use brk_core::{Error, Result};
use crate::{AnyVec, File, HEADER_OFFSET, Header, file::Reader}; use crate::{AnyVec, HEADER_OFFSET, Header, file::Reader};
use super::{StoredIndex, StoredType}; use super::{StoredIndex, StoredType};
@@ -193,30 +193,6 @@ where
index < self.len_() index < self.len_()
} }
fn file(&self) -> &File;
fn region_index(&self) -> usize;
/// Be careful with deadlocks
///
/// You'll want to drop the reader before mutable ops
fn create_reader(&self) -> Reader<'_> {
self.create_static_reader()
}
/// Be careful with deadlocks
///
/// You'll want to drop the reader before mutable ops
fn create_static_reader(&self) -> Reader<'static> {
unsafe {
std::mem::transmute(
self.file()
.create_region_reader(self.region_index().into())
.unwrap(),
)
}
}
fn flush(&mut self) -> Result<()>; fn flush(&mut self) -> Result<()>;
fn truncate_if_needed(&mut self, index: I) -> Result<()>; fn truncate_if_needed(&mut self, index: I) -> Result<()>;

View File

@@ -189,14 +189,6 @@ where
.cloned()) .cloned())
} }
fn file(&self) -> &File {
self.inner.file()
}
fn region_index(&self) -> usize {
self.inner.region_index()
}
fn header(&self) -> &Header { fn header(&self) -> &Header {
self.inner.header() self.inner.header()
} }
@@ -250,7 +242,7 @@ where
// let mut file = file_opt.unwrap_or(self.open_file()?); // let mut file = file_opt.unwrap_or(self.open_file()?);
let mut pages_meta = self.pages_meta.read(); // let mut pages_meta = self.pages_meta.read();
// let mut starting_page_index = pages_meta.len(); // let mut starting_page_index = pages_meta.len();
// let mut values = vec![]; // let mut values = vec![];
@@ -309,7 +301,7 @@ where
// .flat_map(|(v, _)| v) // .flat_map(|(v, _)| v)
// .collect::<Vec<_>>(); // .collect::<Vec<_>>();
pages_meta.write()?; // pages_meta.write()?;
// if let Some(truncate_at) = truncate_at { // if let Some(truncate_at) = truncate_at {
// self.file_set_len(&mut file, truncate_at)?; // self.file_set_len(&mut file, truncate_at)?;
@@ -406,6 +398,14 @@ where
fn value_type_to_size_of(&self) -> usize { fn value_type_to_size_of(&self) -> usize {
size_of::<T>() size_of::<T>()
} }
fn file(&self) -> &File {
self.inner.file()
}
fn region_index(&self) -> usize {
self.inner.region_index()
}
} }
impl<I, T> Clone for CompressedVec<I, T> { impl<I, T> Clone for CompressedVec<I, T> {

View File

@@ -289,14 +289,6 @@ where
fn reset(&mut self) -> Result<()> { fn reset(&mut self) -> Result<()> {
self.reset_() self.reset_()
} }
fn file(&self) -> &File {
&self.file
}
fn region_index(&self) -> usize {
self.region_index
}
} }
impl<I, T> AnyVec for RawVec<I, T> impl<I, T> AnyVec for RawVec<I, T>
@@ -328,6 +320,14 @@ where
fn value_type_to_size_of(&self) -> usize { fn value_type_to_size_of(&self) -> usize {
size_of::<T>() size_of::<T>()
} }
fn file(&self) -> &File {
&self.file
}
fn region_index(&self) -> usize {
self.region_index
}
} }
impl<I, T> Clone for RawVec<I, T> { impl<I, T> Clone for RawVec<I, T> {

View File

@@ -162,6 +162,14 @@ where
fn value_type_to_size_of(&self) -> usize { fn value_type_to_size_of(&self) -> usize {
size_of::<T>() size_of::<T>()
} }
fn file(&self) -> &File {
self.0.file()
}
fn region_index(&self) -> usize {
self.0.region_index()
}
} }
pub trait AnyStampedVec: AnyVec { pub trait AnyStampedVec: AnyVec {

View File

@@ -8,3 +8,15 @@ impl Stamp {
Self(stamp) Self(stamp)
} }
} }
impl From<u64> for Stamp {
fn from(value: u64) -> Self {
Self(value)
}
}
impl From<Stamp> for u64 {
fn from(value: Stamp) -> Self {
value.0
}
}

View File

@@ -70,22 +70,6 @@ where
} }
} }
#[inline]
fn file(&self) -> &File {
match self {
StoredVec::Raw(v) => v.file(),
StoredVec::Compressed(v) => v.file(),
}
}
#[inline]
fn region_index(&self) -> usize {
match self {
StoredVec::Raw(v) => v.region_index(),
StoredVec::Compressed(v) => v.region_index(),
}
}
#[inline] #[inline]
fn mut_header(&mut self) -> &mut Header { fn mut_header(&mut self) -> &mut Header {
match self { match self {
@@ -203,6 +187,22 @@ where
fn value_type_to_size_of(&self) -> usize { fn value_type_to_size_of(&self) -> usize {
size_of::<T>() size_of::<T>()
} }
#[inline]
fn file(&self) -> &File {
match self {
StoredVec::Raw(v) => v.file(),
StoredVec::Compressed(v) => v.file(),
}
}
#[inline]
fn region_index(&self) -> usize {
match self {
StoredVec::Raw(v) => v.region_index(),
StoredVec::Compressed(v) => v.region_index(),
}
}
} }
#[derive(Debug)] #[derive(Debug)]