Compare commits

..

4 Commits

Author SHA1 Message Date
nym21 7c49e5c749 release: v0.0.19 2025-04-07 15:48:39 +02:00
nym21 cd69ec4fa3 computer: part 7 2025-04-07 15:48:00 +02:00
nym21 4c7e9fbee2 computer: part 6 2025-04-07 12:18:18 +02:00
nym21 1639df5616 computer: part 5 2025-04-06 12:01:45 +02:00
35 changed files with 1606 additions and 544 deletions
+7 -7
View File
@@ -36,7 +36,7 @@ Added git tags for each version though Markdown won't display formatted on Githu
Moved Sanakirja database wrapper to its own crate (`snkrj`) and added a robust auto defragmentation to improve disk usage without the need for user's intervention. Moved Sanakirja database wrapper to its own crate (`snkrj`) and added a robust auto defragmentation to improve disk usage without the need for user's intervention.
Since it's not used anymore it will moved out of the repository relatively soon. Since it's not used anymore it will moved out of the repository relatively soon.
# [v0.5.0](https://github.com/kibo-money/kibo/tree/eea56d394bf92c62c81da8b78b8c47ea730683f5) | [873199](https://mempool.space/block/0000000000000000000270925aa6a565be92e13164565a3f7994ca1966e48050) - 2024/12/04 # [kibo-v0.5.0](https://github.com/kibo-money/kibo/tree/eea56d394bf92c62c81da8b78b8c47ea730683f5) | [873199](https://mempool.space/block/0000000000000000000270925aa6a565be92e13164565a3f7994ca1966e48050) - 2024/12/04
![Image of the kibo Web App version 0.5.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.5.0.jpg) ![Image of the kibo Web App version 0.5.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.5.0.jpg)
@@ -103,7 +103,7 @@ Since it's not used anymore it will moved out of the repository relatively soon.
- Moved back to this repo - Moved back to this repo
# [v0.4.0](https://github.com/kibo-money/kibo/tree/a64c544815d9ef785e2fc1323582f774f16b9200) | [861950](https://mempool.space/block/00000000000000000000530d0e30ccf7deeace122dcc99f2668a06c6dad83629) - 2024/09/19 # [kibo-v0.4.0](https://github.com/kibo-money/kibo/tree/a64c544815d9ef785e2fc1323582f774f16b9200) | [861950](https://mempool.space/block/00000000000000000000530d0e30ccf7deeace122dcc99f2668a06c6dad83629) - 2024/09/19
![Image of the kibo Web App version 0.4.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.4.0.jpg) ![Image of the kibo Web App version 0.4.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.4.0.jpg)
@@ -140,7 +140,7 @@ Since it's not used anymore it will moved out of the repository relatively soon.
- Added serving of the website - Added serving of the website
- Improved `Cache-Control` behavior - Improved `Cache-Control` behavior
# [v0.3.0](https://github.com/kibo-money/kibo/tree/b68b016091c45b071218fba01bac5b76e8eaf18c) | [853930](https://mempool.space/block/00000000000000000002eb5e9a7950ca2d5d98bd1ed28fc9098aa630d417985d) - 2024/07/26 # [kibo-v0.3.0](https://github.com/kibo-money/kibo/tree/b68b016091c45b071218fba01bac5b76e8eaf18c) | [853930](https://mempool.space/block/00000000000000000002eb5e9a7950ca2d5d98bd1ed28fc9098aa630d417985d) - 2024/07/26
![Image of the Satonomics Web App version 0.3.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.3.0.jpg) ![Image of the Satonomics Web App version 0.3.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.3.0.jpg)
@@ -219,7 +219,7 @@ Since it's not used anymore it will moved out of the repository relatively soon.
- Only run with a watcher if `cargo watch` is available - Only run with a watcher if `cargo watch` is available
- Removed id_to_path file in favor for only `paths.d.ts` in `app/src/types` - Removed id_to_path file in favor for only `paths.d.ts` in `app/src/types`
# [v0.2.0](https://github.com/kibo-money/kibo/tree/248187889283597c5dbb806292297453c25e97b8) | [851286](https://mempool.space/block/0000000000000000000281ca7f1bf8c50702bfca168c7af1bdc67c977c1ac8ed) - 2024/07/08 # [kibo-v0.2.0](https://github.com/kibo-money/kibo/tree/248187889283597c5dbb806292297453c25e97b8) | [851286](https://mempool.space/block/0000000000000000000281ca7f1bf8c50702bfca168c7af1bdc67c977c1ac8ed) - 2024/07/08
![Image of the Satonomics Web App version 0.2.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.2.0.jpg) ![Image of the Satonomics Web App version 0.2.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.2.0.jpg)
@@ -255,7 +255,7 @@ Since it's not used anymore it will moved out of the repository relatively soon.
- Fixed ulimit only being run in Mac OS instead of whenever the program is detected - Fixed ulimit only being run in Mac OS instead of whenever the program is detected
# [v0.1.1](https://github.com/kibo-money/kibo/tree/e55b5195a9de9aea306903c94ed63cb1720fda5f) | [849240](https://mempool.space/block/000000000000000000002b8653988655071c07bb5f7181c038f9326bc86db741) - 2024/06/24 # [kibo-v0.1.1](https://github.com/kibo-money/kibo/tree/e55b5195a9de9aea306903c94ed63cb1720fda5f) | [849240](https://mempool.space/block/000000000000000000002b8653988655071c07bb5f7181c038f9326bc86db741) - 2024/06/24
![Image of the Satonomics Web App version 0.1.1](https://github.com/kibo-money/kibo/blob/main/_assets/v0.1.1.jpg) ![Image of the Satonomics Web App version 0.1.1](https://github.com/kibo-money/kibo/blob/main/_assets/v0.1.1.jpg)
@@ -305,10 +305,10 @@ Since it's not used anymore it will moved out of the repository relatively soon.
- Deleted old price datasets and their backups - Deleted old price datasets and their backups
# [v0.1.0](https://github.com/kibo-money/kibo/tree/a1a576d088c8f83ed32d48753a7611f70a964574) | [848642](https://mempool.space/block/000000000000000000020be5761d70751252219a9557f55e91ecdfb86c4e026a) - 2024/06/19 # [kibo-v0.1.0](https://github.com/kibo-money/kibo/tree/a1a576d088c8f83ed32d48753a7611f70a964574) | [848642](https://mempool.space/block/000000000000000000020be5761d70751252219a9557f55e91ecdfb86c4e026a) - 2024/06/19
![Image of the Satonomics Web App version 0.1.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.1.0.jpg) ![Image of the Satonomics Web App version 0.1.0](https://github.com/kibo-money/kibo/blob/main/_assets/v0.1.0.jpg)
# v0.0.1 | [835444](https://mempool.space/block/000000000000000000009f93907a0dd83c080d5585cc7ec82c076d45f6d7c872) - 2024/03/20 # kibo-v0.0.1 | [835444](https://mempool.space/block/000000000000000000009f93907a0dd83c080d5585cc7ec82c076d45f6d7c872) - 2024/03/20
![Image of the Satonomics Web App version 0.0.X](https://github.com/kibo-money/kibo/blob/main/_assets/v0.0.X.jpg) ![Image of the Satonomics Web App version 0.0.X](https://github.com/kibo-money/kibo/blob/main/_assets/v0.0.X.jpg)
Generated
+18 -18
View File
@@ -368,7 +368,7 @@ dependencies = [
[[package]] [[package]]
name = "brk" name = "brk"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"brk_cli", "brk_cli",
"brk_computer", "brk_computer",
@@ -385,7 +385,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_cli" name = "brk_cli"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"brk_computer", "brk_computer",
"brk_core", "brk_core",
@@ -406,7 +406,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_computer" name = "brk_computer"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"brk_core", "brk_core",
"brk_exit", "brk_exit",
@@ -421,7 +421,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_core" name = "brk_core"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"bitcoin", "bitcoin",
"bitcoincore-rpc", "bitcoincore-rpc",
@@ -438,7 +438,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_exit" name = "brk_exit"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"brk_logger", "brk_logger",
"ctrlc", "ctrlc",
@@ -447,7 +447,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_fetcher" name = "brk_fetcher"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"brk_core", "brk_core",
"brk_logger", "brk_logger",
@@ -460,7 +460,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_indexer" name = "brk_indexer"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"bitcoin", "bitcoin",
"bitcoincore-rpc", "bitcoincore-rpc",
@@ -479,7 +479,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_logger" name = "brk_logger"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"color-eyre", "color-eyre",
"env_logger", "env_logger",
@@ -489,7 +489,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_parser" name = "brk_parser"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"bitcoin", "bitcoin",
"bitcoincore-rpc", "bitcoincore-rpc",
@@ -504,7 +504,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_query" name = "brk_query"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"brk_computer", "brk_computer",
"brk_indexer", "brk_indexer",
@@ -520,7 +520,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_server" name = "brk_server"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"axum", "axum",
"brk_computer", "brk_computer",
@@ -546,7 +546,7 @@ dependencies = [
[[package]] [[package]]
name = "brk_vec" name = "brk_vec"
version = "0.0.18" version = "0.0.19"
dependencies = [ dependencies = [
"memmap2", "memmap2",
"rayon", "rayon",
@@ -971,9 +971,9 @@ checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b"
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.4.1" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28cfac68e08048ae1883171632c2aef3ebc555621ae56fbccce1cbf22dd7f058" checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
dependencies = [ dependencies = [
"powerfmt", "powerfmt",
"serde", "serde",
@@ -2403,9 +2403,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.5.10" version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@@ -2915,9 +2915,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.44.1" version = "1.44.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
+3 -1
View File
@@ -4,7 +4,7 @@ members = ["crates/*"]
package.description = "The Bitcoin Research Kit is a suite of tools designed to extract, compute and display data stored on a Bitcoin Core node" package.description = "The Bitcoin Research Kit is a suite of tools designed to extract, compute and display data stored on a Bitcoin Core node"
package.license = "MIT" package.license = "MIT"
package.edition = "2024" package.edition = "2024"
package.version = "0.0.18" package.version = "0.0.19"
package.repository = "https://github.com/bitcoinresearchkit/brk" package.repository = "https://github.com/bitcoinresearchkit/brk"
[profile.release] [profile.release]
@@ -46,6 +46,8 @@ zerocopy = { version = "0.8.24", features = ["derive"] }
[workspace.metadata.release] [workspace.metadata.release]
shared-version = true shared-version = true
tag-name = "v{{version}}" tag-name = "v{{version}}"
pre-release-commit-message = "release: v{{version}}"
tag-message = "release: v{{version}}"
[workspace.metadata.dist] [workspace.metadata.dist]
cargo-dist-version = "0.28.0" cargo-dist-version = "0.28.0"
+1 -1
View File
@@ -61,7 +61,7 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
loop { loop {
let block_count = rpc.get_block_count()?; let block_count = rpc.get_block_count()?;
info!("{block_count} blocks found."); info!("{} blocks found.", block_count + 1);
let starting_indexes = indexer.index(&parser, rpc, &exit)?; let starting_indexes = indexer.index(&parser, rpc, &exit)?;
+2 -2
View File
@@ -13,9 +13,9 @@ pub struct Stores {
impl Stores { impl Stores {
pub fn import(path: &Path) -> color_eyre::Result<Self> { pub fn import(path: &Path) -> color_eyre::Result<Self> {
let address_to_utxos_received = let address_to_utxos_received =
Store::import(&path.join("address_to_utxos_received"), Version::ONE)?; Store::import(&path.join("address_to_utxos_received"), Version::ZERO)?;
let address_to_utxos_spent = let address_to_utxos_spent =
Store::import(&path.join("address_to_utxos_spent"), Version::ONE)?; Store::import(&path.join("address_to_utxos_spent"), Version::ZERO)?;
Ok(Self { Ok(Self {
address_to_utxos_received, address_to_utxos_received,
+15 -15
View File
@@ -31,7 +31,7 @@ where
version: Version, version: Version,
compressed: Compressed, compressed: Compressed,
) -> brk_vec::Result<Self> { ) -> brk_vec::Result<Self> {
let vec = brk_vec::StorableVec::forced_import(path, version, compressed)?; let vec = StorableVec::forced_import(path, version, compressed)?;
Ok(Self { Ok(Self {
computed_version: None, computed_version: None,
@@ -88,11 +88,11 @@ where
self.vec.len() self.vec.len()
} }
pub fn vec(&self) -> &brk_vec::StorableVec<I, T> { pub fn vec(&self) -> &StorableVec<I, T> {
&self.vec &self.vec
} }
pub fn mut_vec(&mut self) -> &mut brk_vec::StorableVec<I, T> { pub fn mut_vec(&mut self) -> &mut StorableVec<I, T> {
&mut self.vec &mut self.vec
} }
@@ -129,14 +129,14 @@ where
pub fn compute_transform<A, B, F>( pub fn compute_transform<A, B, F>(
&mut self, &mut self,
max_from: A, max_from: A,
other: &mut brk_vec::StorableVec<A, B>, other: &mut StorableVec<A, B>,
mut t: F, mut t: F,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
A: StoredIndex, A: StoredIndex,
B: StoredType, B: StoredType,
F: FnMut((A, B, &mut Self, &mut brk_vec::StorableVec<A, B>)) -> (I, T), F: FnMut((A, B, &mut Self, &mut StorableVec<A, B>)) -> (I, T),
{ {
self.validate_computed_version_or_reset_file( self.validate_computed_version_or_reset_file(
Version::ZERO + self.version() + other.version(), Version::ZERO + self.version() + other.version(),
@@ -154,7 +154,7 @@ where
pub fn compute_inverse_more_to_less( pub fn compute_inverse_more_to_less(
&mut self, &mut self,
max_from: T, max_from: T,
other: &mut brk_vec::StorableVec<T, I>, other: &mut StorableVec<T, I>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
@@ -181,8 +181,8 @@ where
pub fn compute_inverse_less_to_more( pub fn compute_inverse_less_to_more(
&mut self, &mut self,
max_from: T, max_from: T,
first_indexes: &mut brk_vec::StorableVec<T, I>, first_indexes: &mut StorableVec<T, I>,
last_indexes: &mut brk_vec::StorableVec<T, I>, last_indexes: &mut StorableVec<T, I>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
@@ -207,7 +207,7 @@ where
pub fn compute_last_index_from_first( pub fn compute_last_index_from_first(
&mut self, &mut self,
max_from: I, max_from: I,
first_indexes: &mut brk_vec::StorableVec<I, T>, first_indexes: &mut StorableVec<I, T>,
final_len: usize, final_len: usize,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
@@ -242,8 +242,8 @@ where
pub fn compute_count_from_indexes<T2>( pub fn compute_count_from_indexes<T2>(
&mut self, &mut self,
max_from: I, max_from: I,
first_indexes: &mut brk_vec::StorableVec<I, T2>, first_indexes: &mut StorableVec<I, T2>,
last_indexes: &mut brk_vec::StorableVec<I, T2>, last_indexes: &mut StorableVec<I, T2>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
@@ -270,8 +270,8 @@ where
pub fn compute_is_first_ordered<A>( pub fn compute_is_first_ordered<A>(
&mut self, &mut self,
max_from: I, max_from: I,
self_to_other: &mut brk_vec::StorableVec<I, A>, self_to_other: &mut StorableVec<I, A>,
other_to_self: &mut brk_vec::StorableVec<A, I>, other_to_self: &mut StorableVec<A, I>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
@@ -294,8 +294,8 @@ where
pub fn compute_sum_from_indexes<T2>( pub fn compute_sum_from_indexes<T2>(
&mut self, &mut self,
max_from: I, max_from: I,
first_indexes: &mut brk_vec::StorableVec<I, T2>, first_indexes: &mut StorableVec<I, T2>,
last_indexes: &mut brk_vec::StorableVec<I, T2>, last_indexes: &mut StorableVec<I, T2>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
+94 -18
View File
@@ -1,12 +1,13 @@
use std::{fs, path::Path}; use std::{fs, path::Path};
use brk_core::{CheckedSub, Dateindex, Timestamp}; use brk_core::{CheckedSub, StoredU32, StoredU64, StoredUsize, Timestamp, Weight};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_parser::bitcoin;
use brk_vec::{AnyStorableVec, Compressed, Version}; use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{ use super::{
ComputedVec, Indexes, Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions}, grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
indexes, indexes,
}; };
@@ -14,8 +15,10 @@ use super::{
#[derive(Clone)] #[derive(Clone)]
pub struct Vecs { pub struct Vecs {
pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>, pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>,
pub dateindex_to_block_count: ComputedVec<Dateindex, u16>, pub indexes_to_block_count: ComputedVecsFromHeight<StoredU32>,
pub dateindex_to_total_block_count: ComputedVec<Dateindex, u32>, pub indexes_to_block_weight: ComputedVecsFromHeight<Weight>,
pub indexes_to_block_vbytes: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_block_size: ComputedVecsFromHeight<StoredUsize>,
} }
impl Vecs { impl Vecs {
@@ -26,22 +29,45 @@ impl Vecs {
indexes_to_block_interval: ComputedVecsFromHeight::forced_import( indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
path, path,
"block_interval", "block_interval",
Version::ONE, true,
Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default() StorableVecGeneatorOptions::default()
.add_percentiles() .add_percentiles()
.add_minmax() .add_minmax()
.add_average(), .add_average(),
)?, )?,
dateindex_to_block_count: ComputedVec::forced_import( indexes_to_block_count: ComputedVecsFromHeight::forced_import(
&path.join("dateindex_to_block_count"), path,
Version::ONE, "block_count",
true,
Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?, )?,
dateindex_to_total_block_count: ComputedVec::forced_import( indexes_to_block_weight: ComputedVecsFromHeight::forced_import(
&path.join("dateindex_to_total_block_count"), path,
Version::ONE, "block_weight",
false,
Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?,
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
path,
"block_size",
false,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?,
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
path,
"block_vbytes",
true,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?, )?,
}) })
} }
@@ -53,10 +79,14 @@ impl Vecs {
starting_indexes: &Indexes, starting_indexes: &Indexes,
exit: &Exit, exit: &Exit,
) -> color_eyre::Result<()> { ) -> color_eyre::Result<()> {
let indexer_vecs = indexer.mut_vecs(); self.indexes_to_block_interval.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
let indexer_vecs = indexer.mut_vecs();
self.indexes_to_block_interval.compute(
|v| {
v.compute_transform( v.compute_transform(
starting_indexes.height, starting_indexes.height,
indexer_vecs.height_to_timestamp.mut_vec(), indexer_vecs.height_to_timestamp.mut_vec(),
@@ -72,9 +102,55 @@ impl Vecs {
exit, exit,
) )
}, },
)?;
self.indexes_to_block_count.compute_all(
indexer,
indexes, indexes,
starting_indexes, starting_indexes,
exit, exit,
|v, indexer, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
indexer.mut_vecs().height_to_block_weight.mut_vec(),
|(h, ..)| (h, StoredU32::from(1_u32)),
exit,
)
},
)?;
self.indexes_to_block_weight.compute_rest(
indexes,
starting_indexes,
exit,
Some(indexer.mut_vecs().height_to_block_weight.mut_vec()),
)?;
self.indexes_to_block_size.compute_rest(
indexes,
starting_indexes,
exit,
Some(indexer.mut_vecs().height_to_block_size.mut_vec()),
)?;
self.indexes_to_block_vbytes.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
v.compute_transform(
starting_indexes.height,
indexer.mut_vecs().height_to_block_weight.mut_vec(),
|(h, w, ..)| {
(
h,
StoredU64::from(bitcoin::Weight::from(w).to_vbytes_floor()),
)
},
exit,
)
},
)?; )?;
Ok(()) Ok(())
@@ -82,11 +158,11 @@ impl Vecs {
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> { pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[ [
vec![
self.dateindex_to_block_count.any_vec(),
self.dateindex_to_total_block_count.any_vec(),
],
self.indexes_to_block_interval.any_vecs(), self.indexes_to_block_interval.any_vecs(),
self.indexes_to_block_count.any_vecs(),
self.indexes_to_block_weight.any_vecs(),
self.indexes_to_block_size.any_vecs(),
self.indexes_to_block_vbytes.any_vecs(),
] ]
.concat() .concat()
} }
@@ -1,7 +1,7 @@
use std::path::Path; use std::path::Path;
use brk_exit::Exit; use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed, Result, StoredIndex, StoredType, Version}; use brk_vec::{AnyStorableVec, Compressed, Result, StorableVec, StoredIndex, StoredType, Version};
use crate::storage::vecs::base::ComputedVec; use crate::storage::vecs::base::ComputedVec;
@@ -24,6 +24,7 @@ where
pub _10p: Option<ComputedVec<I, T>>, pub _10p: Option<ComputedVec<I, T>>,
pub min: Option<ComputedVec<I, T>>, pub min: Option<ComputedVec<I, T>>,
pub last: Option<ComputedVec<I, T>>, pub last: Option<ComputedVec<I, T>>,
pub total: Option<ComputedVec<I, T>>,
} }
impl<I, T> ComputedVecBuilder<I, T> impl<I, T> ComputedVecBuilder<I, T>
@@ -37,77 +38,125 @@ where
compressed: Compressed, compressed: Compressed,
options: StorableVecGeneatorOptions, options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
// let name = path.file_name().unwrap().to_str().unwrap().to_string();
let key = I::to_string().split("::").last().unwrap().to_lowercase(); let key = I::to_string().split("::").last().unwrap().to_lowercase();
let only_one_active = options.is_only_one_active(); let only_one_active = options.is_only_one_active();
let prefix = |s: &str| { let default = || path.join(format!("{key}_to_{name}"));
let prefix = |s: &str| path.join(format!("{key}_to_{s}_{name}"));
let maybe_prefix = |s: &str| {
if only_one_active { if only_one_active {
path.with_file_name(format!("{key}_to_{name}")) default()
} else { } else {
path.with_file_name(format!("{key}_to_{s}_{name}")) prefix(s)
} }
}; };
let suffix = |s: &str| { let suffix = |s: &str| path.join(format!("{key}_to_{name}_{s}"));
let maybe_suffix = |s: &str| {
if only_one_active { if only_one_active {
path.with_file_name(format!("{key}_to_{name}")) default()
} else { } else {
path.with_file_name(format!("{key}_to_{name}_{s}")) suffix(s)
} }
}; };
let s = Self { let s = Self {
first: options.first.then(|| { first: options.first.then(|| {
ComputedVec::forced_import(&prefix("first"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_prefix("first"), Version::ZERO, compressed)
.unwrap()
}), }),
last: options.last.then(|| { last: options.last.then(|| {
ComputedVec::forced_import( ComputedVec::forced_import(
&path.with_file_name(format!("{key}_to_{name}")), &path.join(format!("{key}_to_{name}")),
Version::ONE, Version::ZERO,
compressed, compressed,
) )
.unwrap() .unwrap()
}), }),
min: options.min.then(|| { min: options.min.then(|| {
ComputedVec::forced_import(&suffix("min"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("min"), Version::ZERO, compressed).unwrap()
}), }),
max: options.max.then(|| { max: options.max.then(|| {
ComputedVec::forced_import(&suffix("max"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("max"), Version::ZERO, compressed).unwrap()
}), }),
median: options.median.then(|| { median: options.median.then(|| {
ComputedVec::forced_import(&suffix("median"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("median"), Version::ZERO, compressed)
.unwrap()
}), }),
average: options.average.then(|| { average: options.average.then(|| {
ComputedVec::forced_import(&suffix("average"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("average"), Version::ZERO, compressed)
.unwrap()
}), }),
sum: options.sum.then(|| { sum: options.sum.then(|| {
ComputedVec::forced_import(&suffix("sum"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("sum"), Version::ZERO, compressed).unwrap()
}),
total: options.total.then(|| {
ComputedVec::forced_import(&prefix("total"), Version::ZERO, compressed).unwrap()
}), }),
_90p: options._90p.then(|| { _90p: options._90p.then(|| {
ComputedVec::forced_import(&suffix("90p"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("90p"), Version::ZERO, compressed).unwrap()
}), }),
_75p: options._75p.then(|| { _75p: options._75p.then(|| {
ComputedVec::forced_import(&suffix("75p"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("75p"), Version::ZERO, compressed).unwrap()
}), }),
_25p: options._25p.then(|| { _25p: options._25p.then(|| {
ComputedVec::forced_import(&suffix("25p"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("25p"), Version::ZERO, compressed).unwrap()
}), }),
_10p: options._10p.then(|| { _10p: options._10p.then(|| {
ComputedVec::forced_import(&suffix("10p"), Version::ONE, compressed).unwrap() ComputedVec::forced_import(&maybe_suffix("10p"), Version::ZERO, compressed).unwrap()
}), }),
}; };
Ok(s) Ok(s)
} }
pub fn extend(
&mut self,
max_from: I,
source: &mut StorableVec<I, T>,
exit: &Exit,
) -> Result<()> {
if self.total.is_none() {
return Ok(());
};
let index = self.starting_index(max_from);
let total_vec = self.total.as_mut().unwrap();
source.iter_from(index, |(i, v)| {
let prev = i
.to_usize()
.unwrap()
.checked_sub(1)
.map_or(T::from(0_usize), |prev_i| {
total_vec
.get(I::from(prev_i))
.unwrap()
.unwrap_or(&T::from(0_usize))
.to_owned()
});
let value = v.clone() + prev;
total_vec.forced_push_at(i, value, exit)?;
Ok(())
})?;
self.safe_flush(exit)?;
Ok(())
}
pub fn compute<I2>( pub fn compute<I2>(
&mut self, &mut self,
max_from: I, max_from: I,
source: &mut ComputedVec<I2, T>, source: &mut StorableVec<I2, T>,
first_indexes: &mut brk_vec::StorableVec<I, I2>, first_indexes: &mut StorableVec<I, I2>,
last_indexes: &mut brk_vec::StorableVec<I, I2>, last_indexes: &mut StorableVec<I, I2>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
@@ -134,7 +183,8 @@ where
let first_index = first_index.to_usize()?; let first_index = first_index.to_usize()?;
let last_index = last_index.to_usize()?; let last_index = last_index.to_usize()?;
let needs_sum_or_average = self.sum.is_some() || self.average.is_some(); let needs_sum_or_total = self.sum.is_some() || self.total.is_some();
let needs_average_sum_or_total = needs_sum_or_total || self.average.is_some();
let needs_sorted = self.max.is_some() let needs_sorted = self.max.is_some()
|| self._90p.is_some() || self._90p.is_some()
|| self._75p.is_some() || self._75p.is_some()
@@ -142,7 +192,7 @@ where
|| self._25p.is_some() || self._25p.is_some()
|| self._10p.is_some() || self._10p.is_some()
|| self.min.is_some(); || self.min.is_some();
let needs_values = needs_sorted || needs_sum_or_average; let needs_values = needs_sorted || needs_average_sum_or_total;
if needs_values { if needs_values {
let mut values = let mut values =
@@ -180,7 +230,7 @@ where
} }
} }
if needs_sum_or_average { if needs_average_sum_or_total {
let len = values.len(); let len = values.len();
if let Some(average) = self.average.as_mut() { if let Some(average) = self.average.as_mut() {
@@ -193,9 +243,22 @@ where
average.forced_push_at(i, avg, exit)?; average.forced_push_at(i, avg, exit)?;
} }
if let Some(sum_vec) = self.sum.as_mut() { if needs_sum_or_total {
let sum = values.into_iter().fold(T::from(0), |a, b| a + b); let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
sum_vec.forced_push_at(i, sum, exit)?;
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
if let Some(total_vec) = self.total.as_mut() {
let prev = i.to_usize().unwrap().checked_sub(1).map_or(
T::from(0_usize),
|prev_i| {
total_vec.get(I::from(prev_i)).unwrap().unwrap().to_owned()
},
);
total_vec.forced_push_at(i, prev + sum, exit)?;
}
} }
} }
} }
@@ -213,8 +276,8 @@ where
&mut self, &mut self,
max_from: I, max_from: I,
source: &mut ComputedVecBuilder<I2, T>, source: &mut ComputedVecBuilder<I2, T>,
first_indexes: &mut brk_vec::StorableVec<I, I2>, first_indexes: &mut StorableVec<I, I2>,
last_indexes: &mut brk_vec::StorableVec<I, I2>, last_indexes: &mut StorableVec<I, I2>,
exit: &Exit, exit: &Exit,
) -> Result<()> ) -> Result<()>
where where
@@ -264,9 +327,10 @@ where
let first_index = Some(first_index.to_usize()? as i64); let first_index = Some(first_index.to_usize()? as i64);
let last_index = Some(last_index.to_usize()? as i64); let last_index = Some(last_index.to_usize()? as i64);
let needs_sum_or_average = self.sum.is_some() || self.average.is_some(); let needs_sum_or_total = self.sum.is_some() || self.total.is_some();
let needs_average_sum_or_total = needs_sum_or_total || self.average.is_some();
let needs_sorted = self.max.is_some() || self.min.is_some(); let needs_sorted = self.max.is_some() || self.min.is_some();
let needs_values = needs_sorted || needs_sum_or_average; let needs_values = needs_sorted || needs_average_sum_or_total;
if needs_values { if needs_values {
if needs_sorted { if needs_sorted {
@@ -291,7 +355,7 @@ where
} }
} }
if needs_sum_or_average { if needs_average_sum_or_total {
if let Some(average) = self.average.as_mut() { if let Some(average) = self.average.as_mut() {
let values = source let values = source
.average .average
@@ -309,14 +373,27 @@ where
average.forced_push_at(i, avg, exit)?; average.forced_push_at(i, avg, exit)?;
} }
if let Some(sum_vec) = self.sum.as_mut() { if needs_sum_or_total {
let values = source let values = source
.sum .sum
.as_ref() .as_ref()
.unwrap() .unwrap()
.collect_range(first_index, last_index)?; .collect_range(first_index, last_index)?;
let sum = values.into_iter().fold(T::from(0), |a, b| a + b); let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
sum_vec.forced_push_at(i, sum, exit)?;
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
if let Some(total_vec) = self.total.as_mut() {
let prev = i.to_usize().unwrap().checked_sub(1).map_or(
T::from(0_usize),
|prev_i| {
total_vec.get(I::from(prev_i)).unwrap().unwrap().to_owned()
},
);
total_vec.forced_push_at(i, prev + sum, exit)?;
}
} }
} }
} }
@@ -381,6 +458,9 @@ where
if let Some(sum) = self.sum.as_ref() { if let Some(sum) = self.sum.as_ref() {
v.push(sum.any_vec()); v.push(sum.any_vec());
} }
if let Some(total) = self.total.as_ref() {
v.push(total.any_vec());
}
if let Some(_90p) = self._90p.as_ref() { if let Some(_90p) = self._90p.as_ref() {
v.push(_90p.any_vec()); v.push(_90p.any_vec());
} }
@@ -419,6 +499,9 @@ where
if let Some(sum) = self.sum.as_mut() { if let Some(sum) = self.sum.as_mut() {
sum.safe_flush(exit)?; sum.safe_flush(exit)?;
} }
if let Some(total) = self.total.as_mut() {
total.safe_flush(exit)?;
}
if let Some(_90p) = self._90p.as_mut() { if let Some(_90p) = self._90p.as_mut() {
_90p.safe_flush(exit)?; _90p.safe_flush(exit)?;
} }
@@ -449,6 +532,7 @@ pub struct StorableVecGeneatorOptions {
min: bool, min: bool,
first: bool, first: bool,
last: bool, last: bool,
total: bool,
} }
impl StorableVecGeneatorOptions { impl StorableVecGeneatorOptions {
@@ -507,6 +591,11 @@ impl StorableVecGeneatorOptions {
self self
} }
pub fn add_total(mut self) -> Self {
self.total = true;
self
}
pub fn rm_min(mut self) -> Self { pub fn rm_min(mut self) -> Self {
self.min = false; self.min = false;
self self
@@ -552,6 +641,11 @@ impl StorableVecGeneatorOptions {
self self
} }
pub fn rm_total(mut self) -> Self {
self.total = false;
self
}
pub fn add_minmax(mut self) -> Self { pub fn add_minmax(mut self) -> Self {
self.min = true; self.min = true;
self.max = true; self.max = true;
@@ -589,10 +683,18 @@ impl StorableVecGeneatorOptions {
self.min, self.min,
self.first, self.first,
self.last, self.last,
self.total,
] ]
.iter() .iter()
.filter(|b| **b) .filter(|b| **b)
.count() .count()
== 1 == 1
} }
pub fn copy_self_extra(&self) -> Self {
Self {
total: self.total,
..Self::default()
}
}
} }
@@ -2,6 +2,7 @@ use std::path::Path;
use brk_core::{Dateindex, Decadeindex, Monthindex, Quarterindex, Weekindex, Yearindex}; use brk_core::{Dateindex, Decadeindex, Monthindex, Quarterindex, Weekindex, Yearindex};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, Version}; use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes}; use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
@@ -14,6 +15,7 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub dateindex: ComputedVec<Dateindex, T>, pub dateindex: ComputedVec<Dateindex, T>,
pub dateindex_extra: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>, pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>, pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>, pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
@@ -33,6 +35,9 @@ where
compressed: Compressed, compressed: Compressed,
options: StorableVecGeneatorOptions, options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let dateindex_extra =
ComputedVecBuilder::forced_import(path, name, compressed, options.copy_self_extra())?;
let options = options.remove_percentiles(); let options = options.remove_percentiles();
Ok(Self { Ok(Self {
@@ -41,6 +46,7 @@ where
version, version,
compressed, compressed,
)?, )?,
dateindex_extra,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?, weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
monthindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?, monthindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
quarterindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?, quarterindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
@@ -51,19 +57,35 @@ where
pub fn compute<F>( pub fn compute<F>(
&mut self, &mut self,
mut compute: F, indexer: &mut Indexer,
indexes: &mut indexes::Vecs, indexes: &mut indexes::Vecs,
starting_indexes: &Indexes, starting_indexes: &Indexes,
exit: &Exit, exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()> ) -> color_eyre::Result<()>
where where
F: FnMut(&mut ComputedVec<Dateindex, T>) -> Result<()>, F: FnMut(
&mut ComputedVec<Dateindex, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{ {
compute(&mut self.dateindex)?; compute(
&mut self.dateindex,
indexer,
indexes,
starting_indexes,
exit,
)?;
self.dateindex_extra
.extend(starting_indexes.dateindex, self.dateindex.mut_vec(), exit)?;
self.weekindex.compute( self.weekindex.compute(
starting_indexes.weekindex, starting_indexes.weekindex,
&mut self.dateindex, self.dateindex.mut_vec(),
indexes.weekindex_to_first_dateindex.mut_vec(), indexes.weekindex_to_first_dateindex.mut_vec(),
indexes.weekindex_to_last_dateindex.mut_vec(), indexes.weekindex_to_last_dateindex.mut_vec(),
exit, exit,
@@ -71,7 +93,7 @@ where
self.monthindex.compute( self.monthindex.compute(
starting_indexes.monthindex, starting_indexes.monthindex,
&mut self.dateindex, self.dateindex.mut_vec(),
indexes.monthindex_to_first_dateindex.mut_vec(), indexes.monthindex_to_first_dateindex.mut_vec(),
indexes.monthindex_to_last_dateindex.mut_vec(), indexes.monthindex_to_last_dateindex.mut_vec(),
exit, exit,
@@ -107,6 +129,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> { pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[ [
vec![self.dateindex.any_vec()], vec![self.dateindex.any_vec()],
self.dateindex_extra.any_vecs(),
self.weekindex.any_vecs(), self.weekindex.any_vecs(),
self.monthindex.any_vecs(), self.monthindex.any_vecs(),
self.quarterindex.any_vecs(), self.quarterindex.any_vecs(),
@@ -4,7 +4,8 @@ use brk_core::{
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Weekindex, Yearindex, Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Weekindex, Yearindex,
}; };
use brk_exit::Exit; use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed, Result, Version}; use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, StorableVec, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes}; use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
@@ -15,7 +16,8 @@ pub struct ComputedVecsFromHeight<T>
where where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub height: ComputedVec<Height, T>, pub height: Option<ComputedVec<Height, T>>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>, pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>, pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>, pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
@@ -34,15 +36,18 @@ where
pub fn forced_import( pub fn forced_import(
path: &Path, path: &Path,
name: &str, name: &str,
compute_source: bool,
version: Version, version: Version,
compressed: Compressed, compressed: Compressed,
options: StorableVecGeneatorOptions, options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> { ) -> color_eyre::Result<Self> {
let height = ComputedVec::forced_import( let height = compute_source.then(|| {
&path.join(format!("height_to_{name}")), ComputedVec::forced_import(&path.join(format!("height_to_{name}")), version, compressed)
version, .unwrap()
compressed, });
)?;
let height_extra =
ComputedVecBuilder::forced_import(path, name, compressed, options.copy_self_extra())?;
let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?; let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
@@ -50,6 +55,7 @@ where
Ok(Self { Ok(Self {
height, height,
height_extra,
dateindex, dateindex,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?, weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?, difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
@@ -61,21 +67,51 @@ where
}) })
} }
pub fn compute<F>( pub fn compute_all<F>(
&mut self, &mut self,
mut compute: F, indexer: &mut Indexer,
indexes: &mut indexes::Vecs, indexes: &mut indexes::Vecs,
starting_indexes: &Indexes, starting_indexes: &Indexes,
exit: &Exit, exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()> ) -> color_eyre::Result<()>
where where
F: FnMut(&mut ComputedVec<Height, T>) -> Result<()>, F: FnMut(
&mut ComputedVec<Height, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{ {
compute(&mut self.height)?; compute(
self.height.as_mut().unwrap(),
indexer,
indexes,
starting_indexes,
exit,
)?;
self.compute_rest(indexes, starting_indexes, exit, None)?;
Ok(())
}
pub fn compute_rest(
&mut self,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
height: Option<&mut StorableVec<Height, T>>,
) -> color_eyre::Result<()> {
let height = height.unwrap_or_else(|| self.height.as_mut().unwrap().mut_vec());
self.height_extra
.extend(starting_indexes.height, height, exit)?;
self.dateindex.compute( self.dateindex.compute(
starting_indexes.dateindex, starting_indexes.dateindex,
&mut self.height, height,
indexes.dateindex_to_first_height.mut_vec(), indexes.dateindex_to_first_height.mut_vec(),
indexes.dateindex_to_last_height.mut_vec(), indexes.dateindex_to_last_height.mut_vec(),
exit, exit,
@@ -123,7 +159,7 @@ where
self.difficultyepoch.compute( self.difficultyepoch.compute(
starting_indexes.difficultyepoch, starting_indexes.difficultyepoch,
&mut self.height, height,
indexes.difficultyepoch_to_first_height.mut_vec(), indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(), indexes.difficultyepoch_to_last_height.mut_vec(),
exit, exit,
@@ -134,7 +170,8 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> { pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[ [
vec![self.height.any_vec()], self.height.as_ref().map_or(vec![], |v| vec![v.any_vec()]),
self.height_extra.any_vecs(),
self.dateindex.any_vecs(), self.dateindex.any_vecs(),
self.weekindex.any_vecs(), self.weekindex.any_vecs(),
self.difficultyepoch.any_vecs(), self.difficultyepoch.any_vecs(),
@@ -2,6 +2,7 @@ use std::path::Path;
use brk_core::{Difficultyepoch, Height}; use brk_core::{Difficultyepoch, Height};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, Version}; use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes}; use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
@@ -14,6 +15,7 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub height: ComputedVec<Height, T>, pub height: ComputedVec<Height, T>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>, pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>, // TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
} }
@@ -36,10 +38,14 @@ where
compressed, compressed,
)?; )?;
let height_extra =
ComputedVecBuilder::forced_import(path, name, compressed, options.copy_self_extra())?;
let options = options.remove_percentiles(); let options = options.remove_percentiles();
Ok(Self { Ok(Self {
height, height,
height_extra,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?, difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, compressed, options)?, // halvingepoch: StorableVecGeneator::forced_import(path, name, compressed, options)?,
}) })
@@ -47,19 +53,29 @@ where
pub fn compute<F>( pub fn compute<F>(
&mut self, &mut self,
mut compute: F, indexer: &mut Indexer,
indexes: &mut indexes::Vecs, indexes: &mut indexes::Vecs,
starting_indexes: &Indexes, starting_indexes: &Indexes,
exit: &Exit, exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()> ) -> color_eyre::Result<()>
where where
F: FnMut(&mut ComputedVec<Height, T>) -> Result<()>, F: FnMut(
&mut ComputedVec<Height, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{ {
compute(&mut self.height)?; compute(&mut self.height, indexer, indexes, starting_indexes, exit)?;
self.height_extra
.extend(starting_indexes.height, self.height.mut_vec(), exit)?;
self.difficultyepoch.compute( self.difficultyepoch.compute(
starting_indexes.difficultyepoch, starting_indexes.difficultyepoch,
&mut self.height, self.height.mut_vec(),
indexes.difficultyepoch_to_first_height.mut_vec(), indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(), indexes.difficultyepoch_to_last_height.mut_vec(),
exit, exit,
@@ -71,6 +87,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> { pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[ [
vec![self.height.any_vec()], vec![self.height.any_vec()],
self.height_extra.any_vecs(),
self.difficultyepoch.any_vecs(), self.difficultyepoch.any_vecs(),
// self.halvingepoch.as_any_vecs(), // self.halvingepoch.as_any_vecs(),
] ]
@@ -18,6 +18,7 @@ where
T: ComputedType + PartialOrd, T: ComputedType + PartialOrd,
{ {
pub txindex: ComputedVec<Txindex, T>, pub txindex: ComputedVec<Txindex, T>,
pub txindex_extra: ComputedVecBuilder<Txindex, T>,
pub height: ComputedVecBuilder<Height, T>, pub height: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>, pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>, pub weekindex: ComputedVecBuilder<Weekindex, T>,
@@ -47,6 +48,13 @@ where
compressed, compressed,
)?; )?;
let txindex_extra = ComputedVecBuilder::forced_import(
path,
name,
compressed,
StorableVecGeneatorOptions::default(),
)?;
let height = ComputedVecBuilder::forced_import(path, name, compressed, options)?; let height = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?; let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
@@ -54,6 +62,7 @@ where
Ok(Self { Ok(Self {
txindex, txindex,
txindex_extra,
height, height,
dateindex, dateindex,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?, weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
@@ -68,20 +77,29 @@ where
pub fn compute<F>( pub fn compute<F>(
&mut self, &mut self,
mut compute: F,
indexer: &mut Indexer, indexer: &mut Indexer,
indexes: &mut indexes::Vecs, indexes: &mut indexes::Vecs,
starting_indexes: &Indexes, starting_indexes: &Indexes,
exit: &Exit, exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()> ) -> color_eyre::Result<()>
where where
F: FnMut(&mut ComputedVec<Txindex, T>) -> Result<()>, F: FnMut(
&mut ComputedVec<Txindex, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{ {
compute(&mut self.txindex)?; compute(&mut self.txindex, indexer, indexes, starting_indexes, exit)?;
self.txindex_extra
.extend(starting_indexes.txindex, self.txindex.mut_vec(), exit)?;
self.height.compute( self.height.compute(
starting_indexes.height, starting_indexes.height,
&mut self.txindex, self.txindex.mut_vec(),
indexer.mut_vecs().height_to_first_txindex.mut_vec(), indexer.mut_vecs().height_to_first_txindex.mut_vec(),
indexes.height_to_last_txindex.mut_vec(), indexes.height_to_last_txindex.mut_vec(),
exit, exit,
@@ -149,6 +167,7 @@ where
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> { pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[ [
vec![self.txindex.any_vec()], vec![self.txindex.any_vec()],
self.txindex_extra.any_vecs(),
self.height.any_vecs(), self.height.any_vecs(),
self.dateindex.any_vecs(), self.dateindex.any_vecs(),
self.weekindex.any_vecs(), self.weekindex.any_vecs(),
+49 -49
View File
@@ -71,242 +71,242 @@ impl Vecs {
Ok(Self { Ok(Self {
dateindex_to_date: ComputedVec::forced_import( dateindex_to_date: ComputedVec::forced_import(
&path.join("dateindex_to_date"), &path.join("dateindex_to_date"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_dateindex: ComputedVec::forced_import( dateindex_to_dateindex: ComputedVec::forced_import(
&path.join("dateindex_to_dateindex"), &path.join("dateindex_to_dateindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_first_height: ComputedVec::forced_import( dateindex_to_first_height: ComputedVec::forced_import(
&path.join("dateindex_to_first_height"), &path.join("dateindex_to_first_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_last_height: ComputedVec::forced_import( dateindex_to_last_height: ComputedVec::forced_import(
&path.join("dateindex_to_last_height"), &path.join("dateindex_to_last_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_real_date: ComputedVec::forced_import( height_to_real_date: ComputedVec::forced_import(
&path.join("height_to_real_date"), &path.join("height_to_real_date"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_fixed_date: ComputedVec::forced_import( height_to_fixed_date: ComputedVec::forced_import(
&path.join("height_to_fixed_date"), &path.join("height_to_fixed_date"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_dateindex: ComputedVec::forced_import( height_to_dateindex: ComputedVec::forced_import(
&path.join("height_to_dateindex"), &path.join("height_to_dateindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_height: ComputedVec::forced_import( height_to_height: ComputedVec::forced_import(
&path.join("height_to_height"), &path.join("height_to_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_last_txindex: ComputedVec::forced_import( height_to_last_txindex: ComputedVec::forced_import(
&path.join("height_to_last_txindex"), &path.join("height_to_last_txindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_last_txinindex: ComputedVec::forced_import( txindex_to_last_txinindex: ComputedVec::forced_import(
&path.join("txindex_to_last_txinindex"), &path.join("txindex_to_last_txinindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_last_txoutindex: ComputedVec::forced_import( txindex_to_last_txoutindex: ComputedVec::forced_import(
&path.join("txindex_to_last_txoutindex"), &path.join("txindex_to_last_txoutindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
difficultyepoch_to_first_height: ComputedVec::forced_import( difficultyepoch_to_first_height: ComputedVec::forced_import(
&path.join("difficultyepoch_to_first_height"), &path.join("difficultyepoch_to_first_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
difficultyepoch_to_last_height: ComputedVec::forced_import( difficultyepoch_to_last_height: ComputedVec::forced_import(
&path.join("difficultyepoch_to_last_height"), &path.join("difficultyepoch_to_last_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
halvingepoch_to_first_height: ComputedVec::forced_import( halvingepoch_to_first_height: ComputedVec::forced_import(
&path.join("halvingepoch_to_first_height"), &path.join("halvingepoch_to_first_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
halvingepoch_to_last_height: ComputedVec::forced_import( halvingepoch_to_last_height: ComputedVec::forced_import(
&path.join("halvingepoch_to_last_height"), &path.join("halvingepoch_to_last_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
weekindex_to_first_dateindex: ComputedVec::forced_import( weekindex_to_first_dateindex: ComputedVec::forced_import(
&path.join("weekindex_to_first_dateindex"), &path.join("weekindex_to_first_dateindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
weekindex_to_last_dateindex: ComputedVec::forced_import( weekindex_to_last_dateindex: ComputedVec::forced_import(
&path.join("weekindex_to_last_dateindex"), &path.join("weekindex_to_last_dateindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_first_dateindex: ComputedVec::forced_import( monthindex_to_first_dateindex: ComputedVec::forced_import(
&path.join("monthindex_to_first_dateindex"), &path.join("monthindex_to_first_dateindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_last_dateindex: ComputedVec::forced_import( monthindex_to_last_dateindex: ComputedVec::forced_import(
&path.join("monthindex_to_last_dateindex"), &path.join("monthindex_to_last_dateindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
yearindex_to_first_monthindex: ComputedVec::forced_import( yearindex_to_first_monthindex: ComputedVec::forced_import(
&path.join("yearindex_to_first_monthindex"), &path.join("yearindex_to_first_monthindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
yearindex_to_last_monthindex: ComputedVec::forced_import( yearindex_to_last_monthindex: ComputedVec::forced_import(
&path.join("yearindex_to_last_monthindex"), &path.join("yearindex_to_last_monthindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
decadeindex_to_first_yearindex: ComputedVec::forced_import( decadeindex_to_first_yearindex: ComputedVec::forced_import(
&path.join("decadeindex_to_first_yearindex"), &path.join("decadeindex_to_first_yearindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
decadeindex_to_last_yearindex: ComputedVec::forced_import( decadeindex_to_last_yearindex: ComputedVec::forced_import(
&path.join("decadeindex_to_last_yearindex"), &path.join("decadeindex_to_last_yearindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_weekindex: ComputedVec::forced_import( dateindex_to_weekindex: ComputedVec::forced_import(
&path.join("dateindex_to_weekindex"), &path.join("dateindex_to_weekindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_monthindex: ComputedVec::forced_import( dateindex_to_monthindex: ComputedVec::forced_import(
&path.join("dateindex_to_monthindex"), &path.join("dateindex_to_monthindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_yearindex: ComputedVec::forced_import( monthindex_to_yearindex: ComputedVec::forced_import(
&path.join("monthindex_to_yearindex"), &path.join("monthindex_to_yearindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
yearindex_to_decadeindex: ComputedVec::forced_import( yearindex_to_decadeindex: ComputedVec::forced_import(
&path.join("yearindex_to_decadeindex"), &path.join("yearindex_to_decadeindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_difficultyepoch: ComputedVec::forced_import( height_to_difficultyepoch: ComputedVec::forced_import(
&path.join("height_to_difficultyepoch"), &path.join("height_to_difficultyepoch"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_halvingepoch: ComputedVec::forced_import( height_to_halvingepoch: ComputedVec::forced_import(
&path.join("height_to_halvingepoch"), &path.join("height_to_halvingepoch"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
weekindex_to_weekindex: ComputedVec::forced_import( weekindex_to_weekindex: ComputedVec::forced_import(
&path.join("weekindex_to_weekindex"), &path.join("weekindex_to_weekindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_monthindex: ComputedVec::forced_import( monthindex_to_monthindex: ComputedVec::forced_import(
&path.join("monthindex_to_monthindex"), &path.join("monthindex_to_monthindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
yearindex_to_yearindex: ComputedVec::forced_import( yearindex_to_yearindex: ComputedVec::forced_import(
&path.join("yearindex_to_yearindex"), &path.join("yearindex_to_yearindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
decadeindex_to_decadeindex: ComputedVec::forced_import( decadeindex_to_decadeindex: ComputedVec::forced_import(
&path.join("decadeindex_to_decadeindex"), &path.join("decadeindex_to_decadeindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
difficultyepoch_to_difficultyepoch: ComputedVec::forced_import( difficultyepoch_to_difficultyepoch: ComputedVec::forced_import(
&path.join("difficultyepoch_to_difficultyepoch"), &path.join("difficultyepoch_to_difficultyepoch"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
halvingepoch_to_halvingepoch: ComputedVec::forced_import( halvingepoch_to_halvingepoch: ComputedVec::forced_import(
&path.join("halvingepoch_to_halvingepoch"), &path.join("halvingepoch_to_halvingepoch"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_timestamp: ComputedVec::forced_import( dateindex_to_timestamp: ComputedVec::forced_import(
&path.join("dateindex_to_timestamp"), &path.join("dateindex_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
decadeindex_to_timestamp: ComputedVec::forced_import( decadeindex_to_timestamp: ComputedVec::forced_import(
&path.join("decadeindex_to_timestamp"), &path.join("decadeindex_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
difficultyepoch_to_timestamp: ComputedVec::forced_import( difficultyepoch_to_timestamp: ComputedVec::forced_import(
&path.join("difficultyepoch_to_timestamp"), &path.join("difficultyepoch_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
halvingepoch_to_timestamp: ComputedVec::forced_import( halvingepoch_to_timestamp: ComputedVec::forced_import(
&path.join("halvingepoch_to_timestamp"), &path.join("halvingepoch_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_timestamp: ComputedVec::forced_import( monthindex_to_timestamp: ComputedVec::forced_import(
&path.join("monthindex_to_timestamp"), &path.join("monthindex_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
weekindex_to_timestamp: ComputedVec::forced_import( weekindex_to_timestamp: ComputedVec::forced_import(
&path.join("weekindex_to_timestamp"), &path.join("weekindex_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
yearindex_to_timestamp: ComputedVec::forced_import( yearindex_to_timestamp: ComputedVec::forced_import(
&path.join("yearindex_to_timestamp"), &path.join("yearindex_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_fixed_timestamp: ComputedVec::forced_import( height_to_fixed_timestamp: ComputedVec::forced_import(
&path.join("height_to_fixed_timestamp"), &path.join("height_to_fixed_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_quarterindex: ComputedVec::forced_import( monthindex_to_quarterindex: ComputedVec::forced_import(
&path.join("monthindex_to_quarterindex"), &path.join("monthindex_to_quarterindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
quarterindex_to_first_monthindex: ComputedVec::forced_import( quarterindex_to_first_monthindex: ComputedVec::forced_import(
&path.join("quarterindex_to_first_monthindex"), &path.join("quarterindex_to_first_monthindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
quarterindex_to_last_monthindex: ComputedVec::forced_import( quarterindex_to_last_monthindex: ComputedVec::forced_import(
&path.join("quarterindex_to_last_monthindex"), &path.join("quarterindex_to_last_monthindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
quarterindex_to_quarterindex: ComputedVec::forced_import( quarterindex_to_quarterindex: ComputedVec::forced_import(
&path.join("quarterindex_to_quarterindex"), &path.join("quarterindex_to_quarterindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
quarterindex_to_timestamp: ComputedVec::forced_import( quarterindex_to_timestamp: ComputedVec::forced_import(
&path.join("quarterindex_to_timestamp"), &path.join("quarterindex_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
}) })
@@ -320,7 +320,7 @@ impl Vecs {
) -> color_eyre::Result<Indexes> { ) -> color_eyre::Result<Indexes> {
let indexer_vecs = indexer.mut_vecs(); let indexer_vecs = indexer.mut_vecs();
let height_count = indexer_vecs.height_to_size.len(); let height_count = indexer_vecs.height_to_block_size.len();
let txindexes_count = indexer_vecs.txindex_to_txid.len(); let txindexes_count = indexer_vecs.txindex_to_txid.len();
let txinindexes_count = indexer_vecs.txinindex_to_txoutindex.len(); let txinindexes_count = indexer_vecs.txinindex_to_txoutindex.len();
let txoutindexes_count = indexer_vecs.txoutindex_to_addressindex.len(); let txoutindexes_count = indexer_vecs.txoutindex_to_addressindex.len();
@@ -55,166 +55,171 @@ impl Vecs {
pub fn forced_import(path: &Path, compressed: Compressed) -> color_eyre::Result<Self> { pub fn forced_import(path: &Path, compressed: Compressed) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?; fs::create_dir_all(path)?;
let mut fetched_path = path.to_owned();
fetched_path.pop();
fetched_path.pop();
fetched_path = fetched_path.join("fetched/vecs");
Ok(Self { Ok(Self {
dateindex_to_ohlc_in_cents: ComputedVec::forced_import( dateindex_to_ohlc_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_ohlc_in_cents"), &fetched_path.join("dateindex_to_ohlc_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_ohlc: ComputedVec::forced_import( dateindex_to_ohlc: ComputedVec::forced_import(
&path.join("dateindex_to_ohlc"), &path.join("dateindex_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_close_in_cents: ComputedVec::forced_import( dateindex_to_close_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_close_in_cents"), &path.join("dateindex_to_close_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_high_in_cents: ComputedVec::forced_import( dateindex_to_high_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_high_in_cents"), &path.join("dateindex_to_high_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_low_in_cents: ComputedVec::forced_import( dateindex_to_low_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_low_in_cents"), &path.join("dateindex_to_low_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
dateindex_to_open_in_cents: ComputedVec::forced_import( dateindex_to_open_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_open_in_cents"), &path.join("dateindex_to_open_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_ohlc_in_cents: ComputedVec::forced_import( height_to_ohlc_in_cents: ComputedVec::forced_import(
&path.join("height_to_ohlc_in_cents"), &fetched_path.join("height_to_ohlc_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_ohlc: ComputedVec::forced_import( height_to_ohlc: ComputedVec::forced_import(
&path.join("height_to_ohlc"), &path.join("height_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_close_in_cents: ComputedVec::forced_import( height_to_close_in_cents: ComputedVec::forced_import(
&path.join("height_to_close_in_cents"), &path.join("height_to_close_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_high_in_cents: ComputedVec::forced_import( height_to_high_in_cents: ComputedVec::forced_import(
&path.join("height_to_high_in_cents"), &path.join("height_to_high_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_low_in_cents: ComputedVec::forced_import( height_to_low_in_cents: ComputedVec::forced_import(
&path.join("height_to_low_in_cents"), &path.join("height_to_low_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_open_in_cents: ComputedVec::forced_import( height_to_open_in_cents: ComputedVec::forced_import(
&path.join("height_to_open_in_cents"), &path.join("height_to_open_in_cents"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
timeindexes_to_open: ComputedVecsFromDateindex::forced_import( timeindexes_to_open: ComputedVecsFromDateindex::forced_import(
path, path,
"open", "open",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_first(), StorableVecGeneatorOptions::default().add_first(),
)?, )?,
timeindexes_to_high: ComputedVecsFromDateindex::forced_import( timeindexes_to_high: ComputedVecsFromDateindex::forced_import(
path, path,
"high", "high",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_max(), StorableVecGeneatorOptions::default().add_max(),
)?, )?,
timeindexes_to_low: ComputedVecsFromDateindex::forced_import( timeindexes_to_low: ComputedVecsFromDateindex::forced_import(
path, path,
"low", "low",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_min(), StorableVecGeneatorOptions::default().add_min(),
)?, )?,
timeindexes_to_close: ComputedVecsFromDateindex::forced_import( timeindexes_to_close: ComputedVecsFromDateindex::forced_import(
path, path,
"close", "close",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_last(), StorableVecGeneatorOptions::default().add_last(),
)?, )?,
timeindexes_to_sats_per_dollar: ComputedVecsFromDateindex::forced_import( timeindexes_to_sats_per_dollar: ComputedVecsFromDateindex::forced_import(
path, path,
"sats_per_dollar", "sats_per_dollar",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_last(), StorableVecGeneatorOptions::default().add_last(),
)?, )?,
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
path, path,
"open", "open",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_first(), StorableVecGeneatorOptions::default().add_first(),
)?, )?,
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
path, path,
"high", "high",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_max(), StorableVecGeneatorOptions::default().add_max(),
)?, )?,
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
path, path,
"low", "low",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_min(), StorableVecGeneatorOptions::default().add_min(),
)?, )?,
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
path, path,
"close", "close",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_last(), StorableVecGeneatorOptions::default().add_last(),
)?, )?,
chainindexes_to_sats_per_dollar: ComputedVecsFromHeightStrict::forced_import( chainindexes_to_sats_per_dollar: ComputedVecsFromHeightStrict::forced_import(
path, path,
"sats_per_dollar", "sats_per_dollar",
Version::ONE, Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_last(), StorableVecGeneatorOptions::default().add_last(),
)?, )?,
weekindex_to_ohlc: ComputedVec::forced_import( weekindex_to_ohlc: ComputedVec::forced_import(
&path.join("weekindex_to_ohlc"), &path.join("weekindex_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
difficultyepoch_to_ohlc: ComputedVec::forced_import( difficultyepoch_to_ohlc: ComputedVec::forced_import(
&path.join("difficultyepoch_to_ohlc"), &path.join("difficultyepoch_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
monthindex_to_ohlc: ComputedVec::forced_import( monthindex_to_ohlc: ComputedVec::forced_import(
&path.join("monthindex_to_ohlc"), &path.join("monthindex_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
quarterindex_to_ohlc: ComputedVec::forced_import( quarterindex_to_ohlc: ComputedVec::forced_import(
&path.join("quarterindex_to_ohlc"), &path.join("quarterindex_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
yearindex_to_ohlc: ComputedVec::forced_import( yearindex_to_ohlc: ComputedVec::forced_import(
&path.join("yearindex_to_ohlc"), &path.join("yearindex_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
// halvingepoch_to_ohlc: StorableVec::forced_import(&path.join("halvingepoch_to_ohlc"), Version::ONE, compressed)?, // halvingepoch_to_ohlc: StorableVec::forced_import(&path.join("halvingepoch_to_ohlc"), Version::ZERO, compressed)?,
decadeindex_to_ohlc: ComputedVec::forced_import( decadeindex_to_ohlc: ComputedVec::forced_import(
&path.join("decadeindex_to_ohlc"), &path.join("decadeindex_to_ohlc"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
}) })
@@ -328,7 +333,11 @@ impl Vecs {
)?; )?;
self.timeindexes_to_close.compute( self.timeindexes_to_close.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.dateindex, starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(), self.dateindex_to_ohlc.mut_vec(),
@@ -336,13 +345,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.timeindexes_to_high.compute( self.timeindexes_to_high.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.dateindex, starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(), self.dateindex_to_ohlc.mut_vec(),
@@ -350,13 +360,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.timeindexes_to_low.compute( self.timeindexes_to_low.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.dateindex, starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(), self.dateindex_to_ohlc.mut_vec(),
@@ -364,13 +375,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.timeindexes_to_open.compute( self.timeindexes_to_open.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.dateindex, starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(), self.dateindex_to_ohlc.mut_vec(),
@@ -378,13 +390,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.chainindexes_to_close.compute( self.chainindexes_to_close.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.height, starting_indexes.height,
self.height_to_ohlc.mut_vec(), self.height_to_ohlc.mut_vec(),
@@ -392,13 +405,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.chainindexes_to_high.compute( self.chainindexes_to_high.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.height, starting_indexes.height,
self.height_to_ohlc.mut_vec(), self.height_to_ohlc.mut_vec(),
@@ -406,13 +420,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.chainindexes_to_low.compute( self.chainindexes_to_low.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.height, starting_indexes.height,
self.height_to_ohlc.mut_vec(), self.height_to_ohlc.mut_vec(),
@@ -420,13 +435,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.chainindexes_to_open.compute( self.chainindexes_to_open.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.height, starting_indexes.height,
self.height_to_ohlc.mut_vec(), self.height_to_ohlc.mut_vec(),
@@ -434,9 +450,6 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.weekindex_to_ohlc.compute_transform( self.weekindex_to_ohlc.compute_transform(
@@ -720,7 +733,11 @@ impl Vecs {
)?; )?;
self.chainindexes_to_sats_per_dollar.compute( self.chainindexes_to_sats_per_dollar.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.height, starting_indexes.height,
self.chainindexes_to_close.height.mut_vec(), self.chainindexes_to_close.height.mut_vec(),
@@ -728,13 +745,14 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
self.timeindexes_to_sats_per_dollar.compute( self.timeindexes_to_sats_per_dollar.compute(
|v| { indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_transform( v.compute_transform(
starting_indexes.dateindex, starting_indexes.dateindex,
self.timeindexes_to_close.dateindex.mut_vec(), self.timeindexes_to_close.dateindex.mut_vec(),
@@ -742,9 +760,6 @@ impl Vecs {
exit, exit,
) )
}, },
indexes,
starting_indexes,
exit,
)?; )?;
Ok(()) Ok(())
@@ -1,11 +1,15 @@
use std::{fs, path::Path}; use std::{fs, path::Path};
use brk_core::Txindex; use brk_core::{StoredU64, Txindex};
use brk_exit::Exit; use brk_exit::Exit;
use brk_indexer::Indexer; use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version}; use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{ComputedVec, Indexes, indexes}; use super::{
ComputedVec, Indexes,
grouped::{ComputedVecsFromTxindex, StorableVecGeneatorOptions},
indexes,
};
#[derive(Clone)] #[derive(Clone)]
pub struct Vecs { pub struct Vecs {
@@ -21,10 +25,10 @@ pub struct Vecs {
// pub txindex_to_fee: ComputedVec<Txindex, Sats>, // pub txindex_to_fee: ComputedVec<Txindex, Sats>,
pub txindex_to_is_coinbase: ComputedVec<Txindex, bool>, pub txindex_to_is_coinbase: ComputedVec<Txindex, bool>,
// pub txindex_to_feerate: ComputedVec<Txindex, Feerate>, // pub txindex_to_feerate: ComputedVec<Txindex, Feerate>,
pub txindex_to_inputs_count: ComputedVec<Txindex, u32>, pub txindex_to_input_count: ComputedVecsFromTxindex<StoredU64>,
// pub txindex_to_inputs_sum: ComputedVec<Txindex, Sats>, // pub txindex_to_input_sum: ComputedVec<Txindex, Sats>,
pub txindex_to_outputs_count: ComputedVec<Txindex, u32>, pub txindex_to_output_count: ComputedVecsFromTxindex<StoredU64>,
// pub txindex_to_outputs_sum: ComputedVec<Txindex, Sats>, // pub txindex_to_output_sum: ComputedVec<Txindex, Sats>,
// pub txinindex_to_value: ComputedVec<Txinindex, Sats>, // pub txinindex_to_value: ComputedVec<Txinindex, Sats>,
} }
@@ -33,52 +37,48 @@ impl Vecs {
fs::create_dir_all(path)?; fs::create_dir_all(path)?;
Ok(Self { Ok(Self {
// height_to_fee: StorableVec::forced_import(&path.join("height_to_fee"), Version::ONE)?, // height_to_fee: StorableVec::forced_import(&path.join("height_to_fee"), Version::ZERO)?,
// height_to_input_count: StorableVec::forced_import( // height_to_input_count: StorableVec::forced_import(
// &path.join("height_to_input_count"), // &path.join("height_to_input_count"),
// Version::ONE, // Version::ZERO,
// )?, // )?,
// height_to_maxfeerate: StorableVec::forced_import(&path.join("height_to_maxfeerate"), Version::ONE)?, // height_to_maxfeerate: StorableVec::forced_import(&path.join("height_to_maxfeerate"), Version::ZERO)?,
// height_to_medianfeerate: StorableVec::forced_import(&path.join("height_to_medianfeerate"), Version::ONE)?, // height_to_medianfeerate: StorableVec::forced_import(&path.join("height_to_medianfeerate"), Version::ZERO)?,
// height_to_minfeerate: StorableVec::forced_import(&path.join("height_to_minfeerate"), Version::ONE)?, // height_to_minfeerate: StorableVec::forced_import(&path.join("height_to_minfeerate"), Version::ZERO)?,
// height_to_output_count: StorableVec::forced_import( // height_to_output_count: StorableVec::forced_import(
// &path.join("height_to_output_count"), // &path.join("height_to_output_count"),
// Version::ONE, // Version::ZERO,
// )?, // )?,
// height_to_subsidy: StorableVec::forced_import(&path.join("height_to_subsidy"), Version::ONE)?, // height_to_subsidy: StorableVec::forced_import(&path.join("height_to_subsidy"), Version::ZERO)?,
// height_to_totalfees: StorableVec::forced_import(&path.join("height_to_totalfees"), Version::ONE)?, // height_to_totalfees: StorableVec::forced_import(&path.join("height_to_totalfees"), Version::ZERO)?,
// height_to_txcount: StorableVec::forced_import(&path.join("height_to_txcount"), Version::ONE)?, // height_to_txcount: StorableVec::forced_import(&path.join("height_to_txcount"), Version::ZERO)?,
// txindex_to_fee: StorableVec::forced_import( // txindex_to_fee: StorableVec::forced_import(
// &path.join("txindex_to_fee"), // &path.join("txindex_to_fee"),
// Version::ONE, // Version::ZERO,
// )?, // )?,
txindex_to_is_coinbase: ComputedVec::forced_import( txindex_to_is_coinbase: ComputedVec::forced_import(
&path.join("txindex_to_is_coinbase"), &path.join("txindex_to_is_coinbase"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
// txindex_to_feerate: StorableVec::forced_import(&path.join("txindex_to_feerate"), Version::ONE)?, // txindex_to_feerate: StorableVec::forced_import(&path.join("txindex_to_feerate"), Version::ZERO)?,
txindex_to_inputs_count: ComputedVec::forced_import( txindex_to_input_count: ComputedVecsFromTxindex::forced_import(
&path.join("txindex_to_inputs_count"), path,
Version::ONE, "input_count",
Version::ZERO,
compressed, compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?, )?,
// txindex_to_inputs_sum: StorableVec::forced_import( txindex_to_output_count: ComputedVecsFromTxindex::forced_import(
// &path.join("txindex_to_inputs_sum"), path,
// Version::ONE, "output_count",
// )?, Version::ZERO,
txindex_to_outputs_count: ComputedVec::forced_import(
&path.join("txindex_to_outputs_count"),
Version::ONE,
compressed, compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?, )?,
// txindex_to_outputs_sum: StorableVec::forced_import(
// &path.join("txindex_to_outputs_sum"),
// Version::ONE,
// )?,
// txinindex_to_value: StorableVec::forced_import( // txinindex_to_value: StorableVec::forced_import(
// &path.join("txinindex_to_value"), // &path.join("txinindex_to_value"),
// Version::ONE, // Version::ZERO,
// compressed, // compressed,
// )?, // )?,
}) })
@@ -91,22 +91,38 @@ impl Vecs {
starting_indexes: &Indexes, starting_indexes: &Indexes,
exit: &Exit, exit: &Exit,
) -> color_eyre::Result<()> { ) -> color_eyre::Result<()> {
self.txindex_to_input_count.compute(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, indexes, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
indexer.mut_vecs().txindex_to_first_txinindex.mut_vec(),
indexes.txindex_to_last_txinindex.mut_vec(),
exit,
)
},
)?;
self.txindex_to_output_count.compute(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, indexes, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
indexer.mut_vecs().txindex_to_first_txoutindex.mut_vec(),
indexes.txindex_to_last_txoutindex.mut_vec(),
exit,
)
},
)?;
let indexer_vecs = indexer.mut_vecs(); let indexer_vecs = indexer.mut_vecs();
self.txindex_to_inputs_count.compute_count_from_indexes(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txinindex.mut_vec(),
indexes.txindex_to_last_txinindex.mut_vec(),
exit,
)?;
self.txindex_to_outputs_count.compute_count_from_indexes(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txoutindex.mut_vec(),
indexes.txindex_to_last_txoutindex.mut_vec(),
exit,
)?;
self.txindex_to_is_coinbase.compute_is_first_ordered( self.txindex_to_is_coinbase.compute_is_first_ordered(
starting_indexes.txindex, starting_indexes.txindex,
indexer_vecs.txindex_to_height.mut_vec(), indexer_vecs.txindex_to_height.mut_vec(),
@@ -135,31 +151,15 @@ impl Vecs {
// &mut indexer.vecs().height_to_first_txindex, // &mut indexer.vecs().height_to_first_txindex,
// )?; // )?;
// self.vecs.height_to_dateindex.compute(...)
// ---
// Date to X
// ---
// ...
// ---
// Month to X
// ---
// ...
// ---
// Year to X
// ---
// ...
Ok(()) Ok(())
} }
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> { pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
vec![ [
self.txindex_to_is_coinbase.any_vec(), vec![self.txindex_to_is_coinbase.any_vec()],
self.txindex_to_inputs_count.any_vec(), self.txindex_to_output_count.any_vecs(),
self.txindex_to_outputs_count.any_vec(), self.txindex_to_input_count.any_vecs(),
] ]
.concat()
} }
} }
+6
View File
@@ -20,6 +20,9 @@ mod monthindex;
mod ohlc; mod ohlc;
mod quarterindex; mod quarterindex;
mod sats; mod sats;
mod stored_u32;
mod stored_u64;
mod stored_usize;
mod timestamp; mod timestamp;
mod txid; mod txid;
mod txindex; mod txindex;
@@ -55,6 +58,9 @@ pub use monthindex::*;
pub use ohlc::*; pub use ohlc::*;
pub use quarterindex::*; pub use quarterindex::*;
pub use sats::*; pub use sats::*;
pub use stored_u32::*;
pub use stored_u64::*;
pub use stored_usize::*;
pub use timestamp::*; pub use timestamp::*;
pub use txid::*; pub use txid::*;
pub use txindex::*; pub use txindex::*;
+79
View File
@@ -0,0 +1,79 @@
use std::ops::{Add, Div};
use derive_deref::Deref;
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct StoredU32(u32);
impl StoredU32 {
pub const ZERO: Self = Self(0);
pub fn new(counter: u32) -> Self {
Self(counter)
}
}
impl From<u32> for StoredU32 {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<usize> for StoredU32 {
fn from(value: usize) -> Self {
Self(value as u32)
}
}
impl CheckedSub<StoredU32> for StoredU32 {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Div<usize> for StoredU32 {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
Self(self.0 / rhs as u32)
}
}
impl Add for StoredU32 {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl From<f64> for StoredU32 {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {
panic!()
}
Self(value as u32)
}
}
impl From<StoredU32> for f64 {
fn from(value: StoredU32) -> Self {
value.0 as f64
}
}
+93
View File
@@ -0,0 +1,93 @@
use std::ops::{Add, Div};
use derive_deref::Deref;
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Txinindex, Txoutindex};
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct StoredU64(u64);
impl StoredU64 {
pub const ZERO: Self = Self(0);
pub fn new(counter: u64) -> Self {
Self(counter)
}
}
impl From<u64> for StoredU64 {
fn from(value: u64) -> Self {
Self(value)
}
}
impl From<usize> for StoredU64 {
fn from(value: usize) -> Self {
Self(value as u64)
}
}
impl CheckedSub<StoredU64> for StoredU64 {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Div<usize> for StoredU64 {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
Self(self.0 / rhs as u64)
}
}
impl Add for StoredU64 {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl From<f64> for StoredU64 {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {
panic!()
}
Self(value as u64)
}
}
impl From<StoredU64> for f64 {
fn from(value: StoredU64) -> Self {
value.0 as f64
}
}
impl From<Txinindex> for StoredU64 {
fn from(value: Txinindex) -> Self {
Self(*value)
}
}
impl From<Txoutindex> for StoredU64 {
fn from(value: Txoutindex) -> Self {
Self(*value)
}
}
@@ -0,0 +1,73 @@
use std::ops::{Add, Div};
use derive_deref::Deref;
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
pub struct StoredUsize(usize);
impl StoredUsize {
pub const ZERO: Self = Self(0);
pub fn new(counter: usize) -> Self {
Self(counter)
}
}
impl From<usize> for StoredUsize {
fn from(value: usize) -> Self {
Self(value)
}
}
impl CheckedSub<StoredUsize> for StoredUsize {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Div<usize> for StoredUsize {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
Self(self.0 / rhs)
}
}
impl Add for StoredUsize {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl From<f64> for StoredUsize {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {
panic!()
}
Self(value as usize)
}
}
impl From<StoredUsize> for f64 {
fn from(value: StoredUsize) -> Self {
value.0 as f64
}
}
+49 -1
View File
@@ -1,8 +1,24 @@
use std::ops::{Add, Div};
use derive_deref::Deref; use derive_deref::Deref;
use serde::Serialize; use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
#[derive(Debug, Deref, Clone, Copy, Immutable, IntoBytes, KnownLayout, FromBytes, Serialize)] #[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Immutable,
IntoBytes,
KnownLayout,
FromBytes,
Serialize,
)]
pub struct Weight(u64); pub struct Weight(u64);
impl From<bitcoin::Weight> for Weight { impl From<bitcoin::Weight> for Weight {
@@ -16,3 +32,35 @@ impl From<Weight> for bitcoin::Weight {
Self::from_wu(*value) Self::from_wu(*value)
} }
} }
impl From<usize> for Weight {
fn from(value: usize) -> Self {
Self(value as u64)
}
}
impl From<f64> for Weight {
fn from(value: f64) -> Self {
Self(value as u64)
}
}
impl From<Weight> for f64 {
fn from(value: Weight) -> Self {
value.0 as f64
}
}
impl Add for Weight {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl Div<usize> for Weight {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
Self::from(self.0 as usize / rhs)
}
}
+116 -32
View File
@@ -5,9 +5,10 @@ use brk_core::{
Pushonlyindex, Txindex, Txinindex, Txoutindex, Unknownindex, Pushonlyindex, Txindex, Txinindex, Txoutindex, Unknownindex,
}; };
use brk_parser::NUMBER_OF_UNSAFE_BLOCKS; use brk_parser::NUMBER_OF_UNSAFE_BLOCKS;
use brk_vec::{Result, StoredIndex, StoredType, Value};
use color_eyre::eyre::ContextCompat; use color_eyre::eyre::ContextCompat;
use crate::{Stores, Vecs}; use crate::{IndexedVec, Stores, Vecs};
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct Indexes { pub struct Indexes {
@@ -65,13 +66,7 @@ impl Indexes {
.push_if_needed(height, self.p2wpkhindex)?; .push_if_needed(height, self.p2wpkhindex)?;
vecs.height_to_first_p2wshindex vecs.height_to_first_p2wshindex
.push_if_needed(height, self.p2wshindex)?; .push_if_needed(height, self.p2wshindex)?;
Ok(())
}
pub fn push_future_if_needed(&mut self, vecs: &mut Vecs) -> brk_vec::Result<()> {
self.height.increment();
self.push_if_needed(vecs)?;
self.height.decrement();
Ok(()) Ok(())
} }
} }
@@ -111,32 +106,121 @@ impl TryFrom<(&mut Vecs, &Stores, &Client)> for Indexes {
.unwrap_or(starting_height); .unwrap_or(starting_height);
Ok(Self { Ok(Self {
addressindex: *vecs.height_to_first_addressindex.get(height)?.context("")?, addressindex: *starting_index(
emptyindex: *vecs.height_to_first_emptyindex.get(height)?.context("")?, &vecs.height_to_first_addressindex,
&vecs.addressindex_to_height,
height,
)?
.context("")?,
emptyindex: *starting_index(
&vecs.height_to_first_emptyindex,
&vecs.emptyindex_to_height,
height,
)?
.context("")?,
height, height,
multisigindex: *vecs multisigindex: *starting_index(
.height_to_first_multisigindex &vecs.height_to_first_multisigindex,
.get(height)? &vecs.multisigindex_to_height,
.context("")?, height,
opreturnindex: *vecs )?
.height_to_first_opreturnindex .context("")?,
.get(height)? opreturnindex: *starting_index(
.context("")?, &vecs.height_to_first_opreturnindex,
p2pk33index: *vecs.height_to_first_p2pk33index.get(height)?.context("")?, &vecs.opreturnindex_to_height,
p2pk65index: *vecs.height_to_first_p2pk65index.get(height)?.context("")?, height,
p2pkhindex: *vecs.height_to_first_p2pkhindex.get(height)?.context("")?, )?
p2shindex: *vecs.height_to_first_p2shindex.get(height)?.context("")?, .context("")?,
p2trindex: *vecs.height_to_first_p2trindex.get(height)?.context("")?, p2pk33index: *starting_index(
p2wpkhindex: *vecs.height_to_first_p2wpkhindex.get(height)?.context("")?, &vecs.height_to_first_p2pk33index,
p2wshindex: *vecs.height_to_first_p2wshindex.get(height)?.context("")?, &vecs.p2pk33index_to_height,
pushonlyindex: *vecs height,
.height_to_first_pushonlyindex )?
.get(height)? .context("")?,
.context("")?, p2pk65index: *starting_index(
txindex: *vecs.height_to_first_txindex.get(height)?.context("")?, &vecs.height_to_first_p2pk65index,
txinindex: *vecs.height_to_first_txinindex.get(height)?.context("")?, &vecs.p2pk65index_to_height,
txoutindex: *vecs.height_to_first_txoutindex.get(height)?.context("")?, height,
unknownindex: *vecs.height_to_first_unknownindex.get(height)?.context("")?, )?
.context("")?,
p2pkhindex: *starting_index(
&vecs.height_to_first_p2pkhindex,
&vecs.p2pkhindex_to_height,
height,
)?
.context("")?,
p2shindex: *starting_index(
&vecs.height_to_first_p2shindex,
&vecs.p2shindex_to_height,
height,
)?
.context("")?,
p2trindex: *starting_index(
&vecs.height_to_first_p2trindex,
&vecs.p2trindex_to_height,
height,
)?
.context("")?,
p2wpkhindex: *starting_index(
&vecs.height_to_first_p2wpkhindex,
&vecs.p2wpkhindex_to_height,
height,
)?
.context("")?,
p2wshindex: *starting_index(
&vecs.height_to_first_p2wshindex,
&vecs.p2wshindex_to_height,
height,
)?
.context("")?,
pushonlyindex: *starting_index(
&vecs.height_to_first_pushonlyindex,
&vecs.pushonlyindex_to_height,
height,
)?
.context("")?,
txindex: *starting_index(
&vecs.height_to_first_txindex,
&vecs.txindex_to_height,
height,
)?
.context("")?,
txinindex: *starting_index(
&vecs.height_to_first_txinindex,
&vecs.txinindex_to_height,
height,
)?
.context("")?,
txoutindex: *starting_index(
&vecs.height_to_first_txoutindex,
&vecs.txoutindex_to_height,
height,
)?
.context("")?,
unknownindex: *starting_index(
&vecs.height_to_first_unknownindex,
&vecs.unknownindex_to_height,
height,
)?
.context("")?,
}) })
} }
} }
pub fn starting_index<'a, I>(
height_to_index: &'a IndexedVec<Height, I>,
index_to_height: &'a IndexedVec<I, Height>,
starting_height: Height,
) -> Result<Option<Value<'a, I>>>
where
I: StoredType + StoredIndex + From<usize>,
{
if height_to_index
.height()
.is_ok_and(|h| h + 1_u32 == starting_height)
{
Ok(Some(Value::Owned(I::from(index_to_height.len()))))
} else {
height_to_index.get(starting_height)
}
}
+62 -17
View File
@@ -31,7 +31,7 @@ pub use stores::*;
pub use vecs::*; pub use vecs::*;
const SNAPSHOT_BLOCK_RANGE: usize = 1000; const SNAPSHOT_BLOCK_RANGE: usize = 1000;
const COLLISIONS_CHECKED_UP_TO: u32 = 888_000; const COLLISIONS_CHECKED_UP_TO: u32 = 890_000;
#[derive(Clone)] #[derive(Clone)]
pub struct Indexer { pub struct Indexer {
@@ -101,6 +101,7 @@ impl Indexer {
let vecs = self.vecs.as_mut().unwrap(); let vecs = self.vecs.as_mut().unwrap();
let stores = self.stores.as_mut().unwrap(); let stores = self.stores.as_mut().unwrap();
// Cloned because we want to return starting indexes for the computer
let mut idxs = starting_indexes.clone(); let mut idxs = starting_indexes.clone();
let start = Some(idxs.height); let start = Some(idxs.height);
@@ -153,6 +154,8 @@ impl Indexer {
return Err(eyre!("Collision, expect prefix to need be set yet")); return Err(eyre!("Collision, expect prefix to need be set yet"));
} }
idxs.push_if_needed(vecs)?;
stores stores
.blockhash_prefix_to_height .blockhash_prefix_to_height
.insert_if_needed(blockhash_prefix, height, height); .insert_if_needed(blockhash_prefix, height, height);
@@ -162,8 +165,8 @@ impl Indexer {
.push_if_needed(height, block.header.difficulty_float())?; .push_if_needed(height, block.header.difficulty_float())?;
vecs.height_to_timestamp vecs.height_to_timestamp
.push_if_needed(height, Timestamp::from(block.header.time))?; .push_if_needed(height, Timestamp::from(block.header.time))?;
vecs.height_to_size.push_if_needed(height, block.total_size())?; vecs.height_to_block_size.push_if_needed(height, block.total_size().into())?;
vecs.height_to_weight.push_if_needed(height, block.weight().into())?; vecs.height_to_block_weight.push_if_needed(height, block.weight().into())?;
let inputs = block let inputs = block
.txdata .txdata
@@ -462,6 +465,9 @@ impl Indexer {
vecs.txoutindex_to_value.push_if_needed(txoutindex, sats)?; vecs.txoutindex_to_value.push_if_needed(txoutindex, sats)?;
vecs.txoutindex_to_height
.push_if_needed(txoutindex, height)?;
let mut addressindex = idxs.addressindex; let mut addressindex = idxs.addressindex;
let mut addresshash = None; let mut addresshash = None;
@@ -481,18 +487,55 @@ impl Indexer {
idxs.addressindex.increment(); idxs.addressindex.increment();
let addresstypeindex = match addresstype { let addresstypeindex = match addresstype {
Addresstype::Empty => idxs.emptyindex.copy_then_increment(), Addresstype::Empty => {
Addresstype::Multisig => idxs.multisigindex.copy_then_increment(), vecs.emptyindex_to_height
Addresstype::OpReturn => idxs.opreturnindex.copy_then_increment(), .push_if_needed(idxs.emptyindex, height)?;
Addresstype::PushOnly => idxs.pushonlyindex.copy_then_increment(), idxs.emptyindex.copy_then_increment()
Addresstype::Unknown => idxs.unknownindex.copy_then_increment(), },
Addresstype::P2PK65 => idxs.p2pk65index.copy_then_increment(), Addresstype::Multisig => {
Addresstype::P2PK33 => idxs.p2pk33index.copy_then_increment(), vecs.multisigindex_to_height.push_if_needed(idxs.multisigindex, height)?;
Addresstype::P2PKH => idxs.p2pkhindex.copy_then_increment(), idxs.multisigindex.copy_then_increment()
Addresstype::P2SH => idxs.p2shindex.copy_then_increment(), },
Addresstype::P2WPKH => idxs.p2wpkhindex.copy_then_increment(), Addresstype::OpReturn => {
Addresstype::P2WSH => idxs.p2wshindex.copy_then_increment(), vecs.opreturnindex_to_height.push_if_needed(idxs.opreturnindex, height)?;
Addresstype::P2TR => idxs.p2trindex.copy_then_increment(), idxs.opreturnindex.copy_then_increment()
},
Addresstype::PushOnly => {
vecs.pushonlyindex_to_height.push_if_needed(idxs.pushonlyindex, height)?;
idxs.pushonlyindex.copy_then_increment()
},
Addresstype::Unknown => {
vecs.unknownindex_to_height.push_if_needed(idxs.unknownindex, height)?;
idxs.unknownindex.copy_then_increment()
},
Addresstype::P2PK65 => {
vecs.p2pk65index_to_height.push_if_needed(idxs.p2pk65index, height)?;
idxs.p2pk65index.copy_then_increment()
},
Addresstype::P2PK33 => {
vecs.p2pk33index_to_height.push_if_needed(idxs.p2pk33index, height)?;
idxs.p2pk33index.copy_then_increment()
},
Addresstype::P2PKH => {
vecs.p2pkhindex_to_height.push_if_needed(idxs.p2pkhindex, height)?;
idxs.p2pkhindex.copy_then_increment()
},
Addresstype::P2SH => {
vecs.p2shindex_to_height.push_if_needed(idxs.p2shindex, height)?;
idxs.p2shindex.copy_then_increment()
},
Addresstype::P2WPKH => {
vecs.p2wpkhindex_to_height.push_if_needed(idxs.p2wpkhindex, height)?;
idxs.p2wpkhindex.copy_then_increment()
},
Addresstype::P2WSH => {
vecs.p2wshindex_to_height.push_if_needed(idxs.p2wshindex, height)?;
idxs.p2wshindex.copy_then_increment()
},
Addresstype::P2TR => {
vecs.p2trindex_to_height.push_if_needed(idxs.p2trindex, height)?;
idxs.p2trindex.copy_then_increment()
},
}; };
vecs.addressindex_to_addresstype vecs.addressindex_to_addresstype
@@ -580,6 +623,10 @@ impl Indexer {
vecs.txinindex_to_txoutindex.push_if_needed(txinindex, txoutindex)?; vecs.txinindex_to_txoutindex.push_if_needed(txinindex, txoutindex)?;
vecs.txinindex_to_height
.push_if_needed(txinindex, height)?;
Ok(()) Ok(())
})?; })?;
@@ -668,8 +715,6 @@ impl Indexer {
idxs.txinindex += Txinindex::from(inputs_len); idxs.txinindex += Txinindex::from(inputs_len);
idxs.txoutindex += Txoutindex::from(outputs_len); idxs.txoutindex += Txoutindex::from(outputs_len);
idxs.push_future_if_needed(vecs)?;
export_if_needed(stores, vecs, height, false, exit)?; export_if_needed(stores, vecs, height, false, exit)?;
Ok(()) Ok(())
+3 -3
View File
@@ -27,11 +27,11 @@ impl Stores {
pub fn import(path: &Path) -> color_eyre::Result<Self> { pub fn import(path: &Path) -> color_eyre::Result<Self> {
thread::scope(|scope| { thread::scope(|scope| {
let addresshash_to_addressindex = scope let addresshash_to_addressindex = scope
.spawn(|| Store::import(&path.join("addresshash_to_addressindex"), Version::ONE)); .spawn(|| Store::import(&path.join("addresshash_to_addressindex"), Version::ZERO));
let blockhash_prefix_to_height = scope let blockhash_prefix_to_height = scope
.spawn(|| Store::import(&path.join("blockhash_prefix_to_height"), Version::ONE)); .spawn(|| Store::import(&path.join("blockhash_prefix_to_height"), Version::ZERO));
let txid_prefix_to_txindex = let txid_prefix_to_txindex =
scope.spawn(|| Store::import(&path.join("txid_prefix_to_txindex"), Version::ONE)); scope.spawn(|| Store::import(&path.join("txid_prefix_to_txindex"), Version::ZERO));
Ok(Self { Ok(Self {
addresshash_to_addressindex: addresshash_to_addressindex.join().unwrap()?, addresshash_to_addressindex: addresshash_to_addressindex.join().unwrap()?,
+4 -4
View File
@@ -33,7 +33,7 @@ where
version: Version, version: Version,
compressed: Compressed, compressed: Compressed,
) -> brk_vec::Result<Self> { ) -> brk_vec::Result<Self> {
let mut vec = brk_vec::StorableVec::forced_import(path, version, compressed)?; let mut vec = StorableVec::forced_import(path, version, compressed)?;
vec.enable_large_cache(); vec.enable_large_cache();
@@ -107,7 +107,7 @@ where
Ok(()) Ok(())
} }
Ordering::Less => { Ordering::Less => {
dbg!(index, value); dbg!(index, value, self.vec.len(), self.path_height());
Err(Error::IndexTooHigh) Err(Error::IndexTooHigh)
} }
} }
@@ -126,11 +126,11 @@ where
self.vec.flush() self.vec.flush()
} }
pub fn vec(&self) -> &brk_vec::StorableVec<I, T> { pub fn vec(&self) -> &StorableVec<I, T> {
&self.vec &self.vec
} }
pub fn mut_vec(&mut self) -> &mut brk_vec::StorableVec<I, T> { pub fn mut_vec(&mut self) -> &mut StorableVec<I, T> {
&mut self.vec &mut self.vec
} }
+226 -84
View File
@@ -5,7 +5,7 @@ use brk_core::{
LockTime, Multisigindex, Opreturnindex, P2PK33AddressBytes, P2PK33index, P2PK65AddressBytes, LockTime, Multisigindex, Opreturnindex, P2PK33AddressBytes, P2PK33index, P2PK65AddressBytes,
P2PK65index, P2PKHAddressBytes, P2PKHindex, P2SHAddressBytes, P2SHindex, P2TRAddressBytes, P2PK65index, P2PKHAddressBytes, P2PKHindex, P2SHAddressBytes, P2SHindex, P2TRAddressBytes,
P2TRindex, P2WPKHAddressBytes, P2WPKHindex, P2WSHAddressBytes, P2WSHindex, Pushonlyindex, Sats, P2TRindex, P2WPKHAddressBytes, P2WPKHindex, P2WSHAddressBytes, P2WSHindex, Pushonlyindex, Sats,
Timestamp, TxVersion, Txid, Txindex, Txinindex, Txoutindex, Unknownindex, Weight, StoredUsize, Timestamp, TxVersion, Txid, Txindex, Txinindex, Txoutindex, Unknownindex, Weight,
}; };
use brk_vec::{AnyStorableVec, Compressed, Version}; use brk_vec::{AnyStorableVec, Compressed, Version};
use rayon::prelude::*; use rayon::prelude::*;
@@ -21,17 +21,13 @@ pub struct Vecs {
pub addressindex_to_addresstype: IndexedVec<Addressindex, Addresstype>, pub addressindex_to_addresstype: IndexedVec<Addressindex, Addresstype>,
pub addressindex_to_addresstypeindex: IndexedVec<Addressindex, Addresstypeindex>, pub addressindex_to_addresstypeindex: IndexedVec<Addressindex, Addresstypeindex>,
pub addressindex_to_height: IndexedVec<Addressindex, Height>, pub addressindex_to_height: IndexedVec<Addressindex, Height>,
pub emptyindex_to_height: IndexedVec<Emptyindex, Height>,
pub height_to_blockhash: IndexedVec<Height, BlockHash>, pub height_to_blockhash: IndexedVec<Height, BlockHash>,
pub height_to_difficulty: IndexedVec<Height, f64>, pub height_to_difficulty: IndexedVec<Height, f64>,
pub height_to_first_addressindex: IndexedVec<Height, Addressindex>, pub height_to_first_addressindex: IndexedVec<Height, Addressindex>,
pub height_to_first_emptyindex: IndexedVec<Height, Emptyindex>, pub height_to_first_emptyindex: IndexedVec<Height, Emptyindex>,
pub height_to_first_multisigindex: IndexedVec<Height, Multisigindex>, pub height_to_first_multisigindex: IndexedVec<Height, Multisigindex>,
pub height_to_first_opreturnindex: IndexedVec<Height, Opreturnindex>, pub height_to_first_opreturnindex: IndexedVec<Height, Opreturnindex>,
pub height_to_first_pushonlyindex: IndexedVec<Height, Pushonlyindex>,
pub height_to_first_txindex: IndexedVec<Height, Txindex>,
pub height_to_first_txinindex: IndexedVec<Height, Txinindex>,
pub height_to_first_txoutindex: IndexedVec<Height, Txoutindex>,
pub height_to_first_unknownindex: IndexedVec<Height, Unknownindex>,
pub height_to_first_p2pk33index: IndexedVec<Height, P2PK33index>, pub height_to_first_p2pk33index: IndexedVec<Height, P2PK33index>,
pub height_to_first_p2pk65index: IndexedVec<Height, P2PK65index>, pub height_to_first_p2pk65index: IndexedVec<Height, P2PK65index>,
pub height_to_first_p2pkhindex: IndexedVec<Height, P2PKHindex>, pub height_to_first_p2pkhindex: IndexedVec<Height, P2PKHindex>,
@@ -39,29 +35,47 @@ pub struct Vecs {
pub height_to_first_p2trindex: IndexedVec<Height, P2TRindex>, pub height_to_first_p2trindex: IndexedVec<Height, P2TRindex>,
pub height_to_first_p2wpkhindex: IndexedVec<Height, P2WPKHindex>, pub height_to_first_p2wpkhindex: IndexedVec<Height, P2WPKHindex>,
pub height_to_first_p2wshindex: IndexedVec<Height, P2WSHindex>, pub height_to_first_p2wshindex: IndexedVec<Height, P2WSHindex>,
pub height_to_size: IndexedVec<Height, usize>, pub height_to_first_pushonlyindex: IndexedVec<Height, Pushonlyindex>,
pub height_to_first_txindex: IndexedVec<Height, Txindex>,
pub height_to_first_txinindex: IndexedVec<Height, Txinindex>,
pub height_to_first_txoutindex: IndexedVec<Height, Txoutindex>,
pub height_to_first_unknownindex: IndexedVec<Height, Unknownindex>,
pub height_to_block_size: IndexedVec<Height, StoredUsize>,
pub height_to_timestamp: IndexedVec<Height, Timestamp>, pub height_to_timestamp: IndexedVec<Height, Timestamp>,
pub height_to_weight: IndexedVec<Height, Weight>, pub height_to_block_weight: IndexedVec<Height, Weight>,
pub multisigindex_to_height: IndexedVec<Multisigindex, Height>,
pub opreturnindex_to_height: IndexedVec<Opreturnindex, Height>,
pub p2pk33index_to_height: IndexedVec<P2PK33index, Height>,
pub p2pk33index_to_p2pk33addressbytes: IndexedVec<P2PK33index, P2PK33AddressBytes>, pub p2pk33index_to_p2pk33addressbytes: IndexedVec<P2PK33index, P2PK33AddressBytes>,
pub p2pk65index_to_height: IndexedVec<P2PK65index, Height>,
pub p2pk65index_to_p2pk65addressbytes: IndexedVec<P2PK65index, P2PK65AddressBytes>, pub p2pk65index_to_p2pk65addressbytes: IndexedVec<P2PK65index, P2PK65AddressBytes>,
pub p2pkhindex_to_height: IndexedVec<P2PKHindex, Height>,
pub p2pkhindex_to_p2pkhaddressbytes: IndexedVec<P2PKHindex, P2PKHAddressBytes>, pub p2pkhindex_to_p2pkhaddressbytes: IndexedVec<P2PKHindex, P2PKHAddressBytes>,
pub p2shindex_to_height: IndexedVec<P2SHindex, Height>,
pub p2shindex_to_p2shaddressbytes: IndexedVec<P2SHindex, P2SHAddressBytes>, pub p2shindex_to_p2shaddressbytes: IndexedVec<P2SHindex, P2SHAddressBytes>,
pub p2trindex_to_height: IndexedVec<P2TRindex, Height>,
pub p2trindex_to_p2traddressbytes: IndexedVec<P2TRindex, P2TRAddressBytes>, pub p2trindex_to_p2traddressbytes: IndexedVec<P2TRindex, P2TRAddressBytes>,
pub p2wpkhindex_to_height: IndexedVec<P2WPKHindex, Height>,
pub p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec<P2WPKHindex, P2WPKHAddressBytes>, pub p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec<P2WPKHindex, P2WPKHAddressBytes>,
pub p2wshindex_to_height: IndexedVec<P2WSHindex, Height>,
pub p2wshindex_to_p2wshaddressbytes: IndexedVec<P2WSHindex, P2WSHAddressBytes>, pub p2wshindex_to_p2wshaddressbytes: IndexedVec<P2WSHindex, P2WSHAddressBytes>,
pub pushonlyindex_to_height: IndexedVec<Pushonlyindex, Height>,
pub txindex_to_base_size: IndexedVec<Txindex, usize>,
pub txindex_to_first_txinindex: IndexedVec<Txindex, Txinindex>, pub txindex_to_first_txinindex: IndexedVec<Txindex, Txinindex>,
pub txindex_to_first_txoutindex: IndexedVec<Txindex, Txoutindex>, pub txindex_to_first_txoutindex: IndexedVec<Txindex, Txoutindex>,
pub txindex_to_height: IndexedVec<Txindex, Height>, pub txindex_to_height: IndexedVec<Txindex, Height>,
pub txindex_to_locktime: IndexedVec<Txindex, LockTime>,
pub txindex_to_txid: IndexedVec<Txindex, Txid>,
pub txindex_to_base_size: IndexedVec<Txindex, usize>,
pub txindex_to_total_size: IndexedVec<Txindex, usize>,
pub txindex_to_is_explicitly_rbf: IndexedVec<Txindex, bool>, pub txindex_to_is_explicitly_rbf: IndexedVec<Txindex, bool>,
pub txindex_to_locktime: IndexedVec<Txindex, LockTime>,
pub txindex_to_total_size: IndexedVec<Txindex, usize>,
pub txindex_to_txid: IndexedVec<Txindex, Txid>,
pub txindex_to_txversion: IndexedVec<Txindex, TxVersion>, pub txindex_to_txversion: IndexedVec<Txindex, TxVersion>,
pub txinindex_to_height: IndexedVec<Txinindex, Height>,
/// If txoutindex == Txoutindex MAX then is it's coinbase /// If txoutindex == Txoutindex MAX then is it's coinbase
pub txinindex_to_txoutindex: IndexedVec<Txinindex, Txoutindex>, pub txinindex_to_txoutindex: IndexedVec<Txinindex, Txoutindex>,
pub txoutindex_to_addressindex: IndexedVec<Txoutindex, Addressindex>, pub txoutindex_to_addressindex: IndexedVec<Txoutindex, Addressindex>,
pub txoutindex_to_height: IndexedVec<Txoutindex, Height>,
pub txoutindex_to_value: IndexedVec<Txoutindex, Sats>, pub txoutindex_to_value: IndexedVec<Txoutindex, Sats>,
pub unknownindex_to_height: IndexedVec<Unknownindex, Height>,
} }
impl Vecs { impl Vecs {
@@ -71,217 +85,287 @@ impl Vecs {
Ok(Self { Ok(Self {
addressindex_to_addresstype: IndexedVec::forced_import( addressindex_to_addresstype: IndexedVec::forced_import(
&path.join("addressindex_to_addresstype"), &path.join("addressindex_to_addresstype"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
addressindex_to_addresstypeindex: IndexedVec::forced_import( addressindex_to_addresstypeindex: IndexedVec::forced_import(
&path.join("addressindex_to_addresstypeindex"), &path.join("addressindex_to_addresstypeindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
addressindex_to_height: IndexedVec::forced_import( addressindex_to_height: IndexedVec::forced_import(
&path.join("addressindex_to_height"), &path.join("addressindex_to_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_blockhash: IndexedVec::forced_import( height_to_blockhash: IndexedVec::forced_import(
&path.join("height_to_blockhash"), &path.join("height_to_blockhash"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
height_to_difficulty: IndexedVec::forced_import( height_to_difficulty: IndexedVec::forced_import(
&path.join("height_to_difficulty"), &path.join("height_to_difficulty"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_addressindex: IndexedVec::forced_import( height_to_first_addressindex: IndexedVec::forced_import(
&path.join("height_to_first_addressindex"), &path.join("height_to_first_addressindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_emptyindex: IndexedVec::forced_import( height_to_first_emptyindex: IndexedVec::forced_import(
&path.join("height_to_first_emptyindex"), &path.join("height_to_first_emptyindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_multisigindex: IndexedVec::forced_import( height_to_first_multisigindex: IndexedVec::forced_import(
&path.join("height_to_first_multisigindex"), &path.join("height_to_first_multisigindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_opreturnindex: IndexedVec::forced_import( height_to_first_opreturnindex: IndexedVec::forced_import(
&path.join("height_to_first_opreturnindex"), &path.join("height_to_first_opreturnindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_pushonlyindex: IndexedVec::forced_import( height_to_first_pushonlyindex: IndexedVec::forced_import(
&path.join("height_to_first_pushonlyindex"), &path.join("height_to_first_pushonlyindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_txindex: IndexedVec::forced_import( height_to_first_txindex: IndexedVec::forced_import(
&path.join("height_to_first_txindex"), &path.join("height_to_first_txindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_txinindex: IndexedVec::forced_import( height_to_first_txinindex: IndexedVec::forced_import(
&path.join("height_to_first_txinindex"), &path.join("height_to_first_txinindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_txoutindex: IndexedVec::forced_import( height_to_first_txoutindex: IndexedVec::forced_import(
&path.join("height_to_first_txoutindex"), &path.join("height_to_first_txoutindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_unknownindex: IndexedVec::forced_import( height_to_first_unknownindex: IndexedVec::forced_import(
&path.join("height_to_first_unkownindex"), &path.join("height_to_first_unkownindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2pk33index: IndexedVec::forced_import( height_to_first_p2pk33index: IndexedVec::forced_import(
&path.join("height_to_first_p2pk33index"), &path.join("height_to_first_p2pk33index"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2pk65index: IndexedVec::forced_import( height_to_first_p2pk65index: IndexedVec::forced_import(
&path.join("height_to_first_p2pk65index"), &path.join("height_to_first_p2pk65index"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2pkhindex: IndexedVec::forced_import( height_to_first_p2pkhindex: IndexedVec::forced_import(
&path.join("height_to_first_p2pkhindex"), &path.join("height_to_first_p2pkhindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2shindex: IndexedVec::forced_import( height_to_first_p2shindex: IndexedVec::forced_import(
&path.join("height_to_first_p2shindex"), &path.join("height_to_first_p2shindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2trindex: IndexedVec::forced_import( height_to_first_p2trindex: IndexedVec::forced_import(
&path.join("height_to_first_p2trindex"), &path.join("height_to_first_p2trindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2wpkhindex: IndexedVec::forced_import( height_to_first_p2wpkhindex: IndexedVec::forced_import(
&path.join("height_to_first_p2wpkhindex"), &path.join("height_to_first_p2wpkhindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_first_p2wshindex: IndexedVec::forced_import( height_to_first_p2wshindex: IndexedVec::forced_import(
&path.join("height_to_first_p2wshindex"), &path.join("height_to_first_p2wshindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_size: IndexedVec::forced_import( height_to_block_size: IndexedVec::forced_import(
&path.join("height_to_size"), &path.join("height_to_block_size"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_timestamp: IndexedVec::forced_import( height_to_timestamp: IndexedVec::forced_import(
&path.join("height_to_timestamp"), &path.join("height_to_timestamp"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
height_to_weight: IndexedVec::forced_import( height_to_block_weight: IndexedVec::forced_import(
&path.join("height_to_weight"), &path.join("height_to_block_weight"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
p2pk33index_to_p2pk33addressbytes: IndexedVec::forced_import( p2pk33index_to_p2pk33addressbytes: IndexedVec::forced_import(
&path.join("p2pk33index_to_p2pk33addressbytes"), &path.join("p2pk33index_to_p2pk33addressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
p2pk65index_to_p2pk65addressbytes: IndexedVec::forced_import( p2pk65index_to_p2pk65addressbytes: IndexedVec::forced_import(
&path.join("p2pk65index_to_p2pk65addressbytes"), &path.join("p2pk65index_to_p2pk65addressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
p2pkhindex_to_p2pkhaddressbytes: IndexedVec::forced_import( p2pkhindex_to_p2pkhaddressbytes: IndexedVec::forced_import(
&path.join("p2pkhindex_to_p2pkhaddressbytes"), &path.join("p2pkhindex_to_p2pkhaddressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
p2shindex_to_p2shaddressbytes: IndexedVec::forced_import( p2shindex_to_p2shaddressbytes: IndexedVec::forced_import(
&path.join("p2shindex_to_p2shaddressbytes"), &path.join("p2shindex_to_p2shaddressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
p2trindex_to_p2traddressbytes: IndexedVec::forced_import( p2trindex_to_p2traddressbytes: IndexedVec::forced_import(
&path.join("p2trindex_to_p2traddressbytes"), &path.join("p2trindex_to_p2traddressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec::forced_import( p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec::forced_import(
&path.join("p2wpkhindex_to_p2wpkhaddressbytes"), &path.join("p2wpkhindex_to_p2wpkhaddressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
p2wshindex_to_p2wshaddressbytes: IndexedVec::forced_import( p2wshindex_to_p2wshaddressbytes: IndexedVec::forced_import(
&path.join("p2wshindex_to_p2wshaddressbytes"), &path.join("p2wshindex_to_p2wshaddressbytes"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
txindex_to_first_txinindex: IndexedVec::forced_import( txindex_to_first_txinindex: IndexedVec::forced_import(
&path.join("txindex_to_first_txinindex"), &path.join("txindex_to_first_txinindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_first_txoutindex: IndexedVec::forced_import( txindex_to_first_txoutindex: IndexedVec::forced_import(
&path.join("txindex_to_first_txoutindex"), &path.join("txindex_to_first_txoutindex"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
txindex_to_height: IndexedVec::forced_import( txindex_to_height: IndexedVec::forced_import(
&path.join("txindex_to_height"), &path.join("txindex_to_height"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_locktime: IndexedVec::forced_import( txindex_to_locktime: IndexedVec::forced_import(
&path.join("txindex_to_locktime"), &path.join("txindex_to_locktime"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_txid: IndexedVec::forced_import( txindex_to_txid: IndexedVec::forced_import(
&path.join("txindex_to_txid"), &path.join("txindex_to_txid"),
Version::ONE, Version::ZERO,
Compressed::NO, Compressed::NO,
)?, )?,
txindex_to_base_size: IndexedVec::forced_import( txindex_to_base_size: IndexedVec::forced_import(
&path.join("txindex_to_base_size"), &path.join("txindex_to_base_size"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_total_size: IndexedVec::forced_import( txindex_to_total_size: IndexedVec::forced_import(
&path.join("txindex_to_total_size"), &path.join("txindex_to_total_size"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_is_explicitly_rbf: IndexedVec::forced_import( txindex_to_is_explicitly_rbf: IndexedVec::forced_import(
&path.join("txindex_to_is_explicitly_rbf"), &path.join("txindex_to_is_explicitly_rbf"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txindex_to_txversion: IndexedVec::forced_import( txindex_to_txversion: IndexedVec::forced_import(
&path.join("txindex_to_txversion"), &path.join("txindex_to_txversion"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txinindex_to_txoutindex: IndexedVec::forced_import( txinindex_to_txoutindex: IndexedVec::forced_import(
&path.join("txinindex_to_txoutindex"), &path.join("txinindex_to_txoutindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txoutindex_to_addressindex: IndexedVec::forced_import( txoutindex_to_addressindex: IndexedVec::forced_import(
&path.join("txoutindex_to_addressindex"), &path.join("txoutindex_to_addressindex"),
Version::ONE, Version::ZERO,
compressed, compressed,
)?, )?,
txoutindex_to_value: IndexedVec::forced_import( txoutindex_to_value: IndexedVec::forced_import(
&path.join("txoutindex_to_value"), &path.join("txoutindex_to_value"),
Version::ONE, Version::ZERO,
compressed,
)?,
emptyindex_to_height: IndexedVec::forced_import(
&path.join("emptyindex_to_height"),
Version::ZERO,
compressed,
)?,
multisigindex_to_height: IndexedVec::forced_import(
&path.join("multisigindex_to_height"),
Version::ZERO,
compressed,
)?,
opreturnindex_to_height: IndexedVec::forced_import(
&path.join("opreturnindex_to_height"),
Version::ZERO,
compressed,
)?,
pushonlyindex_to_height: IndexedVec::forced_import(
&path.join("pushonlyindex_to_height"),
Version::ZERO,
compressed,
)?,
txinindex_to_height: IndexedVec::forced_import(
&path.join("txinindex_to_height"),
Version::ZERO,
compressed,
)?,
txoutindex_to_height: IndexedVec::forced_import(
&path.join("txoutindex_to_height"),
Version::ZERO,
compressed,
)?,
unknownindex_to_height: IndexedVec::forced_import(
&path.join("unknownindex_to_height"),
Version::ZERO,
compressed,
)?,
p2pk33index_to_height: IndexedVec::forced_import(
&path.join("p2pk33index_to_height"),
Version::ZERO,
compressed,
)?,
p2pk65index_to_height: IndexedVec::forced_import(
&path.join("p2pk65index_to_height"),
Version::ZERO,
compressed,
)?,
p2pkhindex_to_height: IndexedVec::forced_import(
&path.join("p2pkhindex_to_height"),
Version::ZERO,
compressed,
)?,
p2shindex_to_height: IndexedVec::forced_import(
&path.join("p2shindex_to_height"),
Version::ZERO,
compressed,
)?,
p2trindex_to_height: IndexedVec::forced_import(
&path.join("p2trindex_to_height"),
Version::ZERO,
compressed,
)?,
p2wpkhindex_to_height: IndexedVec::forced_import(
&path.join("p2wpkhindex_to_height"),
Version::ZERO,
compressed,
)?,
p2wshindex_to_height: IndexedVec::forced_import(
&path.join("p2wshindex_to_height"),
Version::ZERO,
compressed, compressed,
)?, )?,
}) })
@@ -290,8 +374,26 @@ impl Vecs {
pub fn rollback_if_needed(&mut self, starting_indexes: &Indexes) -> brk_vec::Result<()> { pub fn rollback_if_needed(&mut self, starting_indexes: &Indexes) -> brk_vec::Result<()> {
let saved_height = starting_indexes.height.decremented().unwrap_or_default(); let saved_height = starting_indexes.height.decremented().unwrap_or_default();
// We don't want to override the starting indexes so we cut from n + 1 // Now we can cut everything that's out of date
let height = starting_indexes.height.incremented(); let &Indexes {
addressindex,
height,
p2pk33index,
p2pk65index,
p2pkhindex,
p2shindex,
p2trindex,
p2wpkhindex,
p2wshindex,
txindex,
txinindex,
txoutindex,
unknownindex,
pushonlyindex,
opreturnindex,
multisigindex,
emptyindex,
} = starting_indexes;
self.height_to_first_addressindex self.height_to_first_addressindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
@@ -326,32 +428,15 @@ impl Vecs {
self.height_to_first_unknownindex self.height_to_first_unknownindex
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
// Now we can cut everything that's out of date
let &Indexes {
addressindex,
height,
p2pk33index,
p2pk65index,
p2pkhindex,
p2shindex,
p2trindex,
p2wpkhindex,
p2wshindex,
txindex,
txinindex,
txoutindex,
..
} = starting_indexes;
self.height_to_blockhash self.height_to_blockhash
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
self.height_to_difficulty self.height_to_difficulty
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
self.height_to_size self.height_to_block_size
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
self.height_to_timestamp self.height_to_timestamp
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
self.height_to_weight self.height_to_block_weight
.truncate_if_needed(height, saved_height)?; .truncate_if_needed(height, saved_height)?;
self.addressindex_to_addresstype self.addressindex_to_addresstype
@@ -403,6 +488,35 @@ impl Vecs {
self.txoutindex_to_value self.txoutindex_to_value
.truncate_if_needed(txoutindex, saved_height)?; .truncate_if_needed(txoutindex, saved_height)?;
self.emptyindex_to_height
.truncate_if_needed(emptyindex, saved_height)?;
self.multisigindex_to_height
.truncate_if_needed(multisigindex, saved_height)?;
self.opreturnindex_to_height
.truncate_if_needed(opreturnindex, saved_height)?;
self.pushonlyindex_to_height
.truncate_if_needed(pushonlyindex, saved_height)?;
self.txinindex_to_height
.truncate_if_needed(txinindex, saved_height)?;
self.txoutindex_to_height
.truncate_if_needed(txoutindex, saved_height)?;
self.unknownindex_to_height
.truncate_if_needed(unknownindex, saved_height)?;
self.p2pk33index_to_height
.truncate_if_needed(p2pk33index, saved_height)?;
self.p2pk65index_to_height
.truncate_if_needed(p2pk65index, saved_height)?;
self.p2pkhindex_to_height
.truncate_if_needed(p2pkhindex, saved_height)?;
self.p2shindex_to_height
.truncate_if_needed(p2shindex, saved_height)?;
self.p2trindex_to_height
.truncate_if_needed(p2trindex, saved_height)?;
self.p2wpkhindex_to_height
.truncate_if_needed(p2wpkhindex, saved_height)?;
self.p2wshindex_to_height
.truncate_if_needed(p2wshindex, saved_height)?;
Ok(()) Ok(())
} }
@@ -518,9 +632,9 @@ impl Vecs {
self.height_to_first_p2trindex.any_vec(), self.height_to_first_p2trindex.any_vec(),
self.height_to_first_p2wpkhindex.any_vec(), self.height_to_first_p2wpkhindex.any_vec(),
self.height_to_first_p2wshindex.any_vec(), self.height_to_first_p2wshindex.any_vec(),
self.height_to_size.any_vec(), self.height_to_block_size.any_vec(),
self.height_to_timestamp.any_vec(), self.height_to_timestamp.any_vec(),
self.height_to_weight.any_vec(), self.height_to_block_weight.any_vec(),
self.p2pk33index_to_p2pk33addressbytes.any_vec(), self.p2pk33index_to_p2pk33addressbytes.any_vec(),
self.p2pk65index_to_p2pk65addressbytes.any_vec(), self.p2pk65index_to_p2pk65addressbytes.any_vec(),
self.p2pkhindex_to_p2pkhaddressbytes.any_vec(), self.p2pkhindex_to_p2pkhaddressbytes.any_vec(),
@@ -540,6 +654,20 @@ impl Vecs {
self.txinindex_to_txoutindex.any_vec(), self.txinindex_to_txoutindex.any_vec(),
self.txoutindex_to_addressindex.any_vec(), self.txoutindex_to_addressindex.any_vec(),
self.txoutindex_to_value.any_vec(), self.txoutindex_to_value.any_vec(),
self.emptyindex_to_height.any_vec(),
self.multisigindex_to_height.any_vec(),
self.opreturnindex_to_height.any_vec(),
self.pushonlyindex_to_height.any_vec(),
self.txinindex_to_height.any_vec(),
self.txoutindex_to_height.any_vec(),
self.unknownindex_to_height.any_vec(),
self.p2pk33index_to_height.any_vec(),
self.p2pk65index_to_height.any_vec(),
self.p2pkhindex_to_height.any_vec(),
self.p2shindex_to_height.any_vec(),
self.p2trindex_to_height.any_vec(),
self.p2wpkhindex_to_height.any_vec(),
self.p2wshindex_to_height.any_vec(),
] ]
} }
@@ -566,9 +694,9 @@ impl Vecs {
&mut self.height_to_first_p2trindex, &mut self.height_to_first_p2trindex,
&mut self.height_to_first_p2wpkhindex, &mut self.height_to_first_p2wpkhindex,
&mut self.height_to_first_p2wshindex, &mut self.height_to_first_p2wshindex,
&mut self.height_to_size, &mut self.height_to_block_size,
&mut self.height_to_timestamp, &mut self.height_to_timestamp,
&mut self.height_to_weight, &mut self.height_to_block_weight,
&mut self.p2pk33index_to_p2pk33addressbytes, &mut self.p2pk33index_to_p2pk33addressbytes,
&mut self.p2pk65index_to_p2pk65addressbytes, &mut self.p2pk65index_to_p2pk65addressbytes,
&mut self.p2pkhindex_to_p2pkhaddressbytes, &mut self.p2pkhindex_to_p2pkhaddressbytes,
@@ -588,6 +716,20 @@ impl Vecs {
&mut self.txinindex_to_txoutindex, &mut self.txinindex_to_txoutindex,
&mut self.txoutindex_to_addressindex, &mut self.txoutindex_to_addressindex,
&mut self.txoutindex_to_value, &mut self.txoutindex_to_value,
&mut self.emptyindex_to_height,
&mut self.multisigindex_to_height,
&mut self.opreturnindex_to_height,
&mut self.pushonlyindex_to_height,
&mut self.txinindex_to_height,
&mut self.txoutindex_to_height,
&mut self.unknownindex_to_height,
&mut self.p2pk33index_to_height,
&mut self.p2pk65index_to_height,
&mut self.p2pkhindex_to_height,
&mut self.p2shindex_to_height,
&mut self.p2trindex_to_height,
&mut self.p2wpkhindex_to_height,
&mut self.p2wshindex_to_height,
] ]
} }
} }
+22 -1
View File
@@ -24,10 +24,15 @@ pub enum Index {
Decadeindex, Decadeindex,
Difficultyepoch, Difficultyepoch,
Halvingepoch, Halvingepoch,
Emptyindex,
Multisigindex,
Opreturnindex,
Pushonlyindex,
Unknownindex,
} }
impl Index { impl Index {
pub fn all() -> [Self; 20] { pub fn all() -> [Self; 25] {
[ [
Self::Height, Self::Height,
Self::Dateindex, Self::Dateindex,
@@ -49,6 +54,11 @@ impl Index {
Self::Txindex, Self::Txindex,
Self::Txinindex, Self::Txinindex,
Self::Txoutindex, Self::Txoutindex,
Self::Emptyindex,
Self::Multisigindex,
Self::Opreturnindex,
Self::Pushonlyindex,
Self::Unknownindex,
] ]
} }
@@ -75,6 +85,11 @@ impl Index {
Self::P2TRindex => &["p2tr", "p2trindex"], Self::P2TRindex => &["p2tr", "p2trindex"],
Self::P2WPKHindex => &["p2wpkh", "p2wpkhindex"], Self::P2WPKHindex => &["p2wpkh", "p2wpkhindex"],
Self::P2WSHindex => &["p2wsh", "p2wshindex"], Self::P2WSHindex => &["p2wsh", "p2wshindex"],
Self::Emptyindex => &["empty", "emptyindex"],
Self::Multisigindex => &["multisig", "multisigindex"],
Self::Opreturnindex => &["opreturn", "opreturnindex"],
Self::Pushonlyindex => &["pushonly", "pushonlyindex"],
Self::Unknownindex => &["unknown", "unknownindex"],
} }
} }
@@ -122,6 +137,12 @@ impl TryFrom<&str> for Index {
v if (Self::Difficultyepoch).possible_values().contains(&v) => Self::Difficultyepoch, v if (Self::Difficultyepoch).possible_values().contains(&v) => Self::Difficultyepoch,
v if (Self::Halvingepoch).possible_values().contains(&v) => Self::Halvingepoch, v if (Self::Halvingepoch).possible_values().contains(&v) => Self::Halvingepoch,
v if (Self::Quarterindex).possible_values().contains(&v) => Self::Quarterindex, v if (Self::Quarterindex).possible_values().contains(&v) => Self::Quarterindex,
v if (Self::Quarterindex).possible_values().contains(&v) => Self::Quarterindex,
v if (Self::Emptyindex).possible_values().contains(&v) => Self::Emptyindex,
v if (Self::Multisigindex).possible_values().contains(&v) => Self::Multisigindex,
v if (Self::Opreturnindex).possible_values().contains(&v) => Self::Opreturnindex,
v if (Self::Pushonlyindex).possible_values().contains(&v) => Self::Pushonlyindex,
v if (Self::Unknownindex).possible_values().contains(&v) => Self::Unknownindex,
_ => return Err(eyre!("Bad index")), _ => return Err(eyre!("Bad index")),
}) })
} }
+1
View File
@@ -17,6 +17,7 @@ impl<'a> VecTrees<'a> {
let file_name = vec.file_name(); let file_name = vec.file_name();
let split = file_name.split("_to_").collect::<Vec<_>>(); let split = file_name.split("_to_").collect::<Vec<_>>();
if split.len() != 2 { if split.len() != 2 {
dbg!(&file_name, &split);
panic!(); panic!();
} }
let str = vec let str = vec
+1 -1
View File
@@ -23,7 +23,7 @@ log = { workspace = true }
minreq = { workspace = true } minreq = { workspace = true }
oxc = { version = "0.62.0", features = ["codegen", "minifier"] } oxc = { version = "0.62.0", features = ["codegen", "minifier"] }
serde = { workspace = true } serde = { workspace = true }
tokio = { version = "1.44.1", features = ["full"] } tokio = { version = "1.44.2", features = ["full"] }
tower-http = { version = "0.6.2", features = ["compression-full", "trace"] } tower-http = { version = "0.6.2", features = ["compression-full", "trace"] }
zip = "2.6.1" zip = "2.6.1"
tracing = "0.1.41" tracing = "0.1.41"
-5
View File
@@ -10,7 +10,6 @@ use brk_parser::{
rpc::{self, RpcApi}, rpc::{self, RpcApi},
}; };
use brk_server::{Server, Website}; use brk_server::{Server, Website};
use log::info;
pub fn main() -> color_eyre::Result<()> { pub fn main() -> color_eyre::Result<()> {
color_eyre::install()?; color_eyre::install()?;
@@ -60,14 +59,10 @@ pub fn main() -> color_eyre::Result<()> {
loop { loop {
let block_count = rpc.get_block_count()?; let block_count = rpc.get_block_count()?;
info!("{block_count} blocks found.");
let starting_indexes = indexer.index(&parser, rpc, &exit)?; let starting_indexes = indexer.index(&parser, rpc, &exit)?;
computer.compute(&mut indexer, starting_indexes, &exit)?; computer.compute(&mut indexer, starting_indexes, &exit)?;
info!("Waiting for new blocks...");
while block_count == rpc.get_block_count()? { while block_count == rpc.get_block_count()? {
sleep(Duration::from_secs(1)) sleep(Duration::from_secs(1))
} }
+5 -6
View File
@@ -129,15 +129,14 @@ impl Server {
let status = response.status(); let status = response.status();
let uri = response.extensions().get::<Uri>().unwrap(); let uri = response.extensions().get::<Uri>().unwrap();
match status { match status {
StatusCode::INTERNAL_SERVER_ERROR => {
error!("{} {} {:?}", status.as_u16().red(), uri, latency)
}
StatusCode::NOT_MODIFIED => {
info!("{} {} {:?}", status.as_u16().bright_black(), uri, latency)
}
StatusCode::OK => { StatusCode::OK => {
info!("{} {} {:?}", status.as_u16().green(), uri, latency) info!("{} {} {:?}", status.as_u16().green(), uri, latency)
} }
StatusCode::NOT_MODIFIED
| StatusCode::TEMPORARY_REDIRECT
| StatusCode::PERMANENT_REDIRECT => {
info!("{} {} {:?}", status.as_u16().bright_black(), uri, latency)
}
_ => error!("{} {} {:?}", status.as_u16().red(), uri, latency), _ => error!("{} {} {:?}", status.as_u16().red(), uri, latency),
} }
}, },
+3 -3
View File
@@ -7,7 +7,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
{ {
let mut vec: StorableVec<usize, u32> = let mut vec: StorableVec<usize, u32> =
StorableVec::forced_import(Path::new("./vec"), Version::ONE, Compressed::YES)?; StorableVec::forced_import(Path::new("./vec"), Version::ZERO, Compressed::YES)?;
(0..21_u32).for_each(|v| { (0..21_u32).for_each(|v| {
vec.push(v); vec.push(v);
@@ -21,7 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
{ {
let mut vec: StorableVec<usize, u32> = let mut vec: StorableVec<usize, u32> =
StorableVec::forced_import(Path::new("./vec"), Version::ONE, Compressed::YES)?; StorableVec::forced_import(Path::new("./vec"), Version::ZERO, Compressed::YES)?;
dbg!(vec.get(0)?); dbg!(vec.get(0)?);
dbg!(vec.get(0)?); dbg!(vec.get(0)?);
@@ -43,7 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
{ {
let mut vec: StorableVec<usize, u32> = let mut vec: StorableVec<usize, u32> =
StorableVec::forced_import(Path::new("./vec"), Version::ONE, Compressed::YES)?; StorableVec::forced_import(Path::new("./vec"), Version::ZERO, Compressed::YES)?;
vec.enable_large_cache(); vec.enable_large_cache();
+2 -2
View File
@@ -20,7 +20,7 @@ pub enum Error {
ExpectVecToHaveIndex, ExpectVecToHaveIndex,
FailedKeyTryIntoUsize, FailedKeyTryIntoUsize,
UnsupportedUnflushedState, UnsupportedUnflushedState,
RangeFromAfterTo, RangeFromAfterTo(usize, usize),
DifferentCompressionMode, DifferentCompressionMode,
} }
@@ -66,7 +66,7 @@ impl fmt::Display for Error {
) )
} }
Error::ZeroCopyError => write!(f, "Zero copy convert error"), Error::ZeroCopyError => write!(f, "Zero copy convert error"),
Error::RangeFromAfterTo => write!(f, "Range, from is after to"), Error::RangeFromAfterTo(from, to) => write!(f, "Range, from {from} is after to {to}"),
Error::DifferentCompressionMode => write!(f, "Different compression mode chosen"), Error::DifferentCompressionMode => write!(f, "Different compression mode chosen"),
} }
} }
+1 -1
View File
@@ -224,7 +224,7 @@ where
}); });
if from > to { if from > to {
return Err(Error::RangeFromAfterTo); return Err(Error::RangeFromAfterTo(from, to));
} }
let mut page: Option<(usize, Values<T>)> = None; let mut page: Option<(usize, Values<T>)> = None;
+227 -64
View File
@@ -644,6 +644,167 @@ function initGroups() {
* @returns {PartialOptionsTree} * @returns {PartialOptionsTree}
*/ */
function createPartialOptions(colors) { function createPartialOptions(colors) {
/**
* @typedef {"total-"} TotalPrefix
* @typedef {Extract<VecId, `${TotalPrefix}${string}`>} TotalVecId
* @typedef {"-sum"} SumSuffix
* @typedef {Extract<VecId, `${string}${SumSuffix}`>} VecIdSum
* @typedef {"-average"} AverageSuffix
* @typedef {Extract<VecId, `${string}${AverageSuffix}`>} VecIdAverage
* @typedef {"-median"} MedianSuffix
* @typedef {Extract<VecId, `${string}${MedianSuffix}`>} VecIdMedian
* @typedef {"-90p"} _90pSuffix
* @typedef {Extract<VecId, `${string}${_90pSuffix}`>} VecId90p
* @typedef {"-75p"} _75pSuffix
* @typedef {Extract<VecId, `${string}${_75pSuffix}`>} VecId75p
* @typedef {"-25p"} _25pSuffix
* @typedef {Extract<VecId, `${string}${_25pSuffix}`>} VecId25p
* @typedef {"-10p"} _10pSuffix
* @typedef {Extract<VecId, `${string}${_10pSuffix}`>} VecId10p
* @typedef {"-max"} MaxSuffix
* @typedef {Extract<VecId, `${string}${MaxSuffix}`>} VecIdMax
* @typedef {"-min"} MinSuffix
* @typedef {Extract<VecId, `${string}${MinSuffix}`>} VecIdMin
* @typedef {VecId extends infer X
? X extends string
? `${X}${SumSuffix}` extends VecIdSum
? `${TotalPrefix}${X}` extends TotalVecId
? X
: never
: never
: never
: never} BaseTotalSumVecId
* @typedef {VecId extends infer X
? X extends string
? `${X}${MinSuffix}` extends VecIdMin
? `${X}${MaxSuffix}` extends VecIdMax
? X
: never
: never
: never
: never} MinMaxVecId
* @typedef {VecId extends infer X
? X extends string
? `${X}${AverageSuffix}` extends VecIdAverage
? X
: never
: never
: never} AverageVecId
* @typedef {VecId extends infer X
? X extends string
? `${X}${MedianSuffix}` extends VecIdMedian
? X
: never
: never
: never} MedianVecId
* @typedef {VecId extends infer X
? X extends string
? `${X}${_90pSuffix}` extends VecId90p
? `${X}${_75pSuffix}` extends VecId75p
? `${X}${_25pSuffix}` extends VecId25p
? `${X}${_10pSuffix}` extends VecId10p
? X
: never
: never
: never
: never
: never
: never} PercentilesVecId
* @typedef {AverageVecId & MinMaxVecId & MedianVecId & PercentilesVecId} AverageMinMaxPercentilesVecId
*/
/**
* @template {BaseTotalSumVecId} T
* @param {Object} args
* @param {string} args.name
* @param {string} args.title
* @param {T} args.key
*/
function createBaseSumTotal({ name, title, key }) {
return /** @satisfies {PartialChartOption} */ ({
name,
title,
bottom: [
{ key, title: name, color: colors.bitcoin },
{
key: `${key}-sum`,
title: "Sum",
color: colors.bitcoin,
},
{
key: `total-${key}`,
title: "Total",
color: colors.offBitcoin,
defaultActive: false,
},
],
});
}
/**
* @template {AverageMinMaxPercentilesVecId} T
* @param {Object} args
* @param {string} args.name
* @param {string} args.title
* @param {T} args.key
*/
function createBaseAverageMinMaxPercentiles({ name, title, key }) {
return /** @satisfies {PartialChartOption} */ ({
name,
title,
bottom: [
{ key, title: name, color: colors.bitcoin },
{
key: `${key}-average`,
title: "Average",
color: colors.orange,
},
{
key: `${key}-median`,
title: "Median",
color: colors.amber,
defaultActive: false,
},
{
key: `${key}-75p`,
title: "75p",
color: colors.red,
defaultActive: false,
},
{
key: `${key}-25p`,
title: "25p",
color: colors.yellow,
defaultActive: false,
},
{
key: `${key}-90p`,
title: "90p",
color: colors.rose,
defaultActive: false,
},
{
key: `${key}-10p`,
title: "10p",
color: colors.lime,
defaultActive: false,
},
{
key: `${key}-max`,
title: "Max",
color: colors.pink,
defaultActive: false,
},
{
key: `${key}-min`,
title: "Min",
color: colors.green,
defaultActive: false,
},
],
});
}
return [ return [
{ {
name: "Charts", name: "Charts",
@@ -667,74 +828,54 @@ function createPartialOptions(colors) {
{ {
name: "Blocks", name: "Blocks",
tree: [ tree: [
{ createBaseSumTotal({
name: "Count", name: "Count",
title: "Block Count", title: "Block Count",
bottom: [ key: "block-count",
{ key: "block-count", title: "Count", color: colors.bitcoin }, }),
{ createBaseAverageMinMaxPercentiles({
key: "total-block-count", name: "Interval",
title: "Total", title: "Block Interval",
color: colors.bitcoin, key: "block-interval",
}, }),
createBaseSumTotal({
name: "Size",
title: "Block Size",
key: "block-size",
}),
createBaseSumTotal({
name: "Weight",
title: "Block Weight",
key: "block-weight",
}),
createBaseSumTotal({
name: "Vbytes",
title: "Block Virtual Bytes",
key: "block-vbytes",
}),
],
},
{
name: "Transactions",
tree: [
{
name: "Inputs",
tree: [
createBaseSumTotal({
name: "Count",
title: "Transaction Input Count",
key: "input-count",
}),
], ],
}, },
{ {
name: "Interval", name: "Outputs",
title: "Block Interval", tree: [
bottom: [ createBaseSumTotal({
{ name: "Count",
key: "block-interval", title: "Transaction Output Count",
title: "Interval", key: "output-count",
color: colors.bitcoin, }),
},
{
key: "block-interval-average",
title: "Average",
color: colors.orange,
},
{
key: "block-interval-median",
title: "Median",
color: colors.amber,
defaultActive: false,
},
{
key: "block-interval-75p",
title: "75p",
color: colors.red,
defaultActive: false,
},
{
key: "block-interval-25p",
title: "25p",
color: colors.yellow,
defaultActive: false,
},
{
key: "block-interval-90p",
title: "90p",
color: colors.rose,
defaultActive: false,
},
{
key: "block-interval-10p",
title: "10p",
color: colors.lime,
defaultActive: false,
},
{
key: "block-interval-max",
title: "Max",
color: colors.pink,
defaultActive: false,
},
{
key: "block-interval-min",
title: "Min",
color: colors.green,
defaultActive: false,
},
], ],
}, },
], ],
@@ -754,6 +895,10 @@ function createPartialOptions(colors) {
{ {
name: "Social", name: "Social",
tree: [ tree: [
{
name: "Github",
url: () => "https://github.com/bitcoinresearchkit/brk",
},
{ {
name: "Nostr", name: "Nostr",
url: () => url: () =>
@@ -767,6 +912,10 @@ function createPartialOptions(colors) {
name: "Bluesky", name: "Bluesky",
url: () => "https://bsky.app/profile/bitcoinresearchkit.org", url: () => "https://bsky.app/profile/bitcoinresearchkit.org",
}, },
{
name: "x",
url: () => "https://x.com/brkdotorg",
},
], ],
}, },
{ {
@@ -777,9 +926,17 @@ function createPartialOptions(colors) {
url: () => "/api", url: () => "/api",
}, },
{ {
name: "Github", name: "Source",
url: () => "https://github.com/bitcoinresearchkit/brk", url: () => "https://github.com/bitcoinresearchkit/brk",
}, },
{
name: "Status",
url: () => "https://status.kibo.money/",
},
{
name: "Crate",
url: () => "https://crates.io/crates/brk",
},
], ],
}, },
{ {
@@ -1081,6 +1238,12 @@ export function initOptions({
anyPartial.unit = "Satoshis"; anyPartial.unit = "Satoshis";
} else if (key.includes("count")) { } else if (key.includes("count")) {
anyPartial.unit = "Count"; anyPartial.unit = "Count";
} else if (key.includes("-size")) {
anyPartial.unit = "Megabytes";
} else if (key.includes("-weight")) {
anyPartial.unit = "Weight";
} else if (key.includes("-vbytes")) {
anyPartial.unit = "Virtual Bytes";
} else { } else {
console.log(anyPartial); console.log(anyPartial);
throw Error("Unit not set"); throw Error("Unit not set");
@@ -22,8 +22,13 @@
/** @typedef {17} Txindex */ /** @typedef {17} Txindex */
/** @typedef {18} Txinindex */ /** @typedef {18} Txinindex */
/** @typedef {19} Txoutindex */ /** @typedef {19} Txoutindex */
/** @typedef {20} Emptyindex */
/** @typedef {21} Multisigindex */
/** @typedef {22} Opreturnindex */
/** @typedef {23} Pushonlyindex */
/** @typedef {24} Unknownindex */
/** @typedef {Height | Dateindex | Weekindex | Difficultyepoch | Monthindex | Quarterindex | Yearindex | Decadeindex | Halvingepoch | Addressindex | P2PK33index | P2PK65index | P2PKHindex | P2SHindex | P2TRindex | P2WPKHindex | P2WSHindex | Txindex | Txinindex | Txoutindex} Index */ /** @typedef {Height | Dateindex | Weekindex | Difficultyepoch | Monthindex | Quarterindex | Yearindex | Decadeindex | Halvingepoch | Addressindex | P2PK33index | P2PK65index | P2PKHindex | P2SHindex | P2TRindex | P2WPKHindex | P2WSHindex | Txindex | Txinindex | Txoutindex | Emptyindex | Multisigindex | Opreturnindex | Pushonlyindex | Unknownindex} Index */
export function createVecIdToIndexes() { export function createVecIdToIndexes() {
const Height = /** @satisfies {Height} */ (0); const Height = /** @satisfies {Height} */ (0);
@@ -46,13 +51,19 @@ export function createVecIdToIndexes() {
const Txindex = /** @satisfies {Txindex} */ (17); const Txindex = /** @satisfies {Txindex} */ (17);
const Txinindex = /** @satisfies {Txinindex} */ (18); const Txinindex = /** @satisfies {Txinindex} */ (18);
const Txoutindex = /** @satisfies {Txoutindex} */ (19); const Txoutindex = /** @satisfies {Txoutindex} */ (19);
const Emptyindex = /** @satisfies {Emptyindex} */ (20);
const Multisigindex = /** @satisfies {Multisigindex} */ (21);
const Opreturnindex = /** @satisfies {Opreturnindex} */ (22);
const Pushonlyindex = /** @satisfies {Pushonlyindex} */ (23);
const Unknownindex = /** @satisfies {Unknownindex} */ (24);
return { return {
addressindex: [Txoutindex], addressindex: [Txoutindex],
addresstype: [Addressindex], addresstype: [Addressindex],
addresstypeindex: [Addressindex], addresstypeindex: [Addressindex],
"base-size": [Txindex], "base-size": [Txindex],
"block-count": [Dateindex], "block-count": [Height],
"block-count-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"block-interval": [Height], "block-interval": [Height],
"block-interval-10p": [Dateindex], "block-interval-10p": [Dateindex],
"block-interval-25p": [Dateindex], "block-interval-25p": [Dateindex],
@@ -62,6 +73,12 @@ export function createVecIdToIndexes() {
"block-interval-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], "block-interval-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"block-interval-median": [Dateindex], "block-interval-median": [Dateindex],
"block-interval-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], "block-interval-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"block-size": [Height],
"block-size-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"block-vbytes": [Height],
"block-vbytes-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"block-weight": [Height],
"block-weight-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
blockhash: [Height], blockhash: [Height],
close: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], close: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"close-in-cents": [Dateindex, Height], "close-in-cents": [Dateindex, Height],
@@ -93,10 +110,11 @@ export function createVecIdToIndexes() {
"fixed-date": [Height], "fixed-date": [Height],
"fixed-timestamp": [Height], "fixed-timestamp": [Height],
halvingepoch: [Height, Halvingepoch], halvingepoch: [Height, Halvingepoch],
height: [Addressindex, Height, Txindex], height: [Addressindex, Height, P2PK33index, P2PK65index, P2PKHindex, P2SHindex, P2TRindex, P2WPKHindex, P2WSHindex, Txindex, Txinindex, Txoutindex, Emptyindex, Multisigindex, Opreturnindex, Pushonlyindex, Unknownindex],
high: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], high: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"high-in-cents": [Dateindex, Height], "high-in-cents": [Dateindex, Height],
"inputs-count": [Txindex], "input-count": [Txindex],
"input-count-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"is-coinbase": [Txindex], "is-coinbase": [Txindex],
"is-explicitly-rbf": [Txindex], "is-explicitly-rbf": [Txindex],
"last-dateindex": [Weekindex, Monthindex], "last-dateindex": [Weekindex, Monthindex],
@@ -114,7 +132,8 @@ export function createVecIdToIndexes() {
"ohlc-in-cents": [Dateindex, Height], "ohlc-in-cents": [Dateindex, Height],
open: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], open: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"open-in-cents": [Dateindex, Height], "open-in-cents": [Dateindex, Height],
"outputs-count": [Txindex], "output-count": [Txindex],
"output-count-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
p2pk33addressbytes: [P2PK33index], p2pk33addressbytes: [P2PK33index],
p2pk65addressbytes: [P2PK65index], p2pk65addressbytes: [P2PK65index],
p2pkhaddressbytes: [P2PKHindex], p2pkhaddressbytes: [P2PKHindex],
@@ -125,16 +144,19 @@ export function createVecIdToIndexes() {
quarterindex: [Monthindex, Quarterindex], quarterindex: [Monthindex, Quarterindex],
"real-date": [Height], "real-date": [Height],
"sats-per-dollar": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], "sats-per-dollar": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
size: [Height],
timestamp: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch, Halvingepoch], timestamp: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch, Halvingepoch],
"total-block-count": [Dateindex], "total-block-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"total-block-size": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"total-block-vbytes": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"total-block-weight": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"total-input-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"total-output-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch],
"total-size": [Txindex], "total-size": [Txindex],
txid: [Txindex], txid: [Txindex],
txoutindex: [Txinindex], txoutindex: [Txinindex],
txversion: [Txindex], txversion: [Txindex],
value: [Txoutindex], value: [Txoutindex],
weekindex: [Dateindex, Weekindex], weekindex: [Dateindex, Weekindex],
weight: [Height],
yearindex: [Monthindex, Yearindex], yearindex: [Monthindex, Yearindex],
} }
} }