Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stacks-inspect: add index-range option to replay-blocks #4885

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
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