Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
538 changes: 442 additions & 96 deletions blockzilla/get-block/resolver/src/catalog.rs

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions blockzilla/get-block/resolver/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use anyhow::{Context, Result, ensure};
use blockzilla_resolution_service::{catalog::Catalog, http, recent::RecentClient};
use clap::Parser;
use blockzilla_resolution_service::{
catalog::{Catalog, StartupVerify},
http,
recent::RecentClient,
};
use clap::{Parser, ValueEnum};
use std::{net::SocketAddr, path::PathBuf, sync::Arc};

#[derive(Clone, Copy, ValueEnum)]
enum StartupVerifyArg {
Sha256,
Metadata,
}

#[derive(Parser)]
struct Args {
#[arg(long)]
Expand All @@ -17,6 +27,9 @@ struct Args {
cache_mib: usize,
#[arg(long, default_value_t = 16)]
max_concurrent: usize,
/// Startup index verification mode (`sha256` or `metadata`).
#[arg(long, value_enum, default_value_t = StartupVerifyArg::Sha256)]
startup_verify: StartupVerifyArg,
/// Read original retained frames through the existing read-only BankSource.
#[arg(long)]
recent_config: Option<PathBuf>,
Expand All @@ -39,7 +52,15 @@ async fn main() -> Result<()> {
"result caching is disabled; --cache-mib must be 0"
);
let token = std::fs::read_to_string(&args.token_file).context("read private token file")?;
let catalog = Arc::new(Catalog::load(&args.mirror_root, &args.catalog)?);
let verify = match args.startup_verify {
StartupVerifyArg::Sha256 => StartupVerify::Sha256,
StartupVerifyArg::Metadata => StartupVerify::Metadata,
};
let catalog = Arc::new(Catalog::load_with_verification(
&args.mirror_root,
&args.catalog,
verify,
)?);
let recent = args
.recent_config
.as_deref()
Expand Down
29 changes: 28 additions & 1 deletion blockzilla/get-block/src/bin/bench_get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use blockzilla_get_block::{
worker::bench_support::{
decode_hot_block_zero_copy, plan_registry_ranges_32, plan_registry_ranges_32_s3,
render_base64_json_buffered, render_base64_json_streamed,
render_base64_json_streamed_after_collect,
},
};
use blockzilla_primitives::{CompactPubkey, wincode_leb128_config};
Expand Down Expand Up @@ -737,8 +738,27 @@ fn main() {
stream_samples_ms.push(t0.elapsed().as_secs_f64() * 1e3);
}

let (_, pre_check) = render_base64_json_streamed_after_collect(
fixture.hot_bytes.clone(),
fixture.hot_row,
clone_access(&fixture.access),
)
.unwrap();
assert_eq!(buf_sha, pre_check.sha256, "Predecoded JSON SHA-256 parity");

let mut pre_samples_ms = Vec::with_capacity(25);
for _ in 0..25 {
let hot = fixture.hot_bytes.clone();
let access = clone_access(&fixture.access);
let (render_ms, stats) =
render_base64_json_streamed_after_collect(hot, fixture.hot_row, access).unwrap();
black_box(stats);
pre_samples_ms.push(render_ms);
}

let buf_med_ms = median_us(buf_samples_ms);
let stream_med_ms = median_us(stream_samples_ms);
let pre_med_ms = median_us(pre_samples_ms);
let json_mib = buf_bytes as f64 / (1024.0 * 1024.0);
println!(
"## 3. Worker Base64 JSON Rendering ({:.2} MiB JSON output, SHA-256 verified identical)",
Expand All @@ -753,12 +773,19 @@ fn main() {
buf_peak_cap as f64 / (1024.0 * 1024.0)
);
println!(
"| Streamed `JsonByteWriter::channel(64 KiB)` | **{:.2} ms** | **{:.1} MiB/s** | {} | **{:.1} KiB** |\n",
"| Streamed `JsonByteWriter::channel(64 KiB)` | **{:.2} ms** | **{:.1} MiB/s** | {} | **{:.1} KiB** |",
stream_med_ms,
json_mib / (stream_med_ms * 1e-3),
stream_check.chunk_count,
stream_check.peak_chunk_capacity as f64 / 1024.0
);
println!(
"| Streamed + predecoded reuse (Foundation path) | **{:.2} ms** | **{:.1} MiB/s** | {} | **{:.1} KiB** |\n",
pre_med_ms,
json_mib / (pre_med_ms * 1e-3),
pre_check.chunk_count,
pre_check.peak_chunk_capacity as f64 / 1024.0
);

// 4. Foundation Native Resolver Pipeline (owned BTree collect vs zero-copy Vec collect + scratch pread + single-pass encode).
let decoded_owned_once = deserialize_archive_v2_hot_block_blob(&fixture.hot_bytes).unwrap();
Expand Down
44 changes: 41 additions & 3 deletions blockzilla/get-block/src/slot_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ fn compact_votes(votes: &mut Vec<(u32, u8)>) -> Result<(), String> {
Ok(())
}

pub(crate) type PredecodedTxList = Vec<(
ArchiveV2HotMessagePayload,
Option<blockzilla_compact::CompactMetaV1>,
)>;

#[allow(clippy::too_many_arguments)]
pub(crate) fn collect_from_parts(
header: &ArchiveV2HotBlockHeader,
Expand All @@ -231,6 +236,33 @@ pub(crate) fn collect_from_parts(
hot: &ArchiveV2HotBlockIndexRow,
message_schema: u8,
metadata_schema: u8,
) -> Result<SlotReferences, String> {
collect_from_parts_retaining(
header,
tx_count,
tx_rows_len,
tx_rows,
message_bytes,
metadata_bytes,
hot,
message_schema,
metadata_schema,
None,
)
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn collect_from_parts_retaining(
header: &ArchiveV2HotBlockHeader,
tx_count: u32,
tx_rows_len: usize,
tx_rows: impl IntoIterator<Item = ArchiveV2HotTxRow>,
message_bytes: &[u8],
metadata_bytes: &[u8],
hot: &ArchiveV2HotBlockIndexRow,
message_schema: u8,
metadata_schema: u8,
mut retained: Option<&mut PredecodedTxList>,
) -> Result<SlotReferences, String> {
if header.slot != hot.slot
|| tx_count != hot.tx_count
Expand Down Expand Up @@ -356,7 +388,7 @@ pub(crate) fn collect_from_parts(
_ => {}
}
}
if row.flags & ARCHIVE_V2_TX_FLAG_HAS_METADATA != 0 {
let decoded_meta = if row.flags & ARCHIVE_V2_TX_FLAG_HAS_METADATA != 0 {
let meta = archive_schema::decode_metadata(
metadata_schema,
region(metadata_bytes, row.metadata_offset, row.metadata_len)?,
Expand All @@ -383,15 +415,21 @@ pub(crate) fn collect_from_parts(
for reward in &meta.rewards {
push_key(reward.pubkey, &mut pubkeys)?;
}
if let Some(value) = meta.return_data {
if let Some(value) = &meta.return_data {
push_key(value.program_id, &mut pubkeys)?;
}
if let Some(logs) = meta.logs {
if let Some(logs) = &meta.logs {
logs.try_for_each_pubkey(|value| {
push_key(value, &mut pubkeys)?;
Ok::<(), String>(())
})?;
}
Some(meta)
} else {
None
};
if let Some(out) = retained.as_deref_mut() {
out.push((message, decoded_meta));
}
}
compact_sorted(&mut pubkeys, "pubkey reference family")?;
Expand Down
Loading