Skip to content

Conversation

@brice-stacks
Copy link
Contributor

Improves the UX by merging validate-naka-block and validate-block, improves the lookup time by optimizing the queries, and improves the output for a better experience. Adds --early-exit flag to exit on first error instead of completing all blocks.

Improves the UX by merging `validate-naka-block` and `validate-block,`
improves the lookup time by optimizing the queries, and improves the
output for a better experience. Adds `--early-exit` flag to exit on
first error instead of completing all blocks.
@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 1.88679% with 208 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.72%. Comparing base (7ff75a2) to head (aa76fe4).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
contrib/stacks-inspect/src/lib.rs 0.00% 207 Missing ⚠️
stackslib/src/chainstate/stacks/db/blocks.rs 80.00% 1 Missing ⚠️

❌ Your project check has failed because the head coverage (40.72%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (7ff75a2) and HEAD (aa76fe4). Click for more details.

HEAD has 88 uploads less than BASE
Flag BASE (7ff75a2) HEAD (aa76fe4)
127 39
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #6735       +/-   ##
============================================
- Coverage    70.05%   40.72%   -29.33%     
============================================
  Files          578      578               
  Lines       358373   358445       +72     
============================================
- Hits        251064   145985   -105079     
- Misses      107309   212460   +105151     
Files with missing lines Coverage Δ
contrib/stacks-inspect/src/main.rs 0.00% <ø> (ø)
stackslib/src/chainstate/stacks/db/blocks.rs 42.56% <80.00%> (-30.00%) ⬇️
contrib/stacks-inspect/src/lib.rs 0.00% <0.00%> (-19.88%) ⬇️

... and 470 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ff75a2...aa76fe4. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +227 to +231
fn collect_block_entries_for_selection(
db_path: &str,
selection: &BlockSelection,
chainstate: &StacksChainState,
) -> Vec<BlockScanEntry> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sanity check: isn't this method currently returning 2n blocks when called with BlockSelection::Last and BlockSelection::First? seems like it will get the first N and last N blocks from both tables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I decided to just remove first, since that doesn't really seem like a useful scenario any way, and then fixed last.

panic!("Failed to open staging blocks DB at {staging_blocks_db_path}: {e}");
});
let sql = format!(
"SELECT index_block_hash, consensus_hash, anchored_block_hash, height FROM staging_blocks {clause}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since we are only consuming index_block_hash, maybe we can simplity the query as SELECT index_block_hash FROM staging_blocks {clause}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had that there originally because I needed other fields when I was also reusing the new structure in other places, but then ended up deleting that code. I'll delete these now.

for (i, index_block_hash) in index_block_hashes.iter().enumerate() {
if i % 100 == 0 {
println!("Checked {i}...");
let sql = format!("SELECT index_block_hash, height FROM nakamoto_staging_blocks {clause}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since we are only consuming index_block_hash, maybe we can simplity the query as SELECT index_block_hash FROM nakamoto_staging_blocks {clause}

Comment on lines 232 to 233
let mut seen = HashSet::new();
let mut entries = Vec::new();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suuuuper nit: These two variables hold over 5 million index_block_hash values each when the function is called with BlockSelection::All, stored as 64 bytes hex strings. ~320 MB for each variable (plus additional overhead from the data structures). It's not a concern right now, but we could reduce memory usage by about half if we move the

let index_block_hash = StacksBlockId::from_hex(&index_block_hash_hex).unwrap();

processing inside this function and avoid keeping the hex strings around.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as always, feel free to skip the changes for the nits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point. Also, a good reason to just remove the seen tracking altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Remove the `seen` tracking since it doesn't really gain us much and uses
a lot of space when processing many blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants