You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.5 KiB
92 lines
2.5 KiB
use anyhow::Result;
|
|
use filecoin_proofs_v1::{constants::SectorShape32GiB, verify_seal, VerifyInput};
|
|
use std::env;
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
use std::ops::Range;
|
|
use std::path::Path;
|
|
use std::process::exit;
|
|
|
|
fn main() {
|
|
let args: Vec<String> = env::args().collect();
|
|
if args.len() == 1{
|
|
println!("用法:\n./verify-tool <sector_id> // 校验单个扇区\n./verify-tool <sector_id>..<sector_id> // (检验范围内的扇区, 不包含最后一个)");
|
|
exit(0);
|
|
}
|
|
if args.len() > 2 {
|
|
println!("格式错误");
|
|
exit(0);
|
|
}
|
|
if let Ok(sector_id) = args[1].parse::<u64>() {
|
|
verify_single(sector_id);
|
|
} else {
|
|
let mut split = args[1].split("..");
|
|
if split.clone().count() != 2 {
|
|
println!("sector_id 格式错误");
|
|
exit(0);
|
|
}
|
|
let start = split.next().unwrap().parse().unwrap();
|
|
let end = split.next().unwrap().parse().unwrap();
|
|
|
|
verify_range(start..end);
|
|
}
|
|
}
|
|
|
|
fn verify_range(range: Range<u64>) {
|
|
for sector in range {
|
|
verify_single(sector);
|
|
}
|
|
}
|
|
|
|
fn verify_single(sector_id: u64) {
|
|
if let Ok(path) = env::var("VERIFY_INPUT_DIR") {
|
|
let path = Path::new(&path).join(format!("{}", sector_id));
|
|
if path.exists() {
|
|
let mut file = File::open(&path).unwrap();
|
|
let mut buf: Vec<u8> = Vec::new();
|
|
file.read(&mut buf).unwrap();
|
|
|
|
let decode: VerifyInput = bincode::deserialize(&buf).unwrap();
|
|
match verify_call(decode) {
|
|
Ok(true) => {
|
|
println!("sector: {} 校验通过", sector_id);
|
|
}
|
|
Ok(false) => {
|
|
println!("sector: {} 未通过", sector_id);
|
|
}
|
|
Err(err) => {
|
|
println!("校验失败, {}", err);
|
|
}
|
|
}
|
|
} else {
|
|
println!("sector {} verify 文件不存在", sector_id);
|
|
}
|
|
} else {
|
|
println!("请设置 VERIFY_INPUT_DIR");
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
fn verify_call(input: VerifyInput) -> Result<bool> {
|
|
let VerifyInput {
|
|
porep_config,
|
|
comm_r_in,
|
|
comm_d_in,
|
|
prover_id,
|
|
sector_id,
|
|
ticket,
|
|
seed,
|
|
proof_vec,
|
|
} = input;
|
|
|
|
verify_seal::<SectorShape32GiB>(
|
|
porep_config,
|
|
comm_r_in,
|
|
comm_d_in,
|
|
prover_id,
|
|
sector_id,
|
|
ticket,
|
|
seed,
|
|
&proof_vec,
|
|
)
|
|
}
|