mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
computer: simplified a bunch of things
This commit is contained in:
@@ -3,15 +3,17 @@ use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, blocks, indexes, transactions};
|
||||
use crate::{ComputeIndexes, blocks, indexes, prices, transactions};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
blocks: &blocks::Vecs,
|
||||
transactions: &transactions::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
@@ -21,6 +23,7 @@ impl Vecs {
|
||||
indexes,
|
||||
&blocks.count,
|
||||
&transactions.fees,
|
||||
prices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -5,7 +5,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Version;
|
||||
use vecdb::{Database, PAGE_SIZE};
|
||||
|
||||
use crate::{indexes, prices};
|
||||
use crate::indexes;
|
||||
|
||||
use super::{HashrateVecs, RewardsVecs, Vecs};
|
||||
|
||||
@@ -14,14 +14,13 @@ impl Vecs {
|
||||
parent_path: &Path,
|
||||
parent_version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let db = Database::open(&parent_path.join(super::DB_NAME))?;
|
||||
db.set_min_len(PAGE_SIZE * 50_000_000)?;
|
||||
|
||||
let version = parent_version;
|
||||
|
||||
let rewards = RewardsVecs::forced_import(&db, version, indexes, prices)?;
|
||||
let rewards = RewardsVecs::forced_import(&db, version, indexes)?;
|
||||
let hashrate = HashrateVecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
|
||||
@@ -4,19 +4,23 @@ use brk_types::{CheckedSub, HalvingEpoch, Sats, StoredF32};
|
||||
use vecdb::{Exit, ReadableVec, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, blocks, indexes, transactions};
|
||||
use crate::{ComputeIndexes, blocks, indexes, prices, transactions};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
count_vecs: &blocks::CountVecs,
|
||||
transactions_fees: &transactions::FeesVecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.coinbase.compute(starting_indexes, exit, |vec| {
|
||||
let window_starts = count_vecs.window_starts();
|
||||
|
||||
self.coinbase.compute(starting_indexes.height, &window_starts, prices, exit, |vec| {
|
||||
// Cursors avoid per-height PcoVec page decompression for the
|
||||
// tx-indexed lookups. Coinbase txindex values are strictly
|
||||
// increasing, so the cursors only advance forward.
|
||||
@@ -48,7 +52,6 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let window_starts = count_vecs.window_starts();
|
||||
self.coinbase_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
@@ -57,7 +60,7 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let fee_sats_source = transactions_fees.fee.sum_cum.sum.inner();
|
||||
let fee_sats_source = transactions_fees.fee.sum_cumulative.sum.inner();
|
||||
let fee_usd_source = &transactions_fees.fee_usd_sum;
|
||||
self.fee_sum.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
@@ -67,11 +70,11 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.subsidy.compute(starting_indexes, exit, |vec| {
|
||||
self.subsidy.compute(starting_indexes.height, &window_starts, prices, exit, |vec| {
|
||||
vec.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.coinbase.sats.height,
|
||||
transactions_fees.fee.sum_cum.sum.inner(),
|
||||
transactions_fees.fee.sum_cumulative.sum.inner(),
|
||||
|(height, coinbase, fees, ..)| {
|
||||
(
|
||||
height,
|
||||
@@ -87,7 +90,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.unclaimed_rewards
|
||||
.compute(starting_indexes, exit, |vec| {
|
||||
.compute(starting_indexes.height, &window_starts, prices, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.subsidy.sats.height,
|
||||
@@ -104,8 +107,8 @@ impl Vecs {
|
||||
// All-time cumulative fee dominance
|
||||
self.fee_dominance.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
transactions_fees.fee.sum_cum.cumulative.inner(),
|
||||
self.coinbase.sats.rest.height_cumulative.inner(),
|
||||
transactions_fees.fee.sum_cumulative.cumulative.inner(),
|
||||
&self.coinbase.sats.cumulative.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -138,8 +141,8 @@ impl Vecs {
|
||||
// All-time cumulative subsidy dominance
|
||||
self.subsidy_dominance.height.compute_percentage(
|
||||
starting_indexes.height,
|
||||
self.subsidy.sats.rest.height_cumulative.inner(),
|
||||
self.coinbase.sats.rest.height_cumulative.inner(),
|
||||
&self.subsidy.sats.cumulative.height,
|
||||
&self.coinbase.sats.cumulative.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightFull, ValueFromHeightSumCum},
|
||||
prices,
|
||||
internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightFull, ValueFromHeightSumCumulative},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -14,19 +13,17 @@ impl Vecs {
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
coinbase_sum: StoredValueRollingWindows::forced_import(db, "coinbase_sum", version, indexes)?,
|
||||
fee_sum: StoredValueRollingWindows::forced_import(db, "fee_sum", version, indexes)?,
|
||||
coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes, prices)?,
|
||||
subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes, prices)?,
|
||||
unclaimed_rewards: ValueFromHeightSumCum::forced_import(
|
||||
coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes)?,
|
||||
subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes)?,
|
||||
unclaimed_rewards: ValueFromHeightSumCumulative::forced_import(
|
||||
db,
|
||||
"unclaimed_rewards",
|
||||
version,
|
||||
indexes,
|
||||
prices,
|
||||
)?,
|
||||
fee_dominance: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Dollars, StoredF32};
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightFull, ValueFromHeightSumCum};
|
||||
use crate::internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightFull, ValueFromHeightSumCumulative};
|
||||
|
||||
/// Coinbase/subsidy/rewards metrics
|
||||
#[derive(Traversable)]
|
||||
@@ -11,7 +11,7 @@ pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub fee_sum: StoredValueRollingWindows<M>,
|
||||
pub coinbase: ValueFromHeightFull<M>,
|
||||
pub subsidy: ValueFromHeightFull<M>,
|
||||
pub unclaimed_rewards: ValueFromHeightSumCum<M>,
|
||||
pub unclaimed_rewards: ValueFromHeightSumCumulative<M>,
|
||||
pub fee_dominance: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub fee_dominance_24h: ComputedFromHeightLast<StoredF32, M>,
|
||||
pub fee_dominance_7d: ComputedFromHeightLast<StoredF32, M>,
|
||||
|
||||
Reference in New Issue
Block a user