diff --git a/venus-worker/src/bin/venus-worker/generator/mod.rs b/venus-worker/src/bin/venus-worker/generator/mod.rs index 05f602329..bb9e3e6f4 100644 --- a/venus-worker/src/bin/venus-worker/generator/mod.rs +++ b/venus-worker/src/bin/venus-worker/generator/mod.rs @@ -1,14 +1,18 @@ use anyhow::{anyhow, Result}; use byte_unit::Byte; use clap::{value_t, App, AppSettings, Arg, ArgMatches, SubCommand}; +use std::convert::TryFrom; +use std::path::PathBuf; use tracing::{error, info}; -use venus_worker::generate_static_tree_d; +use venus_worker::create_tree_d; + +use venus_worker::{RegisteredSealProof, SealProof}; pub const SUB_CMD_NAME: &str = "generator"; pub fn subcommand<'a, 'b>() -> App<'a, 'b> { - let pieces_cmd = SubCommand::with_name("tree-d") + let tree_d_cmd = SubCommand::with_name("tree-d") .arg( Arg::with_name("sector-size") .long("sector-size") @@ -26,7 +30,7 @@ pub fn subcommand<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name(SUB_CMD_NAME) .setting(AppSettings::ArgRequiredElseHelp) - .subcommand(pieces_cmd) + .subcommand(tree_d_cmd) } pub(crate) fn submatch<'a>(subargs: &ArgMatches<'a>) -> Result<()> { @@ -36,7 +40,11 @@ pub(crate) fn submatch<'a>(subargs: &ArgMatches<'a>) -> Result<()> { let size = Byte::from_str(size_str)?; let path = value_t!(m, "path", String)?; - match generate_static_tree_d(size.get_bytes() as u64, path) { + let proof_type = SealProof::try_from(size.get_bytes() as u64)?; + let registered_proof = RegisteredSealProof::from(proof_type); + let cache_dir = PathBuf::from(&path); + + match create_tree_d(registered_proof, None, cache_dir) { Ok(_) => info!("generate static tree-d succeed"), Err(e) => error!("generate static tree-d {}", e), } diff --git a/venus-worker/src/lib.rs b/venus-worker/src/lib.rs index ce40ee06a..b9fc39173 100644 --- a/venus-worker/src/lib.rs +++ b/venus-worker/src/lib.rs @@ -16,13 +16,14 @@ mod util; pub use config::Config; pub use infra::objstore; pub use run::{start_deamon, start_mock}; -pub use sealing::generator::generate_static_tree_d; pub use sealing::processor::{ + create_tree_d, external::sub::{run, run_c2, run_pc1, run_pc2, run_tree_d}, - Input, SnapProveReplicaUpdateInput, SnapReplicaUpdateInput, + Input, RegisteredSealProof, SnapProveReplicaUpdateInput, SnapReplicaUpdateInput, }; pub use sealing::store; pub use sealing::util as seal_util; +pub use types::SealProof; pub use util::task::block_on; pub use watchdog::dones; diff --git a/venus-worker/src/sealing/generator.rs b/venus-worker/src/sealing/generator.rs deleted file mode 100644 index ddd883b39..000000000 --- a/venus-worker/src/sealing/generator.rs +++ /dev/null @@ -1,32 +0,0 @@ -use anyhow::Result; - -use filecoin_proofs::{ - get_base_tree_leafs, get_base_tree_size, DefaultBinaryTree, DefaultPieceHasher, SectorSize, - StoreConfig, BINARY_ARITY, -}; - -use storage_proofs_core::{ - cache_key::CacheKey, - merkle::{create_base_merkle_tree, BinaryMerkleTree}, - util::default_rows_to_discard, -}; - -/// generate tree-d file for cc sector -pub fn generate_static_tree_d(sector_size: u64, path: String) -> Result<()> { - let sz = SectorSize::from(sector_size as u64); - - let tree_size = get_base_tree_size::(SectorSize::from(sz))?; - let tree_leafs = get_base_tree_leafs::(tree_size)?; - - let data = vec![0; sz.0 as usize]; - - let cfg = StoreConfig::new( - &path, - CacheKey::CommDTree.to_string(), - default_rows_to_discard(tree_leafs, BINARY_ARITY), - ); - - create_base_merkle_tree::>(Some(cfg), tree_leafs, &data)?; - - Ok(()) -} diff --git a/venus-worker/src/sealing/mod.rs b/venus-worker/src/sealing/mod.rs index 2e3945103..76a540df5 100644 --- a/venus-worker/src/sealing/mod.rs +++ b/venus-worker/src/sealing/mod.rs @@ -2,7 +2,6 @@ mod worker; -pub mod generator; pub mod processor; pub mod resource; pub mod service; diff --git a/venus-worker/src/sealing/processor/safe.rs b/venus-worker/src/sealing/processor/safe.rs index a2574d71f..d6df2239c 100644 --- a/venus-worker/src/sealing/processor/safe.rs +++ b/venus-worker/src/sealing/processor/safe.rs @@ -105,6 +105,7 @@ pub fn seal_pre_commit_phase2( } } +/// create tree-d file pub fn create_tree_d( registered_proof: RegisteredSealProof, in_path: Option,