mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -1,27 +1,32 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![doc = "\n## Example\n\n```rust"]
|
||||
#![doc = include_str!("main.rs")]
|
||||
#![doc = "```"]
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_indexer::{Indexer, Indexes};
|
||||
pub use brk_parser::rpc;
|
||||
|
||||
mod storage;
|
||||
|
||||
use brk_core::Date;
|
||||
use brk_vec::SINGLE_THREAD;
|
||||
use storage::{Stores, Vecs};
|
||||
|
||||
pub struct Computer<const MODE: u8> {
|
||||
#[derive(Clone)]
|
||||
pub struct Computer {
|
||||
path: PathBuf,
|
||||
pub vecs: Vecs<MODE>,
|
||||
pub vecs: Vecs,
|
||||
pub stores: Stores,
|
||||
}
|
||||
|
||||
impl<const MODE: u8> Computer<MODE> {
|
||||
impl Computer {
|
||||
pub fn import(computed_dir: &Path) -> color_eyre::Result<Self> {
|
||||
let vecs = Vecs::import(&computed_dir.join("vecs"))?;
|
||||
let stores = Stores::import(&computed_dir.join("fjall"))?;
|
||||
|
||||
let stores = Stores::import(&computed_dir.join("stores"))?;
|
||||
|
||||
Ok(Self {
|
||||
path: computed_dir.to_owned(),
|
||||
vecs,
|
||||
@@ -30,8 +35,8 @@ impl<const MODE: u8> Computer<MODE> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Computer<SINGLE_THREAD> {
|
||||
pub fn compute(&mut self, mut indexer: Indexer<SINGLE_THREAD>, exit: &Exit) -> color_eyre::Result<()> {
|
||||
impl Computer {
|
||||
pub fn compute(&mut self, indexer: &mut Indexer, starting_indexes: Indexes, exit: &Exit) -> color_eyre::Result<()> {
|
||||
let height_count = indexer.vecs.height_to_size.len();
|
||||
let txindexes_count = indexer.vecs.txindex_to_txid.len();
|
||||
let txinindexes_count = indexer.vecs.txinindex_to_txoutindex.len();
|
||||
@@ -39,53 +44,61 @@ impl Computer<SINGLE_THREAD> {
|
||||
|
||||
// TODO: Remove all outdated
|
||||
|
||||
self.vecs.txindex_to_last_txinindex.compute_last_index_from_first(
|
||||
&mut indexer.vecs.txindex_to_first_txinindex,
|
||||
txinindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.txindex_to_last_txinindex.compute_last_index_from_first(
|
||||
// starting_indexes.txindex,
|
||||
// &mut indexer.vecs.txindex_to_first_txinindex,
|
||||
// txinindexes_count,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
self.vecs.txindex_to_inputs_count.compute_count_from_indexes(
|
||||
&mut indexer.vecs.txindex_to_first_txinindex,
|
||||
&mut self.vecs.txindex_to_last_txinindex,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.txindex_to_inputs_count.compute_count_from_indexes(
|
||||
// starting_indexes.txindex,
|
||||
// &mut indexer.vecs.txindex_to_first_txinindex,
|
||||
// &mut self.vecs.txindex_to_last_txinindex,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
self.vecs.txindex_to_last_txoutindex.compute_last_index_from_first(
|
||||
&mut indexer.vecs.txindex_to_first_txoutindex,
|
||||
txoutindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.txindex_to_last_txoutindex.compute_last_index_from_first(
|
||||
// starting_indexes.txindex,
|
||||
// &mut indexer.vecs.txindex_to_first_txoutindex,
|
||||
// txoutindexes_count,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
self.vecs.txindex_to_outputs_count.compute_count_from_indexes(
|
||||
&mut indexer.vecs.txindex_to_first_txoutindex,
|
||||
&mut self.vecs.txindex_to_last_txoutindex,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.txindex_to_outputs_count.compute_count_from_indexes(
|
||||
// starting_indexes.txindex,
|
||||
// &mut indexer.vecs.txindex_to_first_txoutindex,
|
||||
// &mut self.vecs.txindex_to_last_txoutindex,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
self.vecs.height_to_date.compute_transform(
|
||||
starting_indexes.height,
|
||||
&mut indexer.vecs.height_to_timestamp,
|
||||
|timestamp| Date::from(*timestamp),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.vecs.height_to_last_txindex.compute_last_index_from_first(
|
||||
&mut indexer.vecs.height_to_first_txindex,
|
||||
height_count,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.height_to_last_txindex.compute_last_index_from_first(
|
||||
// starting_indexes.height,
|
||||
// &mut indexer.vecs.height_to_first_txindex,
|
||||
// height_count,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
self.vecs.txindex_to_height.compute_inverse_less_to_more(
|
||||
&mut indexer.vecs.height_to_first_txindex,
|
||||
&mut self.vecs.height_to_last_txindex,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.txindex_to_height.compute_inverse_less_to_more(
|
||||
// starting_indexes.height,
|
||||
// &mut indexer.vecs.height_to_first_txindex,
|
||||
// &mut self.vecs.height_to_last_txindex,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
self.vecs.txindex_to_is_coinbase.compute_is_first_ordered(
|
||||
&mut self.vecs.txindex_to_height,
|
||||
&mut indexer.vecs.height_to_first_txindex,
|
||||
exit,
|
||||
)?;
|
||||
// self.vecs.txindex_to_is_coinbase.compute_is_first_ordered(
|
||||
// starting_indexes.txindex,
|
||||
// &mut self.vecs.txindex_to_height,
|
||||
// &mut indexer.vecs.height_to_first_txindex,
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
// self.vecs.txindex_to_fee.compute_transform(
|
||||
// &mut self.vecs.txindex_to_height,
|
||||
@@ -96,9 +109,9 @@ impl Computer<SINGLE_THREAD> {
|
||||
|
||||
// self.vecs.height_to_dateindex.compute(...)
|
||||
|
||||
self.vecs
|
||||
.dateindex_to_first_height
|
||||
.compute_inverse_more_to_less(&mut self.vecs.height_to_dateindex, exit)?;
|
||||
// self.vecs
|
||||
// .dateindex_to_first_height
|
||||
// .compute_inverse_more_to_less(&mut self.vecs.height_to_dateindex, exit)?;
|
||||
|
||||
// ---
|
||||
// Date to X
|
||||
|
||||
@@ -7,7 +7,6 @@ use brk_parser::{
|
||||
Parser,
|
||||
rpc::{self, RpcApi},
|
||||
};
|
||||
use brk_vec::CACHED_GETS;
|
||||
use log::info;
|
||||
|
||||
pub fn main() -> color_eyre::Result<()> {
|
||||
@@ -26,25 +25,26 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
|
||||
let outputs_dir = Path::new("../../_outputs");
|
||||
|
||||
let indexer: Indexer<CACHED_GETS> = Indexer::import(&outputs_dir.join("indexes"))?;
|
||||
let mut indexer = Indexer::import(&outputs_dir.join("indexed"))?;
|
||||
|
||||
// let mut computer = Computer::import(&outputs_dir.join("computed"))?;
|
||||
let mut computer = Computer::import(&outputs_dir.join("computed"))?;
|
||||
|
||||
// loop {
|
||||
// let block_count = rpc.get_block_count()?;
|
||||
loop {
|
||||
let block_count = rpc.get_block_count()?;
|
||||
|
||||
// info!("{block_count} blocks found.");
|
||||
info!("{block_count} blocks found.");
|
||||
|
||||
// indexer.index(&parser, rpc, &exit)?;
|
||||
let starting_indexes = indexer.index(&parser, rpc, &exit)?;
|
||||
|
||||
// computer.compute(indexer, &exit)?;
|
||||
computer.compute(&mut indexer, starting_indexes, &exit)?;
|
||||
|
||||
// info!("Waiting for new blocks...");
|
||||
info!("Waiting for new blocks...");
|
||||
|
||||
// while block_count == rpc.get_block_count()? {
|
||||
// sleep(Duration::from_secs(1))
|
||||
// }
|
||||
// }
|
||||
while block_count == rpc.get_block_count()? {
|
||||
sleep(Duration::from_secs(1))
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unreachable_code)]
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use brk_core::{AddressindexTxoutindex, Unit};
|
||||
use brk_indexer::Store;
|
||||
use brk_vec::Version;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Stores {
|
||||
pub address_to_utxos_received: Store<AddressindexTxoutindex, Unit>,
|
||||
pub address_to_utxos_spent: Store<AddressindexTxoutindex, Unit>,
|
||||
|
||||
@@ -4,59 +4,60 @@ use brk_core::{
|
||||
Addressindex, Cents, Close, Date, Dateindex, Dollars, Feerate, Height, High, Low, Open, Sats, Timestamp, Txindex,
|
||||
Txinindex, Txoutindex,
|
||||
};
|
||||
use brk_vec::{StorableVec, Version};
|
||||
use brk_vec::{AnyStorableVec, StorableVec, Version};
|
||||
|
||||
// mod base;
|
||||
|
||||
// use base::*;
|
||||
|
||||
pub struct Vecs<const MODE: u8> {
|
||||
pub dateindex_to_first_height: StorableVec<Dateindex, Height, MODE>,
|
||||
// pub dateindex_to_last_height: StorableVec<Dateindex, Height, MODE>,
|
||||
// pub height_to_block_interval: StorableVec<Height, Timestamp, MODE>,
|
||||
pub dateindex_to_close_in_cents: StorableVec<Dateindex, Close<Cents>, MODE>,
|
||||
pub dateindex_to_close_in_dollars: StorableVec<Dateindex, Close<Dollars>, MODE>,
|
||||
pub dateindex_to_high_in_cents: StorableVec<Dateindex, High<Cents>, MODE>,
|
||||
pub dateindex_to_high_in_dollars: StorableVec<Dateindex, High<Dollars>, MODE>,
|
||||
pub dateindex_to_low_in_cents: StorableVec<Dateindex, Low<Cents>, MODE>,
|
||||
pub dateindex_to_low_in_dollars: StorableVec<Dateindex, Low<Dollars>, MODE>,
|
||||
pub dateindex_to_open_in_cents: StorableVec<Dateindex, Open<Cents>, MODE>,
|
||||
pub dateindex_to_open_in_dollars: StorableVec<Dateindex, Open<Dollars>, MODE>,
|
||||
pub height_to_close_in_cents: StorableVec<Height, Close<Cents>, MODE>,
|
||||
pub height_to_close_in_dollars: StorableVec<Height, Close<Dollars>, MODE>,
|
||||
pub height_to_high_in_cents: StorableVec<Height, High<Cents>, MODE>,
|
||||
pub height_to_high_in_dollars: StorableVec<Height, High<Dollars>, MODE>,
|
||||
pub height_to_low_in_cents: StorableVec<Height, Low<Cents>, MODE>,
|
||||
pub height_to_low_in_dollars: StorableVec<Height, Low<Dollars>, MODE>,
|
||||
pub height_to_open_in_cents: StorableVec<Height, Open<Cents>, MODE>,
|
||||
pub height_to_open_in_dollars: StorableVec<Height, Open<Dollars>, MODE>,
|
||||
pub height_to_date: StorableVec<Height, Date, MODE>,
|
||||
pub height_to_dateindex: StorableVec<Height, Dateindex, MODE>,
|
||||
// pub height_to_fee: StorableVec<Txindex, Amount, MODE>,
|
||||
// pub height_to_inputcount: StorableVec<Height, u32, MODE>,
|
||||
// pub height_to_last_addressindex: StorableVec<Height, Addressindex, MODE>,
|
||||
pub height_to_last_txindex: StorableVec<Height, Txindex, MODE>,
|
||||
// pub height_to_last_txoutindex: StorableVec<Height, Txoutindex, MODE>,
|
||||
// pub height_to_maxfeerate: StorableVec<Height, Feerate, MODE>,
|
||||
// pub height_to_medianfeerate: StorableVec<Height, Feerate, MODE>,
|
||||
// pub height_to_minfeerate: StorableVec<Height, Feerate, MODE>,
|
||||
// pub height_to_outputcount: StorableVec<Height, u32, MODE>,
|
||||
// pub height_to_subsidy: StorableVec<Height, u32, MODE>,
|
||||
// pub height_to_totalfees: StorableVec<Height, Amount, MODE>,
|
||||
// pub height_to_txcount: StorableVec<Height, u32, MODE>,
|
||||
pub txindex_to_fee: StorableVec<Txindex, Sats, MODE>,
|
||||
pub txindex_to_height: StorableVec<Txindex, Height, MODE>,
|
||||
pub txindex_to_is_coinbase: StorableVec<Txindex, bool, MODE>,
|
||||
// pub txindex_to_feerate: StorableVec<Txindex, Feerate, MODE>,
|
||||
pub txindex_to_inputs_count: StorableVec<Txindex, u32, MODE>,
|
||||
pub txindex_to_inputs_sum: StorableVec<Txindex, Sats, MODE>,
|
||||
pub txindex_to_last_txinindex: StorableVec<Txindex, Txinindex, MODE>,
|
||||
pub txindex_to_last_txoutindex: StorableVec<Txindex, Txoutindex, MODE>,
|
||||
pub txindex_to_outputs_count: StorableVec<Txindex, u32, MODE>,
|
||||
pub txindex_to_outputs_sum: StorableVec<Txindex, Sats, MODE>,
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub dateindex_to_first_height: StorableVec<Dateindex, Height>,
|
||||
// pub dateindex_to_last_height: StorableVec<Dateindex, Height>,
|
||||
// pub height_to_block_interval: StorableVec<Height, Timestamp>,
|
||||
pub dateindex_to_close_in_cents: StorableVec<Dateindex, Close<Cents>>,
|
||||
pub dateindex_to_close_in_dollars: StorableVec<Dateindex, Close<Dollars>>,
|
||||
pub dateindex_to_high_in_cents: StorableVec<Dateindex, High<Cents>>,
|
||||
pub dateindex_to_high_in_dollars: StorableVec<Dateindex, High<Dollars>>,
|
||||
pub dateindex_to_low_in_cents: StorableVec<Dateindex, Low<Cents>>,
|
||||
pub dateindex_to_low_in_dollars: StorableVec<Dateindex, Low<Dollars>>,
|
||||
pub dateindex_to_open_in_cents: StorableVec<Dateindex, Open<Cents>>,
|
||||
pub dateindex_to_open_in_dollars: StorableVec<Dateindex, Open<Dollars>>,
|
||||
pub height_to_close_in_cents: StorableVec<Height, Close<Cents>>,
|
||||
pub height_to_close_in_dollars: StorableVec<Height, Close<Dollars>>,
|
||||
pub height_to_high_in_cents: StorableVec<Height, High<Cents>>,
|
||||
pub height_to_high_in_dollars: StorableVec<Height, High<Dollars>>,
|
||||
pub height_to_low_in_cents: StorableVec<Height, Low<Cents>>,
|
||||
pub height_to_low_in_dollars: StorableVec<Height, Low<Dollars>>,
|
||||
pub height_to_open_in_cents: StorableVec<Height, Open<Cents>>,
|
||||
pub height_to_open_in_dollars: StorableVec<Height, Open<Dollars>>,
|
||||
pub height_to_date: StorableVec<Height, Date>,
|
||||
pub height_to_dateindex: StorableVec<Height, Dateindex>,
|
||||
// pub height_to_fee: StorableVec<Txindex, Amount>,
|
||||
// pub height_to_inputcount: StorableVec<Height, u32>,
|
||||
// pub height_to_last_addressindex: StorableVec<Height, Addressindex>,
|
||||
pub height_to_last_txindex: StorableVec<Height, Txindex>,
|
||||
// pub height_to_last_txoutindex: StorableVec<Height, Txoutindex>,
|
||||
// pub height_to_maxfeerate: StorableVec<Height, Feerate>,
|
||||
// pub height_to_medianfeerate: StorableVec<Height, Feerate>,
|
||||
// pub height_to_minfeerate: StorableVec<Height, Feerate>,
|
||||
// pub height_to_outputcount: StorableVec<Height, u32>,
|
||||
// pub height_to_subsidy: StorableVec<Height, u32>,
|
||||
// pub height_to_totalfees: StorableVec<Height, Amount>,
|
||||
// pub height_to_txcount: StorableVec<Height, u32>,
|
||||
pub txindex_to_fee: StorableVec<Txindex, Sats>,
|
||||
pub txindex_to_height: StorableVec<Txindex, Height>,
|
||||
pub txindex_to_is_coinbase: StorableVec<Txindex, bool>,
|
||||
// pub txindex_to_feerate: StorableVec<Txindex, Feerate>,
|
||||
pub txindex_to_inputs_count: StorableVec<Txindex, u32>,
|
||||
pub txindex_to_inputs_sum: StorableVec<Txindex, Sats>,
|
||||
pub txindex_to_last_txinindex: StorableVec<Txindex, Txinindex>,
|
||||
pub txindex_to_last_txoutindex: StorableVec<Txindex, Txoutindex>,
|
||||
pub txindex_to_outputs_count: StorableVec<Txindex, u32>,
|
||||
pub txindex_to_outputs_sum: StorableVec<Txindex, Sats>,
|
||||
}
|
||||
|
||||
impl<const MODE: u8> Vecs<MODE> {
|
||||
impl Vecs {
|
||||
pub fn import(path: &Path) -> color_eyre::Result<Self> {
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
@@ -148,45 +149,24 @@ impl<const MODE: u8> Vecs<MODE> {
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn as_slice(&self) -> [&dyn AnyComputedStorableVec; 1] {
|
||||
// [
|
||||
// &self.dateindex_to_close_in_cents as &dyn AnyJsonStorableVec,
|
||||
// &self.dateindex_to_close_in_dollars,
|
||||
// &self.dateindex_to_high_in_cents,
|
||||
// &self.dateindex_to_high_in_dollars,
|
||||
// &self.dateindex_to_low_in_cents,
|
||||
// &self.dateindex_to_low_in_dollars,
|
||||
// &self.dateindex_to_open_in_cents,
|
||||
// &self.dateindex_to_open_in_dollars,
|
||||
// &self.height_to_close_in_cents,
|
||||
// &self.height_to_close_in_dollars,
|
||||
// &self.height_to_high_in_cents,
|
||||
// &self.height_to_high_in_dollars,
|
||||
// &self.height_to_low_in_cents,
|
||||
// &self.height_to_low_in_dollars,
|
||||
// &self.height_to_open_in_cents,
|
||||
// &self.height_to_open_in_dollars,
|
||||
// ]
|
||||
// }
|
||||
|
||||
// pub fn as_mut_slice(&mut self) -> [&mut dyn AnyComputedStorableVec; 1] {
|
||||
// [
|
||||
// &mut self.dateindex_to_close_in_cents as &mut dyn AnyStorableVec,
|
||||
// &mut self.dateindex_to_close_in_dollars,
|
||||
// &mut self.dateindex_to_high_in_cents,
|
||||
// &mut self.dateindex_to_high_in_dollars,
|
||||
// &mut self.dateindex_to_low_in_cents,
|
||||
// &mut self.dateindex_to_low_in_dollars,
|
||||
// &mut self.dateindex_to_open_in_cents,
|
||||
// &mut self.dateindex_to_open_in_dollars,
|
||||
// &mut self.height_to_close_in_cents,
|
||||
// &mut self.height_to_close_in_dollars,
|
||||
// &mut self.height_to_high_in_cents,
|
||||
// &mut self.height_to_high_in_dollars,
|
||||
// &mut self.height_to_low_in_cents,
|
||||
// &mut self.height_to_low_in_dollars,
|
||||
// &mut self.height_to_open_in_cents,
|
||||
// &mut self.height_to_open_in_dollars,
|
||||
// ]
|
||||
// }
|
||||
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
|
||||
vec![
|
||||
&self.height_to_date as &dyn AnyStorableVec,
|
||||
// &self.dateindex_to_close_in_dollars,
|
||||
// &self.dateindex_to_high_in_cents,
|
||||
// &self.dateindex_to_high_in_dollars,
|
||||
// &self.dateindex_to_low_in_cents,
|
||||
// &self.dateindex_to_low_in_dollars,
|
||||
// &self.dateindex_to_open_in_cents,
|
||||
// &self.dateindex_to_open_in_dollars,
|
||||
// &self.height_to_close_in_cents,
|
||||
// &self.height_to_close_in_dollars,
|
||||
// &self.height_to_high_in_cents,
|
||||
// &self.height_to_high_in_dollars,
|
||||
// &self.height_to_low_in_cents,
|
||||
// &self.height_to_low_in_dollars,
|
||||
// &self.height_to_open_in_cents,
|
||||
// &self.height_to_open_in_dollars,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
0
crates/brk_computer/src/storage/vecs_/base.rs
Normal file
0
crates/brk_computer/src/storage/vecs_/base.rs
Normal file
0
crates/brk_computer/src/storage/vecs_/mod.rs
Normal file
0
crates/brk_computer/src/storage/vecs_/mod.rs
Normal file
Reference in New Issue
Block a user