liusen
3 years ago
commit
b498fa5cb8
5 changed files with 1798 additions and 0 deletions
-
1.gitignore
-
1678Cargo.lock
-
18Cargo.toml
-
9README.md
-
92src/main.rs
@ -0,0 +1 @@ |
|||
/target |
1678
Cargo.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,18 @@ |
|||
[package] |
|||
name = "verify-tool" |
|||
version = "0.1.0" |
|||
edition = "2021" |
|||
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
|||
|
|||
[dependencies] |
|||
serde = { version = "1.0", features = ["rc", "derive"] } |
|||
bincode = "1.1.2" |
|||
anyhow = "1.0.55" |
|||
|
|||
[dependencies.filecoin-proofs-v1] |
|||
git = "http://193.200.130.186:3000/IPFSNETS/rust-fil-proofs" |
|||
branch = "sen_dev" |
|||
package = "filecoin-proofs" |
|||
# version = "~11.0" |
|||
default-features = false |
@ -0,0 +1,9 @@ |
|||
- 运行 worker 时设置环境变量保存扇区的校验参数,校验程序会从这个路径中读取检验参数 |
|||
``` |
|||
export VERIFY_INPUT_DIR="保存校验参数的文件夹" |
|||
``` |
|||
- 程序有两种用法 |
|||
``` |
|||
./verify-tool <sector_id> // 校验单个扇区 |
|||
./verify-tool <sector_id>..<sector_id> // (检验范围内的扇区, 不包含最后一个) |
|||
``` |
@ -0,0 +1,92 @@ |
|||
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,
|
|||
)
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue