From 610fbd43004fdab0c65dcc5f2d6f35f91cf67201 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Thu, 20 Apr 2023 15:37:17 +0200 Subject: [PATCH] refactor: less mutability, clearer code Make the config configurations more obvious. --- filecoin-proofs/src/api/update.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/filecoin-proofs/src/api/update.rs b/filecoin-proofs/src/api/update.rs index ca3a5d515..f75cff8ec 100644 --- a/filecoin-proofs/src/api/update.rs +++ b/filecoin-proofs/src/api/update.rs @@ -104,32 +104,29 @@ fn persist_t_aux>( // // Returns a pair of the new tree_d_config and tree_r_last configs fn get_new_configs_from_t_aux_old>( - t_aux_old: &TemporaryAux, + t_aux: &TemporaryAux, new_cache_path: &Path, nodes_count: usize, ) -> Result<(StoreConfig, StoreConfig)> { - let mut t_aux_new = t_aux_old.clone(); - t_aux_new.set_cache_path(new_cache_path); - let tree_count = get_base_tree_count::(); let base_tree_nodes_count = nodes_count / tree_count; - // With the new cache path set, formulate the new tree_d and - // tree_r_last configs. - let tree_d_new_config = StoreConfig::from_config( - &t_aux_new.tree_d_config, - CacheKey::CommDTree.to_string(), - Some(get_merkle_tree_len(nodes_count, TreeDArity::to_usize())?), - ); + let tree_d_new_config = StoreConfig { + path: new_cache_path.into(), + id: t_aux.tree_d_config.id.clone(), + size: Some(get_merkle_tree_len(nodes_count, TreeDArity::to_usize())?), + rows_to_discard: t_aux.tree_d_config.rows_to_discard, + }; - let tree_r_last_new_config = StoreConfig::from_config( - &t_aux_new.tree_r_last_config, - CacheKey::CommRLastTree.to_string(), - Some(get_merkle_tree_len( + let tree_r_last_new_config = StoreConfig { + path: new_cache_path.into(), + id: t_aux.tree_r_last_config.id.clone(), + size: Some(get_merkle_tree_len( base_tree_nodes_count, Tree::Arity::to_usize(), )?), - ); + rows_to_discard: t_aux.tree_r_last_config.rows_to_discard, + }; Ok((tree_d_new_config, tree_r_last_new_config)) }