mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -10,24 +10,24 @@ pub const DB_NAME: &str = "constants";
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub constant_0: ConstantVecs<StoredU16>,
|
||||
pub constant_1: ConstantVecs<StoredU16>,
|
||||
pub constant_2: ConstantVecs<StoredU16>,
|
||||
pub constant_3: ConstantVecs<StoredU16>,
|
||||
pub constant_4: ConstantVecs<StoredU16>,
|
||||
pub constant_20: ConstantVecs<StoredU16>,
|
||||
pub constant_30: ConstantVecs<StoredU16>,
|
||||
pub constant_38_2: ConstantVecs<StoredF32>,
|
||||
pub constant_50: ConstantVecs<StoredU16>,
|
||||
pub constant_61_8: ConstantVecs<StoredF32>,
|
||||
pub constant_70: ConstantVecs<StoredU16>,
|
||||
pub constant_80: ConstantVecs<StoredU16>,
|
||||
pub constant_100: ConstantVecs<StoredU16>,
|
||||
pub constant_600: ConstantVecs<StoredU16>,
|
||||
pub constant_minus_1: ConstantVecs<StoredI8>,
|
||||
pub constant_minus_2: ConstantVecs<StoredI8>,
|
||||
pub constant_minus_3: ConstantVecs<StoredI8>,
|
||||
pub constant_minus_4: ConstantVecs<StoredI8>,
|
||||
pub _0: ConstantVecs<StoredU16>,
|
||||
pub _1: ConstantVecs<StoredU16>,
|
||||
pub _2: ConstantVecs<StoredU16>,
|
||||
pub _3: ConstantVecs<StoredU16>,
|
||||
pub _4: ConstantVecs<StoredU16>,
|
||||
pub _20: ConstantVecs<StoredU16>,
|
||||
pub _30: ConstantVecs<StoredU16>,
|
||||
pub _38_2: ConstantVecs<StoredF32>,
|
||||
pub _50: ConstantVecs<StoredU16>,
|
||||
pub _61_8: ConstantVecs<StoredF32>,
|
||||
pub _70: ConstantVecs<StoredU16>,
|
||||
pub _80: ConstantVecs<StoredU16>,
|
||||
pub _100: ConstantVecs<StoredU16>,
|
||||
pub _600: ConstantVecs<StoredU16>,
|
||||
pub _minus_1: ConstantVecs<StoredI8>,
|
||||
pub _minus_2: ConstantVecs<StoredI8>,
|
||||
pub _minus_3: ConstantVecs<StoredI8>,
|
||||
pub _minus_4: ConstantVecs<StoredI8>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -35,24 +35,24 @@ impl Vecs {
|
||||
let v = version;
|
||||
|
||||
Self {
|
||||
constant_0: ConstantVecs::new::<ReturnU16<0>>("constant_0", v, indexes),
|
||||
constant_1: ConstantVecs::new::<ReturnU16<1>>("constant_1", v, indexes),
|
||||
constant_2: ConstantVecs::new::<ReturnU16<2>>("constant_2", v, indexes),
|
||||
constant_3: ConstantVecs::new::<ReturnU16<3>>("constant_3", v, indexes),
|
||||
constant_4: ConstantVecs::new::<ReturnU16<4>>("constant_4", v, indexes),
|
||||
constant_20: ConstantVecs::new::<ReturnU16<20>>("constant_20", v, indexes),
|
||||
constant_30: ConstantVecs::new::<ReturnU16<30>>("constant_30", v, indexes),
|
||||
constant_38_2: ConstantVecs::new::<ReturnF32Tenths<382>>("constant_38_2", v, indexes),
|
||||
constant_50: ConstantVecs::new::<ReturnU16<50>>("constant_50", v, indexes),
|
||||
constant_61_8: ConstantVecs::new::<ReturnF32Tenths<618>>("constant_61_8", v, indexes),
|
||||
constant_70: ConstantVecs::new::<ReturnU16<70>>("constant_70", v, indexes),
|
||||
constant_80: ConstantVecs::new::<ReturnU16<80>>("constant_80", v, indexes),
|
||||
constant_100: ConstantVecs::new::<ReturnU16<100>>("constant_100", v, indexes),
|
||||
constant_600: ConstantVecs::new::<ReturnU16<600>>("constant_600", v, indexes),
|
||||
constant_minus_1: ConstantVecs::new::<ReturnI8<-1>>("constant_minus_1", v, indexes),
|
||||
constant_minus_2: ConstantVecs::new::<ReturnI8<-2>>("constant_minus_2", v, indexes),
|
||||
constant_minus_3: ConstantVecs::new::<ReturnI8<-3>>("constant_minus_3", v, indexes),
|
||||
constant_minus_4: ConstantVecs::new::<ReturnI8<-4>>("constant_minus_4", v, indexes),
|
||||
_0: ConstantVecs::new::<ReturnU16<0>>("constant_0", v, indexes),
|
||||
_1: ConstantVecs::new::<ReturnU16<1>>("constant_1", v, indexes),
|
||||
_2: ConstantVecs::new::<ReturnU16<2>>("constant_2", v, indexes),
|
||||
_3: ConstantVecs::new::<ReturnU16<3>>("constant_3", v, indexes),
|
||||
_4: ConstantVecs::new::<ReturnU16<4>>("constant_4", v, indexes),
|
||||
_20: ConstantVecs::new::<ReturnU16<20>>("constant_20", v, indexes),
|
||||
_30: ConstantVecs::new::<ReturnU16<30>>("constant_30", v, indexes),
|
||||
_38_2: ConstantVecs::new::<ReturnF32Tenths<382>>("constant_38_2", v, indexes),
|
||||
_50: ConstantVecs::new::<ReturnU16<50>>("constant_50", v, indexes),
|
||||
_61_8: ConstantVecs::new::<ReturnF32Tenths<618>>("constant_61_8", v, indexes),
|
||||
_70: ConstantVecs::new::<ReturnU16<70>>("constant_70", v, indexes),
|
||||
_80: ConstantVecs::new::<ReturnU16<80>>("constant_80", v, indexes),
|
||||
_100: ConstantVecs::new::<ReturnU16<100>>("constant_100", v, indexes),
|
||||
_600: ConstantVecs::new::<ReturnU16<600>>("constant_600", v, indexes),
|
||||
_minus_1: ConstantVecs::new::<ReturnI8<-1>>("constant_minus_1", v, indexes),
|
||||
_minus_2: ConstantVecs::new::<ReturnI8<-2>>("constant_minus_2", v, indexes),
|
||||
_minus_3: ConstantVecs::new::<ReturnI8<-3>>("constant_minus_3", v, indexes),
|
||||
_minus_4: ConstantVecs::new::<ReturnI8<-4>>("constant_minus_4", v, indexes),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::path::Path;
|
||||
use brk_error::Result;
|
||||
use brk_types::{Age, Cents, CentsCompact, CentsSats, CentsSquaredSats, CostBasisSnapshot, Height, Sats, SupplyState};
|
||||
|
||||
use super::super::cost_basis::{Accumulate, CostBasisData, CostBasisOps, PendingDelta, RealizedOps, UnrealizedState};
|
||||
use super::super::{cost_basis::{Accumulate, CostBasisData, CostBasisOps, RealizedOps, UnrealizedState}, pending::PendingDelta};
|
||||
|
||||
pub struct SendPrecomputed {
|
||||
pub sats: Sats,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
collections::{btree_map::Entry, BTreeMap},
|
||||
collections::{BTreeMap, btree_map::Entry},
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@@ -12,34 +12,11 @@ use rustc_hash::FxHashMap;
|
||||
use vecdb::{Bytes, unlikely};
|
||||
|
||||
use super::{Accumulate, CachedUnrealizedState, UnrealizedState};
|
||||
use crate::distribution::state::pending::{PendingCapDelta, PendingDelta, PendingInvestorCapDelta};
|
||||
|
||||
/// Type alias for the price-to-sats map used in cost basis data.
|
||||
pub(super) type CostBasisMap = BTreeMap<CentsCompact, Sats>;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct PendingRaw {
|
||||
cap_inc: CentsSats,
|
||||
cap_dec: CentsSats,
|
||||
investor_cap_inc: CentsSquaredSats,
|
||||
investor_cap_dec: CentsSquaredSats,
|
||||
}
|
||||
|
||||
impl PendingRaw {
|
||||
fn is_zero(&self) -> bool {
|
||||
self.cap_inc == CentsSats::ZERO
|
||||
&& self.cap_dec == CentsSats::ZERO
|
||||
&& self.investor_cap_inc == CentsSquaredSats::ZERO
|
||||
&& self.investor_cap_dec == CentsSquaredSats::ZERO
|
||||
}
|
||||
}
|
||||
|
||||
/// Pending increments and decrements for a single price bucket.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct PendingDelta {
|
||||
pub inc: Sats,
|
||||
pub dec: Sats,
|
||||
}
|
||||
|
||||
const STATE_TO_KEEP: usize = 10;
|
||||
|
||||
/// Common interface for cost basis tracking.
|
||||
@@ -90,14 +67,14 @@ impl RawState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightweight cost basis tracking: only cap_raw and investor_cap_raw scalars.
|
||||
/// Lightweight cost basis tracking: only cap_raw scalar.
|
||||
/// No BTreeMap, no unrealized computation, no pending map.
|
||||
/// Used by cohorts that only need realized cap on restart (amount_range, address).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CostBasisRaw {
|
||||
pathbuf: PathBuf,
|
||||
state: Option<RawState>,
|
||||
pending_raw: PendingRaw,
|
||||
pending_cap: PendingCapDelta,
|
||||
}
|
||||
|
||||
impl CostBasisRaw {
|
||||
@@ -136,24 +113,24 @@ impl CostBasisRaw {
|
||||
}
|
||||
|
||||
fn apply_pending_raw(&mut self) {
|
||||
if self.pending_raw.is_zero() {
|
||||
if self.pending_cap.is_zero() {
|
||||
return;
|
||||
}
|
||||
let state = self.state.as_mut().unwrap();
|
||||
|
||||
state.cap_raw += self.pending_raw.cap_inc;
|
||||
if unlikely(state.cap_raw.inner() < self.pending_raw.cap_dec.inner()) {
|
||||
state.cap_raw += self.pending_cap.inc;
|
||||
if unlikely(state.cap_raw.inner() < self.pending_cap.dec.inner()) {
|
||||
panic!(
|
||||
"CostBasis cap_raw underflow!\n\
|
||||
Path: {:?}\n\
|
||||
Current cap_raw (after increments): {}\n\
|
||||
Trying to decrement by: {}",
|
||||
self.pathbuf, state.cap_raw, self.pending_raw.cap_dec
|
||||
self.pathbuf, state.cap_raw, self.pending_cap.dec
|
||||
);
|
||||
}
|
||||
state.cap_raw -= self.pending_raw.cap_dec;
|
||||
state.cap_raw -= self.pending_cap.dec;
|
||||
|
||||
self.pending_raw = PendingRaw::default();
|
||||
self.pending_cap = PendingCapDelta::default();
|
||||
}
|
||||
|
||||
fn write_and_cleanup(&mut self, height: Height, cleanup: bool) -> Result<()> {
|
||||
@@ -175,7 +152,7 @@ impl CostBasisOps for CostBasisRaw {
|
||||
Self {
|
||||
pathbuf: path.join(format!("{name}_cost_basis")),
|
||||
state: None,
|
||||
pending_raw: PendingRaw::default(),
|
||||
pending_cap: PendingCapDelta::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,12 +173,12 @@ impl CostBasisOps for CostBasisRaw {
|
||||
let (_, rest) = CostBasisDistribution::deserialize_with_rest(&data)?;
|
||||
RawState::deserialize(rest)?
|
||||
});
|
||||
self.pending_raw = PendingRaw::default();
|
||||
self.pending_cap = PendingCapDelta::default();
|
||||
Ok(height)
|
||||
}
|
||||
|
||||
fn cap_raw(&self) -> CentsSats {
|
||||
debug_assert!(self.pending_raw.is_zero());
|
||||
debug_assert!(self.pending_cap.is_zero());
|
||||
self.state.as_ref().unwrap().cap_raw
|
||||
}
|
||||
|
||||
@@ -217,7 +194,7 @@ impl CostBasisOps for CostBasisRaw {
|
||||
price_sats: CentsSats,
|
||||
_investor_cap: CentsSquaredSats,
|
||||
) {
|
||||
self.pending_raw.cap_inc += price_sats;
|
||||
self.pending_cap.inc += price_sats;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -228,7 +205,7 @@ impl CostBasisOps for CostBasisRaw {
|
||||
price_sats: CentsSats,
|
||||
_investor_cap: CentsSquaredSats,
|
||||
) {
|
||||
self.pending_raw.cap_dec += price_sats;
|
||||
self.pending_cap.dec += price_sats;
|
||||
}
|
||||
|
||||
fn apply_pending(&mut self) {
|
||||
@@ -237,7 +214,7 @@ impl CostBasisOps for CostBasisRaw {
|
||||
|
||||
fn init(&mut self) {
|
||||
self.state.replace(RawState::default());
|
||||
self.pending_raw = PendingRaw::default();
|
||||
self.pending_cap = PendingCapDelta::default();
|
||||
}
|
||||
|
||||
fn clean(&mut self) -> Result<()> {
|
||||
@@ -273,6 +250,8 @@ pub struct CostBasisData<S: Accumulate> {
|
||||
cache: Option<CachedUnrealizedState<S>>,
|
||||
rounding_digits: Option<i32>,
|
||||
generation: u64,
|
||||
investor_cap_raw: CentsSquaredSats,
|
||||
pending_investor_cap: PendingInvestorCapDelta,
|
||||
}
|
||||
|
||||
impl<S: Accumulate> CostBasisData<S> {
|
||||
@@ -285,7 +264,7 @@ impl<S: Accumulate> CostBasisData<S> {
|
||||
}
|
||||
|
||||
pub(crate) fn map(&self) -> &CostBasisMap {
|
||||
debug_assert!(self.pending.is_empty() && self.raw.pending_raw.is_zero());
|
||||
debug_assert!(self.pending.is_empty() && self.raw.pending_cap.is_zero());
|
||||
&self.map.as_ref().unwrap().map
|
||||
}
|
||||
|
||||
@@ -375,6 +354,8 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
cache: None,
|
||||
rounding_digits: None,
|
||||
generation: 0,
|
||||
investor_cap_raw: CentsSquaredSats::ZERO,
|
||||
pending_investor_cap: PendingInvestorCapDelta::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,8 +373,10 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
let (base, rest) = CostBasisDistribution::deserialize_with_rest(&data)?;
|
||||
self.map = Some(base);
|
||||
self.raw.state = Some(RawState::deserialize(rest)?);
|
||||
self.investor_cap_raw = CentsSquaredSats::from_bytes(&rest[16..32])?;
|
||||
self.pending.clear();
|
||||
self.raw.pending_raw = PendingRaw::default();
|
||||
self.raw.pending_cap = PendingCapDelta::default();
|
||||
self.pending_investor_cap = PendingInvestorCapDelta::default();
|
||||
self.cache = None;
|
||||
Ok(height)
|
||||
}
|
||||
@@ -403,7 +386,7 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
}
|
||||
|
||||
fn investor_cap_raw(&self) -> CentsSquaredSats {
|
||||
self.raw.investor_cap_raw()
|
||||
self.investor_cap_raw
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -416,9 +399,9 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
) {
|
||||
let price = self.round_price(price);
|
||||
self.pending.entry(price.into()).or_default().inc += sats;
|
||||
self.raw.pending_raw.cap_inc += price_sats;
|
||||
self.raw.pending_cap.inc += price_sats;
|
||||
if investor_cap != CentsSquaredSats::ZERO {
|
||||
self.raw.pending_raw.investor_cap_inc += investor_cap;
|
||||
self.pending_investor_cap.inc += investor_cap;
|
||||
}
|
||||
if let Some(cache) = self.cache.as_mut() {
|
||||
cache.on_receive(price, sats);
|
||||
@@ -435,9 +418,9 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
) {
|
||||
let price = self.round_price(price);
|
||||
self.pending.entry(price.into()).or_default().dec += sats;
|
||||
self.raw.pending_raw.cap_dec += price_sats;
|
||||
self.raw.pending_cap.dec += price_sats;
|
||||
if investor_cap != CentsSquaredSats::ZERO {
|
||||
self.raw.pending_raw.investor_cap_dec += investor_cap;
|
||||
self.pending_investor_cap.dec += investor_cap;
|
||||
}
|
||||
if let Some(cache) = self.cache.as_mut() {
|
||||
cache.on_send(price, sats);
|
||||
@@ -447,6 +430,9 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
fn apply_pending(&mut self) {
|
||||
self.apply_map_pending();
|
||||
self.raw.apply_pending_raw();
|
||||
self.investor_cap_raw += self.pending_investor_cap.inc;
|
||||
self.investor_cap_raw -= self.pending_investor_cap.dec;
|
||||
self.pending_investor_cap = PendingInvestorCapDelta::default();
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
@@ -454,6 +440,8 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
self.map.replace(CostBasisDistribution::default());
|
||||
self.pending.clear();
|
||||
self.cache = None;
|
||||
self.investor_cap_raw = CentsSquaredSats::ZERO;
|
||||
self.pending_investor_cap = PendingInvestorCapDelta::default();
|
||||
}
|
||||
|
||||
fn clean(&mut self) -> Result<()> {
|
||||
@@ -469,6 +457,7 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
let raw_state = self.raw.state.as_ref().unwrap();
|
||||
let mut buffer = self.map.as_ref().unwrap().serialize()?;
|
||||
buffer.extend(raw_state.cap_raw.to_bytes());
|
||||
buffer.extend(self.investor_cap_raw.to_bytes());
|
||||
fs::write(self.raw.path_state(height), buffer)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
mod block;
|
||||
mod cohort;
|
||||
mod cost_basis;
|
||||
mod pending;
|
||||
mod transacted;
|
||||
|
||||
pub use block::*;
|
||||
pub use cohort::*;
|
||||
pub use cost_basis::*;
|
||||
pub use pending::*;
|
||||
pub use transacted::*;
|
||||
|
||||
26
crates/brk_computer/src/distribution/state/pending.rs
Normal file
26
crates/brk_computer/src/distribution/state/pending.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use brk_types::{CentsSats, CentsSquaredSats, Sats};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct PendingCapDelta {
|
||||
pub inc: CentsSats,
|
||||
pub dec: CentsSats,
|
||||
}
|
||||
|
||||
impl PendingCapDelta {
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.inc == CentsSats::ZERO && self.dec == CentsSats::ZERO
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct PendingInvestorCapDelta {
|
||||
pub inc: CentsSquaredSats,
|
||||
pub dec: CentsSquaredSats,
|
||||
}
|
||||
|
||||
/// Pending increments and decrements for a single price bucket.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct PendingDelta {
|
||||
pub inc: Sats,
|
||||
pub dec: Sats,
|
||||
}
|
||||
@@ -240,6 +240,15 @@ impl Vecs {
|
||||
|
||||
// 1. Find minimum height we have data for across stateful vecs
|
||||
let current_height = Height::from(self.supply_state.len());
|
||||
debug!("supply_state.len={}", self.supply_state.len());
|
||||
debug!("utxo_cohorts.min={}", self.utxo_cohorts.min_separate_stateful_height_len());
|
||||
debug!("address_cohorts.min={}", self.address_cohorts.min_separate_stateful_height_len());
|
||||
debug!("address_indexes.min={}", self.any_address_indexes.min_stamped_height());
|
||||
debug!("addresses_data.min={}", self.addresses_data.min_stamped_height());
|
||||
debug!("addr_count.min={}", self.addr_count.min_stateful_height());
|
||||
debug!("empty_addr_count.min={}", self.empty_addr_count.min_stateful_height());
|
||||
debug!("address_activity.min={}", self.address_activity.min_stateful_height());
|
||||
debug!("coinblocks_destroyed.raw.height.len={}", self.coinblocks_destroyed.raw.height.len());
|
||||
let min_stateful = self.min_stateful_height_len();
|
||||
|
||||
// 2. Determine start mode and recover/reset state
|
||||
|
||||
@@ -19,8 +19,8 @@ pub const DB_NAME: &str = "positions";
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
db: Database,
|
||||
|
||||
pub block_position: M::Stored<PcoVec<Height, BlkPosition>>,
|
||||
pub tx_position: M::Stored<PcoVec<TxIndex, BlkPosition>>,
|
||||
pub block: M::Stored<PcoVec<Height, BlkPosition>>,
|
||||
pub tx: M::Stored<PcoVec<TxIndex, BlkPosition>>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -29,8 +29,8 @@ impl Vecs {
|
||||
let version = parent_version;
|
||||
|
||||
let this = Self {
|
||||
block_position: PcoVec::forced_import(&db, "position", version + Version::TWO)?,
|
||||
tx_position: PcoVec::forced_import(&db, "position", version + Version::TWO)?,
|
||||
block: PcoVec::forced_import(&db, "position", version + Version::TWO)?,
|
||||
tx: PcoVec::forced_import(&db, "position", version + Version::TWO)?,
|
||||
db,
|
||||
};
|
||||
finalize_db(&this.db, &this)?;
|
||||
@@ -62,8 +62,8 @@ impl Vecs {
|
||||
Some(c) if c == current => return Ok(()),
|
||||
Some(_) => {
|
||||
info!("XOR bytes changed, resetting positions...");
|
||||
self.block_position.reset()?;
|
||||
self.tx_position.reset()?;
|
||||
self.block.reset()?;
|
||||
self.tx.reset()?;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@@ -85,12 +85,12 @@ impl Vecs {
|
||||
// Validate computed versions against dependencies
|
||||
let dep_version = indexer.vecs.transactions.first_txindex.version()
|
||||
+ indexer.vecs.transactions.height.version();
|
||||
self.block_position
|
||||
self.block
|
||||
.validate_computed_version_or_reset(dep_version)?;
|
||||
self.tx_position
|
||||
self.tx
|
||||
.validate_computed_version_or_reset(dep_version)?;
|
||||
|
||||
let min_txindex = TxIndex::from(self.tx_position.len()).min(starting_indexes.txindex);
|
||||
let min_txindex = TxIndex::from(self.tx.len()).min(starting_indexes.txindex);
|
||||
|
||||
let Some(min_height) = indexer
|
||||
.vecs
|
||||
@@ -116,7 +116,7 @@ impl Vecs {
|
||||
.try_for_each(|block| -> Result<()> {
|
||||
let height = block.height();
|
||||
|
||||
self.block_position
|
||||
self.block
|
||||
.truncate_push(height, block.metadata().position())?;
|
||||
|
||||
let txindex = first_txindex_cursor.next().unwrap();
|
||||
@@ -124,7 +124,7 @@ impl Vecs {
|
||||
block.tx_metadata().iter().enumerate().try_for_each(
|
||||
|(index, metadata)| -> Result<()> {
|
||||
let txindex = txindex + index;
|
||||
self.tx_position
|
||||
self.tx
|
||||
.truncate_push(txindex, metadata.position())?;
|
||||
Ok(())
|
||||
},
|
||||
@@ -132,16 +132,16 @@ impl Vecs {
|
||||
|
||||
if *height % 1_000 == 0 {
|
||||
let _lock = exit.lock();
|
||||
self.block_position.flush()?;
|
||||
self.tx_position.flush()?;
|
||||
self.block.flush()?;
|
||||
self.tx.flush()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let _lock = exit.lock();
|
||||
self.block_position.flush()?;
|
||||
self.tx_position.flush()?;
|
||||
self.block.flush()?;
|
||||
self.tx.flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user