mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
global: snapshot
This commit is contained in:
@@ -13,7 +13,7 @@ pub mod grouped;
|
||||
pub mod indexes;
|
||||
pub mod market;
|
||||
pub mod mining;
|
||||
pub mod statefull;
|
||||
pub mod stateful;
|
||||
pub mod transactions;
|
||||
|
||||
pub use indexes::Indexes;
|
||||
@@ -28,7 +28,7 @@ pub struct Vecs {
|
||||
pub mining: mining::Vecs,
|
||||
pub market: market::Vecs,
|
||||
pub transactions: transactions::Vecs,
|
||||
pub statefull: statefull::Vecs,
|
||||
pub stateful: stateful::Vecs,
|
||||
pub fetched: Option<fetched::Vecs>,
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ impl Vecs {
|
||||
computation,
|
||||
compressed,
|
||||
)?,
|
||||
statefull: statefull::Vecs::forced_import(
|
||||
stateful: stateful::Vecs::forced_import(
|
||||
path,
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
@@ -154,7 +154,7 @@ impl Vecs {
|
||||
)?;
|
||||
}
|
||||
|
||||
self.statefull.compute(
|
||||
self.stateful.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&self.transactions,
|
||||
@@ -174,7 +174,7 @@ impl Vecs {
|
||||
self.mining.vecs(),
|
||||
self.market.vecs(),
|
||||
self.transactions.vecs(),
|
||||
self.statefull.vecs(),
|
||||
self.stateful.vecs(),
|
||||
self.fetched.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
]
|
||||
.into_iter()
|
||||
|
||||
@@ -23,10 +23,11 @@ pub struct Vecs {
|
||||
starting_height: Height,
|
||||
pub state: CohortState,
|
||||
|
||||
// Cumulative
|
||||
pub height_to_realized_cap: Option<EagerVec<Height, Dollars>>,
|
||||
pub height_to_supply: EagerVec<Height, Sats>,
|
||||
pub height_to_utxo_count: EagerVec<Height, StoredUsize>,
|
||||
|
||||
// Single
|
||||
pub height_to_realized_profit: Option<EagerVec<Height, Dollars>>,
|
||||
pub height_to_realized_loss: Option<EagerVec<Height, Dollars>>,
|
||||
pub height_to_value_created: Option<EagerVec<Height, Dollars>>,
|
||||
@@ -129,7 +130,6 @@ impl Vecs {
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)?,
|
||||
|
||||
indexes_to_realized_price: compute_dollars.then(|| {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
@@ -197,7 +197,7 @@ impl Vecs {
|
||||
path,
|
||||
&suffix("negative_realized_loss"),
|
||||
true,
|
||||
version + VERSION + Version::ZERO,
|
||||
version + VERSION + Version::ONE,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
)
|
||||
@@ -227,7 +227,7 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_value"),
|
||||
false,
|
||||
true,
|
||||
version + VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
@@ -318,7 +318,7 @@ impl Vecs {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("sell_side_risk_ratio"),
|
||||
version + VERSION + Version::ZERO,
|
||||
version + VERSION + Version::ONE,
|
||||
compressed,
|
||||
)
|
||||
.unwrap()
|
||||
@@ -504,7 +504,7 @@ impl Vecs {
|
||||
|
||||
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
|
||||
let realized = self.state.realized.as_ref().unwrap_or_else(|| {
|
||||
dbg!(&self.state);
|
||||
dbg!((&self.state.realized, &self.state.supply));
|
||||
panic!();
|
||||
});
|
||||
|
||||
@@ -674,7 +674,7 @@ impl Vecs {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.height_to_realized_loss.as_ref().unwrap(),
|
||||
|(i, v, ..)| (i, v * -1.0),
|
||||
|(i, v, ..)| (i, v * -1_i64),
|
||||
exit,
|
||||
)
|
||||
},
|
||||
@@ -809,7 +809,7 @@ impl Vecs {
|
||||
self.dateindex_to_sell_side_risk_ratio
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute_divide(
|
||||
.compute_percentage(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_realized_value
|
||||
.as_ref()
|
||||
@@ -919,31 +919,30 @@ impl Clone for Vecs {
|
||||
state: CohortState::default(),
|
||||
|
||||
height_to_realized_cap: self.height_to_realized_cap.clone(),
|
||||
indexes_to_realized_cap: self.indexes_to_realized_cap.clone(),
|
||||
height_to_supply: self.height_to_supply.clone(),
|
||||
indexes_to_supply: self.indexes_to_supply.clone(),
|
||||
height_to_utxo_count: self.height_to_utxo_count.clone(),
|
||||
indexes_to_utxo_count: self.indexes_to_utxo_count.clone(),
|
||||
|
||||
height_to_realized_profit: self.height_to_realized_profit.clone(),
|
||||
indexes_to_realized_profit: self.indexes_to_realized_profit.clone(),
|
||||
height_to_realized_loss: self.height_to_realized_loss.clone(),
|
||||
height_to_value_created: self.height_to_value_created.clone(),
|
||||
height_to_adjusted_value_created: self.height_to_adjusted_value_created.clone(),
|
||||
height_to_value_destroyed: self.height_to_value_destroyed.clone(),
|
||||
height_to_adjusted_value_destroyed: self.height_to_adjusted_value_destroyed.clone(),
|
||||
|
||||
indexes_to_supply: self.indexes_to_supply.clone(),
|
||||
indexes_to_utxo_count: self.indexes_to_utxo_count.clone(),
|
||||
indexes_to_realized_cap: self.indexes_to_realized_cap.clone(),
|
||||
indexes_to_realized_profit: self.indexes_to_realized_profit.clone(),
|
||||
indexes_to_realized_loss: self.indexes_to_realized_loss.clone(),
|
||||
indexes_to_negative_realized_loss: self.indexes_to_negative_realized_loss.clone(),
|
||||
height_to_value_created: self.height_to_value_created.clone(),
|
||||
indexes_to_value_created: self.indexes_to_value_created.clone(),
|
||||
height_to_adjusted_value_created: self.height_to_adjusted_value_created.clone(),
|
||||
indexes_to_adjusted_value_created: self.indexes_to_adjusted_value_created.clone(),
|
||||
height_to_value_destroyed: self.height_to_value_destroyed.clone(),
|
||||
indexes_to_value_destroyed: self.indexes_to_value_destroyed.clone(),
|
||||
height_to_adjusted_value_destroyed: self.height_to_adjusted_value_destroyed.clone(),
|
||||
indexes_to_adjusted_value_destroyed: self.indexes_to_adjusted_value_destroyed.clone(),
|
||||
dateindex_to_realized_cap_30d_change: self.dateindex_to_realized_cap_30d_change.clone(),
|
||||
indexes_to_realized_value: self.indexes_to_realized_value.clone(),
|
||||
indexes_to_net_realized_profit_and_loss: self
|
||||
.indexes_to_net_realized_profit_and_loss
|
||||
.clone(),
|
||||
|
||||
indexes_to_realized_price: self.indexes_to_realized_price.clone(),
|
||||
dateindex_to_sell_side_risk_ratio: self.dateindex_to_sell_side_risk_ratio.clone(),
|
||||
indexes_to_realized_price_extra: self.indexes_to_realized_price_extra.clone(),
|
||||
@@ -1032,7 +1032,7 @@ impl Vecs {
|
||||
.iter_mut()
|
||||
.for_each(|(_, v)| v.state.reset_single_iteration_values());
|
||||
|
||||
info!("Processing utxo set at {height}...");
|
||||
info!("Processing chain at {height}...");
|
||||
|
||||
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
|
||||
let price = height_to_close_iter
|
||||
@@ -1182,8 +1182,6 @@ impl Vecs {
|
||||
};
|
||||
|
||||
if chain_state_starting_height <= height {
|
||||
// RECEIVE
|
||||
|
||||
// Push current block state before processing sends and receives
|
||||
chain_state.push(BlockState {
|
||||
supply: received.spendable_supply.clone(),
|
||||
@@ -1193,10 +1191,6 @@ impl Vecs {
|
||||
|
||||
self.utxos_vecs.receive(received, height, price);
|
||||
|
||||
// ---
|
||||
|
||||
// SEND
|
||||
|
||||
let unsafe_chain_state = UnsafeSlice::new(&mut chain_state);
|
||||
|
||||
height_to_sent.par_iter().for_each(|(height, sent)| unsafe {
|
||||
@@ -1229,8 +1223,6 @@ impl Vecs {
|
||||
|
||||
exit.block();
|
||||
|
||||
info!("Computing utxo set datasets...");
|
||||
|
||||
let mut flat_vecs_ = self.utxos_vecs.as_mut_vec();
|
||||
|
||||
info!("Flushing...");
|
||||
@@ -1240,11 +1232,17 @@ impl Vecs {
|
||||
.par_iter_mut()
|
||||
.try_for_each(|(_, v)| v.safe_flush_height_vecs(exit))?;
|
||||
self.height_to_unspendable_supply.safe_flush(exit)?;
|
||||
flat_vecs_
|
||||
.par_iter_mut()
|
||||
.try_for_each(|(_, v)| v.safe_flush_height_vecs(exit))?;
|
||||
self.height_to_opreturn_supply.safe_flush(exit)?;
|
||||
|
||||
// Save chain state
|
||||
self.chain_state.truncate_if_needed(Height::ZERO)?;
|
||||
mem::take(&mut chain_state)
|
||||
.into_iter()
|
||||
.for_each(|block_state| {
|
||||
self.chain_state.push(block_state.supply);
|
||||
});
|
||||
self.chain_state.flush()?;
|
||||
|
||||
info!("Computing rest...");
|
||||
|
||||
// Compute other vecs from height vecs
|
||||
@@ -1268,17 +1266,6 @@ impl Vecs {
|
||||
Some(&self.height_to_opreturn_supply),
|
||||
)?;
|
||||
|
||||
info!("Chain state...");
|
||||
|
||||
// Save chain state
|
||||
self.chain_state.truncate_if_needed(Height::ZERO)?;
|
||||
mem::take(&mut chain_state)
|
||||
.into_iter()
|
||||
.for_each(|block_state| {
|
||||
self.chain_state.push(block_state.supply);
|
||||
});
|
||||
self.chain_state.flush()?;
|
||||
|
||||
exit.release();
|
||||
|
||||
Ok(())
|
||||
Reference in New Issue
Block a user