mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-20 07:28:11 -07:00
global: snapshot
This commit is contained in:
@@ -17,7 +17,7 @@ impl Vecs {
|
||||
self.adjustment.bps.height.compute_ratio_change(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
1,
|
||||
2016,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ impl Vecs {
|
||||
adjustment: PercentPerBlock::forced_import(
|
||||
db,
|
||||
"difficulty_adjustment",
|
||||
version,
|
||||
version + Version::ONE,
|
||||
indexes,
|
||||
)?,
|
||||
epoch: PerBlock::forced_import(db, "difficulty_epoch", version, indexes)?,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Cents, Indexes};
|
||||
use brk_types::{Dollars, Indexes};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::{activity, value};
|
||||
@@ -59,7 +59,8 @@ impl Vecs {
|
||||
let destroyed: f64 = *destroyed;
|
||||
let supply: f64 = supply.into();
|
||||
let stored: f64 = *stored;
|
||||
(i, Cents::from(destroyed * supply / stored))
|
||||
let usd = Dollars::from(destroyed * supply / stored);
|
||||
(i, usd.to_cents())
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -3,7 +3,10 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::{FiatPerBlock, RatioPerBlock}};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{FiatPerBlock, RatioPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -16,7 +19,12 @@ impl Vecs {
|
||||
investor: FiatPerBlock::forced_import(db, "investor_cap", version, indexes)?,
|
||||
vaulted: FiatPerBlock::forced_import(db, "vaulted_cap", version, indexes)?,
|
||||
active: FiatPerBlock::forced_import(db, "active_cap", version, indexes)?,
|
||||
cointime: FiatPerBlock::forced_import(db, "cointime_cap", version, indexes)?,
|
||||
cointime: FiatPerBlock::forced_import(
|
||||
db,
|
||||
"cointime_cap",
|
||||
version + Version::ONE,
|
||||
indexes,
|
||||
)?,
|
||||
aviv: RatioPerBlock::forced_import(db, "aviv", version, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ impl Vecs {
|
||||
let activity = ActivityVecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
let supply = SupplyVecs::forced_import(&db, v1, indexes)?;
|
||||
let value = ValueVecs::forced_import(&db, v1, indexes, cached_starts)?;
|
||||
let cap = CapVecs::forced_import(&db, v1, indexes)?;
|
||||
let prices = PricesVecs::forced_import(&db, version, indexes)?;
|
||||
let cap = CapVecs::forced_import(&db, version + Version::TWO, indexes)?;
|
||||
let prices = PricesVecs::forced_import(&db, version + Version::new(3), indexes)?;
|
||||
let adjusted = AdjustedVecs::forced_import(&db, version, indexes)?;
|
||||
let reserve_risk = ReserveRiskVecs::forced_import(&db, v1, indexes)?;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{Cents, Indexes};
|
||||
use vecdb::{Exit, VecIndex};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::{activity, cap, supply};
|
||||
use super::Vecs;
|
||||
@@ -21,7 +21,6 @@ impl Vecs {
|
||||
let all_metrics = &distribution.utxo_cohorts.all.metrics;
|
||||
let circulating_supply = &all_metrics.supply.total.btc.height;
|
||||
let realized_price = &all_metrics.realized.price.cents.height;
|
||||
let realized_cap = &all_metrics.realized.cap.cents.height;
|
||||
|
||||
self.vaulted.compute_all(
|
||||
prices,
|
||||
@@ -45,10 +44,13 @@ impl Vecs {
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
Ok(v.compute_multiply(
|
||||
Ok(v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&activity.liveliness.height,
|
||||
|(i, price, liveliness, ..)| {
|
||||
(i, Cents::from(f64::from(price) / f64::from(liveliness)))
|
||||
},
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
@@ -71,7 +73,6 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
// cointime_price = cointime_cap / circulating_supply
|
||||
self.cointime.compute_all(
|
||||
prices,
|
||||
starting_indexes,
|
||||
@@ -89,72 +90,6 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
// transfer_price = cointime_price - vaulted_price
|
||||
self.transfer.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.cointime.cents.height,
|
||||
&self.vaulted.cents.height,
|
||||
|(i, cointime, vaulted, ..)| (i, cointime.saturating_sub(vaulted)),
|
||||
exit,
|
||||
)?;
|
||||
self.transfer.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
// balanced_price = (realized_price + transfer_price) / 2
|
||||
self.balanced.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
realized_price,
|
||||
&self.transfer.cents.height,
|
||||
|(i, realized, transfer, ..)| (i, (realized + transfer) / 2u64),
|
||||
exit,
|
||||
)?;
|
||||
self.balanced.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
// terminal_price = 21M × transfer_price / circulating_supply_btc
|
||||
self.terminal.cents.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.transfer.cents.height,
|
||||
circulating_supply,
|
||||
|(i, transfer, supply_btc, ..)| {
|
||||
let supply = f64::from(supply_btc);
|
||||
if supply == 0.0 {
|
||||
(i, Cents::ZERO)
|
||||
} else {
|
||||
(i, Cents::from(f64::from(transfer) * 21_000_000.0 / supply))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
self.terminal.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
// cumulative_market_cap = Σ(market_cap) in dollars
|
||||
self.cumulative_market_cap
|
||||
.height
|
||||
.compute_cumulative(
|
||||
starting_indexes.height,
|
||||
&all_metrics.supply.total.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// delta_price = (realized_cap - average_cap) / circulating_supply
|
||||
// average_cap = cumulative_market_cap / (height + 1)
|
||||
self.delta.cents.height.compute_transform3(
|
||||
starting_indexes.height,
|
||||
realized_cap,
|
||||
&self.cumulative_market_cap.height,
|
||||
circulating_supply,
|
||||
|(i, realized_cap_cents, cum_mcap_dollars, supply_btc, ..)| {
|
||||
let supply = f64::from(supply_btc);
|
||||
if supply == 0.0 {
|
||||
return (i, Cents::ZERO);
|
||||
}
|
||||
let avg_cap_cents = f64::from(cum_mcap_dollars) * 100.0 / (i.to_usize() + 1) as f64;
|
||||
let delta = (f64::from(realized_cap_cents) - avg_cap_cents) / supply;
|
||||
(i, Cents::from(delta.max(0.0)))
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
self.delta.compute_rest(prices, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{PerBlock, PriceWithRatioExtendedPerBlock},
|
||||
internal::PriceWithRatioExtendedPerBlock,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -25,16 +25,6 @@ impl Vecs {
|
||||
active: import!("active_price"),
|
||||
true_market_mean: import!("true_market_mean"),
|
||||
cointime: import!("cointime_price"),
|
||||
transfer: import!("transfer_price"),
|
||||
balanced: import!("balanced_price"),
|
||||
terminal: import!("terminal_price"),
|
||||
delta: import!("delta_price"),
|
||||
cumulative_market_cap: PerBlock::forced_import(
|
||||
db,
|
||||
"cumulative_market_cap",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,4 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub active: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub true_market_mean: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub cointime: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub transfer: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub balanced: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub terminal: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub delta: PriceWithRatioExtendedPerBlock<M>,
|
||||
|
||||
#[traversable(hidden)]
|
||||
pub cumulative_market_cap: PerBlock<Dollars, M>,
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
internal::{
|
||||
CentsUnsignedToDollars, PerBlock, PerBlockCumulative,
|
||||
PerBlockCumulativeWithSums, FiatPerBlockCumulativeWithSums,
|
||||
LazyPerBlock, PercentPerBlock, PercentRollingWindows, Price,
|
||||
LazyPerBlock, PercentPerBlock, PercentRollingWindows,
|
||||
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
|
||||
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
|
||||
RatioPerBlockPercentiles, RatioPerBlockStdDevBands, RatioSma, RollingWindows,
|
||||
@@ -70,8 +70,6 @@ pub struct RealizedPeakRegret<M: StorageMode = Rw> {
|
||||
#[derive(Traversable)]
|
||||
pub struct RealizedInvestor<M: StorageMode = Rw> {
|
||||
pub price: PriceWithRatioExtendedPerBlock<M>,
|
||||
pub investor_lower_band: Price<PerBlock<Cents, M>>,
|
||||
pub investor_upper_band: Price<PerBlock<Cents, M>>,
|
||||
#[traversable(hidden)]
|
||||
pub cap_raw: M::Stored<BytesVec<Height, CentsSquaredSats>>,
|
||||
}
|
||||
@@ -176,8 +174,6 @@ impl RealizedFull {
|
||||
// Investor
|
||||
let investor = RealizedInvestor {
|
||||
price: cfg.import("investor_price", v0)?,
|
||||
investor_lower_band: cfg.import("investor_lower_band", v0)?,
|
||||
investor_upper_band: cfg.import("investor_upper_band", v0)?,
|
||||
cap_raw: cfg.import("investor_cap_raw", v0)?,
|
||||
};
|
||||
|
||||
@@ -486,46 +482,6 @@ impl RealizedFull {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.investor
|
||||
.investor_lower_band
|
||||
.cents
|
||||
.height
|
||||
.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.price.cents.height,
|
||||
&self.investor.price.cents.height,
|
||||
|(i, rp, ip, ..)| {
|
||||
let rp = rp.as_u128();
|
||||
let ip = ip.as_u128();
|
||||
if ip == 0 {
|
||||
(i, Cents::ZERO)
|
||||
} else {
|
||||
(i, Cents::from(rp * rp / ip))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.investor
|
||||
.investor_upper_band
|
||||
.cents
|
||||
.height
|
||||
.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.investor.price.cents.height,
|
||||
&self.core.minimal.price.cents.height,
|
||||
|(i, ip, rp, ..)| {
|
||||
let ip = ip.as_u128();
|
||||
let rp = rp.as_u128();
|
||||
if rp == 0 {
|
||||
(i, Cents::ZERO)
|
||||
} else {
|
||||
(i, Cents::from(ip * ip / rp))
|
||||
}
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Sell-side risk ratios
|
||||
for (ssrr, rv) in self
|
||||
.sell_side_risk_ratio
|
||||
|
||||
@@ -1,22 +1,8 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use brk_types::{BasisPoints32, Cents, StoredF32, StoredF64, StoredU64, Timestamp};
|
||||
use brk_types::{BasisPoints32, Cents, StoredF32, StoredF64};
|
||||
use vecdb::{BinaryTransform, UnaryTransform};
|
||||
|
||||
pub struct PerSec;
|
||||
|
||||
impl BinaryTransform<StoredU64, Timestamp, StoredF32> for PerSec {
|
||||
#[inline(always)]
|
||||
fn apply(count: StoredU64, interval: Timestamp) -> StoredF32 {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
if interval_f64 > 0.0 {
|
||||
StoredF32::from(*count as f64 / interval_f64)
|
||||
} else {
|
||||
StoredF32::NAN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DaysToYears;
|
||||
|
||||
impl UnaryTransform<StoredF32, StoredF32> for DaysToYears {
|
||||
|
||||
@@ -6,26 +6,28 @@ mod ratio;
|
||||
mod specialized;
|
||||
|
||||
pub use arithmetic::{
|
||||
BlocksToDaysF32, DifficultyToHashF64, HalveCents, HalveDollars, HalveSats,
|
||||
HalveSatsToBitcoin, Identity, MaskSats, OneMinusBp16, OneMinusF64, ReturnF32Tenths, ReturnI8,
|
||||
ReturnU16, ThsToPhsF32, VBytesToWeight, VSizeToWeight,
|
||||
BlocksToDaysF32, DifficultyToHashF64, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin,
|
||||
Identity, MaskSats, OneMinusBp16, OneMinusF64, ReturnF32Tenths, ReturnI8, ReturnU16,
|
||||
ThsToPhsF32, VBytesToWeight, VSizeToWeight,
|
||||
};
|
||||
pub use bps::{
|
||||
Bp16ToFloat, Bp16ToPercent, Bp32ToFloat, Bp32ToPercent, Bps16ToFloat, Bps16ToPercent, Bps32ToFloat,
|
||||
Bps32ToPercent,
|
||||
Bp16ToFloat, Bp16ToPercent, Bp32ToFloat, Bp32ToPercent, Bps16ToFloat, Bps16ToPercent,
|
||||
Bps32ToFloat, Bps32ToPercent,
|
||||
};
|
||||
pub use currency::{
|
||||
CentsSignedToDollars, CentsSubtractToCentsSigned, CentsTimesTenths,
|
||||
CentsUnsignedToDollars, CentsUnsignedToSats, DollarsToSatsFract, NegCentsUnsignedToDollars,
|
||||
SatsToBitcoin, SatsToCents,
|
||||
CentsSignedToDollars, CentsSubtractToCentsSigned, CentsTimesTenths, CentsUnsignedToDollars,
|
||||
CentsUnsignedToSats, DollarsToSatsFract, NegCentsUnsignedToDollars, SatsToBitcoin, SatsToCents,
|
||||
};
|
||||
pub use derived::{
|
||||
Days1, Days7, Days30, Days365, DaysToYears, PerSec, PriceTimesRatioBp32Cents, PriceTimesRatioCents,
|
||||
Days1, Days7, Days30, Days365, DaysToYears, PriceTimesRatioBp32Cents, PriceTimesRatioCents,
|
||||
RatioCents64, TimesSqrt,
|
||||
};
|
||||
pub use ratio::{
|
||||
RatioCentsBp32, RatioCentsSignedCentsBps32,
|
||||
RatioCentsSignedDollarsBps32, RatioDiffCentsBps32, RatioDiffDollarsBps32, RatioDiffF32Bps32,
|
||||
RatioDollarsBp16, RatioDollarsBp32, RatioDollarsBps32, RatioSatsBp16, RatioU64Bp16,
|
||||
RatioCentsBp32, RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDiffCentsBps32,
|
||||
RatioDiffDollarsBps32, RatioDiffF32Bps32, RatioDollarsBp16, RatioDollarsBp32,
|
||||
RatioDollarsBps32, RatioSatsBp16, RatioU64Bp16,
|
||||
};
|
||||
pub use specialized::{
|
||||
BlockCountTarget1m, BlockCountTarget1w, BlockCountTarget1y, BlockCountTarget24h,
|
||||
OhlcCentsToDollars, OhlcCentsToSats,
|
||||
};
|
||||
pub use specialized::{BlockCountTarget24h, BlockCountTarget1w, BlockCountTarget1m, BlockCountTarget1y, OhlcCentsToDollars, OhlcCentsToSats};
|
||||
|
||||
@@ -349,7 +349,6 @@ impl Computer {
|
||||
timed("Computed scripts", || {
|
||||
self.scripts.compute(
|
||||
indexer,
|
||||
&self.outputs,
|
||||
&self.prices,
|
||||
&starting_indexes,
|
||||
exit,
|
||||
|
||||
@@ -97,24 +97,17 @@ impl Vecs {
|
||||
)?;
|
||||
self.subsidy.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
self.unclaimed.compute(
|
||||
self.unclaimed.base.sats.height.compute_transform(
|
||||
starting_indexes.height,
|
||||
prices,
|
||||
exit,
|
||||
|vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.subsidy.base.sats.height,
|
||||
|(height, subsidy, ..)| {
|
||||
let halving = Halving::from(height);
|
||||
let expected = Sats::FIFTY_BTC / 2_usize.pow(halving.to_usize() as u32);
|
||||
(height, expected.checked_sub(subsidy).unwrap())
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
&self.subsidy.base.sats.height,
|
||||
|(height, subsidy, ..)| {
|
||||
let halving = Halving::from(height);
|
||||
let expected = Sats::FIFTY_BTC / 2_usize.pow(halving.to_usize() as u32);
|
||||
(height, expected.checked_sub(subsidy).unwrap())
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
self.unclaimed.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
self.fee_dominance
|
||||
.compute_binary::<Sats, Sats, RatioSatsBp16>(
|
||||
|
||||
@@ -38,12 +38,11 @@ impl Vecs {
|
||||
)?,
|
||||
subsidy: AmountPerBlockCumulative::forced_import(db, "subsidy", version, indexes)?,
|
||||
fees: AmountPerBlockFull::forced_import(db, "fees", version, indexes, cached_starts)?,
|
||||
unclaimed: AmountPerBlockCumulativeWithSums::forced_import(
|
||||
unclaimed: AmountPerBlockCumulative::forced_import(
|
||||
db,
|
||||
"unclaimed_rewards",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
fee_dominance: PercentPerBlock::forced_import(db, "fee_dominance", version, indexes)?,
|
||||
fee_dominance_rolling,
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub coinbase: AmountPerBlockCumulativeWithSums<M>,
|
||||
pub subsidy: AmountPerBlockCumulative<M>,
|
||||
pub fees: AmountPerBlockFull<M>,
|
||||
pub unclaimed: AmountPerBlockCumulativeWithSums<M>,
|
||||
pub unclaimed: AmountPerBlockCumulative<M>,
|
||||
#[traversable(wrap = "fees", rename = "dominance")]
|
||||
pub fee_dominance: PercentPerBlock<BasisPoints16, M>,
|
||||
#[traversable(wrap = "fees", rename = "dominance")]
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{BasisPoints16, Indexes, Version};
|
||||
use vecdb::{Database, Exit, Rw, StorageMode};
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{PercentPerBlock, RatioU64Bp16},
|
||||
outputs,
|
||||
};
|
||||
|
||||
use super::count::Vecs as CountVecs;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub taproot: PercentPerBlock<BasisPoints16, M>,
|
||||
pub segwit: PercentPerBlock<BasisPoints16, M>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
taproot: PercentPerBlock::forced_import(db, "taproot_adoption", version, indexes)?,
|
||||
segwit: PercentPerBlock::forced_import(db, "segwit_adoption", version, indexes)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
count: &CountVecs,
|
||||
outputs_count: &outputs::CountVecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.taproot.compute_binary::<_, _, RatioU64Bp16>(
|
||||
starting_indexes.height,
|
||||
&count.p2tr.base.height,
|
||||
&outputs_count.total.sum.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.segwit.compute_binary::<_, _, RatioU64Bp16>(
|
||||
starting_indexes.height,
|
||||
&count.segwit.base.height,
|
||||
&outputs_count.total.sum.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
||||
use brk_types::Indexes;
|
||||
use vecdb::Exit;
|
||||
|
||||
use crate::{outputs, prices};
|
||||
use crate::prices;
|
||||
|
||||
use super::Vecs;
|
||||
|
||||
@@ -11,20 +11,15 @@ impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
outputs: &outputs::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.count
|
||||
.compute(indexer, starting_indexes, exit)?;
|
||||
self.count.compute(indexer, starting_indexes, exit)?;
|
||||
|
||||
self.value
|
||||
.compute(indexer, prices, starting_indexes, exit)?;
|
||||
|
||||
self.adoption
|
||||
.compute(&self.count, &outputs.count, starting_indexes, exit)?;
|
||||
|
||||
let _lock = exit.lock();
|
||||
self.db.compact()?;
|
||||
Ok(())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Indexes, StoredU64};
|
||||
use brk_types::Indexes;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
@@ -12,105 +12,95 @@ impl Vecs {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.p2a
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2a.first_index,
|
||||
&indexer.vecs.addrs.p2a.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2a.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2a.first_index,
|
||||
&indexer.vecs.addrs.p2a.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2ms
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.p2ms.first_index,
|
||||
&indexer.vecs.scripts.p2ms.to_tx_index,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2ms.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.p2ms.first_index,
|
||||
&indexer.vecs.scripts.p2ms.to_tx_index,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2pk33
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2pk33.first_index,
|
||||
&indexer.vecs.addrs.p2pk33.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2pk33.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2pk33.first_index,
|
||||
&indexer.vecs.addrs.p2pk33.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2pk65
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2pk65.first_index,
|
||||
&indexer.vecs.addrs.p2pk65.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2pk65.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2pk65.first_index,
|
||||
&indexer.vecs.addrs.p2pk65.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2pkh
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2pkh.first_index,
|
||||
&indexer.vecs.addrs.p2pkh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2pkh.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2pkh.first_index,
|
||||
&indexer.vecs.addrs.p2pkh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2sh
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2sh.first_index,
|
||||
&indexer.vecs.addrs.p2sh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2sh.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2sh.first_index,
|
||||
&indexer.vecs.addrs.p2sh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2tr
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2tr.first_index,
|
||||
&indexer.vecs.addrs.p2tr.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2tr.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2tr.first_index,
|
||||
&indexer.vecs.addrs.p2tr.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2wpkh
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2wpkh.first_index,
|
||||
&indexer.vecs.addrs.p2wpkh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2wpkh.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2wpkh.first_index,
|
||||
&indexer.vecs.addrs.p2wpkh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.p2wsh
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2wsh.first_index,
|
||||
&indexer.vecs.addrs.p2wsh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.p2wsh.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addrs.p2wsh.first_index,
|
||||
&indexer.vecs.addrs.p2wsh.bytes,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.op_return
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.op_return.first_index,
|
||||
&indexer.vecs.scripts.op_return.to_tx_index,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
self.op_return.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.op_return.first_index,
|
||||
&indexer.vecs.scripts.op_return.to_tx_index,
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
self.unknown_output
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
@@ -132,19 +122,6 @@ impl Vecs {
|
||||
)?)
|
||||
})?;
|
||||
|
||||
// Compute segwit = p2wpkh + p2wsh + p2tr
|
||||
self.segwit
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_transform3(
|
||||
starting_indexes.height,
|
||||
&self.p2wpkh.base.height,
|
||||
&self.p2wsh.base.height,
|
||||
&self.p2tr.base.height,
|
||||
|(h, p2wpkh, p2wsh, p2tr, ..)| (h, StoredU64::from(*p2wpkh + *p2wsh + *p2tr)),
|
||||
exit,
|
||||
)?)
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ impl Vecs {
|
||||
PerBlockCumulativeWithSums::forced_import(db, "p2wpkh_count", version, indexes, cached_starts)?;
|
||||
let p2wsh =
|
||||
PerBlockCumulativeWithSums::forced_import(db, "p2wsh_count", version, indexes, cached_starts)?;
|
||||
let segwit =
|
||||
PerBlockCumulativeWithSums::forced_import(db, "segwit_count", version, indexes, cached_starts)?;
|
||||
|
||||
Ok(Self {
|
||||
p2a,
|
||||
p2ms,
|
||||
@@ -67,7 +64,6 @@ impl Vecs {
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
segwit,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,4 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub op_return: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub empty_output: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub unknown_output: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
|
||||
pub segwit: PerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
internal::db_utils::{finalize_db, open_db},
|
||||
};
|
||||
|
||||
use super::{AdoptionVecs, CountVecs, ValueVecs, Vecs};
|
||||
use super::{CountVecs, ValueVecs, Vecs};
|
||||
use crate::internal::CachedWindowStarts;
|
||||
|
||||
impl Vecs {
|
||||
@@ -23,14 +23,8 @@ impl Vecs {
|
||||
|
||||
let count = CountVecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
let value = ValueVecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
let adoption = AdoptionVecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
count,
|
||||
value,
|
||||
adoption,
|
||||
};
|
||||
let this = Self { db, count, value };
|
||||
finalize_db(&this.db, &this)?;
|
||||
Ok(this)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod adoption;
|
||||
pub mod count;
|
||||
pub mod value;
|
||||
|
||||
@@ -8,7 +7,6 @@ mod import;
|
||||
use brk_traversable::Traversable;
|
||||
use vecdb::{Database, Rw, StorageMode};
|
||||
|
||||
pub use adoption::Vecs as AdoptionVecs;
|
||||
pub use count::Vecs as CountVecs;
|
||||
pub use value::Vecs as ValueVecs;
|
||||
|
||||
@@ -21,5 +19,4 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
|
||||
pub count: CountVecs<M>,
|
||||
pub value: ValueVecs<M>,
|
||||
pub adoption: AdoptionVecs<M>,
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@ impl Vecs {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let (r1, (r2, r3)) = rayon::join(
|
||||
|| self.count.compute(indexer, &blocks.lookback, starting_indexes, exit),
|
||||
|| {
|
||||
self.count
|
||||
.compute(indexer, &blocks.lookback, starting_indexes, exit)
|
||||
},
|
||||
|| {
|
||||
rayon::join(
|
||||
|| self.versions.compute(indexer, starting_indexes, exit),
|
||||
@@ -33,13 +36,18 @@ impl Vecs {
|
||||
r2?;
|
||||
r3?;
|
||||
|
||||
self.fees
|
||||
.compute(indexer, indexes, &inputs.spent, &self.size, starting_indexes, exit)?;
|
||||
self.fees.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
&inputs.spent,
|
||||
&self.size,
|
||||
starting_indexes,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.volume.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
blocks,
|
||||
prices,
|
||||
&self.count,
|
||||
&self.fees,
|
||||
|
||||
@@ -5,14 +5,9 @@ use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::transactions::{count, fees};
|
||||
use crate::{blocks, indexes, inputs, outputs, prices};
|
||||
use crate::{indexes, inputs, outputs, prices};
|
||||
|
||||
const WINDOW_SECS: [f64; 4] = [
|
||||
86400.0,
|
||||
7.0 * 86400.0,
|
||||
30.0 * 86400.0,
|
||||
365.0 * 86400.0,
|
||||
];
|
||||
const WINDOW_SECS: [f64; 4] = [86400.0, 7.0 * 86400.0, 30.0 * 86400.0, 365.0 * 86400.0];
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -20,7 +15,6 @@ impl Vecs {
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
count_vecs: &count::Vecs,
|
||||
fees_vecs: &fees::Vecs,
|
||||
@@ -29,11 +23,8 @@ impl Vecs {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.transfer_volume.compute(
|
||||
starting_indexes.height,
|
||||
prices,
|
||||
exit,
|
||||
|sats_vec| {
|
||||
self.transfer_volume
|
||||
.compute(starting_indexes.height, prices, exit, |sats_vec| {
|
||||
Ok(sats_vec.compute_filtered_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_tx_index,
|
||||
@@ -42,8 +33,7 @@ impl Vecs {
|
||||
|sats| !sats.is_max(),
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
let h = starting_indexes.height;
|
||||
let tx_sums = count_vecs.total.rolling.sum.0.as_array();
|
||||
@@ -51,14 +41,12 @@ impl Vecs {
|
||||
let output_sums = outputs_count.total.rolling.sum.0.as_array();
|
||||
|
||||
for (i, &secs) in WINDOW_SECS.iter().enumerate() {
|
||||
self.tx_per_sec.as_mut_array()[i]
|
||||
.height
|
||||
.compute_transform(
|
||||
h,
|
||||
&tx_sums[i].height,
|
||||
|(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)),
|
||||
exit,
|
||||
)?;
|
||||
self.tx_per_sec.as_mut_array()[i].height.compute_transform(
|
||||
h,
|
||||
&tx_sums[i].height,
|
||||
|(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)),
|
||||
exit,
|
||||
)?;
|
||||
self.inputs_per_sec.as_mut_array()[i]
|
||||
.height
|
||||
.compute_transform(
|
||||
|
||||
Reference in New Issue
Block a user