global: snapshot

This commit is contained in:
nym21
2026-04-08 12:09:35 +02:00
parent 0a4cb0601f
commit 3a7887348c
36 changed files with 5220 additions and 1585 deletions
+45 -14
View File
@@ -252,7 +252,6 @@ impl Query {
let fa_pct90 = fad.pct90.height.collect_range_at(begin, end);
let fa_max = fad.max.height.collect_range_at(begin, end);
// Bulk read median time window
let median_start = begin.saturating_sub(10);
let median_timestamps = indexer
@@ -272,20 +271,47 @@ impl Query {
// Single reader for header + coinbase (adjacent in blk file)
let varint_len = Self::compact_size_len(tx_count) as usize;
let (raw_header, coinbase_raw, coinbase_address, coinbase_addresses, coinbase_signature, coinbase_signature_ascii, scriptsig_bytes) = match reader.reader_at(positions[i]) {
let (
raw_header,
coinbase_raw,
coinbase_address,
coinbase_addresses,
coinbase_signature,
coinbase_signature_ascii,
scriptsig_bytes,
) = match reader.reader_at(positions[i]) {
Ok(mut blk) => {
let mut header_buf = [0u8; HEADER_SIZE];
if blk.read_exact(&mut header_buf).is_err() {
([0u8; HEADER_SIZE], String::new(), None, vec![], String::new(), String::new(), vec![])
(
[0u8; HEADER_SIZE],
String::new(),
None,
vec![],
String::new(),
String::new(),
vec![],
)
} else {
// Skip tx count varint
let mut skip = [0u8; 5];
let _ = blk.read_exact(&mut skip[..varint_len]);
let coinbase = Self::parse_coinbase_from_read(blk);
(header_buf, coinbase.0, coinbase.1, coinbase.2, coinbase.3, coinbase.4, coinbase.5)
(
header_buf, coinbase.0, coinbase.1, coinbase.2, coinbase.3, coinbase.4,
coinbase.5,
)
}
}
Err(_) => ([0u8; HEADER_SIZE], String::new(), None, vec![], String::new(), String::new(), vec![]),
Err(_) => (
[0u8; HEADER_SIZE],
String::new(),
None,
vec![],
String::new(),
String::new(),
vec![],
),
};
let header = Self::decode_header(&raw_header)?;
@@ -517,12 +543,20 @@ impl Query {
fn parse_coinbase_from_read(
reader: impl Read,
) -> (String, Option<String>, Vec<String>, String, String, Vec<u8>) {
let empty = (String::new(), None, vec![], String::new(), String::new(), vec![]);
let empty = (
String::new(),
None,
vec![],
String::new(),
String::new(),
vec![],
);
let tx = match bitcoin::Transaction::consensus_decode(&mut bitcoin::io::FromStd::new(reader)) {
Ok(tx) => tx,
Err(_) => return empty,
};
let tx =
match bitcoin::Transaction::consensus_decode(&mut bitcoin::io::FromStd::new(reader)) {
Ok(tx) => tx,
Err(_) => return empty,
};
let scriptsig_bytes: Vec<u8> = tx
.input
@@ -532,10 +566,7 @@ impl Query {
let coinbase_raw = scriptsig_bytes.to_lower_hex_string();
let coinbase_signature_ascii: String = scriptsig_bytes
.iter()
.map(|&b| b as char)
.collect();
let coinbase_signature_ascii: String = scriptsig_bytes.iter().map(|&b| b as char).collect();
let mut coinbase_addresses: Vec<String> = tx
.output
@@ -9,7 +9,12 @@ impl Query {
pub fn block_fee_rates(&self, time_period: TimePeriod) -> Result<Vec<BlockFeeRatesEntry>> {
let bw = BlockWindow::new(self, time_period);
let computer = self.computer();
let frd = &computer.transactions.fees.effective_fee_rate.distribution.block;
let frd = &computer
.transactions
.fees
.effective_fee_rate
.distribution
.block;
let min = frd.min.height.collect_range_at(bw.start, bw.end);
let pct10 = frd.pct10.height.collect_range_at(bw.start, bw.end);
+1 -4
View File
@@ -62,10 +62,7 @@ impl Query {
let mut hashrates = Vec::with_capacity(total_days / step + 1);
let mut di = start_day1.to_usize();
while di <= end_day1.to_usize() {
if let (Some(Some(hr)), Some(timestamp)) = (
hr_cursor.get(di),
ts_cursor.get(di),
) {
if let (Some(Some(hr)), Some(timestamp)) = (hr_cursor.get(di), ts_cursor.get(di)) {
hashrates.push(HashrateEntry {
timestamp,
avg_hashrate: *hr as u128,
+17 -5
View File
@@ -53,8 +53,18 @@ impl Query {
};
// Get block info for status
let height = indexer.vecs.transactions.height.collect_one(tx_index).unwrap();
let block_hash = indexer.vecs.blocks.blockhash.reader().get(height.to_usize());
let height = indexer
.vecs
.transactions
.height
.collect_one(tx_index)
.unwrap();
let block_hash = indexer
.vecs
.blocks
.blockhash
.reader()
.get(height.to_usize());
let block_time = indexer.vecs.blocks.timestamp.collect_one(height).unwrap();
Ok(TxStatus {
@@ -110,7 +120,10 @@ impl Query {
}
pub fn outspend(&self, txid: &Txid, vout: Vout) -> Result<TxOutspend> {
if self.mempool().is_some_and(|m| m.get_txs().contains_key(txid)) {
if self
.mempool()
.is_some_and(|m| m.get_txs().contains_key(txid))
{
return Ok(TxOutspend::UNSPENT);
}
let (_, first_txout, output_count) = self.resolve_tx_outputs(txid)?;
@@ -150,8 +163,7 @@ impl Query {
}
let spending_tx_index = input_tx_cursor.get(usize::from(txin_index)).unwrap();
let spending_first_txin =
first_txin_cursor.get(spending_tx_index.to_usize()).unwrap();
let spending_first_txin = first_txin_cursor.get(spending_tx_index.to_usize()).unwrap();
let vin = Vin::from(usize::from(txin_index) - usize::from(spending_first_txin));
let spending_txid = txid_reader.get(spending_tx_index.to_usize());
let spending_height = height_cursor.get(spending_tx_index.to_usize()).unwrap();