diff --git a/Cargo.lock b/Cargo.lock index ed2f22100..c96f1c23e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,7 +645,6 @@ dependencies = [ name = "brk_computer" version = "0.0.111" dependencies = [ - "allocative", "bitcoin", "brk_error", "brk_fetcher", @@ -1318,7 +1317,6 @@ dependencies = [ name = "brk_types" version = "0.0.111" dependencies = [ - "allocative", "bitcoin", "brk_error", "byteview 0.6.1", @@ -4110,9 +4108,9 @@ dependencies = [ [[package]] name = "rawdb" -version = "0.3.11" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f79d5eea2a18c2cf7318e327bb3ead546514ea3bbea5f42c4e0cc0a89df2b46d" +checksum = "b22052ecbd46a8bd9b1f80075a8f44727ba38cec22ff4cb505ea8bb4eecb5a7b" dependencies = [ "libc", "memmap2", @@ -5323,9 +5321,9 @@ checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23" [[package]] name = "vecdb" -version = "0.3.11" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7393aaf472d72417bb7b3366addc225ae4b65f64ceef6ec975dd2891e18b08cf" +checksum = "8ff065db35c03b4ddd2e3319ec18c17b46cd85583795b1a6dd7eba468fa87f13" dependencies = [ "allocative", "ctrlc", @@ -5342,9 +5340,9 @@ dependencies = [ [[package]] name = "vecdb_derive" -version = "0.3.11" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "323a1fc669d513d1ad83a2fb1d1a589dfb502c9c626993a3313a834361bc64b5" +checksum = "073dcff2ffaae6d8af87100342d23faec293c55c2d160a9fc8a62f74db5b06de" dependencies = [ "quote", "syn 2.0.109", diff --git a/Cargo.toml b/Cargo.toml index 26b3b6b06..9b6c6d999 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ inherits = "release" [workspace.dependencies] aide = { version = "0.15.2", features = ["axum-json", "axum-query"], package = "brk-aide" } -allocative = { version = "0.3.4", features = ["parking_lot"] } axum = "0.8.6" bitcoin = { version = "0.32.7", features = ["serde"] } bitcoincore-rpc = "0.19.0" @@ -75,7 +74,7 @@ serde_json = { version = "1.0.145", features = ["float_roundtrip"] } sonic-rs = "0.5.6" tokio = { version = "1.48.0", features = ["rt-multi-thread"] } # vecdb = { path = "../seqdb/crates/vecdb", features = ["derive"] } -vecdb = { version = "0.3.11", features = ["derive"] } +vecdb = { version = "0.3.15", features = ["derive"] } zerocopy = { version = "0.8.27", features = ["derive"] } [workspace.metadata.release] diff --git a/crates/brk_computer/Cargo.toml b/crates/brk_computer/Cargo.toml index 92aba721c..97840a068 100644 --- a/crates/brk_computer/Cargo.toml +++ b/crates/brk_computer/Cargo.toml @@ -10,7 +10,6 @@ rust-version.workspace = true build = "build.rs" [dependencies] -allocative = { workspace = true } bitcoin = { workspace = true } brk_error = { workspace = true } brk_fetcher = { workspace = true } diff --git a/crates/brk_computer/examples/pools.rs b/crates/brk_computer/examples/pools.rs index 924cd860f..bda6b719d 100644 --- a/crates/brk_computer/examples/pools.rs +++ b/crates/brk_computer/examples/pools.rs @@ -5,7 +5,7 @@ use brk_error::Result; use brk_fetcher::Fetcher; use brk_indexer::Indexer; use brk_types::{Address, AddressBytes, OutputType, TxOutIndex, pools}; -use vecdb::{AnyIterableVec, Exit, VecIterator}; +use vecdb::{AnyIterableVec, Exit, VecIterator, VecIteratorExtended}; fn main() -> Result<()> { brk_logger::init(Some(Path::new(".log")))?; @@ -31,24 +31,26 @@ fn main() -> Result<()> { let vecs = indexer.vecs; let stores = indexer.stores; - let mut height_to_first_txindex_iter = vecs.height_to_first_txindex.iter(); - let mut txindex_to_first_txoutindex_iter = vecs.txindex_to_first_txoutindex.iter(); + let mut height_to_first_txindex_iter = vecs.height_to_first_txindex.iter()?; + let mut txindex_to_first_txoutindex_iter = vecs.txindex_to_first_txoutindex.iter()?; let mut txindex_to_output_count_iter = computer.indexes.txindex_to_output_count.iter(); - let mut txoutindex_to_outputtype_iter = vecs.txoutindex_to_outputtype.iter(); - let mut txoutindex_to_typeindex_iter = vecs.txoutindex_to_typeindex.iter(); + let mut txoutindex_to_outputtype_iter = vecs.txoutindex_to_outputtype.iter()?; + let mut txoutindex_to_typeindex_iter = vecs.txoutindex_to_typeindex.iter()?; let mut p2pk65addressindex_to_p2pk65bytes_iter = - vecs.p2pk65addressindex_to_p2pk65bytes.iter(); + vecs.p2pk65addressindex_to_p2pk65bytes.iter()?; let mut p2pk33addressindex_to_p2pk33bytes_iter = - vecs.p2pk33addressindex_to_p2pk33bytes.iter(); + vecs.p2pk33addressindex_to_p2pk33bytes.iter()?; let mut p2pkhaddressindex_to_p2pkhbytes_iter = - vecs.p2pkhaddressindex_to_p2pkhbytes.iter(); - let mut p2shaddressindex_to_p2shbytes_iter = vecs.p2shaddressindex_to_p2shbytes.iter(); + vecs.p2pkhaddressindex_to_p2pkhbytes.iter()?; + let mut p2shaddressindex_to_p2shbytes_iter = + vecs.p2shaddressindex_to_p2shbytes.iter()?; let mut p2wpkhaddressindex_to_p2wpkhbytes_iter = - vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter(); + vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter()?; let mut p2wshaddressindex_to_p2wshbytes_iter = - vecs.p2wshaddressindex_to_p2wshbytes.iter(); - let mut p2traddressindex_to_p2trbytes_iter = vecs.p2traddressindex_to_p2trbytes.iter(); - let mut p2aaddressindex_to_p2abytes_iter = vecs.p2aaddressindex_to_p2abytes.iter(); + vecs.p2wshaddressindex_to_p2wshbytes.iter()?; + let mut p2traddressindex_to_p2trbytes_iter = + vecs.p2traddressindex_to_p2trbytes.iter()?; + let mut p2aaddressindex_to_p2abytes_iter = vecs.p2aaddressindex_to_p2abytes.iter()?; let unknown = pools.get_unknown(); @@ -56,50 +58,45 @@ fn main() -> Result<()> { .height_to_coinbase_tag .iter() .for_each(|(height, coinbase_tag)| { - let txindex = height_to_first_txindex_iter.unwrap_get_inner(height); - let txoutindex = txindex_to_first_txoutindex_iter.unwrap_get_inner(txindex); - let outputcount = txindex_to_output_count_iter.unwrap_get_inner(txindex); + let txindex = height_to_first_txindex_iter.get_unwrap(height); + let txoutindex = txindex_to_first_txoutindex_iter.get_unwrap(txindex); + let outputcount = txindex_to_output_count_iter.get_unwrap(txindex); let pool = (*txoutindex..(*txoutindex + *outputcount)) .map(TxOutIndex::from) .find_map(|txoutindex| { - let outputtype = - txoutindex_to_outputtype_iter.unwrap_get_inner(txoutindex); - let typeindex = - txoutindex_to_typeindex_iter.unwrap_get_inner(txoutindex); + let outputtype = txoutindex_to_outputtype_iter.get_unwrap(txoutindex); + let typeindex = txoutindex_to_typeindex_iter.get_unwrap(txoutindex); match outputtype { OutputType::P2PK65 => Some(AddressBytes::from( p2pk65addressindex_to_p2pk65bytes_iter - .unwrap_get_inner(typeindex.into()), + .get_unwrap(typeindex.into()), )), OutputType::P2PK33 => Some(AddressBytes::from( p2pk33addressindex_to_p2pk33bytes_iter - .unwrap_get_inner(typeindex.into()), + .get_unwrap(typeindex.into()), )), OutputType::P2PKH => Some(AddressBytes::from( p2pkhaddressindex_to_p2pkhbytes_iter - .unwrap_get_inner(typeindex.into()), + .get_unwrap(typeindex.into()), )), OutputType::P2SH => Some(AddressBytes::from( - p2shaddressindex_to_p2shbytes_iter - .unwrap_get_inner(typeindex.into()), + p2shaddressindex_to_p2shbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2WPKH => Some(AddressBytes::from( p2wpkhaddressindex_to_p2wpkhbytes_iter - .unwrap_get_inner(typeindex.into()), + .get_unwrap(typeindex.into()), )), OutputType::P2WSH => Some(AddressBytes::from( p2wshaddressindex_to_p2wshbytes_iter - .unwrap_get_inner(typeindex.into()), + .get_unwrap(typeindex.into()), )), OutputType::P2TR => Some(AddressBytes::from( - p2traddressindex_to_p2trbytes_iter - .unwrap_get_inner(typeindex.into()), + p2traddressindex_to_p2trbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2A => Some(AddressBytes::from( - p2aaddressindex_to_p2abytes_iter - .unwrap_get_inner(typeindex.into()), + p2aaddressindex_to_p2abytes_iter.get_unwrap(typeindex.into()), )), _ => None, } diff --git a/crates/brk_computer/src/chain.rs b/crates/brk_computer/src/chain.rs index 1475d7c52..aba9cf41d 100644 --- a/crates/brk_computer/src/chain.rs +++ b/crates/brk_computer/src/chain.rs @@ -1,6 +1,5 @@ use std::path::Path; -use allocative::Allocative; use brk_error::Result; use brk_indexer::Indexer; use brk_traversable::Traversable; @@ -12,7 +11,7 @@ use brk_types::{ }; use vecdb::{ AnyCloneableIterableVec, AnyIterableVec, Database, EagerVec, Exit, LazyVecFrom1, LazyVecFrom2, - LazyVecFrom3, PAGE_SIZE, StoredIndex, VecIterator, VecIteratorExtended, + LazyVecFrom3, PAGE_SIZE, StoredIndex, VecIteratorExtended, }; use crate::grouped::{ @@ -33,7 +32,7 @@ const TARGET_BLOCKS_PER_YEAR: u64 = 2 * TARGET_BLOCKS_PER_SEMESTER; const TARGET_BLOCKS_PER_DECADE: u64 = 10 * TARGET_BLOCKS_PER_YEAR; const ONE_TERA_HASH: f64 = 1_000_000_000_000.0; -#[derive(Clone, Traversable, Allocative)] +#[derive(Clone, Traversable)] pub struct Vecs { db: Database, @@ -168,16 +167,14 @@ impl Vecs { indexer.vecs.txindex_to_total_size.boxed_clone(), |index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| { let index = index.to_usize(); - txindex_to_base_size_iter - .next_at(index) - .map(|(_, base_size)| { - let total_size = txindex_to_total_size_iter.next_at(index).unwrap().1; + txindex_to_base_size_iter.get_at(index).map(|base_size| { + let total_size = txindex_to_total_size_iter.get_at_unwrap(index); - // This is the exact definition of a weight unit, as defined by BIP-141 (quote above). - let wu = usize::from(base_size) * 3 + usize::from(total_size); + // This is the exact definition of a weight unit, as defined by BIP-141 (quote above). + let wu = usize::from(base_size) * 3 + usize::from(total_size); - Weight::from(bitcoin::Weight::from_wu_usize(wu)) - }) + Weight::from(bitcoin::Weight::from_wu_usize(wu)) + }) }, ); @@ -186,8 +183,7 @@ impl Vecs { version + Version::ZERO, txindex_to_weight.boxed_clone(), |index: TxIndex, iter| { - let index = index.to_usize(); - iter.next_at(index).map(|(_, weight)| { + iter.get(index).map(|weight| { StoredU64::from(bitcoin::Weight::from(weight).to_vbytes_ceil() as usize) }) }, @@ -199,15 +195,10 @@ impl Vecs { indexer.vecs.txindex_to_height.boxed_clone(), indexer.vecs.height_to_first_txindex.boxed_clone(), |index: TxIndex, txindex_to_height_iter, height_to_first_txindex_iter| { - txindex_to_height_iter - .next_at(index.to_usize()) - .map(|(_, height)| { - let txindex = height_to_first_txindex_iter - .next_at(height.to_usize()) - .unwrap() - .1; - StoredBool::from(index == txindex) - }) + txindex_to_height_iter.get(index).map(|height| { + let txindex = height_to_first_txindex_iter.get_unwrap(height); + StoredBool::from(index == txindex) + }) }, ); @@ -223,13 +214,13 @@ impl Vecs { txinindex_to_value_iter| { let txindex = index.to_usize(); txindex_to_first_txinindex_iter - .next_at(txindex) - .map(|(_, first_index)| { + .get_at(txindex) + .map(|first_index| { let first_index = usize::from(first_index); - let count = *txindex_to_input_count_iter.next_at(txindex).unwrap().1; + let count = *txindex_to_input_count_iter.get_at_unwrap(txindex); let range = first_index..first_index + count as usize; range.into_iter().fold(Sats::ZERO, |total, txinindex| { - total + txinindex_to_value_iter.next_at(txinindex).unwrap().1 + total + txinindex_to_value_iter.get_at_unwrap(txinindex) }) }) }, @@ -261,13 +252,13 @@ impl Vecs { txoutindex_to_value_iter| { let txindex = index.to_usize(); txindex_to_first_txoutindex_iter - .next_at(txindex) - .map(|(_, first_index)| { + .get_at(txindex) + .map(|first_index| { let first_index = usize::from(first_index); - let count = *txindex_to_output_count_iter.next_at(txindex).unwrap().1; + let count = *txindex_to_output_count_iter.get_at_unwrap(txindex); let range = first_index..first_index + count as usize; range.into_iter().fold(Sats::ZERO, |total, txoutindex| { - let v = txoutindex_to_value_iter.next_at(txoutindex).unwrap().1; + let v = txoutindex_to_value_iter.get_at_unwrap(txoutindex); total + v }) }) @@ -1152,7 +1143,7 @@ impl Vecs { starting_indexes.height, &indexes.height_to_timestamp_fixed, |(h, t, ..)| { - while t.difference_in_days_between(height_to_timestamp_fixed_iter.unsafe_get(prev)) + while t.difference_in_days_between(height_to_timestamp_fixed_iter.get_unwrap(prev)) > 0 { prev.increment(); @@ -1209,13 +1200,13 @@ impl Vecs { Ok(()) })?; - let mut height_to_timestamp_iter = indexer.vecs.height_to_timestamp.iter(); + let mut height_to_timestamp_iter = indexer.vecs.height_to_timestamp.iter()?; self.height_to_interval.compute_transform( starting_indexes.height, &indexer.vecs.height_to_timestamp, |(height, timestamp, ..)| { let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| { - let prev_timestamp = height_to_timestamp_iter.unsafe_get(prev_h); + let prev_timestamp = height_to_timestamp_iter.get_unwrap(prev_h); timestamp .checked_sub(prev_timestamp) .unwrap_or(Timestamp::ZERO) @@ -1270,14 +1261,14 @@ impl Vecs { self.difficultyepoch_to_timestamp.compute_transform( starting_indexes.difficultyepoch, &indexes.difficultyepoch_to_first_height, - |(i, h, ..)| (i, height_to_timestamp_iter.unsafe_get(h)), + |(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)), exit, )?; self.halvingepoch_to_timestamp.compute_transform( starting_indexes.halvingepoch, &indexes.halvingepoch_to_first_height, - |(i, h, ..)| (i, height_to_timestamp_iter.unsafe_get(h)), + |(i, h, ..)| (i, height_to_timestamp_iter.get_unwrap(h)), exit, )?; @@ -1292,7 +1283,7 @@ impl Vecs { ( di, height_to_difficultyepoch_iter - .unsafe_get(height + (*height_count_iter.unsafe_get(di) - 1)), + .get_unwrap(height + (*height_count_iter.get_unwrap(di) - 1)), ) }, exit, @@ -1311,7 +1302,7 @@ impl Vecs { ( di, height_to_halvingepoch_iter - .unsafe_get(height + (*height_count_iter.unsafe_get(di) - 1)), + .get_unwrap(height + (*height_count_iter.get_unwrap(di) - 1)), ) }, exit, @@ -1355,14 +1346,14 @@ impl Vecs { let compute_indexes_to_tx_vany = |indexes_to_tx_vany: &mut ComputedVecsFromHeight, txversion| { - let mut txindex_to_txversion_iter = indexer.vecs.txindex_to_txversion.iter(); + let mut txindex_to_txversion_iter = indexer.vecs.txindex_to_txversion.iter()?; indexes_to_tx_vany.compute_all(indexes, starting_indexes, exit, |vec| { vec.compute_filtered_count_from_indexes( starting_indexes.height, &indexer.vecs.height_to_first_txindex, &indexer.vecs.txindex_to_txid, |txindex| { - let v = txindex_to_txversion_iter.unsafe_get(txindex); + let v = txindex_to_txversion_iter.get_unwrap(txindex); v == txversion }, exit, @@ -1382,7 +1373,7 @@ impl Vecs { let value = if txoutindex == TxOutIndex::COINBASE { Sats::MAX } else { - txoutindex_to_value_iter.unsafe_get(txoutindex) + txoutindex_to_value_iter.get_unwrap(txoutindex) }; (txinindex, value) }, @@ -1392,13 +1383,13 @@ impl Vecs { // indexes.txinindex_to_txoutindex.boxed_clone(), // indexer.vecs.txoutindex_to_value.boxed_clone(), // |index: TxInIndex, txinindex_to_txoutindex_iter, txoutindex_to_value_iter| { - // txinindex_to_txoutindex_iter.next_at(index.to_usize()).map( + // txinindex_to_txoutindex_iter.get_unwrap(index.to_usize()).map( // |(txinindex, txoutindex)| { // let txoutindex = txoutindex; // if txoutindex == TxOutIndex::COINBASE { // Sats::MAX // } else if let Some((_, value)) = - // txoutindex_to_value_iter.next_at(txoutindex.to_usize()) + // txoutindex_to_value_iter.get_unwrap(txoutindex.to_usize()) // { // value // } else { @@ -1514,22 +1505,22 @@ impl Vecs { self.indexes_to_coinbase .compute_all(indexes, price, starting_indexes, exit, |vec| { let mut txindex_to_first_txoutindex_iter = - indexer.vecs.txindex_to_first_txoutindex.iter(); + indexer.vecs.txindex_to_first_txoutindex.iter()?; let mut txindex_to_output_count_iter = indexes.txindex_to_output_count.iter(); - let mut txoutindex_to_value_iter = indexer.vecs.txoutindex_to_value.iter(); + let mut txoutindex_to_value_iter = indexer.vecs.txoutindex_to_value.iter()?; vec.compute_transform( starting_indexes.height, &indexer.vecs.height_to_first_txindex, |(height, txindex, ..)| { let first_txoutindex = txindex_to_first_txoutindex_iter - .unsafe_get(txindex) + .get_unwrap(txindex) .to_usize(); - let output_count = txindex_to_output_count_iter.unsafe_get(txindex); + let output_count = txindex_to_output_count_iter.get_unwrap(txindex); let mut sats = Sats::ZERO; (first_txoutindex..first_txoutindex + usize::from(output_count)).for_each( |txoutindex| { sats += txoutindex_to_value_iter - .unsafe_get(TxOutIndex::from(txoutindex)); + .get_unwrap(TxOutIndex::from(txoutindex)); }, ); (height, sats) @@ -1553,7 +1544,7 @@ impl Vecs { let range = *h - (*count - 1)..=*h; let sum = range .map(Height::from) - .map(|h| height_to_coinbase_iter.unsafe_get(h)) + .map(|h| height_to_coinbase_iter.get_unwrap(h)) .sum::(); (h, sum) }, @@ -1572,7 +1563,7 @@ impl Vecs { let range = *h - (*count - 1)..=*h; let sum = range .map(Height::from) - .map(|h| height_to_coinbase_iter.unsafe_get(h)) + .map(|h| height_to_coinbase_iter.get_unwrap(h)) .sum::(); (h, sum) }, @@ -1590,7 +1581,7 @@ impl Vecs { starting_indexes.height, self.indexes_to_coinbase.sats.height.as_ref().unwrap(), |(height, coinbase, ..)| { - let fees = indexes_to_fee_sum_iter.unsafe_get(height); + let fees = indexes_to_fee_sum_iter.get_unwrap(height); (height, coinbase.checked_sub(fees).unwrap()) }, exit, @@ -1784,8 +1775,8 @@ impl Vecs { starting_indexes.height, self.indexes_to_output_count.height.unwrap_cumulative(), |(h, output_count, ..)| { - let input_count = input_count_iter.unsafe_get(h); - let opreturn_count = opreturn_count_iter.unsafe_get(h); + let input_count = input_count_iter.get_unwrap(h); + let opreturn_count = opreturn_count_iter.get_unwrap(h); let block_count = u64::from(h + 1_usize); // -1 > genesis output is unspendable let mut utxo_count = diff --git a/crates/brk_computer/src/cointime.rs b/crates/brk_computer/src/cointime.rs index 933fe293a..a386a9e2a 100644 --- a/crates/brk_computer/src/cointime.rs +++ b/crates/brk_computer/src/cointime.rs @@ -3,7 +3,7 @@ use std::path::Path; use brk_error::Result; use brk_traversable::Traversable; use brk_types::{Bitcoin, CheckedSub, Dollars, StoredF32, StoredF64, Version}; -use vecdb::{Database, Exit, PAGE_SIZE, VecIterator}; +use vecdb::{Database, Exit, PAGE_SIZE, VecIteratorExtended}; use crate::grouped::ComputedVecsFromDateIndex; @@ -339,7 +339,7 @@ impl Vecs { starting_indexes.height, self.indexes_to_coinblocks_created.height.as_ref().unwrap(), |(i, created, ..)| { - let destroyed = coinblocks_destroyed_iter.unsafe_get(i); + let destroyed = coinblocks_destroyed_iter.get_unwrap(i); (i, created.checked_sub(destroyed).unwrap()) }, exit, diff --git a/crates/brk_computer/src/fetched.rs b/crates/brk_computer/src/fetched.rs index 4d8cf30e3..ec087788c 100644 --- a/crates/brk_computer/src/fetched.rs +++ b/crates/brk_computer/src/fetched.rs @@ -87,7 +87,7 @@ impl Vecs { i.into(), v, i.decremented().map(|prev_i| { - height_to_timestamp.into_iter().get_unwrap_at(prev_i) + height_to_timestamp.into_iter().get_at_unwrap(prev_i) }), ) .unwrap(), @@ -112,7 +112,7 @@ impl Vecs { prev.replace(if i > 0 { self.dateindex_to_price_ohlc_in_cents .into_iter() - .get_unwrap_at(i - 1) + .get_at_unwrap(i - 1) } else { OHLCCents::default() }); diff --git a/crates/brk_computer/src/grouped/builder_eager.rs b/crates/brk_computer/src/grouped/builder_eager.rs index a372d864e..0bbf11e32 100644 --- a/crates/brk_computer/src/grouped/builder_eager.rs +++ b/crates/brk_computer/src/grouped/builder_eager.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_error::{Error, Result}; use brk_traversable::Traversable; use brk_types::{CheckedSub, StoredU64, Version}; @@ -11,7 +10,7 @@ use crate::utils::get_percentile; use super::ComputedType; -#[derive(Clone, Debug, Traversable, Allocative)] +#[derive(Clone, Debug, Traversable)] pub struct EagerVecsBuilder where I: StoredIndex, @@ -219,11 +218,11 @@ where let cumulative_vec = self.cumulative.as_mut().unwrap(); let mut cumulative = index.decremented().map_or(T::from(0_usize), |index| { - cumulative_vec.iter().unsafe_get(index) + cumulative_vec.iter().get_unwrap(index) }); source .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, v)| -> Result<()> { cumulative += v; @@ -260,17 +259,20 @@ where let mut cumulative = cumulative_vec.map(|cumulative_vec| { index.decremented().map_or(T::from(0_usize), |index| { - cumulative_vec.iter().unsafe_get(index) + cumulative_vec.iter().get_unwrap(index) }) }); - first_indexes.iter().skip(index).enumerate().try_for_each( - |(index, first_index)| -> Result<()> { - let count_index = count_indexes_iter.unsafe_get(index); + first_indexes + .iter() + .skip(index.to_usize()) + .enumerate() + .try_for_each(|(index, first_index)| -> Result<()> { + let count_index = count_indexes_iter.get_at_unwrap(index); if let Some(first) = self.first.as_mut() { let f = source_iter - .get_inner(first_index) + .get(first_index) .unwrap_or_else(|| T::from(0_usize)); first.forced_push_at(index, f, exit)?; } @@ -281,7 +283,7 @@ where panic!("should compute last if count can be 0") } let last_index = first_index + (count_index - 1); - let v = source_iter.unsafe_get(last_index); + let v = source_iter.get_unwrap(last_index); // .context("to work") // .inspect_err(|_| { // dbg!(first_index, count_index, last_index); @@ -304,10 +306,9 @@ where let needs_values = needs_sorted || needs_average_sum_or_cumulative; if needs_values { - source_iter.set(first_index); + source_iter.set_position(first_index); let mut values = (&mut source_iter) .take(*count_index as usize) - .map(|(_, v)| v) .collect::>(); if needs_sorted { @@ -385,8 +386,7 @@ where } Ok(()) - }, - )?; + })?; self.safe_flush(exit)?; @@ -431,16 +431,19 @@ where let mut cumulative = self.cumulative.as_mut().map(|cumulative_vec| { index.decremented().map_or(T::from(0_usize), |index| { - cumulative_vec.iter().unsafe_get(index) + cumulative_vec.iter().get_unwrap(index) }) }); - first_indexes.iter().skip(index).enumerate().try_for_each( - |(index, first_index, ..)| -> Result<()> { - let count_index = count_indexes_iter.unsafe_get(index); + first_indexes + .iter() + .skip(index.to_usize()) + .enumerate() + .try_for_each(|(index, first_index, ..)| -> Result<()> { + let count_index = count_indexes_iter.get_at_unwrap(index); if let Some(first) = self.first.as_mut() { - let v = source_first_iter.as_mut().unwrap().unsafe_get(first_index); + let v = source_first_iter.as_mut().unwrap().get_unwrap(first_index); first.forced_push_at(index, v, exit)?; } @@ -450,7 +453,7 @@ where panic!("should compute last if count can be 0") } let last_index = first_index + (count_index - 1); - let v = source_last_iter.as_mut().unwrap().unsafe_get(last_index); + let v = source_last_iter.as_mut().unwrap().get_unwrap(last_index); last.forced_push_at(index, v, exit)?; } @@ -464,10 +467,9 @@ where if needs_sorted { if let Some(max) = self.max.as_mut() { let source_max_iter = source_max_iter.as_mut().unwrap(); - source_max_iter.set(first_index); + source_max_iter.set_position(first_index); let mut values = source_max_iter .take(*count_index as usize) - .map(|(_, v)| v) .collect::>(); values.sort_unstable(); max.forced_push_at(index, *values.last().unwrap(), exit)?; @@ -475,10 +477,9 @@ where if let Some(min) = self.min.as_mut() { let source_min_iter = source_min_iter.as_mut().unwrap(); - source_min_iter.set(first_index); + source_min_iter.set_position(first_index); let mut values = source_min_iter .take(*count_index as usize) - .map(|(_, v)| v) .collect::>(); values.sort_unstable(); min.forced_push_at(index, *values.first().unwrap(), exit)?; @@ -488,10 +489,9 @@ where if needs_average_sum_or_cumulative { if let Some(average) = self.average.as_mut() { let source_average_iter = source_average_iter.as_mut().unwrap(); - source_average_iter.set(first_index); + source_average_iter.set_position(first_index); let values = source_average_iter .take(*count_index as usize) - .map(|(_, v)| v) .collect::>(); let len = values.len(); @@ -504,10 +504,9 @@ where if needs_sum_or_cumulative { let source_sum_iter = source_sum_iter.as_mut().unwrap(); - source_sum_iter.set(first_index); + source_sum_iter.set_position(first_index); let values = source_sum_iter .take(*count_index as usize) - .map(|(_, v)| v) .collect::>(); let sum = values.into_iter().fold(T::from(0), |a, b| a + b); @@ -526,8 +525,7 @@ where } Ok(()) - }, - )?; + })?; self.safe_flush(exit)?; diff --git a/crates/brk_computer/src/grouped/builder_lazy.rs b/crates/brk_computer/src/grouped/builder_lazy.rs index 08192cb0b..e550534f9 100644 --- a/crates/brk_computer/src/grouped/builder_lazy.rs +++ b/crates/brk_computer/src/grouped/builder_lazy.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_traversable::Traversable; use brk_types::Version; use vecdb::{ @@ -10,7 +9,7 @@ use crate::grouped::{EagerVecsBuilder, VecBuilderOptions}; use super::ComputedType; #[allow(clippy::type_complexity)] -#[derive(Clone, Traversable, Allocative)] +#[derive(Clone, Traversable)] pub struct LazyVecsBuilder where I: StoredIndex, @@ -71,7 +70,7 @@ where if i.to_usize() >= len_source.len() { return None; } - source.next_at(S1I::min_from(i)).map(|(_, v)| v) + source.get_at(S1I::min_from(i)) }, )) }), @@ -96,9 +95,7 @@ where if i.to_usize() >= len_source.len() { return None; } - source - .next_at(S1I::max_from(i, source.len())) - .map(|(_, v)| v) + source.get_at(S1I::max_from(i, source.len())) }, )) }), @@ -116,7 +113,7 @@ where return None; } S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, v)| v)) + .flat_map(|i| source.get_at(i)) .min() }, )) @@ -135,7 +132,7 @@ where return None; } S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, v)| v)) + .flat_map(|i| source.get_at(i)) .max() }, )) @@ -154,7 +151,7 @@ where return None; } let vec = S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, v)| v)) + .flat_map(|i| source.get_at(i)) .collect::>(); if vec.is_empty() { return None; @@ -184,7 +181,7 @@ where return None; } let vec = S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, v)| v)) + .flat_map(|i| source.get_at(i)) .collect::>(); if vec.is_empty() { return None; @@ -205,9 +202,7 @@ where if i.to_usize() >= len_source.len() { return None; } - source - .next_at(S1I::max_from(i, source.len())) - .map(|(_, v)| v) + source.get_at(S1I::max_from(i, source.len())) }, )) }), diff --git a/crates/brk_computer/src/grouped/from_dateindex.rs b/crates/brk_computer/src/grouped/from_dateindex.rs index 4c07b0bb3..8fe01bbeb 100644 --- a/crates/brk_computer/src/grouped/from_dateindex.rs +++ b/crates/brk_computer/src/grouped/from_dateindex.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_error::Result; use brk_traversable::Traversable; @@ -11,7 +10,7 @@ use crate::{Indexes, grouped::LazyVecsBuilder, indexes}; use super::{ComputedType, EagerVecsBuilder, Source, VecBuilderOptions}; -#[derive(Clone, Allocative)] +#[derive(Clone)] pub struct ComputedVecsFromDateIndex where T: ComputedType + PartialOrd, diff --git a/crates/brk_computer/src/grouped/from_height.rs b/crates/brk_computer/src/grouped/from_height.rs index b712bef1f..f9a146d11 100644 --- a/crates/brk_computer/src/grouped/from_height.rs +++ b/crates/brk_computer/src/grouped/from_height.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_error::Result; use brk_traversable::Traversable; @@ -16,7 +15,7 @@ use crate::{ use super::{ComputedType, EagerVecsBuilder, VecBuilderOptions}; -#[derive(Clone, Allocative)] +#[derive(Clone)] pub struct ComputedVecsFromHeight where T: ComputedType + PartialOrd, diff --git a/crates/brk_computer/src/grouped/from_txindex.rs b/crates/brk_computer/src/grouped/from_txindex.rs index cfd8e5eeb..684f36b83 100644 --- a/crates/brk_computer/src/grouped/from_txindex.rs +++ b/crates/brk_computer/src/grouped/from_txindex.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_error::Result; use brk_indexer::Indexer; use brk_traversable::Traversable; @@ -8,7 +7,7 @@ use brk_types::{ }; use vecdb::{ AnyCloneableIterableVec, AnyVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec, - StoredIndex, VecIterator, + StoredIndex, VecIteratorExtended, }; use crate::{ @@ -19,7 +18,7 @@ use crate::{ use super::{ComputedType, EagerVecsBuilder, VecBuilderOptions}; -#[derive(Clone, Allocative)] +#[derive(Clone)] pub struct ComputedVecsFromTxindex where T: ComputedType + PartialOrd, @@ -253,90 +252,90 @@ impl ComputedVecsFromTxindex { .map(Height::from) .try_for_each(|height| -> Result<()> { if let Some(first) = self.height.first.as_mut() { - first.forced_push_at( + first.forced_push( height, - Bitcoin::from(sats.height.unwrap_first().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_first().into_iter().get_unwrap(height)), exit, )?; } if let Some(average) = self.height.average.as_mut() { - average.forced_push_at( + average.forced_push( height, - Bitcoin::from(sats.height.unwrap_average().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_average().into_iter().get_unwrap(height)), exit, )?; } if let Some(sum) = self.height.sum.as_mut() { - sum.forced_push_at( + sum.forced_push( height, - Bitcoin::from(sats.height.unwrap_sum().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_sum().into_iter().get_unwrap(height)), exit, )?; } if let Some(max) = self.height.max.as_mut() { - max.forced_push_at( + max.forced_push( height, - Bitcoin::from(sats.height.unwrap_max().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_max().into_iter().get_unwrap(height)), exit, )?; } if let Some(pct90) = self.height.pct90.as_mut() { - pct90.forced_push_at( + pct90.forced_push( height, - Bitcoin::from(sats.height.unwrap_pct90().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_pct90().into_iter().get_unwrap(height)), exit, )?; } if let Some(pct75) = self.height.pct75.as_mut() { - pct75.forced_push_at( + pct75.forced_push( height, - Bitcoin::from(sats.height.unwrap_pct75().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_pct75().into_iter().get_unwrap(height)), exit, )?; } if let Some(median) = self.height.median.as_mut() { - median.forced_push_at( + median.forced_push( height, - Bitcoin::from(sats.height.unwrap_median().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_median().into_iter().get_unwrap(height)), exit, )?; } if let Some(pct25) = self.height.pct25.as_mut() { - pct25.forced_push_at( + pct25.forced_push( height, - Bitcoin::from(sats.height.unwrap_pct25().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_pct25().into_iter().get_unwrap(height)), exit, )?; } if let Some(pct10) = self.height.pct10.as_mut() { - pct10.forced_push_at( + pct10.forced_push( height, - Bitcoin::from(sats.height.unwrap_pct10().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_pct10().into_iter().get_unwrap(height)), exit, )?; } if let Some(min) = self.height.min.as_mut() { - min.forced_push_at( + min.forced_push( height, - Bitcoin::from(sats.height.unwrap_min().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_min().into_iter().get_unwrap(height)), exit, )?; } if let Some(last) = self.height.last.as_mut() { - last.forced_push_at( + last.forced_push( height, - Bitcoin::from(sats.height.unwrap_last().into_iter().unsafe_get(height)), + Bitcoin::from(sats.height.unwrap_last().into_iter().get_unwrap(height)), exit, )?; } if let Some(cumulative) = self.height.cumulative.as_mut() { - cumulative.forced_push_at( + cumulative.forced_push( height, Bitcoin::from( sats.height .unwrap_cumulative() .into_iter() - .unsafe_get(height), + .get_unwrap(height), ), exit, )?; @@ -378,104 +377,104 @@ impl ComputedVecsFromTxindex { (starting_index.to_usize()..indexer.vecs.height_to_weight.len()) .map(Height::from) .try_for_each(|height| -> Result<()> { - let price = *close_iter.unsafe_get(height); + let price = *close_iter.get_unwrap(height); if let Some(first) = self.height.first.as_mut() { - first.forced_push_at( + first.forced_push( height, - price * bitcoin.height.unwrap_first().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_first().into_iter().get_unwrap(height), exit, )?; } if let Some(average) = self.height.average.as_mut() { - average.forced_push_at( + average.forced_push( height, price * bitcoin .height .unwrap_average() .into_iter() - .unsafe_get(height), + .get_unwrap(height), exit, )?; } if let Some(sum) = self.height.sum.as_mut() { - sum.forced_push_at( + sum.forced_push( height, - price * bitcoin.height.unwrap_sum().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_sum().into_iter().get_unwrap(height), exit, )?; } if let Some(max) = self.height.max.as_mut() { - max.forced_push_at( + max.forced_push( height, - price * bitcoin.height.unwrap_max().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_max().into_iter().get_unwrap(height), exit, )?; } if let Some(pct90) = self.height.pct90.as_mut() { - pct90.forced_push_at( + pct90.forced_push( height, - price * bitcoin.height.unwrap_pct90().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_pct90().into_iter().get_unwrap(height), exit, )?; } if let Some(pct75) = self.height.pct75.as_mut() { - pct75.forced_push_at( + pct75.forced_push( height, - price * bitcoin.height.unwrap_pct75().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_pct75().into_iter().get_unwrap(height), exit, )?; } if let Some(median) = self.height.median.as_mut() { - median.forced_push_at( + median.forced_push( height, price * bitcoin .height .unwrap_median() .into_iter() - .unsafe_get(height), + .get_unwrap(height), exit, )?; } if let Some(pct25) = self.height.pct25.as_mut() { - pct25.forced_push_at( + pct25.forced_push( height, - price * bitcoin.height.unwrap_pct25().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_pct25().into_iter().get_unwrap(height), exit, )?; } if let Some(pct10) = self.height.pct10.as_mut() { - pct10.forced_push_at( + pct10.forced_push( height, - price * bitcoin.height.unwrap_pct10().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_pct10().into_iter().get_unwrap(height), exit, )?; } if let Some(min) = self.height.min.as_mut() { - min.forced_push_at( + min.forced_push( height, - price * bitcoin.height.unwrap_min().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_min().into_iter().get_unwrap(height), exit, )?; } if let Some(last) = self.height.last.as_mut() { - last.forced_push_at( + last.forced_push( height, - price * bitcoin.height.unwrap_last().into_iter().unsafe_get(height), + price * bitcoin.height.unwrap_last().into_iter().get_unwrap(height), exit, )?; } if let Some(cumulative) = self.height.cumulative.as_mut() { - cumulative.forced_push_at( + cumulative.forced_push( height, price * bitcoin .height .unwrap_cumulative() .into_iter() - .unsafe_get(height), + .get_unwrap(height), exit, )?; } diff --git a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs index 4cf49ed42..70fd58cab 100644 --- a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::{Date, DateIndex, Dollars, StoredF32, Version}; use vecdb::{ AnyIterableVec, AnyStoredVec, AnyVec, CollectableVec, Database, EagerVec, Exit, - GenericStoredVec, StoredIndex, VecIterator, + GenericStoredVec, StoredIndex, VecIteratorExtended, }; use crate::{ @@ -383,8 +383,10 @@ impl ComputedRatioVecsFromDateIndex { .unwrap() .min(starting_indexes.dateindex); + let min_ratio_date_usize = min_ratio_date.to_usize(); + let mut sorted = self.ratio.dateindex.as_ref().unwrap().collect_range( - Some(min_ratio_date.to_usize()), + Some(min_ratio_date_usize), Some(starting_dateindex.to_usize()), ); @@ -395,10 +397,10 @@ impl ComputedRatioVecsFromDateIndex { .as_ref() .unwrap() .iter() - .skip(starting_dateindex) + .skip(starting_dateindex.to_usize()) .enumerate() .try_for_each(|(index, ratio)| -> Result<()> { - if index < min_ratio_date { + if index < min_ratio_date_usize { self.ratio_pct5 .as_mut() .unwrap() @@ -547,7 +549,7 @@ impl ComputedRatioVecsFromDateIndex { starting_indexes.dateindex, date_to_price, |(i, price, ..)| { - let multiplier = iter.unsafe_get(i); + let multiplier = iter.get_unwrap(i); (i, price * multiplier) }, exit, @@ -564,7 +566,7 @@ impl ComputedRatioVecsFromDateIndex { starting_indexes.dateindex, date_to_price, |(i, price, ..)| { - let multiplier = iter.unsafe_get(i); + let multiplier = iter.get_unwrap(i); (i, price * multiplier) }, exit, diff --git a/crates/brk_computer/src/grouped/sd_from_dateindex.rs b/crates/brk_computer/src/grouped/sd_from_dateindex.rs index bb2e6933b..0e2be20b0 100644 --- a/crates/brk_computer/src/grouped/sd_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/sd_from_dateindex.rs @@ -1,6 +1,6 @@ use brk_error::Result; use brk_traversable::Traversable; -use brk_types::{CheckedSub, Date, DateIndex, Dollars, StoredF32, Version}; +use brk_types::{Date, DateIndex, Dollars, StoredF32, Version}; use vecdb::{ AnyIterableVec, AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec, Exit, GenericStoredVec, StoredIndex, @@ -498,12 +498,14 @@ impl ComputedStandardDeviationVecsFromDateIndex { let mut m2_5sd = self.m2_5sd.as_mut().map(|c| c.dateindex.as_mut().unwrap()); let mut m3sd = self.m3sd.as_mut().map(|c| c.dateindex.as_mut().unwrap()); + let min_date_usize = min_date.to_usize(); + source .iter() - .skip(starting_dateindex) + .skip(starting_dateindex.to_usize()) .enumerate() .try_for_each(|(index, ratio)| -> Result<()> { - if index < min_date { + if index < min_date_usize { self.sd.dateindex.as_mut().unwrap().forced_push_at( index, StoredF32::NAN, @@ -550,9 +552,10 @@ impl ComputedStandardDeviationVecsFromDateIndex { let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos); sorted.insert(pos, ratio); - let avg = sma_iter.unsafe_get(index); + let avg = sma_iter.get_at_unwrap(index); - let population = index.checked_sub(min_date).unwrap().to_usize() as f32 + 1.0; + let population = + index.checked_sub(min_date_usize).unwrap().to_usize() as f32 + 1.0; let sd = StoredF32::from( (sorted.iter().map(|v| (**v - *avg).powi(2)).sum::() / population) @@ -639,7 +642,7 @@ impl ComputedStandardDeviationVecsFromDateIndex { starting_indexes.dateindex, price, |(i, price, ..)| { - let multiplier = iter.unsafe_get(i); + let multiplier = iter.get_unwrap(i); (i, price * multiplier) }, exit, diff --git a/crates/brk_computer/src/grouped/value_from_height.rs b/crates/brk_computer/src/grouped/value_from_height.rs index 02c74576d..ce1b771dd 100644 --- a/crates/brk_computer/src/grouped/value_from_height.rs +++ b/crates/brk_computer/src/grouped/value_from_height.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_error::Result; use brk_traversable::Traversable; use brk_types::{Bitcoin, Dollars, Height, Sats, Version}; @@ -13,7 +12,7 @@ use crate::{ use super::{ComputedVecsFromHeight, VecBuilderOptions}; -#[derive(Clone, Traversable, Allocative)] +#[derive(Clone, Traversable)] pub struct ComputedValueVecsFromHeight { pub sats: ComputedVecsFromHeight, pub bitcoin: ComputedVecsFromHeight, diff --git a/crates/brk_computer/src/grouped/value_from_txindex.rs b/crates/brk_computer/src/grouped/value_from_txindex.rs index c6985da6c..96c4791cc 100644 --- a/crates/brk_computer/src/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/grouped/value_from_txindex.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use brk_error::Result; use brk_indexer::Indexer; use brk_traversable::Traversable; @@ -12,7 +11,7 @@ use crate::{Indexes, grouped::Source, indexes, price}; use super::{ComputedVecsFromTxindex, VecBuilderOptions}; -#[derive(Clone, Traversable, Allocative)] +#[derive(Clone, Traversable)] pub struct ComputedValueVecsFromTxindex { pub sats: ComputedVecsFromTxindex, pub bitcoin_txindex: LazyVecFrom1, @@ -59,8 +58,8 @@ impl ComputedValueVecsFromTxindex { version + VERSION, source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s), |txindex: TxIndex, iter| { - iter.next_at(txindex.to_usize()) - .map(|(_, sats)| Bitcoin::from(sats)) + iter.get_at(txindex.to_usize()) + .map(|sats| Bitcoin::from(sats)) }, ); @@ -85,14 +84,12 @@ impl ComputedValueVecsFromTxindex { txindex_to_height_iter, height_to_price_close_iter| { let txindex = txindex.to_usize(); - txindex_to_btc_iter.next_at(txindex).and_then(|(_, btc)| { - txindex_to_height_iter - .next_at(txindex) - .and_then(|(_, height)| { - height_to_price_close_iter - .next_at(height.to_usize()) - .map(|(_, close)| *close * btc) - }) + txindex_to_btc_iter.get_at(txindex).and_then(|btc| { + txindex_to_height_iter.get_at(txindex).and_then(|height| { + height_to_price_close_iter + .get_at(height.to_usize()) + .map(|close| *close * btc) + }) }) }, ) diff --git a/crates/brk_computer/src/indexes.rs b/crates/brk_computer/src/indexes.rs index 81d1170e4..1a3cdb7e8 100644 --- a/crates/brk_computer/src/indexes.rs +++ b/crates/brk_computer/src/indexes.rs @@ -123,7 +123,7 @@ impl Vecs { return TxOutIndex::COINBASE; } txindex_to_first_txoutindex_iter - .get_unwrap_at(outpoint.txindex().to_usize()) + .get_at_unwrap(outpoint.txindex().to_usize()) + outpoint.vout() }) }, diff --git a/crates/brk_computer/src/lib.rs b/crates/brk_computer/src/lib.rs index 5cc4a4ab4..7ba6e785f 100644 --- a/crates/brk_computer/src/lib.rs +++ b/crates/brk_computer/src/lib.rs @@ -12,16 +12,16 @@ use log::info; use vecdb::{Exit, Format}; mod blks; -// mod chain; -// mod cointime; -// mod constants; +mod chain; +mod cointime; +mod constants; mod fetched; -// mod grouped; +mod grouped; mod indexes; -// mod market; -// mod pools; -// mod price; -// mod stateful; +mod market; +mod pools; +mod price; +mod stateful; mod states; mod traits; mod utils; @@ -35,15 +35,15 @@ use states::*; #[derive(Clone, Traversable)] pub struct Computer { pub blks: blks::Vecs, - // pub chain: chain::Vecs, - // pub cointime: cointime::Vecs, - // pub constants: constants::Vecs, + pub chain: chain::Vecs, + pub cointime: cointime::Vecs, + pub constants: constants::Vecs, pub fetched: Option, pub indexes: indexes::Vecs, - // pub market: market::Vecs, - // pub pools: pools::Vecs, - // pub price: Option, - // pub stateful: stateful::Vecs, + pub market: market::Vecs, + pub pools: pools::Vecs, + pub price: Option, + pub stateful: stateful::Vecs, } const VERSION: Version = Version::new(4); @@ -81,69 +81,69 @@ impl Computer { Ok((indexes, fetched, blks)) })?; - // let (price, constants, market) = thread::scope(|s| -> Result<_> { - // let constants_handle = big_thread().spawn_scoped(s, || { - // constants::Vecs::forced_import(&computed_path, VERSION, &indexes) - // })?; + let (price, constants, market) = thread::scope(|s| -> Result<_> { + let constants_handle = big_thread().spawn_scoped(s, || { + constants::Vecs::forced_import(&computed_path, VERSION, &indexes) + })?; - // let market_handle = big_thread().spawn_scoped(s, || { - // market::Vecs::forced_import(&computed_path, VERSION, &indexes) - // })?; + let market_handle = big_thread().spawn_scoped(s, || { + market::Vecs::forced_import(&computed_path, VERSION, &indexes) + })?; - // let price = fetched - // .is_some() - // .then(|| price::Vecs::forced_import(&computed_path, VERSION, &indexes).unwrap()); + let price = fetched + .is_some() + .then(|| price::Vecs::forced_import(&computed_path, VERSION, &indexes).unwrap()); - // let constants = constants_handle.join().unwrap()?; - // let market = market_handle.join().unwrap()?; + let constants = constants_handle.join().unwrap()?; + let market = market_handle.join().unwrap()?; - // Ok((price, constants, market)) - // })?; + Ok((price, constants, market)) + })?; - // let (chain, pools, cointime) = thread::scope(|s| -> Result<_> { - // let chain_handle = big_thread().spawn_scoped(s, || { - // chain::Vecs::forced_import( - // &computed_path, - // VERSION, - // indexer, - // &indexes, - // price.as_ref(), - // ) - // })?; + let (chain, pools, cointime) = thread::scope(|s| -> Result<_> { + let chain_handle = big_thread().spawn_scoped(s, || { + chain::Vecs::forced_import( + &computed_path, + VERSION, + indexer, + &indexes, + price.as_ref(), + ) + })?; - // let pools_handle = big_thread().spawn_scoped(s, || { - // pools::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref()) - // })?; + let pools_handle = big_thread().spawn_scoped(s, || { + pools::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref()) + })?; - // let cointime = - // cointime::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())?; + let cointime = + cointime::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())?; - // let chain = chain_handle.join().unwrap()?; - // let pools = pools_handle.join().unwrap()?; + let chain = chain_handle.join().unwrap()?; + let pools = pools_handle.join().unwrap()?; - // Ok((chain, pools, cointime)) - // })?; + Ok((chain, pools, cointime)) + })?; - // // Threads inside - // let stateful = stateful::Vecs::forced_import( - // &computed_path, - // VERSION, - // Format::Compressed, - // &indexes, - // price.as_ref(), - // )?; + // Threads inside + let stateful = stateful::Vecs::forced_import( + &computed_path, + VERSION, + Format::Compressed, + &indexes, + price.as_ref(), + )?; Ok(Self { - // constants, - // market, - // stateful, - // chain, + constants, + market, + stateful, + chain, blks, - // pools, - // cointime, + pools, + cointime, indexes, fetched, - // price, + price, }) } @@ -238,7 +238,7 @@ impl Computer { } // pub fn generate_allocation_files(monitored: &pools::Vecs) -> Result<()> { -// info!("Generating Allocative files..."); +// info!("Generating allocative files..."); // let mut flamegraph = allocative::FlameGraphBuilder::default(); // flamegraph.visit_root(monitored); @@ -265,7 +265,7 @@ impl Computer { // std::fs::write(path.join("warnings.txt"), output.warnings())?; -// info!("Successfully generated Allocative files"); +// info!("Successfully generate allocative files"); // Ok(()) // } diff --git a/crates/brk_computer/src/market.rs b/crates/brk_computer/src/market.rs index 568f0e495..d2fca2106 100644 --- a/crates/brk_computer/src/market.rs +++ b/crates/brk_computer/src/market.rs @@ -4,8 +4,7 @@ use brk_error::Result; use brk_traversable::Traversable; use brk_types::{Date, DateIndex, Dollars, Height, Sats, StoredF32, StoredU16, Version}; use vecdb::{ - Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE, StoredIndex, VecIterator, - VecIteratorExtended, + Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE, StoredIndex, VecIteratorExtended, }; use crate::{ @@ -1594,12 +1593,12 @@ impl Vecs { if prev.is_none() { let i = i.to_usize(); prev.replace(if i > 0 { - slf.one_shot_get_any_or_read_(i - 1).unwrap().unwrap() + slf.get_or_read_at_once(i - 1).unwrap().unwrap() } else { StoredU16::default() }); } - let days = if *high_iter.unsafe_get(i) == ath { + let days = if *high_iter.get_unwrap(i) == ath { StoredU16::default() } else { prev.unwrap() + StoredU16::new(1) @@ -1625,7 +1624,7 @@ impl Vecs { if prev.is_none() { let i = i.to_usize(); prev.replace(if i > 0 { - slf.one_shot_get_any_or_read_(i - 1) + slf.get_or_read_at_unwrap_once(i - 1) } else { StoredU16::ZERO }); diff --git a/crates/brk_computer/src/pools/mod.rs b/crates/brk_computer/src/pools/mod.rs index 04ab7017a..f81905908 100644 --- a/crates/brk_computer/src/pools/mod.rs +++ b/crates/brk_computer/src/pools/mod.rs @@ -1,6 +1,5 @@ use std::{collections::BTreeMap, path::Path}; -use allocative::Allocative; use brk_error::Result; use brk_indexer::Indexer; use brk_store::AnyStore; @@ -9,7 +8,7 @@ use brk_types::{Address, AddressBytes, Height, OutputType, PoolId, Pools, TxOutI use rayon::prelude::*; use vecdb::{ AnyIterableVec, AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, PAGE_SIZE, RawVec, - StoredIndex, VecIterator, Version, + StoredIndex, VecIteratorExtended, Version, }; mod vecs; @@ -20,7 +19,7 @@ use crate::{ price, }; -#[derive(Clone, Traversable, Allocative)] +#[derive(Clone, Traversable)] pub struct Vecs { db: Database, pools: &'static Pools, @@ -121,26 +120,28 @@ impl Vecs { self.height_to_pool.version() + indexer.stores.height_to_coinbase_tag.version(), )?; - let mut height_to_first_txindex_iter = indexer.vecs.height_to_first_txindex.iter(); - let mut txindex_to_first_txoutindex_iter = indexer.vecs.txindex_to_first_txoutindex.iter(); + let mut height_to_first_txindex_iter = indexer.vecs.height_to_first_txindex.iter()?; + let mut txindex_to_first_txoutindex_iter = + indexer.vecs.txindex_to_first_txoutindex.iter()?; let mut txindex_to_output_count_iter = indexes.txindex_to_output_count.iter(); - let mut txoutindex_to_outputtype_iter = indexer.vecs.txoutindex_to_outputtype.iter(); - let mut txoutindex_to_typeindex_iter = indexer.vecs.txoutindex_to_typeindex.iter(); + let mut txoutindex_to_outputtype_iter = indexer.vecs.txoutindex_to_outputtype.iter()?; + let mut txoutindex_to_typeindex_iter = indexer.vecs.txoutindex_to_typeindex.iter()?; let mut p2pk65addressindex_to_p2pk65bytes_iter = - indexer.vecs.p2pk65addressindex_to_p2pk65bytes.iter(); + indexer.vecs.p2pk65addressindex_to_p2pk65bytes.iter()?; let mut p2pk33addressindex_to_p2pk33bytes_iter = - indexer.vecs.p2pk33addressindex_to_p2pk33bytes.iter(); + indexer.vecs.p2pk33addressindex_to_p2pk33bytes.iter()?; let mut p2pkhaddressindex_to_p2pkhbytes_iter = - indexer.vecs.p2pkhaddressindex_to_p2pkhbytes.iter(); + indexer.vecs.p2pkhaddressindex_to_p2pkhbytes.iter()?; let mut p2shaddressindex_to_p2shbytes_iter = - indexer.vecs.p2shaddressindex_to_p2shbytes.iter(); + indexer.vecs.p2shaddressindex_to_p2shbytes.iter()?; let mut p2wpkhaddressindex_to_p2wpkhbytes_iter = - indexer.vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter(); + indexer.vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter()?; let mut p2wshaddressindex_to_p2wshbytes_iter = - indexer.vecs.p2wshaddressindex_to_p2wshbytes.iter(); + indexer.vecs.p2wshaddressindex_to_p2wshbytes.iter()?; let mut p2traddressindex_to_p2trbytes_iter = - indexer.vecs.p2traddressindex_to_p2trbytes.iter(); - let mut p2aaddressindex_to_p2abytes_iter = indexer.vecs.p2aaddressindex_to_p2abytes.iter(); + indexer.vecs.p2traddressindex_to_p2trbytes.iter()?; + let mut p2aaddressindex_to_p2abytes_iter = + indexer.vecs.p2aaddressindex_to_p2abytes.iter()?; let unknown = self.pools.get_unknown(); @@ -155,40 +156,40 @@ impl Vecs { .iter() .skip(min) .try_for_each(|(height, coinbase_tag)| -> Result<()> { - let txindex = height_to_first_txindex_iter.unsafe_get(height); - let txoutindex = txindex_to_first_txoutindex_iter.unsafe_get(txindex); - let outputcount = txindex_to_output_count_iter.unsafe_get(txindex); + let txindex = height_to_first_txindex_iter.get_unwrap(height); + let txoutindex = txindex_to_first_txoutindex_iter.get_unwrap(txindex); + let outputcount = txindex_to_output_count_iter.get_unwrap(txindex); let pool = (*txoutindex..(*txoutindex + *outputcount)) .map(TxOutIndex::from) .find_map(|txoutindex| { - let outputtype = txoutindex_to_outputtype_iter.unsafe_get(txoutindex); - let typeindex = txoutindex_to_typeindex_iter.unsafe_get(txoutindex); + let outputtype = txoutindex_to_outputtype_iter.get_unwrap(txoutindex); + let typeindex = txoutindex_to_typeindex_iter.get_unwrap(txoutindex); match outputtype { OutputType::P2PK65 => Some(AddressBytes::from( - p2pk65addressindex_to_p2pk65bytes_iter.unsafe_get(typeindex.into()), + p2pk65addressindex_to_p2pk65bytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2PK33 => Some(AddressBytes::from( - p2pk33addressindex_to_p2pk33bytes_iter.unsafe_get(typeindex.into()), + p2pk33addressindex_to_p2pk33bytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2PKH => Some(AddressBytes::from( - p2pkhaddressindex_to_p2pkhbytes_iter.unsafe_get(typeindex.into()), + p2pkhaddressindex_to_p2pkhbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2SH => Some(AddressBytes::from( - p2shaddressindex_to_p2shbytes_iter.unsafe_get(typeindex.into()), + p2shaddressindex_to_p2shbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2WPKH => Some(AddressBytes::from( - p2wpkhaddressindex_to_p2wpkhbytes_iter.unsafe_get(typeindex.into()), + p2wpkhaddressindex_to_p2wpkhbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2WSH => Some(AddressBytes::from( - p2wshaddressindex_to_p2wshbytes_iter.unsafe_get(typeindex.into()), + p2wshaddressindex_to_p2wshbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2TR => Some(AddressBytes::from( - p2traddressindex_to_p2trbytes_iter.unsafe_get(typeindex.into()), + p2traddressindex_to_p2trbytes_iter.get_unwrap(typeindex.into()), )), OutputType::P2A => Some(AddressBytes::from( - p2aaddressindex_to_p2abytes_iter.unsafe_get(typeindex.into()), + p2aaddressindex_to_p2abytes_iter.get_unwrap(typeindex.into()), )), _ => None, } diff --git a/crates/brk_computer/src/pools/vecs.rs b/crates/brk_computer/src/pools/vecs.rs index c88956d6b..46726ffe4 100644 --- a/crates/brk_computer/src/pools/vecs.rs +++ b/crates/brk_computer/src/pools/vecs.rs @@ -1,8 +1,7 @@ -use allocative::Allocative; use brk_error::Result; use brk_traversable::Traversable; use brk_types::{Height, PoolId, Pools, Sats, StoredF32, StoredU16, StoredU32}; -use vecdb::{AnyIterableVec, Database, Exit, StoredIndex, VecIterator, Version}; +use vecdb::{AnyIterableVec, Database, Exit, GenericStoredVec, StoredIndex, Version}; use crate::{ chain, @@ -14,7 +13,7 @@ use crate::{ price, }; -#[derive(Clone, Traversable, Allocative)] +#[derive(Clone, Traversable)] pub struct Vecs { id: PoolId, @@ -354,7 +353,7 @@ impl Vecs { if prev.is_none() { let i = i.to_usize(); prev.replace(if i > 0 { - slf.one_shot_get_any_or_read_(i - 1) + slf.get_or_read_at_unwrap_once(i - 1) } else { StoredU16::ZERO }); diff --git a/crates/brk_computer/src/price.rs b/crates/brk_computer/src/price.rs index 1bc9c9a18..746731979 100644 --- a/crates/brk_computer/src/price.rs +++ b/crates/brk_computer/src/price.rs @@ -391,11 +391,8 @@ impl Vecs { .skip(index.to_usize()) .enumerate() .try_for_each(|(i, v)| -> Result<()> { - self.height_to_price_ohlc.forced_push_at( - Height::from(i), - OHLCDollars::from(v), - exit, - )?; + self.height_to_price_ohlc + .forced_push_at(i, OHLCDollars::from(v), exit)?; Ok(()) })?; self.height_to_price_ohlc.safe_flush(exit)?; @@ -437,11 +434,8 @@ impl Vecs { .skip(index.to_usize()) .enumerate() .try_for_each(|(i, v)| -> Result<()> { - self.dateindex_to_price_ohlc.forced_push_at( - DateIndex::from(i), - OHLCDollars::from(v), - exit, - )?; + self.dateindex_to_price_ohlc + .forced_push_at(i, OHLCDollars::from(v), exit)?; Ok(()) })?; self.dateindex_to_price_ohlc.safe_flush(exit)?; @@ -551,11 +545,11 @@ impl Vecs { .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = weekindex_first_iter.unsafe_get_(i); - let high = weekindex_max_iter.unsafe_get_(i); - let low = weekindex_min_iter.unsafe_get_(i); + let open = weekindex_first_iter.get_at_unwrap(i); + let high = weekindex_max_iter.get_at_unwrap(i); + let low = weekindex_min_iter.get_at_unwrap(i); self.weekindex_to_price_ohlc.forced_push_at( - WeekIndex::from(i), + i, OHLCDollars { open, high, @@ -590,12 +584,12 @@ impl Vecs { .difficultyepoch .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = difficultyepoch_first_iter.unsafe_get(i); - let high = difficultyepoch_max_iter.unsafe_get(i); - let low = difficultyepoch_min_iter.unsafe_get(i); + let open = difficultyepoch_first_iter.get_at_unwrap(i); + let high = difficultyepoch_max_iter.get_at_unwrap(i); + let low = difficultyepoch_min_iter.get_at_unwrap(i); self.difficultyepoch_to_price_ohlc.forced_push_at( i, OHLCDollars { @@ -628,12 +622,12 @@ impl Vecs { .monthindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = monthindex_first_iter.unsafe_get(i); - let high = monthindex_max_iter.unsafe_get(i); - let low = monthindex_min_iter.unsafe_get(i); + let open = monthindex_first_iter.get_at_unwrap(i); + let high = monthindex_max_iter.get_at_unwrap(i); + let low = monthindex_min_iter.get_at_unwrap(i); self.monthindex_to_price_ohlc.forced_push_at( i, OHLCDollars { @@ -670,12 +664,12 @@ impl Vecs { .quarterindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = quarterindex_first_iter.unsafe_get(i); - let high = quarterindex_max_iter.unsafe_get(i); - let low = quarterindex_min_iter.unsafe_get(i); + let open = quarterindex_first_iter.get_at_unwrap(i); + let high = quarterindex_max_iter.get_at_unwrap(i); + let low = quarterindex_min_iter.get_at_unwrap(i); self.quarterindex_to_price_ohlc.forced_push_at( i, OHLCDollars { @@ -712,12 +706,12 @@ impl Vecs { .semesterindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = semesterindex_first_iter.unsafe_get(i); - let high = semesterindex_max_iter.unsafe_get(i); - let low = semesterindex_min_iter.unsafe_get(i); + let open = semesterindex_first_iter.get_at_unwrap(i); + let high = semesterindex_max_iter.get_at_unwrap(i); + let low = semesterindex_min_iter.get_at_unwrap(i); self.semesterindex_to_price_ohlc.forced_push_at( i, OHLCDollars { @@ -746,12 +740,12 @@ impl Vecs { .yearindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = yearindex_first_iter.unsafe_get(i); - let high = yearindex_max_iter.unsafe_get(i); - let low = yearindex_min_iter.unsafe_get(i); + let open = yearindex_first_iter.get_at_unwrap(i); + let high = yearindex_max_iter.get_at_unwrap(i); + let low = yearindex_min_iter.get_at_unwrap(i); self.yearindex_to_price_ohlc.forced_push_at( i, OHLCDollars { @@ -791,12 +785,12 @@ impl Vecs { .decadeindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { - let open = decadeindex_first_iter.unsafe_get(i); - let high = decadeindex_max_iter.unsafe_get(i); - let low = decadeindex_min_iter.unsafe_get(i); + let open = decadeindex_first_iter.get_at_unwrap(i); + let high = decadeindex_max_iter.get_at_unwrap(i); + let low = decadeindex_min_iter.get_at_unwrap(i); self.decadeindex_to_price_ohlc.forced_push_at( i, OHLCDollars { @@ -908,15 +902,15 @@ impl Vecs { self.chainindexes_to_price_close_in_sats .height .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.height_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: height_first_iter.unsafe_get(i), - high: height_max_iter.unsafe_get(i), - low: height_min_iter.unsafe_get(i), + open: height_first_iter.get_at_unwrap(i), + high: height_max_iter.get_at_unwrap(i), + low: height_min_iter.get_at_unwrap(i), close, }, exit, @@ -951,15 +945,15 @@ impl Vecs { .as_ref() .unwrap() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.dateindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: dateindex_first_iter.unsafe_get(i), - high: dateindex_max_iter.unsafe_get(i), - low: dateindex_min_iter.unsafe_get(i), + open: dateindex_first_iter.get_at_unwrap(i), + high: dateindex_max_iter.get_at_unwrap(i), + low: dateindex_min_iter.get_at_unwrap(i), close, }, exit, @@ -990,15 +984,15 @@ impl Vecs { .weekindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.weekindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: weekindex_first_iter.unsafe_get(i), - high: weekindex_max_iter.unsafe_get(i), - low: weekindex_min_iter.unsafe_get(i), + open: weekindex_first_iter.get_at_unwrap(i), + high: weekindex_max_iter.get_at_unwrap(i), + low: weekindex_min_iter.get_at_unwrap(i), close, }, exit, @@ -1029,15 +1023,15 @@ impl Vecs { .difficultyepoch .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.difficultyepoch_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: difficultyepoch_first_iter.unsafe_get(i), - high: difficultyepoch_max_iter.unsafe_get(i), - low: difficultyepoch_min_iter.unsafe_get(i), + open: difficultyepoch_first_iter.get_at_unwrap(i), + high: difficultyepoch_max_iter.get_at_unwrap(i), + low: difficultyepoch_min_iter.get_at_unwrap(i), close, }, exit, @@ -1069,15 +1063,15 @@ impl Vecs { .monthindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.monthindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: monthindex_first_iter.unsafe_get(i), - high: monthindex_max_iter.unsafe_get(i), - low: monthindex_min_iter.unsafe_get(i), + open: monthindex_first_iter.get_at_unwrap(i), + high: monthindex_max_iter.get_at_unwrap(i), + low: monthindex_min_iter.get_at_unwrap(i), close, }, exit, @@ -1108,15 +1102,15 @@ impl Vecs { .quarterindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.quarterindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: quarterindex_first_iter.unsafe_get(i), - high: quarterindex_max_iter.unsafe_get(i), - low: quarterindex_min_iter.unsafe_get(i), + open: quarterindex_first_iter.get_at_unwrap(i), + high: quarterindex_max_iter.get_at_unwrap(i), + low: quarterindex_min_iter.get_at_unwrap(i), close, }, exit, @@ -1147,15 +1141,15 @@ impl Vecs { .semesterindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.semesterindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: semesterindex_first_iter.unsafe_get(i), - high: semesterindex_max_iter.unsafe_get(i), - low: semesterindex_min_iter.unsafe_get(i), + open: semesterindex_first_iter.get_at_unwrap(i), + high: semesterindex_max_iter.get_at_unwrap(i), + low: semesterindex_min_iter.get_at_unwrap(i), close, }, exit, @@ -1186,15 +1180,15 @@ impl Vecs { .yearindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.yearindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: yearindex_first_iter.unsafe_get(i), - high: yearindex_max_iter.unsafe_get(i), - low: yearindex_min_iter.unsafe_get(i), + open: yearindex_first_iter.get_at_unwrap(i), + high: yearindex_max_iter.get_at_unwrap(i), + low: yearindex_min_iter.get_at_unwrap(i), close, }, exit, @@ -1228,15 +1222,15 @@ impl Vecs { .decadeindex .unwrap_last() .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, close)| -> Result<()> { self.decadeindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { - open: decadeindex_first_iter.unsafe_get(i), - high: decadeindex_max_iter.unsafe_get(i), - low: decadeindex_min_iter.unsafe_get(i), + open: decadeindex_first_iter.get_at_unwrap(i), + high: decadeindex_max_iter.get_at_unwrap(i), + low: decadeindex_min_iter.get_at_unwrap(i), close, }, exit, diff --git a/crates/brk_computer/src/stateful/address_cohort.rs b/crates/brk_computer/src/stateful/address_cohort.rs index e2c0c2179..9def3ccb2 100644 --- a/crates/brk_computer/src/stateful/address_cohort.rs +++ b/crates/brk_computer/src/stateful/address_cohort.rs @@ -5,7 +5,7 @@ use brk_traversable::Traversable; use brk_types::{Bitcoin, DateIndex, Dollars, Height, StoredU64, Version}; use vecdb::{ AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec, - VecIterator, + VecIteratorExtended, }; use crate::{ @@ -112,7 +112,7 @@ impl DynCohortVecs for Vecs { self.state.as_mut().unwrap().addr_count = *self .height_to_addr_count .into_iter() - .unsafe_get(prev_height); + .get_unwrap(prev_height); } Ok(starting_height) @@ -132,7 +132,7 @@ impl DynCohortVecs for Vecs { return Ok(()); } - self.height_to_addr_count.forced_push_at( + self.height_to_addr_count.forced_push( height, self.state.as_ref().unwrap().addr_count.into(), exit, diff --git a/crates/brk_computer/src/stateful/addresstype/addresscount.rs b/crates/brk_computer/src/stateful/addresstype/addresscount.rs index 3f29f8fd8..7560377e4 100644 --- a/crates/brk_computer/src/stateful/addresstype/addresscount.rs +++ b/crates/brk_computer/src/stateful/addresstype/addresscount.rs @@ -1,7 +1,7 @@ use brk_grouper::ByAddressType; use brk_types::Height; use derive_deref::{Deref, DerefMut}; -use vecdb::VecIterator; +use vecdb::VecIteratorExtended; use super::AddressTypeToHeightToAddressCount; @@ -13,14 +13,14 @@ impl From<(&AddressTypeToHeightToAddressCount, Height)> for AddressTypeToAddress fn from((groups, starting_height): (&AddressTypeToHeightToAddressCount, Height)) -> Self { if let Some(prev_height) = starting_height.decremented() { Self(ByAddressType { - p2pk65: groups.p2pk65.into_iter().unsafe_get(prev_height).into(), - p2pk33: groups.p2pk33.into_iter().unsafe_get(prev_height).into(), - p2pkh: groups.p2pkh.into_iter().unsafe_get(prev_height).into(), - p2sh: groups.p2sh.into_iter().unsafe_get(prev_height).into(), - p2wpkh: groups.p2wpkh.into_iter().unsafe_get(prev_height).into(), - p2wsh: groups.p2wsh.into_iter().unsafe_get(prev_height).into(), - p2tr: groups.p2tr.into_iter().unsafe_get(prev_height).into(), - p2a: groups.p2a.into_iter().unsafe_get(prev_height).into(), + p2pk65: groups.p2pk65.into_iter().get_unwrap(prev_height).into(), + p2pk33: groups.p2pk33.into_iter().get_unwrap(prev_height).into(), + p2pkh: groups.p2pkh.into_iter().get_unwrap(prev_height).into(), + p2sh: groups.p2sh.into_iter().get_unwrap(prev_height).into(), + p2wpkh: groups.p2wpkh.into_iter().get_unwrap(prev_height).into(), + p2wsh: groups.p2wsh.into_iter().get_unwrap(prev_height).into(), + p2tr: groups.p2tr.into_iter().get_unwrap(prev_height).into(), + p2a: groups.p2a.into_iter().get_unwrap(prev_height).into(), }) } else { Default::default() diff --git a/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs b/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs index 73e039abb..bf609b841 100644 --- a/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs +++ b/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs @@ -18,28 +18,28 @@ impl From>> for AddressTypeToHeightToA } impl AddressTypeToHeightToAddressCount { - pub fn forced_push_at( + pub fn forced_push( &mut self, height: Height, addresstype_to_usize: &AddressTypeToAddressCount, exit: &Exit, ) -> Result<()> { self.p2pk65 - .forced_push_at(height, addresstype_to_usize.p2pk65.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2pk65.into(), exit)?; self.p2pk33 - .forced_push_at(height, addresstype_to_usize.p2pk33.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2pk33.into(), exit)?; self.p2pkh - .forced_push_at(height, addresstype_to_usize.p2pkh.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2pkh.into(), exit)?; self.p2sh - .forced_push_at(height, addresstype_to_usize.p2sh.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2sh.into(), exit)?; self.p2wpkh - .forced_push_at(height, addresstype_to_usize.p2wpkh.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2wpkh.into(), exit)?; self.p2wsh - .forced_push_at(height, addresstype_to_usize.p2wsh.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2wsh.into(), exit)?; self.p2tr - .forced_push_at(height, addresstype_to_usize.p2tr.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2tr.into(), exit)?; self.p2a - .forced_push_at(height, addresstype_to_usize.p2a.into(), exit)?; + .forced_push(height, addresstype_to_usize.p2a.into(), exit)?; Ok(()) } diff --git a/crates/brk_computer/src/stateful/common.rs b/crates/brk_computer/src/stateful/common.rs index 1963f651b..f4d513a38 100644 --- a/crates/brk_computer/src/stateful/common.rs +++ b/crates/brk_computer/src/stateful/common.rs @@ -5,7 +5,7 @@ use brk_types::{ }; use vecdb::{ AnyCloneableIterableVec, AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit, - Format, GenericStoredVec, VecIterator, + Format, GenericStoredVec, VecIteratorExtended, }; use crate::{ @@ -1338,15 +1338,15 @@ impl Vecs { prev_height = state.import_at_or_before(prev_height)?; } - state.supply.value = self.height_to_supply.into_iter().unsafe_get(prev_height); + state.supply.value = self.height_to_supply.into_iter().get_unwrap(prev_height); state.supply.utxo_count = *self .height_to_utxo_count .into_iter() - .unsafe_get(prev_height); + .get_unwrap(prev_height); if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() { state.realized.as_mut().unwrap().cap = - height_to_realized_cap.into_iter().unsafe_get(prev_height); + height_to_realized_cap.into_iter().get_unwrap(prev_height); } Ok(prev_height.incremented()) @@ -1571,22 +1571,19 @@ impl Vecs { state: &CohortState, ) -> Result<()> { self.height_to_supply - .forced_push_at(height, state.supply.value, exit)?; + .forced_push(height, state.supply.value, exit)?; - self.height_to_utxo_count.forced_push_at( + self.height_to_utxo_count.forced_push( height, StoredU64::from(state.supply.utxo_count), exit, )?; - self.height_to_satblocks_destroyed.forced_push_at( - height, - state.satblocks_destroyed, - exit, - )?; + self.height_to_satblocks_destroyed + .forced_push(height, state.satblocks_destroyed, exit)?; self.height_to_satdays_destroyed - .forced_push_at(height, state.satdays_destroyed, exit)?; + .forced_push(height, state.satdays_destroyed, exit)?; if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() { let realized = state.realized.as_ref().unwrap_or_else(|| { @@ -1594,34 +1591,36 @@ impl Vecs { panic!(); }); - height_to_realized_cap.forced_push_at(height, realized.cap, exit)?; + height_to_realized_cap.forced_push(height, realized.cap, exit)?; self.height_to_realized_profit .as_mut() .unwrap() - .forced_push_at(height, realized.profit, exit)?; - self.height_to_realized_loss - .as_mut() - .unwrap() - .forced_push_at(height, realized.loss, exit)?; - self.height_to_value_created - .as_mut() - .unwrap() - .forced_push_at(height, realized.value_created, exit)?; + .forced_push(height, realized.profit, exit)?; + self.height_to_realized_loss.as_mut().unwrap().forced_push( + height, + realized.loss, + exit, + )?; + self.height_to_value_created.as_mut().unwrap().forced_push( + height, + realized.value_created, + exit, + )?; self.height_to_value_destroyed .as_mut() .unwrap() - .forced_push_at(height, realized.value_destroyed, exit)?; + .forced_push(height, realized.value_destroyed, exit)?; if self.height_to_adjusted_value_created.is_some() { self.height_to_adjusted_value_created .as_mut() .unwrap() - .forced_push_at(height, realized.adj_value_created, exit)?; + .forced_push(height, realized.adj_value_created, exit)?; self.height_to_adjusted_value_destroyed .as_mut() .unwrap() - .forced_push_at(height, realized.adj_value_destroyed, exit)?; + .forced_push(height, realized.adj_value_destroyed, exit)?; } } Ok(()) @@ -1640,7 +1639,7 @@ impl Vecs { self.height_to_min_price_paid .as_mut() .unwrap() - .forced_push_at( + .forced_push( height, state .price_to_amount_first_key_value() @@ -1651,7 +1650,7 @@ impl Vecs { self.height_to_max_price_paid .as_mut() .unwrap() - .forced_push_at( + .forced_push( height, state .price_to_amount_last_key_value() @@ -1666,19 +1665,19 @@ impl Vecs { self.height_to_supply_in_profit .as_mut() .unwrap() - .forced_push_at(height, height_unrealized_state.supply_in_profit, exit)?; + .forced_push(height, height_unrealized_state.supply_in_profit, exit)?; self.height_to_supply_in_loss .as_mut() .unwrap() - .forced_push_at(height, height_unrealized_state.supply_in_loss, exit)?; + .forced_push(height, height_unrealized_state.supply_in_loss, exit)?; self.height_to_unrealized_profit .as_mut() .unwrap() - .forced_push_at(height, height_unrealized_state.unrealized_profit, exit)?; + .forced_push(height, height_unrealized_state.unrealized_profit, exit)?; self.height_to_unrealized_loss .as_mut() .unwrap() - .forced_push_at(height, height_unrealized_state.unrealized_loss, exit)?; + .forced_push(height, height_unrealized_state.unrealized_loss, exit)?; if let Some(date_unrealized_state) = date_unrealized_state { let dateindex = dateindex.unwrap(); @@ -1686,19 +1685,19 @@ impl Vecs { self.dateindex_to_supply_in_profit .as_mut() .unwrap() - .forced_push_at(dateindex, date_unrealized_state.supply_in_profit, exit)?; + .forced_push(dateindex, date_unrealized_state.supply_in_profit, exit)?; self.dateindex_to_supply_in_loss .as_mut() .unwrap() - .forced_push_at(dateindex, date_unrealized_state.supply_in_loss, exit)?; + .forced_push(dateindex, date_unrealized_state.supply_in_loss, exit)?; self.dateindex_to_unrealized_profit .as_mut() .unwrap() - .forced_push_at(dateindex, date_unrealized_state.unrealized_profit, exit)?; + .forced_push(dateindex, date_unrealized_state.unrealized_profit, exit)?; self.dateindex_to_unrealized_loss .as_mut() .unwrap() - .forced_push_at(dateindex, date_unrealized_state.unrealized_loss, exit)?; + .forced_push(dateindex, date_unrealized_state.unrealized_loss, exit)?; } } @@ -2102,11 +2101,11 @@ impl Vecs { starting_indexes.dateindex, &indexes.dateindex_to_first_height, |(i, height, ..)| { - let count = dateindex_to_height_count_iter.unsafe_get(i); + let count = dateindex_to_height_count_iter.get_unwrap(i); if count == StoredU64::default() { unreachable!() } - let supply = height_to_supply_iter.unsafe_get(height + (*count - 1)); + let supply = height_to_supply_iter.get_unwrap(height + (*count - 1)); (i, supply) }, exit, diff --git a/crates/brk_computer/src/stateful/mod.rs b/crates/brk_computer/src/stateful/mod.rs index c99bde064..12d77a89e 100644 --- a/crates/brk_computer/src/stateful/mod.rs +++ b/crates/brk_computer/src/stateful/mod.rs @@ -18,7 +18,7 @@ use smallvec::SmallVec; use vecdb::{ AnyCloneableIterableVec, AnyIterableVec, AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec, Exit, Format, GenericStoredVec, ImportOptions, - LazyVecFrom1, PAGE_SIZE, RawVec, Reader, Stamp, StoredIndex, VecIterator, + LazyVecFrom1, PAGE_SIZE, RawVec, Reader, Stamp, StoredIndex, VecIteratorExtended, }; use crate::{ @@ -189,7 +189,7 @@ impl Vecs { .as_ref() .unwrap() .boxed_clone(), - |height: Height, iter| iter.next_at(height.to_usize()).map(|(_, d)| d), + |height: Height, iter| iter.get(height), ) }), indexes_to_market_cap: compute_dollars.then(|| { @@ -712,10 +712,10 @@ impl Vecs { .enumerate() .map(|(height, supply)| { let height = Height::from(height); - let timestamp = height_to_timestamp_fixed_iter.unsafe_get(height); + let timestamp = height_to_timestamp_fixed_iter.get_unwrap(height); let price = height_to_price_close_iter .as_mut() - .map(|i| *i.unsafe_get(height)); + .map(|i| *i.get_unwrap(height)); BlockState { timestamp, price, @@ -794,14 +794,14 @@ impl Vecs { let mut unspendable_supply = if let Some(prev_height) = starting_height.decremented() { self.height_to_unspendable_supply .into_iter() - .unsafe_get(prev_height) + .get_unwrap(prev_height) } else { Sats::ZERO }; let mut opreturn_supply = if let Some(prev_height) = starting_height.decremented() { self.height_to_opreturn_supply .into_iter() - .unsafe_get(prev_height) + .get_unwrap(prev_height) } else { Sats::ZERO }; @@ -847,18 +847,18 @@ impl Vecs { v.state.as_mut().unwrap().reset_single_iteration_values() }); - let timestamp = height_to_timestamp_fixed_iter.unsafe_get(height); + let timestamp = height_to_timestamp_fixed_iter.get_unwrap(height); let price = height_to_price_close_iter .as_mut() - .map(|i| *i.unsafe_get(height)); - let first_txindex = height_to_first_txindex_iter.unsafe_get(height); + .map(|i| *i.get_unwrap(height)); + let first_txindex = height_to_first_txindex_iter.get_unwrap(height); let first_txoutindex = height_to_first_txoutindex_iter - .unsafe_get(height) + .get_unwrap(height) .to_usize(); - let first_txinindex = height_to_first_txinindex_iter.unsafe_get(height).to_usize(); - let tx_count = height_to_tx_count_iter.unsafe_get(height); - let output_count = height_to_output_count_iter.unsafe_get(height); - let input_count = height_to_input_count_iter.unsafe_get(height); + let first_txinindex = height_to_first_txinindex_iter.get_unwrap(height).to_usize(); + let tx_count = height_to_tx_count_iter.get_unwrap(height); + let output_count = height_to_output_count_iter.get_unwrap(height); + let input_count = height_to_input_count_iter.get_unwrap(height); let txoutindex_to_txindex = build_txoutindex_to_txindex( first_txindex, @@ -874,28 +874,28 @@ impl Vecs { let first_addressindexes: ByAddressType = ByAddressType { p2a: height_to_first_p2aaddressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2pk33: height_to_first_p2pk33addressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2pk65: height_to_first_p2pk65addressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2pkh: height_to_first_p2pkhaddressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2sh: height_to_first_p2shaddressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2tr: height_to_first_p2traddressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2wpkh: height_to_first_p2wpkhaddressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), p2wsh: height_to_first_p2wshaddressindex_iter - .unsafe_get(height) + .get_unwrap(height) .into(), }; @@ -917,17 +917,17 @@ impl Vecs { let txoutindex = TxOutIndex::from(i); let value = txoutindex_to_value - .unwrap_read(txoutindex, &ir.txoutindex_to_value); + .read_unwrap(txoutindex, &ir.txoutindex_to_value); let output_type = txoutindex_to_outputtype - .unwrap_read(txoutindex, &ir.txoutindex_to_outputtype); + .read_unwrap(txoutindex, &ir.txoutindex_to_outputtype); if output_type.is_not_address() { return (value, output_type, None); } let typeindex = txoutindex_to_typeindex - .unwrap_read(txoutindex, &ir.txoutindex_to_typeindex); + .read_unwrap(txoutindex, &ir.txoutindex_to_typeindex); let addressdata_opt = Self::get_addressdatawithsource( output_type, @@ -996,18 +996,18 @@ impl Vecs { let txinindex = TxInIndex::from(i); let outpoint = txinindex_to_outpoint - .unwrap_read(txinindex, &ir.txinindex_to_outpoint); + .read_unwrap(txinindex, &ir.txinindex_to_outpoint); - let txoutindex = txindex_to_first_txoutindex.unwrap_read( + let txoutindex = txindex_to_first_txoutindex.read_unwrap( outpoint.txindex(), &ir.txindex_to_first_txoutindex, ) + outpoint.vout(); let value = txoutindex_to_value - .unwrap_read(txoutindex, &ir.txoutindex_to_value); + .read_unwrap(txoutindex, &ir.txoutindex_to_value); let input_type = txoutindex_to_outputtype - .unwrap_read(txoutindex, &ir.txoutindex_to_outputtype); + .read_unwrap(txoutindex, &ir.txoutindex_to_outputtype); let prev_height = *txoutindex_range_to_height.get(txoutindex).unwrap(); @@ -1017,7 +1017,7 @@ impl Vecs { } let typeindex = txoutindex_to_typeindex - .unwrap_read(txoutindex, &ir.txoutindex_to_typeindex); + .read_unwrap(txoutindex, &ir.txoutindex_to_typeindex); let addressdata_opt = Self::get_addressdatawithsource( input_type, @@ -1209,7 +1209,7 @@ impl Vecs { .into_iter() .map(|state| state.value) .sum::() - + height_to_unclaimed_rewards_iter.unsafe_get(height); + + height_to_unclaimed_rewards_iter.get_unwrap(height); opreturn_supply += transacted.by_type.unspendable.opreturn.value; @@ -1238,34 +1238,34 @@ impl Vecs { self.utxo_cohorts.send(height_to_sent, &mut chain_state); }); - self.height_to_unspendable_supply.forced_push_at( - height, - unspendable_supply, - exit, - )?; + self.height_to_unspendable_supply + .forced_push(height, unspendable_supply, exit)?; self.height_to_opreturn_supply - .forced_push_at(height, opreturn_supply, exit)?; + .forced_push(height, opreturn_supply, exit)?; - self.addresstype_to_height_to_addr_count.forced_push_at( + self.addresstype_to_height_to_addr_count.forced_push( height, &addresstype_to_addr_count, exit, )?; - self.addresstype_to_height_to_empty_addr_count - .forced_push_at(height, &addresstype_to_empty_addr_count, exit)?; + self.addresstype_to_height_to_empty_addr_count.forced_push( + height, + &addresstype_to_empty_addr_count, + exit, + )?; - let date = height_to_date_fixed_iter.unsafe_get(height); + let date = height_to_date_fixed_iter.get_unwrap(height); let dateindex = DateIndex::try_from(date).unwrap(); - let date_first_height = dateindex_to_first_height_iter.unsafe_get(dateindex); - let date_height_count = dateindex_to_height_count_iter.unsafe_get(dateindex); + let date_first_height = dateindex_to_first_height_iter.get_unwrap(dateindex); + let date_height_count = dateindex_to_height_count_iter.get_unwrap(dateindex); let is_date_last_height = date_first_height + Height::from(date_height_count).decremented().unwrap() == height; let date_price = dateindex_to_price_close_iter .as_mut() - .map(|v| is_date_last_height.then(|| *v.unsafe_get(dateindex))); + .map(|v| is_date_last_height.then(|| *v.get_unwrap(dateindex))); let dateindex = is_date_last_height.then_some(dateindex); @@ -1519,7 +1519,7 @@ impl Vecs { let loadedaddressdata = addresses_data .loaded - .get_any_or_read(loadedaddressindex, reader) + .get_or_read(loadedaddressindex, reader) .unwrap() .unwrap(); @@ -1533,7 +1533,7 @@ impl Vecs { let emptyaddressdata = addresses_data .empty - .get_any_or_read(emtpyaddressindex, reader) + .get_or_read(emtpyaddressindex, reader) .unwrap() .unwrap(); @@ -1979,14 +1979,14 @@ impl AnyAddressIndexes { reader: &Reader<'static>, ) -> AnyAddressIndex { let result = match address_type { - OutputType::P2PK33 => self.p2pk33.get_any_or_read(typeindex.into(), reader), - OutputType::P2PK65 => self.p2pk65.get_any_or_read(typeindex.into(), reader), - OutputType::P2PKH => self.p2pkh.get_any_or_read(typeindex.into(), reader), - OutputType::P2SH => self.p2sh.get_any_or_read(typeindex.into(), reader), - OutputType::P2TR => self.p2tr.get_any_or_read(typeindex.into(), reader), - OutputType::P2WPKH => self.p2wpkh.get_any_or_read(typeindex.into(), reader), - OutputType::P2WSH => self.p2wsh.get_any_or_read(typeindex.into(), reader), - OutputType::P2A => self.p2a.get_any_or_read(typeindex.into(), reader), + OutputType::P2PK33 => self.p2pk33.get_or_read(typeindex.into(), reader), + OutputType::P2PK65 => self.p2pk65.get_or_read(typeindex.into(), reader), + OutputType::P2PKH => self.p2pkh.get_or_read(typeindex.into(), reader), + OutputType::P2SH => self.p2sh.get_or_read(typeindex.into(), reader), + OutputType::P2TR => self.p2tr.get_or_read(typeindex.into(), reader), + OutputType::P2WPKH => self.p2wpkh.get_or_read(typeindex.into(), reader), + OutputType::P2WSH => self.p2wsh.get_or_read(typeindex.into(), reader), + OutputType::P2A => self.p2a.get_or_read(typeindex.into(), reader), _ => unreachable!(), }; result.unwrap().unwrap() @@ -2135,7 +2135,7 @@ fn build_txoutindex_to_txindex<'a>( let block_first_txindex = block_first_txindex.to_usize(); for tx_offset in 0..block_tx_count as usize { let txindex = TxIndex::from(block_first_txindex + tx_offset); - let output_count = u64::from(txindex_to_output_count.unsafe_get(txindex)); + let output_count = u64::from(txindex_to_output_count.get_unwrap(txindex)); for _ in 0..output_count { vec.push(txindex); @@ -2155,7 +2155,7 @@ fn build_txinindex_to_txindex<'a>( let block_first_txindex = block_first_txindex.to_usize(); for tx_offset in 0..block_tx_count as usize { let txindex = TxIndex::from(block_first_txindex + tx_offset); - let input_count = u64::from(txindex_to_input_count.unsafe_get(txindex)); + let input_count = u64::from(txindex_to_input_count.get_unwrap(txindex)); for _ in 0..input_count { vec.push(txindex); diff --git a/crates/brk_computer/src/stateful/range_map.rs b/crates/brk_computer/src/stateful/range_map.rs index 42686c44e..7ba972c9c 100644 --- a/crates/brk_computer/src/stateful/range_map.rs +++ b/crates/brk_computer/src/stateful/range_map.rs @@ -29,7 +29,8 @@ where fn from(vec: &RawVec) -> Self { Self( vec.into_iter() - .map(|(i, v)| (v, i)) + .enumerate() + .map(|(i, v)| (v, I::from(i))) .collect::>(), ) } @@ -44,7 +45,8 @@ where fn from(vec: &CompressedVec) -> Self { Self( vec.into_iter() - .map(|(i, v)| (v, i)) + .enumerate() + .map(|(i, v)| (v, I::from(i))) .collect::>(), ) } diff --git a/crates/brk_computer/src/traits.rs b/crates/brk_computer/src/traits.rs index 384adfc3f..d24fc4ce4 100644 --- a/crates/brk_computer/src/traits.rs +++ b/crates/brk_computer/src/traits.rs @@ -1,8 +1,7 @@ use brk_error::Result; use brk_types::{Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Sats, StoredF32}; use vecdb::{ - AnyIterableVec, AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, StoredIndex, - VecIterator, Version, + AnyIterableVec, AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, StoredIndex, Version, }; const DCA_AMOUNT: Dollars = Dollars::mint(100.0); @@ -51,7 +50,7 @@ impl ComputeDCAStackViaLen for EagerVec { if i_usize == 0 { prev.replace(Sats::ZERO); } else { - prev.replace(self.one_shot_get_any_or_read_(i_usize - 1)); + prev.replace(self.read_at_unwrap_once(i_usize - 1)); } } @@ -61,7 +60,7 @@ impl ComputeDCAStackViaLen for EagerVec { stack = prev.unwrap() + Sats::from(Bitcoin::from(DCA_AMOUNT / price)); if i_usize >= len { - let prev_price = *other_iter.get_(i_usize - len); + let prev_price = *other_iter.get_at_unwrap(i_usize - len); if prev_price != Dollars::ZERO { stack = stack .checked_sub(Sats::from(Bitcoin::from(DCA_AMOUNT / prev_price))) @@ -92,11 +91,12 @@ impl ComputeDCAStackViaLen for EagerVec { )?; let mut prev = None; - + let from = from.to_usize(); let index = max_from.min(DateIndex::from(self.len())); + closes .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, closes)| { let price = *closes; @@ -105,7 +105,7 @@ impl ComputeDCAStackViaLen for EagerVec { if i_usize == 0 { prev.replace(Sats::ZERO); } else { - prev.replace(self.one_shot_get_any_or_read_(i_usize - 1)); + prev.replace(self.read_at_unwrap_once(i_usize - 1)); } } @@ -157,7 +157,9 @@ impl ComputeDCAAveragePriceViaLen for EagerVec { let index = max_from.min(DateIndex::from(self.len())); - let first_price_date = DateIndex::try_from(Date::new(2010, 7, 12)).unwrap(); + let first_price_date = DateIndex::try_from(Date::new(2010, 7, 12)) + .unwrap() + .to_usize(); stacks .iter() @@ -193,7 +195,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec { let index = max_from.min(DateIndex::from(self.len())); - let from_usize = from.to_usize(); + let from = from.to_usize(); stacks .iter() @@ -202,7 +204,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec { .try_for_each(|(i, stack)| { let mut avg_price = Dollars::from(f64::NAN); if i >= from { - avg_price = DCA_AMOUNT * (i.to_usize() + 1 - from_usize) / Bitcoin::from(stack); + avg_price = DCA_AMOUNT * (i.to_usize() + 1 - from) / Bitcoin::from(stack); } self.forced_push_at(i, avg_price, exit) })?; @@ -237,7 +239,7 @@ where let index = max_from.min(I::from(self.len())); sats.iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, sats)| { let (i, v) = (i, Bitcoin::from(sats)); @@ -278,10 +280,10 @@ where let index = max_from.min(I::from(self.len())); bitcoin .iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, bitcoin)| { - let dollars = price_iter.unsafe_get(i); + let dollars = price_iter.get_at_unwrap(i); let (i, v) = (i, *dollars * bitcoin); self.forced_push_at(i, v, exit) })?; @@ -319,13 +321,13 @@ where let index = max_from.min(I::from(self.len())); let mut close_iter = close.iter(); ath.iter() - .skip(index) + .skip(index.to_usize()) .enumerate() .try_for_each(|(i, ath)| { if ath == Dollars::ZERO { self.forced_push_at(i, StoredF32::default(), exit) } else { - let close = *close_iter.unsafe_get(i); + let close = *close_iter.get_at_unwrap(i); let drawdown = StoredF32::from((*ath - *close) / *ath * -100.0); self.forced_push_at(i, drawdown, exit) } diff --git a/crates/brk_indexer/src/lib.rs b/crates/brk_indexer/src/lib.rs index 1e3d71514..93788699a 100644 --- a/crates/brk_indexer/src/lib.rs +++ b/crates/brk_indexer/src/lib.rs @@ -31,7 +31,7 @@ pub use vecs::*; // Increment on **change _OR_ addition** const VERSION: Version = Version::new(23); const SNAPSHOT_BLOCK_RANGE: usize = 1_000; -const COLLISIONS_CHECKED_UP_TO: Height = Height::new(0); +const COLLISIONS_CHECKED_UP_TO: Height = Height::new(920_000); #[derive(Clone)] pub struct Indexer { @@ -261,7 +261,7 @@ impl Indexer { let vout = Vout::from(outpoint.vout); - let txoutindex = vecs.txindex_to_first_txoutindex.get_pushed_or_read_with(prev_txindex, &readers.txindex_to_first_txoutindex)? + let txoutindex = vecs.txindex_to_first_txoutindex.get_pushed_or_read(prev_txindex, &readers.txindex_to_first_txoutindex)? .ok_or(Error::Str("Expect txoutindex to not be none")) .inspect_err(|_| { dbg!(outpoint.txid, prev_txindex, vout); @@ -270,7 +270,7 @@ impl Indexer { let outpoint = OutPoint::new(prev_txindex, vout); - let outputtype = vecs.txoutindex_to_outputtype.get_pushed_or_read_with(txoutindex, &readers.txoutindex_to_outputtype)? + let outputtype = vecs.txoutindex_to_outputtype.get_pushed_or_read(txoutindex, &readers.txoutindex_to_outputtype)? .ok_or(Error::Str("Expect outputtype to not be none"))?; let mut tuple = ( @@ -285,7 +285,7 @@ impl Indexer { if outputtype.is_address() { let typeindex = vecs .txoutindex_to_typeindex - .get_pushed_or_read_with(txoutindex, &readers.txoutindex_to_typeindex)? + .get_pushed_or_read(txoutindex, &readers.txoutindex_to_typeindex)? .ok_or(Error::Str("Expect typeindex to not be none"))?; tuple.3 = Some((outputtype, typeindex)); } @@ -373,56 +373,56 @@ impl Indexer { let prev_addressbytes_opt = match outputtype { OutputType::P2PK65 => vecs .p2pk65addressindex_to_p2pk65bytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2pk65addressindex_to_p2pk65bytes, )? .map(AddressBytes::from), OutputType::P2PK33 => vecs .p2pk33addressindex_to_p2pk33bytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2pk33addressindex_to_p2pk33bytes, )? .map(AddressBytes::from), OutputType::P2PKH => vecs .p2pkhaddressindex_to_p2pkhbytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2pkhaddressindex_to_p2pkhbytes, )? .map(AddressBytes::from), OutputType::P2SH => vecs .p2shaddressindex_to_p2shbytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2shaddressindex_to_p2shbytes, )? .map(AddressBytes::from), OutputType::P2WPKH => vecs .p2wpkhaddressindex_to_p2wpkhbytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2wpkhaddressindex_to_p2wpkhbytes, )? .map(AddressBytes::from), OutputType::P2WSH => vecs .p2wshaddressindex_to_p2wshbytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2wshaddressindex_to_p2wshbytes, )? .map(AddressBytes::from), OutputType::P2TR => vecs .p2traddressindex_to_p2trbytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2traddressindex_to_p2trbytes, )? .map(AddressBytes::from), OutputType::P2A => vecs .p2aaddressindex_to_p2abytes - .get_pushed_or_read_with( + .get_pushed_or_read( typeindex.into(), &readers.p2aaddressindex_to_p2abytes, )? diff --git a/crates/brk_indexer/src/stores_v2.rs b/crates/brk_indexer/src/stores_v2.rs index 199897c31..db987677b 100644 --- a/crates/brk_indexer/src/stores_v2.rs +++ b/crates/brk_indexer/src/stores_v2.rs @@ -7,7 +7,7 @@ use brk_types::{ AddressTypeAddressIndexTxIndex, BlockHashPrefix, Height, OutPoint, StoredString, TxIndex, TxOutIndex, TxidPrefix, TypeIndex, Unit, Version, Vout, }; -use fjall2::{Keyspace, PersistMode}; +use fjall2::{PersistMode, TransactionalKeyspace}; use rayon::prelude::*; use vecdb::{AnyVec, GenericStoredVec, StoredIndex, VecIterator, VecIteratorExtended}; @@ -17,7 +17,7 @@ use super::Vecs; #[derive(Clone)] pub struct Stores { - pub keyspace: Keyspace, + pub keyspace: TransactionalKeyspace, pub addressbyteshash_to_typeindex: Store, pub blockhashprefix_to_height: Store, @@ -167,7 +167,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2pk65addressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2pk65addressindex_to_p2pk65bytes_iter = vecs.p2pk65addressindex_to_p2pk65bytes.iter()?; @@ -182,7 +182,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2pk33addressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2pk33addressindex_to_p2pk33bytes_iter = vecs.p2pk33addressindex_to_p2pk33bytes.iter()?; @@ -197,7 +197,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2pkhaddressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2pkhaddressindex_to_p2pkhbytes_iter = vecs.p2pkhaddressindex_to_p2pkhbytes.iter()?; @@ -212,7 +212,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2shaddressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2shaddressindex_to_p2shbytes_iter = vecs.p2shaddressindex_to_p2shbytes.iter()?; @@ -227,7 +227,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2traddressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2traddressindex_to_p2trbytes_iter = vecs.p2traddressindex_to_p2trbytes.iter()?; @@ -242,7 +242,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2wpkhaddressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2wpkhaddressindex_to_p2wpkhbytes_iter = vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter()?; @@ -257,7 +257,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2wshaddressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2wshaddressindex_to_p2wshbytes_iter = vecs.p2wshaddressindex_to_p2wshbytes.iter()?; @@ -272,7 +272,7 @@ impl Stores { if let Ok(mut index) = vecs .height_to_first_p2aaddressindex - .read(starting_indexes.height) + .read_once(starting_indexes.height) { let mut p2aaddressindex_to_p2abytes_iter = vecs.p2aaddressindex_to_p2abytes.iter()?; @@ -331,7 +331,7 @@ impl Stores { ) .filter(|((_, outputtype), _)| outputtype.is_address()) .for_each(|((txoutindex, addresstype), addressindex)| { - let txindex = txoutindex_to_txindex_iter.get_unwrap_at(txoutindex); + let txindex = txoutindex_to_txindex_iter.get_at_unwrap(txoutindex); self.addresstype_to_addressindex_and_txindex.remove( AddressTypeAddressIndexTxIndex::from((addresstype, addressindex, txindex)), diff --git a/crates/brk_indexer/src/stores_v3.rs b/crates/brk_indexer/src/stores_v3.rs index c8aa60343..f983a0786 100644 --- a/crates/brk_indexer/src/stores_v3.rs +++ b/crates/brk_indexer/src/stores_v3.rs @@ -337,7 +337,7 @@ impl Stores { ) .filter(|((_, outputtype), _)| outputtype.is_address()) .for_each(|((txoutindex, addresstype), addressindex)| { - let txindex = txoutindex_to_txindex_iter.get_unwrap_at(txoutindex); + let txindex = txoutindex_to_txindex_iter.get_at_unwrap(txoutindex); self.addresstype_to_addressindex_and_txindex.remove( AddressTypeAddressIndexTxIndex::from((addresstype, addressindex, txindex)), diff --git a/crates/brk_store/src/fjall_v2/meta.rs b/crates/brk_store/src/fjall_v2/meta.rs index 8bcf063eb..8e5e91071 100644 --- a/crates/brk_store/src/fjall_v2/meta.rs +++ b/crates/brk_store/src/fjall_v2/meta.rs @@ -5,7 +5,7 @@ use std::{ use brk_error::Result; use brk_types::Version; -use fjall2::{Keyspace, PartitionHandle, PersistMode}; +use fjall2::{PersistMode, TransactionalKeyspace, TransactionalPartitionHandle}; use super::Height; @@ -18,13 +18,13 @@ pub struct StoreMeta { impl StoreMeta { pub fn checked_open( - keyspace: &Keyspace, + keyspace: &TransactionalKeyspace, path: &Path, version: Version, open_partition_handle: F, - ) -> Result<(Self, PartitionHandle)> + ) -> Result<(Self, TransactionalPartitionHandle)> where - F: Fn() -> Result, + F: Fn() -> Result, { fs::create_dir_all(path)?; diff --git a/crates/brk_store/src/fjall_v2/mod.rs b/crates/brk_store/src/fjall_v2/mod.rs index 4bc097a72..edb9235d5 100644 --- a/crates/brk_store/src/fjall_v2/mod.rs +++ b/crates/brk_store/src/fjall_v2/mod.rs @@ -3,7 +3,10 @@ use std::{borrow::Cow, cmp, fmt::Debug, fs, hash::Hash, mem, path::Path}; use brk_error::Result; use brk_types::{Height, Version}; use byteview6::ByteView; -use fjall2::{InnerItem, Keyspace, PartitionCreateOptions, PartitionHandle, ValueType}; +use fjall2::{ + InnerItem, PartitionCreateOptions, TransactionalKeyspace, TransactionalPartitionHandle, + ValueType, +}; use rustc_hash::{FxHashMap, FxHashSet}; use crate::any::AnyStore; @@ -16,8 +19,8 @@ use meta::*; pub struct StoreFjallV2 { meta: StoreMeta, name: &'static str, - keyspace: Keyspace, - partition: PartitionHandle, + keyspace: TransactionalKeyspace, + partition: TransactionalPartitionHandle, puts: FxHashMap, dels: FxHashSet, mode: Mode, @@ -25,8 +28,10 @@ pub struct StoreFjallV2 { const MAJOR_FJALL_VERSION: Version = Version::TWO; -pub fn open_keyspace(path: &Path) -> fjall2::Result { - fjall2::Config::new(path.join("fjall")).open() +pub fn open_keyspace(path: &Path) -> fjall2::Result { + fjall2::Config::new(path.join("fjall")) + .manual_journal_persist(true) + .open_transactional() } impl StoreFjallV2 @@ -36,23 +41,25 @@ where ByteView: From + From, { fn open_partition_handle( - keyspace: &Keyspace, + keyspace: &TransactionalKeyspace, name: &str, mode: Mode, - ) -> Result { + ) -> Result { let mut options = PartitionCreateOptions::default().manual_journal_persist(true); if mode.is_unique_push_only() { options = options.bloom_filter_bits(Some(7)); } else { - options = options.bloom_filter_bits(None); + options = options + .max_memtable_size(8 * 1024 * 1024) + .bloom_filter_bits(None); } keyspace.open_partition(name, options).map_err(|e| e.into()) } pub fn import( - keyspace: &Keyspace, + keyspace: &TransactionalKeyspace, path: &Path, name: &str, version: Version, @@ -98,12 +105,16 @@ where } pub fn is_empty(&self) -> Result { - self.partition.is_empty().map_err(|e| e.into()) + self.keyspace + .read_tx() + .is_empty(&self.partition) + .map_err(|e| e.into()) } pub fn iter(&self) -> impl Iterator { - self.partition - .iter() + self.keyspace + .read_tx() + .iter(&self.partition) .map(|res| res.unwrap()) .map(|(k, v)| (K::from(ByteView::from(&*k)), V::from(ByteView::from(&*v)))) } @@ -195,8 +206,8 @@ where .collect::>(); items.sort_unstable(); - self.keyspace.batch().commit_partition( - &self.partition, + self.keyspace.inner().batch().commit_partition( + self.partition.inner(), items.into_iter().map(InnerItem::from).collect::>(), )?; // } diff --git a/crates/brk_types/Cargo.toml b/crates/brk_types/Cargo.toml index 9890df5f2..816c0218e 100644 --- a/crates/brk_types/Cargo.toml +++ b/crates/brk_types/Cargo.toml @@ -10,7 +10,6 @@ rust-version.workspace = true build = "build.rs" [dependencies] -allocative = { workspace = true } bitcoin = { workspace = true } brk_error = { workspace = true } byteview = { workspace = true } diff --git a/crates/brk_types/src/addressindexoutpoint.rs b/crates/brk_types/src/addressindexoutpoint.rs new file mode 100644 index 000000000..e04e6e8ef --- /dev/null +++ b/crates/brk_types/src/addressindexoutpoint.rs @@ -0,0 +1,64 @@ +use std::hash::{Hash, Hasher}; + +use byteview::ByteView; +use serde::Serialize; +use zerocopy::IntoBytes; + +use crate::{AddressIndexTxIndex, Vout}; + +use super::{OutPoint, TypeIndex}; + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Serialize)] +#[repr(C)] +pub struct AddressIndexOutPoint { + addressindextxindex: AddressIndexTxIndex, // u64 + vout: Vout, // u16 +} + +impl Hash for AddressIndexOutPoint { + fn hash(&self, state: &mut H) { + let mut buf = [0u8; 11]; + buf[0..8].copy_from_slice(self.addressindextxindex.as_bytes()); + buf[8..].copy_from_slice(self.vout.as_bytes()); + state.write(&buf); + } +} + +impl From<(TypeIndex, OutPoint)> for AddressIndexOutPoint { + #[inline] + fn from((addressindex, outpoint): (TypeIndex, OutPoint)) -> Self { + Self { + addressindextxindex: AddressIndexTxIndex::from((addressindex, outpoint.txindex())), + vout: outpoint.vout(), + } + } +} + +impl From for AddressIndexOutPoint { + #[inline] + fn from(value: ByteView) -> Self { + Self { + addressindextxindex: AddressIndexTxIndex::from(&value[0..8]), + vout: Vout::from(&value[8..]), + } + } +} + +impl From for ByteView { + #[inline] + fn from(value: AddressIndexOutPoint) -> Self { + ByteView::from(&value) + } +} +impl From<&AddressIndexOutPoint> for ByteView { + #[inline] + fn from(value: &AddressIndexOutPoint) -> Self { + ByteView::from( + [ + &ByteView::from(value.addressindextxindex), + value.vout.to_be_bytes().as_slice(), + ] + .concat(), + ) + } +} diff --git a/crates/brk_types/src/addressindextxindex.rs b/crates/brk_types/src/addressindextxindex.rs new file mode 100644 index 000000000..84dfcd679 --- /dev/null +++ b/crates/brk_types/src/addressindextxindex.rs @@ -0,0 +1,70 @@ +use std::hash::Hash; + +use byteview::ByteView; +use serde::Serialize; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; + +use crate::copy_first_8bytes; + +use super::{TxIndex, TypeIndex}; + +#[derive( + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + Clone, + Copy, + Serialize, + FromBytes, + IntoBytes, + Immutable, + KnownLayout, + Hash, +)] +pub struct AddressIndexTxIndex(u64); + +impl AddressIndexTxIndex { + pub fn addressindex(&self) -> u32 { + (self.0 >> 32) as u32 + } + + pub fn txindex(&self) -> u32 { + self.0 as u32 + } +} + +impl From<(TypeIndex, TxIndex)> for AddressIndexTxIndex { + #[inline] + fn from((addressindex, txindex): (TypeIndex, TxIndex)) -> Self { + Self((u64::from(addressindex) << 32) | u64::from(txindex)) + } +} + +impl From for AddressIndexTxIndex { + #[inline] + fn from(value: ByteView) -> Self { + Self::from(&*value) + } +} + +impl From<&[u8]> for AddressIndexTxIndex { + #[inline] + fn from(value: &[u8]) -> Self { + Self(u64::from_be_bytes(copy_first_8bytes(value).unwrap())) + } +} + +impl From for ByteView { + #[inline] + fn from(value: AddressIndexTxIndex) -> Self { + ByteView::from(&value) + } +} +impl From<&AddressIndexTxIndex> for ByteView { + #[inline] + fn from(value: &AddressIndexTxIndex) -> Self { + ByteView::from(value.0.to_be_bytes()) + } +} diff --git a/crates/brk_types/src/bitcoin.rs b/crates/brk_types/src/bitcoin.rs index 8255667ef..6d32669ad 100644 --- a/crates/brk_types/src/bitcoin.rs +++ b/crates/brk_types/src/bitcoin.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div, Mul}, }; -use allocative::Allocative; use serde::Serialize; use vecdb::{CheckedSub, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -21,7 +20,6 @@ use super::{Sats, StoredF64}; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct Bitcoin(f64); diff --git a/crates/brk_types/src/dateindex.rs b/crates/brk_types/src/dateindex.rs index e64f252a1..9374447c3 100644 --- a/crates/brk_types/src/dateindex.rs +++ b/crates/brk_types/src/dateindex.rs @@ -1,6 +1,5 @@ use std::ops::{Add, Rem}; -use allocative::Allocative; use brk_error::Error; use jiff::Span; use serde::Serialize; @@ -26,7 +25,6 @@ use super::Date; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct DateIndex(u16); diff --git a/crates/brk_types/src/decadeindex.rs b/crates/brk_types/src/decadeindex.rs index f152a89de..f78206706 100644 --- a/crates/brk_types/src/decadeindex.rs +++ b/crates/brk_types/src/decadeindex.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -26,7 +25,6 @@ use super::{Date, DateIndex, YearIndex}; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct DecadeIndex(u16); diff --git a/crates/brk_types/src/difficultyepoch.rs b/crates/brk_types/src/difficultyepoch.rs index 69f7d565c..12f374e54 100644 --- a/crates/brk_types/src/difficultyepoch.rs +++ b/crates/brk_types/src/difficultyepoch.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -28,7 +27,6 @@ pub const BLOCKS_PER_DIFF_EPOCHS: u32 = 2016; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct DifficultyEpoch(u16); diff --git a/crates/brk_types/src/dollars.rs b/crates/brk_types/src/dollars.rs index e206ea8bf..036d1f15c 100644 --- a/crates/brk_types/src/dollars.rs +++ b/crates/brk_types/src/dollars.rs @@ -5,7 +5,6 @@ use std::{ ops::{Add, AddAssign, Div, Mul}, }; -use allocative::Allocative; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -29,7 +28,6 @@ use super::{Bitcoin, Cents, Close, High, Sats, StoredF32, StoredF64}; Serialize, Deserialize, StoredCompressed, - Allocative, JsonSchema, )] pub struct Dollars(f64); diff --git a/crates/brk_types/src/feerate.rs b/crates/brk_types/src/feerate.rs index 1df95a900..399a97c95 100644 --- a/crates/brk_types/src/feerate.rs +++ b/crates/brk_types/src/feerate.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::Serialize; use vecdb::StoredCompressed; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -11,16 +10,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Sats, StoredU64}; #[derive( - Debug, - Clone, - Copy, - Serialize, - FromBytes, - Immutable, - IntoBytes, - KnownLayout, - StoredCompressed, - Allocative, + Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, StoredCompressed, )] pub struct FeeRate(f64); diff --git a/crates/brk_types/src/halvingepoch.rs b/crates/brk_types/src/halvingepoch.rs index 9e383ac77..621e02860 100644 --- a/crates/brk_types/src/halvingepoch.rs +++ b/crates/brk_types/src/halvingepoch.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -28,7 +27,6 @@ pub const BLOCKS_PER_HALVING: u32 = 210_000; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct HalvingEpoch(u16); diff --git a/crates/brk_types/src/height.rs b/crates/brk_types/src/height.rs index 4b7c532a2..6240b23f1 100644 --- a/crates/brk_types/src/height.rs +++ b/crates/brk_types/src/height.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Rem}, }; -use allocative::Allocative; use byteview::ByteView; use derive_deref::Deref; use schemars::JsonSchema; @@ -33,7 +32,6 @@ use super::StoredU64; IntoBytes, KnownLayout, StoredCompressed, - Allocative, JsonSchema, Hash, )] diff --git a/crates/brk_types/src/lib.rs b/crates/brk_types/src/lib.rs index d8e500cef..ff08143b7 100644 --- a/crates/brk_types/src/lib.rs +++ b/crates/brk_types/src/lib.rs @@ -8,6 +8,8 @@ mod address; mod addressbytes; mod addressbyteshash; mod addresschainstats; +mod addressindexoutpoint; +mod addressindextxindex; mod addressmempoolstats; mod addressstats; mod addresstypeaddressindexoutpoint; @@ -106,6 +108,8 @@ pub use address::*; pub use addressbytes::*; pub use addressbyteshash::*; pub use addresschainstats::*; +pub use addressindexoutpoint::*; +pub use addressindextxindex::*; pub use addressmempoolstats::*; pub use addressstats::*; pub use addresstypeaddressindexoutpoint::*; diff --git a/crates/brk_types/src/monthindex.rs b/crates/brk_types/src/monthindex.rs index 334612085..2a05dfed1 100644 --- a/crates/brk_types/src/monthindex.rs +++ b/crates/brk_types/src/monthindex.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -26,7 +25,6 @@ use super::{Date, DateIndex, YearIndex}; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct MonthIndex(u16); diff --git a/crates/brk_types/src/ohlc.rs b/crates/brk_types/src/ohlc.rs index 4d8e8c946..13720947d 100644 --- a/crates/brk_types/src/ohlc.rs +++ b/crates/brk_types/src/ohlc.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use derive_deref::{Deref, DerefMut}; use serde::{Serialize, Serializer, ser::SerializeTuple}; use vecdb::StoredCompressed; @@ -586,7 +585,6 @@ where DerefMut, Serialize, StoredCompressed, - Allocative, )] #[repr(transparent)] pub struct Close(T); diff --git a/crates/brk_types/src/outpoint.rs b/crates/brk_types/src/outpoint.rs index d77739f02..247869ec3 100644 --- a/crates/brk_types/src/outpoint.rs +++ b/crates/brk_types/src/outpoint.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use schemars::JsonSchema; use serde::Serialize; use vecdb::StoredCompressed; @@ -20,7 +19,6 @@ use crate::{TxIndex, Vout}; IntoBytes, KnownLayout, Serialize, - Allocative, JsonSchema, Hash, StoredCompressed, diff --git a/crates/brk_types/src/pool.rs b/crates/brk_types/src/pool.rs index e28d40a4c..a7bb88ae8 100644 --- a/crates/brk_types/src/pool.rs +++ b/crates/brk_types/src/pool.rs @@ -1,8 +1,6 @@ -use allocative::Allocative; - use super::PoolId; -#[derive(Debug, Allocative)] +#[derive(Debug)] pub struct Pool { pub id: PoolId, pub name: &'static str, diff --git a/crates/brk_types/src/poolid.rs b/crates/brk_types/src/poolid.rs index f69fb70d5..362c9d005 100644 --- a/crates/brk_types/src/poolid.rs +++ b/crates/brk_types/src/poolid.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use num_enum::{FromPrimitive, IntoPrimitive}; use serde::{Deserialize, Serialize}; use strum::Display; @@ -24,7 +23,6 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; IntoBytes, Immutable, KnownLayout, - Allocative, )] #[serde(rename_all = "lowercase")] #[strum(serialize_all = "lowercase")] diff --git a/crates/brk_types/src/pools.rs b/crates/brk_types/src/pools.rs index f15176116..de261cba4 100644 --- a/crates/brk_types/src/pools.rs +++ b/crates/brk_types/src/pools.rs @@ -1,14 +1,12 @@ use std::{slice::Iter, sync::OnceLock}; -use allocative::Allocative; - use crate::{JSONPool, PoolId}; use super::Pool; const POOL_COUNT: usize = 158; -#[derive(Debug, Allocative)] +#[derive(Debug)] pub struct Pools([Pool; POOL_COUNT]); impl Pools { diff --git a/crates/brk_types/src/quarterindex.rs b/crates/brk_types/src/quarterindex.rs index 6e45b8119..10ffecbd0 100644 --- a/crates/brk_types/src/quarterindex.rs +++ b/crates/brk_types/src/quarterindex.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -26,7 +25,6 @@ use super::MonthIndex; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct QuarterIndex(u16); diff --git a/crates/brk_types/src/sats.rs b/crates/brk_types/src/sats.rs index c87597989..e9c8c8df6 100644 --- a/crates/brk_types/src/sats.rs +++ b/crates/brk_types/src/sats.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div, Mul, SubAssign}, }; -use allocative::Allocative; use bitcoin::Amount; use derive_deref::Deref; use schemars::JsonSchema; @@ -33,7 +32,6 @@ use super::{Bitcoin, Cents, Dollars, Height}; Serialize, Deserialize, StoredCompressed, - Allocative, JsonSchema, )] pub struct Sats(u64); diff --git a/crates/brk_types/src/semesterindex.rs b/crates/brk_types/src/semesterindex.rs index 3b3ea7c8f..5ae83d43e 100644 --- a/crates/brk_types/src/semesterindex.rs +++ b/crates/brk_types/src/semesterindex.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -26,7 +25,6 @@ use super::MonthIndex; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct SemesterIndex(u16); diff --git a/crates/brk_types/src/stored_bool.rs b/crates/brk_types/src/stored_bool.rs index 8224b8362..3d2690003 100644 --- a/crates/brk_types/src/stored_bool.rs +++ b/crates/brk_types/src/stored_bool.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use derive_deref::Deref; use serde::Serialize; use vecdb::{PrintableIndex, StoredCompressed}; @@ -20,7 +19,6 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct StoredBool(u16); diff --git a/crates/brk_types/src/stored_f32.rs b/crates/brk_types/src/stored_f32.rs index 71af8b01c..8d26db158 100644 --- a/crates/brk_types/src/stored_f32.rs +++ b/crates/brk_types/src/stored_f32.rs @@ -6,7 +6,6 @@ use std::{ ops::{Add, AddAssign, Div, Mul, Sub}, }; -use allocative::Allocative; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -28,7 +27,6 @@ use super::{Dollars, StoredF64}; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct StoredF32(f32); diff --git a/crates/brk_types/src/stored_f64.rs b/crates/brk_types/src/stored_f64.rs index c6568a589..f07d2aa2c 100644 --- a/crates/brk_types/src/stored_f64.rs +++ b/crates/brk_types/src/stored_f64.rs @@ -5,7 +5,6 @@ use std::{ ops::{Add, AddAssign, Div, Mul}, }; -use allocative::Allocative; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -25,7 +24,6 @@ use crate::{Bitcoin, Dollars}; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct StoredF64(f64); diff --git a/crates/brk_types/src/stored_u16.rs b/crates/brk_types/src/stored_u16.rs index 261ec154a..1a12046da 100644 --- a/crates/brk_types/src/stored_u16.rs +++ b/crates/brk_types/src/stored_u16.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign, Div}; -use allocative::Allocative; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -28,7 +27,6 @@ use super::{ KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct StoredU16(u16); diff --git a/crates/brk_types/src/stored_u32.rs b/crates/brk_types/src/stored_u32.rs index 96b0fca17..5a49ef48d 100644 --- a/crates/brk_types/src/stored_u32.rs +++ b/crates/brk_types/src/stored_u32.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign, Div, Mul}; -use allocative::Allocative; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -28,7 +27,6 @@ use super::{ KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct StoredU32(u32); diff --git a/crates/brk_types/src/stored_u64.rs b/crates/brk_types/src/stored_u64.rs index 44150afc4..a1f45984d 100644 --- a/crates/brk_types/src/stored_u64.rs +++ b/crates/brk_types/src/stored_u64.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign, Div}; -use allocative::Allocative; use derive_deref::Deref; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -29,7 +28,6 @@ use super::{ KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct StoredU64(u64); diff --git a/crates/brk_types/src/timestamp.rs b/crates/brk_types/src/timestamp.rs index bf4119b3d..cce81179a 100644 --- a/crates/brk_types/src/timestamp.rs +++ b/crates/brk_types/src/timestamp.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign, Div}; -use allocative::Allocative; use derive_deref::Deref; use jiff::{civil::date, tz::TimeZone}; use schemars::JsonSchema; @@ -26,7 +25,6 @@ use super::Date; KnownLayout, Serialize, StoredCompressed, - Allocative, JsonSchema, )] pub struct Timestamp(u32); diff --git a/crates/brk_types/src/txindex.rs b/crates/brk_types/src/txindex.rs index a467402c0..3948d2dbc 100644 --- a/crates/brk_types/src/txindex.rs +++ b/crates/brk_types/src/txindex.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign}; -use allocative::Allocative; use byteview::ByteView; use derive_deref::{Deref, DerefMut}; use schemars::JsonSchema; @@ -29,7 +28,6 @@ use super::StoredU32; KnownLayout, Serialize, StoredCompressed, - Allocative, JsonSchema, Hash, )] diff --git a/crates/brk_types/src/txinindex.rs b/crates/brk_types/src/txinindex.rs index 047b53c82..13b5c2d8d 100644 --- a/crates/brk_types/src/txinindex.rs +++ b/crates/brk_types/src/txinindex.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign}; -use allocative::Allocative; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -25,7 +24,6 @@ use super::Vin; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct TxInIndex(u64); diff --git a/crates/brk_types/src/txoutindex.rs b/crates/brk_types/src/txoutindex.rs index e39dd1283..c8f0c7651 100644 --- a/crates/brk_types/src/txoutindex.rs +++ b/crates/brk_types/src/txoutindex.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign}; -use allocative::Allocative; use derive_deref::{Deref, DerefMut}; use serde::Serialize; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; @@ -27,7 +26,6 @@ use super::Vout; KnownLayout, Serialize, StoredCompressed, - Allocative, )] pub struct TxOutIndex(u64); diff --git a/crates/brk_types/src/vout.rs b/crates/brk_types/src/vout.rs index 57a413aa7..545bbded2 100644 --- a/crates/brk_types/src/vout.rs +++ b/crates/brk_types/src/vout.rs @@ -1,4 +1,3 @@ -use allocative::Allocative; use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; @@ -22,7 +21,6 @@ use crate::copy_first_2bytes; IntoBytes, KnownLayout, Serialize, - Allocative, JsonSchema, Hash, )] diff --git a/crates/brk_types/src/weekindex.rs b/crates/brk_types/src/weekindex.rs index b4617a37a..7eba8699e 100644 --- a/crates/brk_types/src/weekindex.rs +++ b/crates/brk_types/src/weekindex.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -26,7 +25,6 @@ use super::{Date, DateIndex}; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct WeekIndex(u16); diff --git a/crates/brk_types/src/weight.rs b/crates/brk_types/src/weight.rs index 4d3fe008a..cb7e96432 100644 --- a/crates/brk_types/src/weight.rs +++ b/crates/brk_types/src/weight.rs @@ -1,6 +1,5 @@ use std::ops::{Add, AddAssign, Div}; -use allocative::Allocative; use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; @@ -22,7 +21,6 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; FromBytes, Serialize, StoredCompressed, - Allocative, JsonSchema, )] pub struct Weight(u64); diff --git a/crates/brk_types/src/yearindex.rs b/crates/brk_types/src/yearindex.rs index 67878a103..86b862dd9 100644 --- a/crates/brk_types/src/yearindex.rs +++ b/crates/brk_types/src/yearindex.rs @@ -3,7 +3,6 @@ use std::{ ops::{Add, AddAssign, Div}, }; -use allocative::Allocative; use serde::{Deserialize, Serialize}; use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; @@ -26,7 +25,6 @@ use super::{Date, DateIndex, MonthIndex}; IntoBytes, KnownLayout, StoredCompressed, - Allocative, )] pub struct YearIndex(u16);