From 24fe4e30f962f759c184059e760af2d38153ae17 Mon Sep 17 00:00:00 2001 From: Aaron Blankstein Date: Fri, 14 Jun 2024 12:07:43 -0500 Subject: [PATCH] test: add `index-range` option to `stacks-inspect replay-blocks` --- stackslib/src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/stackslib/src/main.rs b/stackslib/src/main.rs index 2bb78a6282..dfd153a068 100644 --- a/stackslib/src/main.rs +++ b/stackslib/src/main.rs @@ -37,6 +37,7 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use std::fs::{File, OpenOptions}; use std::io::prelude::*; use std::io::BufReader; +use std::time::Instant; use std::{env, fs, io, process, thread}; use blockstack_lib::burnchains::bitcoin::indexer::{ @@ -65,7 +66,6 @@ use blockstack_lib::chainstate::stacks::{StacksBlockHeader, *}; use blockstack_lib::clarity::vm::costs::ExecutionCost; use blockstack_lib::clarity::vm::types::StacksAddressExtensions; use blockstack_lib::clarity::vm::ClarityVersion; -use blockstack_lib::clarity_cli; use blockstack_lib::clarity_cli::vm_execute; use blockstack_lib::core::{MemPoolDB, *}; use blockstack_lib::cost_estimates::metrics::UnitMetric; @@ -76,6 +76,7 @@ use blockstack_lib::net::relay::Relayer; use blockstack_lib::net::StacksMessage; use blockstack_lib::util_lib::db::sqlite_open; use blockstack_lib::util_lib::strings::UrlString; +use blockstack_lib::{clarity_cli, util_lib}; use libstackerdb::StackerDBChunkData; use rusqlite::types::ToSql; use rusqlite::{Connection, OpenFlags}; @@ -879,6 +880,7 @@ simulating a miner. eprintln!("Usage:"); eprintln!(" {n} "); eprintln!(" {n} prefix "); + eprintln!(" {n} index-range "); eprintln!(" {n} range "); eprintln!(" {n} "); process::exit(1); @@ -886,6 +888,7 @@ simulating a miner. if argv.len() < 2 { print_help_and_exit(); } + let start = Instant::now(); let stacks_path = &argv[2]; let mode = argv.get(3).map(String::as_str); let staging_blocks_db_path = format!("{stacks_path}/mainnet/chainstate/vm/index.sqlite"); @@ -911,6 +914,14 @@ simulating a miner. let blocks = arg5.saturating_sub(arg4); format!("SELECT index_block_hash FROM staging_blocks ORDER BY height ASC LIMIT {start}, {blocks}") } + Some("index-range") => { + let start = argv[4] + .parse::() + .expect(" not a valid u64"); + let end = argv[5].parse::().expect(" not a valid u64"); + let blocks = end.saturating_sub(start); + format!("SELECT index_block_hash FROM staging_blocks ORDER BY index_block_hash ASC LIMIT {start}, {blocks}") + } Some("last") => format!( "SELECT index_block_hash FROM staging_blocks ORDER BY height DESC LIMIT {}", argv[4] @@ -936,7 +947,7 @@ simulating a miner. } replay_block(stacks_path, index_block_hash); } - println!("Finished!"); + println!("Finished. run_time_seconds = {}", start.elapsed().as_secs()); process::exit(0); }