Skip to content
Open
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
89 changes: 89 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ name = "scroll-proving-sdk"
version = "0.2.0"
edition = "2024"

[[bin]]
name = "scroll-pover-db-tool"
path = "src/bin/pover_db_tool.rs"

[dependencies]
eyre = "0.6"
color-eyre = "0.6"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
Expand All @@ -27,3 +32,7 @@ dotenvy = "0.15"
rocksdb = "0.24"
strum = { version = "0.27", features = ["derive"] }
serde_repr = "0.1"

# ref: https://docs.rs/color-eyre/0.6.5/color_eyre/#improving-perf-on-debug-builds
[profile.dev.package.backtrace]
opt-level = 3
81 changes: 81 additions & 0 deletions src/bin/pover_db_tool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use clap::{Parser, Subcommand};
use eyre::WrapErr;
use scroll_proving_sdk::db::{Db, PROVING_TASK_ID_KEY_PREFIX};
use scroll_proving_sdk::utils::init_color_eyre_hook;
use std::collections::HashMap;
use std::path::PathBuf;

/// Tool to interact with the prover database.
#[derive(Parser)]
struct Cli {
/// Path to the database
#[clap(long, default_value = ".work/db")]
db: PathBuf,

#[command(subcommand)]
commands: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// List all coordinator and prover task ID pairs
List,
/// Get the corresponding task ID
Get {
#[command(subcommand)]
commands: GetCommands,
},
}

#[derive(Subcommand)]
enum GetCommands {
/// Get coordinator task ID by prover task ID
Coordinator { task_id: String },
/// Get prover task ID by coordinator task ID
Prover { task_id: String },
}

fn main() -> eyre::Result<()> {
init_color_eyre_hook();

let cli = Cli::parse();
let db = Db::new(&cli.db).context("open database")?;

let mut c2p = HashMap::new();
let mut p2c = HashMap::new();

for result in db.inner().prefix_iterator(PROVING_TASK_ID_KEY_PREFIX) {
let (proving_task_key_bytes, _) = result.context("iter entry")?;
let public_key =
std::str::from_utf8(&proving_task_key_bytes[PROVING_TASK_ID_KEY_PREFIX.len()..])?;

let Some((coordinator_task, prover_task_id)) = db.get_task(public_key) else {
continue;
};

c2p.insert(coordinator_task.task_id.clone(), prover_task_id.clone());
p2c.insert(prover_task_id, coordinator_task.task_id);
}

match cli.commands {
Commands::List => {
for (c_task_id, p_task_id) in c2p.iter() {
println!("{}\t{}", c_task_id, p_task_id);
}
}
Commands::Get { commands } => match commands {
GetCommands::Coordinator { task_id } => {
if let Some(coordinator_task_id) = p2c.get(&task_id) {
println!("{coordinator_task_id}");
}
}
GetCommands::Prover { task_id } => {
if let Some(prover_task_id) = c2p.get(&task_id) {
println!("{prover_task_id}");
}
}
},
}

Ok(())
}
Loading