global: snapshot

This commit is contained in:
nym21
2025-11-08 14:43:23 +01:00
parent 3d3787a8d9
commit e77fe0253e
69 changed files with 696 additions and 647 deletions

14
Cargo.lock generated
View File

@@ -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",

View File

@@ -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]

View File

@@ -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 }

View File

@@ -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,
}

View File

@@ -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<StoredU64>, 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::<Sats>();
(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::<Dollars>();
(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 =

View File

@@ -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,

View File

@@ -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()
});

View File

@@ -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<I, T>
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::<Vec<_>>();
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::<Vec<_>>();
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::<Vec<_>>();
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::<Vec<_>>();
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::<Vec<_>>();
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
@@ -526,8 +525,7 @@ where
}
Ok(())
},
)?;
})?;
self.safe_flush(exit)?;

View File

@@ -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<I, T, S1I, S2T>
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::<Vec<_>>();
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::<Vec<_>>();
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()))
},
))
}),

View File

@@ -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<T>
where
T: ComputedType + PartialOrd,

View File

@@ -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<T>
where
T: ComputedType + PartialOrd,

View File

@@ -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<T>
where
T: ComputedType + PartialOrd,
@@ -253,90 +252,90 @@ impl ComputedVecsFromTxindex<Bitcoin> {
.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<Dollars> {
(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,
)?;
}

View File

@@ -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,

View File

@@ -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::<f32>() / 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,

View File

@@ -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<Sats>,
pub bitcoin: ComputedVecsFromHeight<Bitcoin>,

View File

@@ -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<Sats>,
pub bitcoin_txindex: LazyVecFrom1<TxIndex, Bitcoin, TxIndex, Sats>,
@@ -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)
})
})
},
)

View File

@@ -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()
})
},

View File

@@ -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<fetched::Vecs>,
pub indexes: indexes::Vecs,
// pub market: market::Vecs,
// pub pools: pools::Vecs,
// pub price: Option<price::Vecs>,
// pub stateful: stateful::Vecs,
pub market: market::Vecs,
pub pools: pools::Vecs,
pub price: Option<price::Vecs>,
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(())
// }

View File

@@ -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
});

View File

@@ -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,
}

View File

@@ -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
});

View File

@@ -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,

View File

@@ -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,

View File

@@ -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()

View File

@@ -18,28 +18,28 @@ impl From<ByAddressType<EagerVec<Height, StoredU64>>> 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(())
}

View File

@@ -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,

View File

@@ -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<TypeIndex> = 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::<Sats>()
+ 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);

View File

@@ -29,7 +29,8 @@ where
fn from(vec: &RawVec<I, T>) -> Self {
Self(
vec.into_iter()
.map(|(i, v)| (v, i))
.enumerate()
.map(|(i, v)| (v, I::from(i)))
.collect::<BTreeMap<_, _>>(),
)
}
@@ -44,7 +45,8 @@ where
fn from(vec: &CompressedVec<I, T>) -> Self {
Self(
vec.into_iter()
.map(|(i, v)| (v, i))
.enumerate()
.map(|(i, v)| (v, I::from(i)))
.collect::<BTreeMap<_, _>>(),
)
}

View File

@@ -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<DateIndex, Sats> {
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<DateIndex, Sats> {
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<DateIndex, Sats> {
)?;
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<DateIndex, Sats> {
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<DateIndex, Dollars> {
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<DateIndex, Dollars> {
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<DateIndex, Dollars> {
.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)
}

View File

@@ -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,
)?

View File

@@ -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<AddressBytesHash, TypeIndex>,
pub blockhashprefix_to_height: Store<BlockHashPrefix, Height>,
@@ -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)),

View File

@@ -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)),

View File

@@ -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<F>(
keyspace: &Keyspace,
keyspace: &TransactionalKeyspace,
path: &Path,
version: Version,
open_partition_handle: F,
) -> Result<(Self, PartitionHandle)>
) -> Result<(Self, TransactionalPartitionHandle)>
where
F: Fn() -> Result<PartitionHandle>,
F: Fn() -> Result<TransactionalPartitionHandle>,
{
fs::create_dir_all(path)?;

View File

@@ -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<Key, Value> {
meta: StoreMeta,
name: &'static str,
keyspace: Keyspace,
partition: PartitionHandle,
keyspace: TransactionalKeyspace,
partition: TransactionalPartitionHandle,
puts: FxHashMap<Key, Value>,
dels: FxHashSet<Key>,
mode: Mode,
@@ -25,8 +28,10 @@ pub struct StoreFjallV2<Key, Value> {
const MAJOR_FJALL_VERSION: Version = Version::TWO;
pub fn open_keyspace(path: &Path) -> fjall2::Result<Keyspace> {
fjall2::Config::new(path.join("fjall")).open()
pub fn open_keyspace(path: &Path) -> fjall2::Result<TransactionalKeyspace> {
fjall2::Config::new(path.join("fjall"))
.manual_journal_persist(true)
.open_transactional()
}
impl<K, V> StoreFjallV2<K, V>
@@ -36,23 +41,25 @@ where
ByteView: From<K> + From<V>,
{
fn open_partition_handle(
keyspace: &Keyspace,
keyspace: &TransactionalKeyspace,
name: &str,
mode: Mode,
) -> Result<PartitionHandle> {
) -> Result<TransactionalPartitionHandle> {
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<bool> {
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<Item = (K, V)> {
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::<Vec<_>>();
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::<Vec<_>>(),
)?;
// }

View File

@@ -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 }

View File

@@ -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<H: Hasher>(&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<ByteView> for AddressIndexOutPoint {
#[inline]
fn from(value: ByteView) -> Self {
Self {
addressindextxindex: AddressIndexTxIndex::from(&value[0..8]),
vout: Vout::from(&value[8..]),
}
}
}
impl From<AddressIndexOutPoint> 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(),
)
}
}

View File

@@ -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<ByteView> 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<AddressIndexTxIndex> 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())
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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,
)]

View File

@@ -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::*;

View File

@@ -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);

View File

@@ -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>(T);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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")]

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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,
)]

View File

@@ -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);

View File

@@ -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);

View File

@@ -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,
)]

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);