mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-17 13:24:49 -07:00
vecs: part 9
This commit is contained in:
@@ -15,7 +15,7 @@ brk_exit = { workspace = true }
|
||||
brk_logger = { workspace = true }
|
||||
brk_parser = { workspace = true }
|
||||
brk_store = { workspace = true }
|
||||
brk_vec = { workspace = true }
|
||||
brk_vecs = { workspace = true }
|
||||
color-eyre = { workspace = true }
|
||||
fjall = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
|
||||
@@ -6,7 +6,7 @@ use brk_core::{
|
||||
Result, TxIndex, TypeIndex, UnknownOutputIndex,
|
||||
};
|
||||
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 crate::{Stores, Vecs};
|
||||
@@ -208,18 +208,18 @@ impl TryFrom<(&mut Vecs, &Stores, &Client)> for Indexes {
|
||||
}
|
||||
|
||||
pub fn starting_index<I, T>(
|
||||
height_to_index: &IndexedVec<Height, I>,
|
||||
index_to_else: &IndexedVec<I, T>,
|
||||
height_to_index: &StampedVec<Height, I>,
|
||||
index_to_else: &StampedVec<I, T>,
|
||||
starting_height: Height,
|
||||
) -> Option<I>
|
||||
where
|
||||
I: StoredType + StoredIndex + From<usize>,
|
||||
T: StoredType,
|
||||
{
|
||||
let h = height_to_index.height();
|
||||
let h = Height::from(u64::from(height_to_index.stamp()));
|
||||
if h.is_zero() {
|
||||
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()))
|
||||
} else {
|
||||
height_to_index.iter().get_inner(starting_height)
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![doc = "\n## Example\n\n```rust"]
|
||||
#![doc = include_str!("../examples/main.rs")]
|
||||
#![doc = include_str!("../examples/indexer.rs")]
|
||||
#![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::{
|
||||
AddressBytes, AddressBytesHash, BlockHash, BlockHashPrefix, Height, InputIndex, OutputIndex,
|
||||
OutputType, Sats, Timestamp, TxIndex, Txid, TxidPrefix, TypeIndex, TypeIndexWithOutputindex,
|
||||
Unit, Version, Vin, Vout, setrlimit,
|
||||
};
|
||||
|
||||
use bitcoin::{Transaction, TxIn, TxOut};
|
||||
use brk_exit::Exit;
|
||||
use brk_parser::Parser;
|
||||
use brk_store::AnyStore;
|
||||
use brk_vec::{AnyVec, Mmap, VecIterator};
|
||||
use brk_vecs::{AnyVec, File, Reader, VecIterator};
|
||||
use color_eyre::eyre::{ContextCompat, eyre};
|
||||
use log::{error, info};
|
||||
use rayon::prelude::*;
|
||||
@@ -33,6 +32,7 @@ const VERSION: Version = Version::ONE;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Indexer {
|
||||
pub file: Arc<File>,
|
||||
pub vecs: Vecs,
|
||||
pub stores: Stores,
|
||||
}
|
||||
@@ -41,9 +41,12 @@ impl Indexer {
|
||||
pub fn forced_import(outputs_dir: &Path) -> color_eyre::Result<Self> {
|
||||
setrlimit()?;
|
||||
|
||||
let file = Arc::new(File::open(&outputs_dir.join("vecs"))?);
|
||||
|
||||
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)?,
|
||||
file,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -101,67 +104,64 @@ impl Indexer {
|
||||
Ok(true)
|
||||
};
|
||||
|
||||
let mut txindex_to_first_outputindex_mmap_opt = None;
|
||||
let mut p2pk65addressindex_to_p2pk65bytes_mmap_opt = None;
|
||||
let mut p2pk33addressindex_to_p2pk33bytes_mmap_opt = None;
|
||||
let mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt = None;
|
||||
let mut p2shaddressindex_to_p2shbytes_mmap_opt = None;
|
||||
let mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt = None;
|
||||
let mut p2wshaddressindex_to_p2wshbytes_mmap_opt = None;
|
||||
let mut p2traddressindex_to_p2trbytes_mmap_opt = None;
|
||||
let mut p2aaddressindex_to_p2abytes_mmap_opt = None;
|
||||
let mut txindex_to_first_outputindex_reader_opt = None;
|
||||
let mut p2pk65addressindex_to_p2pk65bytes_reader_opt = None;
|
||||
let mut p2pk33addressindex_to_p2pk33bytes_reader_opt = None;
|
||||
let mut p2pkhaddressindex_to_p2pkhbytes_reader_opt = None;
|
||||
let mut p2shaddressindex_to_p2shbytes_reader_opt = None;
|
||||
let mut p2wpkhaddressindex_to_p2wpkhbytes_reader_opt = None;
|
||||
let mut p2wshaddressindex_to_p2wshbytes_reader_opt = None;
|
||||
let mut p2traddressindex_to_p2trbytes_reader_opt = None;
|
||||
let mut p2aaddressindex_to_p2abytes_reader_opt = None;
|
||||
|
||||
let reset_mmaps_options =
|
||||
|vecs: &mut Vecs,
|
||||
txindex_to_first_outputindex_mmap_opt: &mut Option<Mmap>,
|
||||
p2pk65addressindex_to_p2pk65bytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2pk33addressindex_to_p2pk33bytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2pkhaddressindex_to_p2pkhbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2shaddressindex_to_p2shbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2wshaddressindex_to_p2wshbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2traddressindex_to_p2trbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2aaddressindex_to_p2abytes_mmap_opt: &mut Option<Mmap>| {
|
||||
txindex_to_first_outputindex_mmap_opt
|
||||
.replace(vecs.txindex_to_first_outputindex.create_mmap().unwrap());
|
||||
p2pk65addressindex_to_p2pk65bytes_mmap_opt.replace(
|
||||
txindex_to_first_outputindex_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2pk65addressindex_to_p2pk65bytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2pk33addressindex_to_p2pk33bytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2pkhaddressindex_to_p2pkhbytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2shaddressindex_to_p2shbytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2wpkhaddressindex_to_p2wpkhbytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2wshaddressindex_to_p2wshbytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2traddressindex_to_p2trbytes_reader_opt: &mut Option<Reader<'static>>,
|
||||
p2aaddressindex_to_p2abytes_reader_opt: &mut Option<Reader<'static>>| {
|
||||
txindex_to_first_outputindex_reader_opt
|
||||
.replace(vecs.txindex_to_first_outputindex.create_static_reader());
|
||||
p2pk65addressindex_to_p2pk65bytes_reader_opt.replace(
|
||||
vecs.p2pk65addressindex_to_p2pk65bytes
|
||||
.create_mmap()
|
||||
.unwrap(),
|
||||
.create_static_reader(),
|
||||
);
|
||||
p2pk33addressindex_to_p2pk33bytes_mmap_opt.replace(
|
||||
p2pk33addressindex_to_p2pk33bytes_reader_opt.replace(
|
||||
vecs.p2pk33addressindex_to_p2pk33bytes
|
||||
.create_mmap()
|
||||
.unwrap(),
|
||||
.create_static_reader(),
|
||||
);
|
||||
p2pkhaddressindex_to_p2pkhbytes_mmap_opt
|
||||
.replace(vecs.p2pkhaddressindex_to_p2pkhbytes.create_mmap().unwrap());
|
||||
p2shaddressindex_to_p2shbytes_mmap_opt
|
||||
.replace(vecs.p2shaddressindex_to_p2shbytes.create_mmap().unwrap());
|
||||
p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt.replace(
|
||||
p2pkhaddressindex_to_p2pkhbytes_reader_opt
|
||||
.replace(vecs.p2pkhaddressindex_to_p2pkhbytes.create_static_reader());
|
||||
p2shaddressindex_to_p2shbytes_reader_opt
|
||||
.replace(vecs.p2shaddressindex_to_p2shbytes.create_static_reader());
|
||||
p2wpkhaddressindex_to_p2wpkhbytes_reader_opt.replace(
|
||||
vecs.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.create_mmap()
|
||||
.unwrap(),
|
||||
.create_static_reader(),
|
||||
);
|
||||
p2wshaddressindex_to_p2wshbytes_mmap_opt
|
||||
.replace(vecs.p2wshaddressindex_to_p2wshbytes.create_mmap().unwrap());
|
||||
p2traddressindex_to_p2trbytes_mmap_opt
|
||||
.replace(vecs.p2traddressindex_to_p2trbytes.create_mmap().unwrap());
|
||||
p2aaddressindex_to_p2abytes_mmap_opt
|
||||
.replace(vecs.p2aaddressindex_to_p2abytes.create_mmap().unwrap());
|
||||
p2wshaddressindex_to_p2wshbytes_reader_opt
|
||||
.replace(vecs.p2wshaddressindex_to_p2wshbytes.create_static_reader());
|
||||
p2traddressindex_to_p2trbytes_reader_opt
|
||||
.replace(vecs.p2traddressindex_to_p2trbytes.create_static_reader());
|
||||
p2aaddressindex_to_p2abytes_reader_opt
|
||||
.replace(vecs.p2aaddressindex_to_p2abytes.create_static_reader());
|
||||
};
|
||||
|
||||
reset_mmaps_options(
|
||||
vecs,
|
||||
&mut txindex_to_first_outputindex_mmap_opt,
|
||||
&mut p2pk65addressindex_to_p2pk65bytes_mmap_opt,
|
||||
&mut p2pk33addressindex_to_p2pk33bytes_mmap_opt,
|
||||
&mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt,
|
||||
&mut p2shaddressindex_to_p2shbytes_mmap_opt,
|
||||
&mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt,
|
||||
&mut p2wshaddressindex_to_p2wshbytes_mmap_opt,
|
||||
&mut p2traddressindex_to_p2trbytes_mmap_opt,
|
||||
&mut p2aaddressindex_to_p2abytes_mmap_opt,
|
||||
&mut txindex_to_first_outputindex_reader_opt,
|
||||
&mut p2pk65addressindex_to_p2pk65bytes_reader_opt,
|
||||
&mut p2pk33addressindex_to_p2pk33bytes_reader_opt,
|
||||
&mut p2pkhaddressindex_to_p2pkhbytes_reader_opt,
|
||||
&mut p2shaddressindex_to_p2shbytes_reader_opt,
|
||||
&mut p2wpkhaddressindex_to_p2wpkhbytes_reader_opt,
|
||||
&mut p2wshaddressindex_to_p2wshbytes_reader_opt,
|
||||
&mut p2traddressindex_to_p2trbytes_reader_opt,
|
||||
&mut p2aaddressindex_to_p2abytes_reader_opt,
|
||||
);
|
||||
|
||||
parser.parse(start, end).iter().try_for_each(
|
||||
@@ -170,15 +170,15 @@ impl Indexer {
|
||||
|
||||
idxs.height = height;
|
||||
|
||||
let txindex_to_first_outputindex_mmap = txindex_to_first_outputindex_mmap_opt.as_ref().unwrap();
|
||||
let p2pk65addressindex_to_p2pk65bytes_mmap = p2pk65addressindex_to_p2pk65bytes_mmap_opt.as_ref().unwrap();
|
||||
let p2pk33addressindex_to_p2pk33bytes_mmap = p2pk33addressindex_to_p2pk33bytes_mmap_opt.as_ref().unwrap();
|
||||
let p2pkhaddressindex_to_p2pkhbytes_mmap = p2pkhaddressindex_to_p2pkhbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2shaddressindex_to_p2shbytes_mmap = p2shaddressindex_to_p2shbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2wpkhaddressindex_to_p2wpkhbytes_mmap = p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2wshaddressindex_to_p2wshbytes_mmap = p2wshaddressindex_to_p2wshbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2traddressindex_to_p2trbytes_mmap = p2traddressindex_to_p2trbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2aaddressindex_to_p2abytes_mmap = p2aaddressindex_to_p2abytes_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_reader_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_reader_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_reader_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_reader_opt.as_ref().unwrap();
|
||||
let p2aaddressindex_to_p2abytes_mmap = p2aaddressindex_to_p2abytes_reader_opt.as_ref().unwrap();
|
||||
|
||||
// Used to check rapidhash collisions
|
||||
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
|
||||
.into_iter()
|
||||
.try_for_each(|(txindex, (tx, txid))| -> color_eyre::Result<()> {
|
||||
@@ -737,20 +739,30 @@ impl Indexer {
|
||||
idxs.inputindex += InputIndex::from(inputs_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)?;
|
||||
|
||||
if exported {
|
||||
reset_mmaps_options(
|
||||
vecs,
|
||||
&mut txindex_to_first_outputindex_mmap_opt,
|
||||
&mut p2pk65addressindex_to_p2pk65bytes_mmap_opt,
|
||||
&mut p2pk33addressindex_to_p2pk33bytes_mmap_opt,
|
||||
&mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt,
|
||||
&mut p2shaddressindex_to_p2shbytes_mmap_opt,
|
||||
&mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt,
|
||||
&mut p2wshaddressindex_to_p2wshbytes_mmap_opt,
|
||||
&mut p2traddressindex_to_p2trbytes_mmap_opt,
|
||||
&mut p2aaddressindex_to_p2abytes_mmap_opt,
|
||||
&mut txindex_to_first_outputindex_reader_opt,
|
||||
&mut p2pk65addressindex_to_p2pk65bytes_reader_opt,
|
||||
&mut p2pk33addressindex_to_p2pk33bytes_reader_opt,
|
||||
&mut p2pkhaddressindex_to_p2pkhbytes_reader_opt,
|
||||
&mut p2shaddressindex_to_p2shbytes_reader_opt,
|
||||
&mut p2wpkhaddressindex_to_p2wpkhbytes_reader_opt,
|
||||
&mut p2wshaddressindex_to_p2wshbytes_reader_opt,
|
||||
&mut p2traddressindex_to_p2trbytes_reader_opt,
|
||||
&mut p2aaddressindex_to_p2abytes_reader_opt,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use brk_core::{
|
||||
OutputType, Result, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit, Version,
|
||||
};
|
||||
use brk_store::{AnyStore, Store};
|
||||
use brk_vec::{AnyIterableVec, VecIterator};
|
||||
use brk_vecs::{AnyIterableVec, VecIterator};
|
||||
use fjall::{PersistMode, TransactionalKeyspace};
|
||||
use rayon::prelude::*;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use brk_core::{
|
||||
AddressBytes, BlockHash, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex,
|
||||
@@ -8,7 +8,7 @@ use brk_core::{
|
||||
RawLockTime, Result, Sats, StoredF64, StoredU32, StoredUsize, Timestamp, TxIndex, TxVersion,
|
||||
Txid, TypeIndex, UnknownOutputIndex, Version, Weight,
|
||||
};
|
||||
use brk_vec::{AnyCollectableVec, AnyIndexedVec, Format, IndexedVec};
|
||||
use brk_vecs::{AnyCollectableVec, AnyStampedVec, File, Format, StampedVec};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::Indexes;
|
||||
@@ -17,317 +17,317 @@ const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub emptyoutputindex_to_txindex: IndexedVec<EmptyOutputIndex, TxIndex>,
|
||||
pub height_to_blockhash: IndexedVec<Height, BlockHash>,
|
||||
pub height_to_difficulty: IndexedVec<Height, StoredF64>,
|
||||
pub height_to_first_emptyoutputindex: IndexedVec<Height, EmptyOutputIndex>,
|
||||
pub height_to_first_inputindex: IndexedVec<Height, InputIndex>,
|
||||
pub height_to_first_opreturnindex: IndexedVec<Height, OpReturnIndex>,
|
||||
pub height_to_first_outputindex: IndexedVec<Height, OutputIndex>,
|
||||
pub height_to_first_p2aaddressindex: IndexedVec<Height, P2AAddressIndex>,
|
||||
pub height_to_first_p2msoutputindex: IndexedVec<Height, P2MSOutputIndex>,
|
||||
pub height_to_first_p2pk33addressindex: IndexedVec<Height, P2PK33AddressIndex>,
|
||||
pub height_to_first_p2pk65addressindex: IndexedVec<Height, P2PK65AddressIndex>,
|
||||
pub height_to_first_p2pkhaddressindex: IndexedVec<Height, P2PKHAddressIndex>,
|
||||
pub height_to_first_p2shaddressindex: IndexedVec<Height, P2SHAddressIndex>,
|
||||
pub height_to_first_p2traddressindex: IndexedVec<Height, P2TRAddressIndex>,
|
||||
pub height_to_first_p2wpkhaddressindex: IndexedVec<Height, P2WPKHAddressIndex>,
|
||||
pub height_to_first_p2wshaddressindex: IndexedVec<Height, P2WSHAddressIndex>,
|
||||
pub height_to_first_txindex: IndexedVec<Height, TxIndex>,
|
||||
pub height_to_first_unknownoutputindex: IndexedVec<Height, UnknownOutputIndex>,
|
||||
pub emptyoutputindex_to_txindex: StampedVec<EmptyOutputIndex, TxIndex>,
|
||||
pub height_to_blockhash: StampedVec<Height, BlockHash>,
|
||||
pub height_to_difficulty: StampedVec<Height, StoredF64>,
|
||||
pub height_to_first_emptyoutputindex: StampedVec<Height, EmptyOutputIndex>,
|
||||
pub height_to_first_inputindex: StampedVec<Height, InputIndex>,
|
||||
pub height_to_first_opreturnindex: StampedVec<Height, OpReturnIndex>,
|
||||
pub height_to_first_outputindex: StampedVec<Height, OutputIndex>,
|
||||
pub height_to_first_p2aaddressindex: StampedVec<Height, P2AAddressIndex>,
|
||||
pub height_to_first_p2msoutputindex: StampedVec<Height, P2MSOutputIndex>,
|
||||
pub height_to_first_p2pk33addressindex: StampedVec<Height, P2PK33AddressIndex>,
|
||||
pub height_to_first_p2pk65addressindex: StampedVec<Height, P2PK65AddressIndex>,
|
||||
pub height_to_first_p2pkhaddressindex: StampedVec<Height, P2PKHAddressIndex>,
|
||||
pub height_to_first_p2shaddressindex: StampedVec<Height, P2SHAddressIndex>,
|
||||
pub height_to_first_p2traddressindex: StampedVec<Height, P2TRAddressIndex>,
|
||||
pub height_to_first_p2wpkhaddressindex: StampedVec<Height, P2WPKHAddressIndex>,
|
||||
pub height_to_first_p2wshaddressindex: StampedVec<Height, P2WSHAddressIndex>,
|
||||
pub height_to_first_txindex: StampedVec<Height, TxIndex>,
|
||||
pub height_to_first_unknownoutputindex: StampedVec<Height, UnknownOutputIndex>,
|
||||
/// Doesn't guarantee continuity due to possible reorgs
|
||||
pub height_to_timestamp: IndexedVec<Height, Timestamp>,
|
||||
pub height_to_total_size: IndexedVec<Height, StoredUsize>,
|
||||
pub height_to_weight: IndexedVec<Height, Weight>,
|
||||
pub height_to_timestamp: StampedVec<Height, Timestamp>,
|
||||
pub height_to_total_size: StampedVec<Height, StoredUsize>,
|
||||
pub height_to_weight: StampedVec<Height, Weight>,
|
||||
/// If outputindex == Outputindex::MAX then it's coinbase
|
||||
pub inputindex_to_outputindex: IndexedVec<InputIndex, OutputIndex>,
|
||||
pub opreturnindex_to_txindex: IndexedVec<OpReturnIndex, TxIndex>,
|
||||
pub outputindex_to_outputtype: IndexedVec<OutputIndex, OutputType>,
|
||||
pub outputindex_to_typeindex: IndexedVec<OutputIndex, TypeIndex>,
|
||||
pub outputindex_to_value: IndexedVec<OutputIndex, Sats>,
|
||||
pub p2aaddressindex_to_p2abytes: IndexedVec<P2AAddressIndex, P2ABytes>,
|
||||
pub p2msoutputindex_to_txindex: IndexedVec<P2MSOutputIndex, TxIndex>,
|
||||
pub p2pk33addressindex_to_p2pk33bytes: IndexedVec<P2PK33AddressIndex, P2PK33Bytes>,
|
||||
pub p2pk65addressindex_to_p2pk65bytes: IndexedVec<P2PK65AddressIndex, P2PK65Bytes>,
|
||||
pub p2pkhaddressindex_to_p2pkhbytes: IndexedVec<P2PKHAddressIndex, P2PKHBytes>,
|
||||
pub p2shaddressindex_to_p2shbytes: IndexedVec<P2SHAddressIndex, P2SHBytes>,
|
||||
pub p2traddressindex_to_p2trbytes: IndexedVec<P2TRAddressIndex, P2TRBytes>,
|
||||
pub p2wpkhaddressindex_to_p2wpkhbytes: IndexedVec<P2WPKHAddressIndex, P2WPKHBytes>,
|
||||
pub p2wshaddressindex_to_p2wshbytes: IndexedVec<P2WSHAddressIndex, P2WSHBytes>,
|
||||
pub txindex_to_base_size: IndexedVec<TxIndex, StoredU32>,
|
||||
pub txindex_to_first_inputindex: IndexedVec<TxIndex, InputIndex>,
|
||||
pub txindex_to_first_outputindex: IndexedVec<TxIndex, OutputIndex>,
|
||||
pub txindex_to_is_explicitly_rbf: IndexedVec<TxIndex, bool>,
|
||||
pub txindex_to_rawlocktime: IndexedVec<TxIndex, RawLockTime>,
|
||||
pub txindex_to_total_size: IndexedVec<TxIndex, StoredU32>,
|
||||
pub txindex_to_txid: IndexedVec<TxIndex, Txid>,
|
||||
pub txindex_to_txversion: IndexedVec<TxIndex, TxVersion>,
|
||||
pub unknownoutputindex_to_txindex: IndexedVec<UnknownOutputIndex, TxIndex>,
|
||||
pub inputindex_to_outputindex: StampedVec<InputIndex, OutputIndex>,
|
||||
pub opreturnindex_to_txindex: StampedVec<OpReturnIndex, TxIndex>,
|
||||
pub outputindex_to_outputtype: StampedVec<OutputIndex, OutputType>,
|
||||
pub outputindex_to_typeindex: StampedVec<OutputIndex, TypeIndex>,
|
||||
pub outputindex_to_value: StampedVec<OutputIndex, Sats>,
|
||||
pub p2aaddressindex_to_p2abytes: StampedVec<P2AAddressIndex, P2ABytes>,
|
||||
pub p2msoutputindex_to_txindex: StampedVec<P2MSOutputIndex, TxIndex>,
|
||||
pub p2pk33addressindex_to_p2pk33bytes: StampedVec<P2PK33AddressIndex, P2PK33Bytes>,
|
||||
pub p2pk65addressindex_to_p2pk65bytes: StampedVec<P2PK65AddressIndex, P2PK65Bytes>,
|
||||
pub p2pkhaddressindex_to_p2pkhbytes: StampedVec<P2PKHAddressIndex, P2PKHBytes>,
|
||||
pub p2shaddressindex_to_p2shbytes: StampedVec<P2SHAddressIndex, P2SHBytes>,
|
||||
pub p2traddressindex_to_p2trbytes: StampedVec<P2TRAddressIndex, P2TRBytes>,
|
||||
pub p2wpkhaddressindex_to_p2wpkhbytes: StampedVec<P2WPKHAddressIndex, P2WPKHBytes>,
|
||||
pub p2wshaddressindex_to_p2wshbytes: StampedVec<P2WSHAddressIndex, P2WSHBytes>,
|
||||
pub txindex_to_base_size: StampedVec<TxIndex, StoredU32>,
|
||||
pub txindex_to_first_inputindex: StampedVec<TxIndex, InputIndex>,
|
||||
pub txindex_to_first_outputindex: StampedVec<TxIndex, OutputIndex>,
|
||||
pub txindex_to_is_explicitly_rbf: StampedVec<TxIndex, bool>,
|
||||
pub txindex_to_rawlocktime: StampedVec<TxIndex, RawLockTime>,
|
||||
pub txindex_to_total_size: StampedVec<TxIndex, StoredU32>,
|
||||
pub txindex_to_txid: StampedVec<TxIndex, Txid>,
|
||||
pub txindex_to_txversion: StampedVec<TxIndex, TxVersion>,
|
||||
pub unknownoutputindex_to_txindex: StampedVec<UnknownOutputIndex, TxIndex>,
|
||||
}
|
||||
|
||||
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 {
|
||||
emptyoutputindex_to_txindex: IndexedVec::forced_import(
|
||||
path,
|
||||
emptyoutputindex_to_txindex: StampedVec::forced_import(
|
||||
file,
|
||||
"txindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_blockhash: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_blockhash: StampedVec::forced_import(
|
||||
file,
|
||||
"blockhash",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_difficulty: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_difficulty: StampedVec::forced_import(
|
||||
file,
|
||||
"difficulty",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_emptyoutputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_emptyoutputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_emptyoutputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_inputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_inputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_inputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_opreturnindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_opreturnindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_opreturnindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_outputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_outputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2aaddressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2aaddressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2aaddressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2msoutputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2msoutputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2msoutputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2pk33addressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2pk33addressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2pk33addressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2pk65addressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2pk65addressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2pk65addressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2pkhaddressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2pkhaddressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2pkhaddressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2shaddressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2shaddressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2shaddressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2traddressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2traddressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2traddressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2wpkhaddressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2wpkhaddressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2wpkhaddressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_p2wshaddressindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_p2wshaddressindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_p2wshaddressindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_txindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_txindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_txindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_first_unknownoutputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_first_unknownoutputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_unknownoutputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_timestamp: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_timestamp: StampedVec::forced_import(
|
||||
file,
|
||||
"timestamp",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_total_size: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_total_size: StampedVec::forced_import(
|
||||
file,
|
||||
"total_size",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
height_to_weight: IndexedVec::forced_import(
|
||||
path,
|
||||
height_to_weight: StampedVec::forced_import(
|
||||
file,
|
||||
"weight",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
inputindex_to_outputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
inputindex_to_outputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
opreturnindex_to_txindex: IndexedVec::forced_import(
|
||||
path,
|
||||
opreturnindex_to_txindex: StampedVec::forced_import(
|
||||
file,
|
||||
"txindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
outputindex_to_outputtype: IndexedVec::forced_import(
|
||||
path,
|
||||
outputindex_to_outputtype: StampedVec::forced_import(
|
||||
file,
|
||||
"outputtype",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
outputindex_to_typeindex: IndexedVec::forced_import(
|
||||
path,
|
||||
outputindex_to_typeindex: StampedVec::forced_import(
|
||||
file,
|
||||
"typeindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
outputindex_to_value: IndexedVec::forced_import(
|
||||
path,
|
||||
outputindex_to_value: StampedVec::forced_import(
|
||||
file,
|
||||
"value",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2aaddressindex_to_p2abytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2aaddressindex_to_p2abytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2abytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2msoutputindex_to_txindex: IndexedVec::forced_import(
|
||||
path,
|
||||
p2msoutputindex_to_txindex: StampedVec::forced_import(
|
||||
file,
|
||||
"txindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2pk33addressindex_to_p2pk33bytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2pk33addressindex_to_p2pk33bytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2pk33bytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2pk65addressindex_to_p2pk65bytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2pk65addressindex_to_p2pk65bytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2pk65bytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2pkhaddressindex_to_p2pkhbytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2pkhaddressindex_to_p2pkhbytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2pkhbytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2shaddressindex_to_p2shbytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2shaddressindex_to_p2shbytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2shbytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2traddressindex_to_p2trbytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2traddressindex_to_p2trbytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2trbytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2wpkhaddressindex_to_p2wpkhbytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2wpkhaddressindex_to_p2wpkhbytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2wpkhbytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
p2wshaddressindex_to_p2wshbytes: IndexedVec::forced_import(
|
||||
path,
|
||||
p2wshaddressindex_to_p2wshbytes: StampedVec::forced_import(
|
||||
file,
|
||||
"p2wshbytes",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_base_size: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_base_size: StampedVec::forced_import(
|
||||
file,
|
||||
"base_size",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_first_inputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_first_inputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_inputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_first_outputindex: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_first_outputindex: StampedVec::forced_import(
|
||||
file,
|
||||
"first_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_is_explicitly_rbf: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_is_explicitly_rbf: StampedVec::forced_import(
|
||||
file,
|
||||
"is_explicitly_rbf",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_rawlocktime: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_rawlocktime: StampedVec::forced_import(
|
||||
file,
|
||||
"rawlocktime",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_total_size: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_total_size: StampedVec::forced_import(
|
||||
file,
|
||||
"total_size",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_txid: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_txid: StampedVec::forced_import(
|
||||
file,
|
||||
"txid",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
txindex_to_txversion: IndexedVec::forced_import(
|
||||
path,
|
||||
txindex_to_txversion: StampedVec::forced_import(
|
||||
file,
|
||||
"txversion",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
)?,
|
||||
unknownoutputindex_to_txindex: IndexedVec::forced_import(
|
||||
path,
|
||||
unknownoutputindex_to_txindex: StampedVec::forced_import(
|
||||
file,
|
||||
"txindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Format::Raw,
|
||||
@@ -357,94 +357,92 @@ impl Vecs {
|
||||
unknownoutputindex,
|
||||
} = starting_indexes;
|
||||
|
||||
let stamp = u64::from(saved_height).into();
|
||||
|
||||
self.emptyoutputindex_to_txindex
|
||||
.truncate_if_needed(emptyoutputindex, saved_height)?;
|
||||
self.height_to_blockhash
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(emptyoutputindex, stamp)?;
|
||||
self.height_to_blockhash.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_difficulty
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_emptyoutputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_inputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_opreturnindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_outputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2aaddressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2msoutputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2pk33addressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2pk65addressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2pkhaddressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2shaddressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2traddressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2wpkhaddressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_p2wshaddressindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_txindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_first_unknownoutputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_timestamp
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_timestamp.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_total_size
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_weight
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
.truncate_if_needed(height, stamp)?;
|
||||
self.height_to_weight.truncate_if_needed(height, stamp)?;
|
||||
self.inputindex_to_outputindex
|
||||
.truncate_if_needed(inputindex, saved_height)?;
|
||||
.truncate_if_needed(inputindex, stamp)?;
|
||||
self.opreturnindex_to_txindex
|
||||
.truncate_if_needed(opreturnindex, saved_height)?;
|
||||
.truncate_if_needed(opreturnindex, stamp)?;
|
||||
self.outputindex_to_outputtype
|
||||
.truncate_if_needed(outputindex, saved_height)?;
|
||||
.truncate_if_needed(outputindex, stamp)?;
|
||||
self.outputindex_to_typeindex
|
||||
.truncate_if_needed(outputindex, saved_height)?;
|
||||
.truncate_if_needed(outputindex, stamp)?;
|
||||
self.outputindex_to_value
|
||||
.truncate_if_needed(outputindex, saved_height)?;
|
||||
.truncate_if_needed(outputindex, stamp)?;
|
||||
self.p2aaddressindex_to_p2abytes
|
||||
.truncate_if_needed(p2aaddressindex, saved_height)?;
|
||||
.truncate_if_needed(p2aaddressindex, stamp)?;
|
||||
self.p2msoutputindex_to_txindex
|
||||
.truncate_if_needed(p2msoutputindex, saved_height)?;
|
||||
.truncate_if_needed(p2msoutputindex, stamp)?;
|
||||
self.p2pk33addressindex_to_p2pk33bytes
|
||||
.truncate_if_needed(p2pk33addressindex, saved_height)?;
|
||||
.truncate_if_needed(p2pk33addressindex, stamp)?;
|
||||
self.p2pk65addressindex_to_p2pk65bytes
|
||||
.truncate_if_needed(p2pk65addressindex, saved_height)?;
|
||||
.truncate_if_needed(p2pk65addressindex, stamp)?;
|
||||
self.p2pkhaddressindex_to_p2pkhbytes
|
||||
.truncate_if_needed(p2pkhaddressindex, saved_height)?;
|
||||
.truncate_if_needed(p2pkhaddressindex, stamp)?;
|
||||
self.p2shaddressindex_to_p2shbytes
|
||||
.truncate_if_needed(p2shaddressindex, saved_height)?;
|
||||
.truncate_if_needed(p2shaddressindex, stamp)?;
|
||||
self.p2traddressindex_to_p2trbytes
|
||||
.truncate_if_needed(p2traddressindex, saved_height)?;
|
||||
.truncate_if_needed(p2traddressindex, stamp)?;
|
||||
self.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.truncate_if_needed(p2wpkhaddressindex, saved_height)?;
|
||||
.truncate_if_needed(p2wpkhaddressindex, stamp)?;
|
||||
self.p2wshaddressindex_to_p2wshbytes
|
||||
.truncate_if_needed(p2wshaddressindex, saved_height)?;
|
||||
.truncate_if_needed(p2wshaddressindex, stamp)?;
|
||||
self.txindex_to_base_size
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_first_inputindex
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_first_outputindex
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_is_explicitly_rbf
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_rawlocktime
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_total_size
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_txid
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_txid.truncate_if_needed(txindex, stamp)?;
|
||||
self.txindex_to_txversion
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
.truncate_if_needed(txindex, stamp)?;
|
||||
self.unknownoutputindex_to_txindex
|
||||
.truncate_if_needed(unknownoutputindex, saved_height)?;
|
||||
.truncate_if_needed(unknownoutputindex, stamp)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -481,14 +479,14 @@ impl Vecs {
|
||||
pub fn flush(&mut self, height: Height) -> Result<()> {
|
||||
self.mut_vecs()
|
||||
.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 {
|
||||
self.mut_vecs()
|
||||
.into_iter()
|
||||
.map(|vec| {
|
||||
let h = vec.height();
|
||||
let h = Height::from(u64::from(vec.stamp()));
|
||||
if h > Height::ZERO { h.incremented() } else { h }
|
||||
})
|
||||
.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![
|
||||
&mut self.emptyoutputindex_to_txindex,
|
||||
&mut self.height_to_blockhash,
|
||||
|
||||
@@ -2,9 +2,8 @@ mod file;
|
||||
mod traits;
|
||||
mod variants;
|
||||
|
||||
use file::*;
|
||||
use variants::*;
|
||||
|
||||
pub use file::{File, PAGE_SIZE};
|
||||
pub use file::{File, PAGE_SIZE, Reader};
|
||||
pub use traits::*;
|
||||
pub use variants::{RawVec, Stamp, StampedVec};
|
||||
pub use variants::{AnyStampedVec, Format, RawVec, Stamp, StampedVec};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use brk_core::{Height, Version};
|
||||
|
||||
use crate::{File, Reader};
|
||||
|
||||
use super::{BoxedVecIterator, StoredIndex, StoredType};
|
||||
|
||||
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]
|
||||
fn i64_to_usize(&self, i: i64) -> usize {
|
||||
let len = self.len();
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::{
|
||||
|
||||
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};
|
||||
|
||||
@@ -193,30 +193,6 @@ where
|
||||
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 truncate_if_needed(&mut self, index: I) -> Result<()>;
|
||||
|
||||
@@ -189,14 +189,6 @@ where
|
||||
.cloned())
|
||||
}
|
||||
|
||||
fn file(&self) -> &File {
|
||||
self.inner.file()
|
||||
}
|
||||
|
||||
fn region_index(&self) -> usize {
|
||||
self.inner.region_index()
|
||||
}
|
||||
|
||||
fn header(&self) -> &Header {
|
||||
self.inner.header()
|
||||
}
|
||||
@@ -250,7 +242,7 @@ where
|
||||
|
||||
// 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 values = vec![];
|
||||
@@ -309,7 +301,7 @@ where
|
||||
// .flat_map(|(v, _)| v)
|
||||
// .collect::<Vec<_>>();
|
||||
|
||||
pages_meta.write()?;
|
||||
// pages_meta.write()?;
|
||||
|
||||
// if let Some(truncate_at) = truncate_at {
|
||||
// self.file_set_len(&mut file, truncate_at)?;
|
||||
@@ -406,6 +398,14 @@ where
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
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> {
|
||||
|
||||
@@ -289,14 +289,6 @@ where
|
||||
fn reset(&mut self) -> Result<()> {
|
||||
self.reset_()
|
||||
}
|
||||
|
||||
fn file(&self) -> &File {
|
||||
&self.file
|
||||
}
|
||||
|
||||
fn region_index(&self) -> usize {
|
||||
self.region_index
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> AnyVec for RawVec<I, T>
|
||||
@@ -328,6 +320,14 @@ where
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
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> {
|
||||
|
||||
@@ -162,6 +162,14 @@ where
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
size_of::<T>()
|
||||
}
|
||||
|
||||
fn file(&self) -> &File {
|
||||
self.0.file()
|
||||
}
|
||||
|
||||
fn region_index(&self) -> usize {
|
||||
self.0.region_index()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AnyStampedVec: AnyVec {
|
||||
|
||||
@@ -8,3 +8,15 @@ impl 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
fn mut_header(&mut self) -> &mut Header {
|
||||
match self {
|
||||
@@ -203,6 +187,22 @@ where
|
||||
fn value_type_to_size_of(&self) -> usize {
|
||||
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)]
|
||||
|
||||
Reference in New Issue
Block a user