Skip to content

Commit

Permalink
test: add index-range option to stacks-inspect replay-blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kantai committed Jun 14, 2024
1 parent 9254679 commit 24fe4e3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions stackslib/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -879,13 +880,15 @@ simulating a miner.
eprintln!("Usage:");
eprintln!(" {n} <chainstate_path>");
eprintln!(" {n} <chainstate_path> prefix <index-block-hash-prefix>");
eprintln!(" {n} <chainstate_path> index-range <start_block> <end_block>");
eprintln!(" {n} <chainstate_path> range <start_block> <end_block>");
eprintln!(" {n} <chainstate_path> <first|last> <block_count>");
process::exit(1);
};
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");
Expand All @@ -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::<u64>()
.expect("<start_block> not a valid u64");
let end = argv[5].parse::<u64>().expect("<end_block> 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]
Expand All @@ -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);
}

Expand Down

0 comments on commit 24fe4e3

Please sign in to comment.