mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-20 06:44:47 -07:00
global + blk
This commit is contained in:
@@ -138,7 +138,7 @@ impl Lengths {
|
||||
}
|
||||
|
||||
/// Read current local lengths. `None` pre-genesis.
|
||||
pub fn from_local(vecs: &mut Vecs, stores: &Stores) -> Option<Self> {
|
||||
pub fn from_local(vecs: &Vecs, stores: &Stores) -> Option<Self> {
|
||||
let height = vecs.next_height().min(stores.next_height());
|
||||
Self::collect_at(height, vecs)
|
||||
}
|
||||
@@ -146,7 +146,7 @@ impl Lengths {
|
||||
/// Read lengths to resume at `required_height`. Reorg-aware:
|
||||
/// - if local is ahead, clamp down to `required_height`;
|
||||
/// - if local is behind, return `None` (caller must full-reset).
|
||||
pub fn resume_at(required_height: Height, vecs: &mut Vecs, stores: &Stores) -> Option<Self> {
|
||||
pub fn resume_at(required_height: Height, vecs: &Vecs, stores: &Stores) -> Option<Self> {
|
||||
let local = vecs.next_height().min(stores.next_height());
|
||||
if local < required_height {
|
||||
return None;
|
||||
@@ -163,7 +163,7 @@ impl Lengths {
|
||||
Self::collect_at(height, vecs)
|
||||
}
|
||||
|
||||
fn collect_at(height: Height, vecs: &mut Vecs) -> Option<Self> {
|
||||
fn collect_at(height: Height, vecs: &Vecs) -> Option<Self> {
|
||||
Some(Self {
|
||||
empty_output_index: next_index(
|
||||
&vecs.scripts.empty.first_index,
|
||||
|
||||
@@ -85,12 +85,17 @@ impl Indexer {
|
||||
|
||||
let tip_blockhash = vecs.blocks.blockhash.collect_last().unwrap_or_default();
|
||||
|
||||
let safe_lengths = SafeLengths::new();
|
||||
if let Some(lengths) = Lengths::from_local(&vecs, &stores) {
|
||||
safe_lengths.advance(lengths);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
path: indexed_path.clone(),
|
||||
vecs,
|
||||
stores,
|
||||
tip_blockhash: Arc::new(RwLock::new(tip_blockhash)),
|
||||
safe_lengths: SafeLengths::new(),
|
||||
safe_lengths,
|
||||
})
|
||||
};
|
||||
|
||||
@@ -157,7 +162,7 @@ impl Indexer {
|
||||
|
||||
let (starting_lengths, prev_hash) = if let Some(hash) = last_blockhash {
|
||||
let (height, hash) = client.get_closest_valid_height(hash)?;
|
||||
match Lengths::resume_at(height.incremented(), &mut self.vecs, &self.stores) {
|
||||
match Lengths::resume_at(height.incremented(), &self.vecs, &self.stores) {
|
||||
Some(starting_lengths) => {
|
||||
if starting_lengths.height > client.get_last_height()? {
|
||||
info!("Up to date, nothing to index.");
|
||||
@@ -368,7 +373,7 @@ impl Indexer {
|
||||
/// bg ingest first so stores are queryable at the new bound.
|
||||
pub fn advance_safe_lengths(&mut self) -> Result<()> {
|
||||
self.vecs.db.sync_bg_tasks()?;
|
||||
if let Some(lengths) = Lengths::from_local(&mut self.vecs, &self.stores) {
|
||||
if let Some(lengths) = Lengths::from_local(&self.vecs, &self.stores) {
|
||||
self.safe_lengths.advance(lengths);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -199,6 +199,28 @@ impl AddrsVecs {
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub fn iter_any(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
[
|
||||
&self.p2pk65.first_index as &dyn AnyStoredVec,
|
||||
&self.p2pk33.first_index,
|
||||
&self.p2pkh.first_index,
|
||||
&self.p2sh.first_index,
|
||||
&self.p2wpkh.first_index,
|
||||
&self.p2wsh.first_index,
|
||||
&self.p2tr.first_index,
|
||||
&self.p2a.first_index,
|
||||
&self.p2pk65.bytes,
|
||||
&self.p2pk33.bytes,
|
||||
&self.p2pkh.bytes,
|
||||
&self.p2sh.bytes,
|
||||
&self.p2wpkh.bytes,
|
||||
&self.p2wsh.bytes,
|
||||
&self.p2tr.bytes,
|
||||
&self.p2a.bytes,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
/// Get address bytes by output type, using the cached VecReader for the specific address type.
|
||||
/// Returns None if the index doesn't exist yet.
|
||||
pub fn get_bytes_by_type(
|
||||
|
||||
@@ -109,4 +109,20 @@ impl BlocksVecs {
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub fn iter_any(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
[
|
||||
&self.blockhash.inner as &dyn AnyStoredVec,
|
||||
&self.coinbase_tag,
|
||||
&self.difficulty,
|
||||
&self.timestamp.inner,
|
||||
&self.total,
|
||||
&self.weight,
|
||||
&self.position,
|
||||
&self.segwit_txs,
|
||||
&self.segwit_size,
|
||||
&self.segwit_weight,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,15 @@ impl InputsVecs {
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub fn iter_any(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
[
|
||||
&self.first_txin_index as &dyn AnyStoredVec,
|
||||
&self.outpoint,
|
||||
&self.tx_index,
|
||||
&self.output_type,
|
||||
&self.type_index,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ impl Vecs {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn next_height(&mut self) -> Height {
|
||||
self.par_iter_mut_any_stored_vec()
|
||||
pub fn next_height(&self) -> Height {
|
||||
self.iter_any_stored_vec()
|
||||
.map(|vec| {
|
||||
let h = Height::from(vec.stamp());
|
||||
if h > Height::ZERO { h.incremented() } else { h }
|
||||
@@ -172,4 +172,14 @@ impl Vecs {
|
||||
.chain(self.addrs.par_iter_mut_any())
|
||||
.chain(self.scripts.par_iter_mut_any())
|
||||
}
|
||||
|
||||
fn iter_any_stored_vec(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
self.blocks
|
||||
.iter_any()
|
||||
.chain(self.transactions.iter_any())
|
||||
.chain(self.inputs.iter_any())
|
||||
.chain(self.outputs.iter_any())
|
||||
.chain(self.addrs.iter_any())
|
||||
.chain(self.scripts.iter_any())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,4 +64,15 @@ impl OutputsVecs {
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub fn iter_any(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
[
|
||||
&self.first_txout_index as &dyn AnyStoredVec,
|
||||
&self.value,
|
||||
&self.output_type,
|
||||
&self.type_index,
|
||||
&self.tx_index,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,18 @@ impl ScriptsVecs {
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub fn iter_any(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
[
|
||||
&self.empty.first_index as &dyn AnyStoredVec,
|
||||
&self.op_return.first_index,
|
||||
&self.p2ms.first_index,
|
||||
&self.unknown.first_index,
|
||||
&self.empty.to_tx_index,
|
||||
&self.op_return.to_tx_index,
|
||||
&self.p2ms.to_tx_index,
|
||||
&self.unknown.to_tx_index,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,4 +142,21 @@ impl TransactionsVecs {
|
||||
]
|
||||
.into_par_iter()
|
||||
}
|
||||
|
||||
pub fn iter_any(&self) -> impl Iterator<Item = &dyn AnyStoredVec> {
|
||||
[
|
||||
&self.first_tx_index as &dyn AnyStoredVec,
|
||||
&self.txid,
|
||||
&self.tx_version,
|
||||
&self.raw_locktime,
|
||||
&self.base_size,
|
||||
&self.total_size,
|
||||
&self.total_sigop_cost,
|
||||
&self.is_explicitly_rbf,
|
||||
&self.first_txin_index,
|
||||
&self.first_txout_index,
|
||||
&self.position,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user