Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.0.3 #4243

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev
starcoin-decrypt = { path = "commons/decrypt" }
starcoin-dev = { path = "vm/dev" }
starcoin-executor = { path = "executor" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "94bcd77e80232b169cf95754ef4e87775645afcd" }
starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "a2546b32ad26d048e97d729e45153e0cba26ba18" }
starcoin-genesis = { path = "genesis" }
starcoin-logger = { path = "commons/logger" }
starcoin-metrics = { path = "commons/metrics" }
Expand Down
1 change: 1 addition & 0 deletions chain/api/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub trait ChainReader {
) -> Result<GhostdagData>;
fn is_dag_ancestor_of(&self, ancestor: HashValue, descendants: Vec<HashValue>) -> Result<bool>;
fn get_pruning_height(&self) -> BlockNumber;
fn get_pruning_config(&self) -> (u64, u64);
}

pub trait ChainWriter {
Expand Down
17 changes: 7 additions & 10 deletions chain/mock/src/mock_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ impl MockChain {
pub fn new_with_params(
net: ChainNetwork,
k: KType,
pruning_depth: u64,
pruning_finality: u64,
) -> Result<Self> {
let (storage, chain_info, _, dag) =
Genesis::init_storage_for_test_with_param(&net, k, pruning_depth, pruning_finality)?;

let (storage, chain_info, _, dag) = Genesis::init_storage_for_test_with_param(&net, k)?;
let chain = BlockChain::new(
net.time_service(),
chain_info.head().id(),
Expand Down Expand Up @@ -263,15 +259,16 @@ impl MockChain {
.dag()
.ghostdata_by_hash(previous_pruning)?
.ok_or_else(|| format_err!("Cannot find ghostdata by hash: {:?}", previous_pruning))?;

let MineNewDagBlockInfo {
tips: pruned_tips,
blue_blocks,
pruning_point,
} = self
.head
.dag()
.calc_mergeset_and_tips(previous_pruning, prevous_ghostdata.as_ref())?;
} = self.head.dag().calc_mergeset_and_tips(
previous_pruning,
prevous_ghostdata.as_ref(),
4,3
)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve code readability and fix typo.

The addition of new parameters to calc_mergeset_and_tips enhances the pruning logic. However, there are a couple of issues to address:

  1. The use of magic numbers (4 and 3) reduces code readability and maintainability. Consider defining these as named constants with clear descriptions of their purpose.

  2. There's a typo in the variable name prevous_ghostdata (should be previous_ghostdata).

Here's a suggested improvement:

+ const PRUNING_INTERVAL: u64 = 4;
+ const PRUNING_DEPTH: u64 = 3;

- prevous_ghostdata
+ previous_ghostdata

- self.head.dag().calc_mergeset_and_tips(
-     previous_pruning,
-     prevous_ghostdata.as_ref(),
-     4,3
- )?;
+ self.head.dag().calc_mergeset_and_tips(
+     previous_pruning,
+     previous_ghostdata.as_ref(),
+     PRUNING_INTERVAL,
+     PRUNING_DEPTH
+ )?;

Also, consider adding comments explaining the significance of PRUNING_INTERVAL and PRUNING_DEPTH.

Committable suggestion was skipped due to low confidence.


debug!(
"tips: {:?}, blue_blocks: {:?}, pruning_point: {:?}",
Expand Down
17 changes: 16 additions & 1 deletion chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use starcoin_types::{
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::account_config::genesis_address;
use starcoin_vm_types::genesis_config::{ChainId, ConsensusStrategy};
use starcoin_vm_types::on_chain_config::FlexiDagConfigV2;
use starcoin_vm_types::on_chain_resource::Epoch;
use std::cmp::min;
use std::iter::Extend;
Expand Down Expand Up @@ -1389,7 +1390,7 @@ impl ChainReader for BlockChain {
.get_block_header_by_hash(header.parent_hash())?
.ok_or_else(|| format_err!("cannot find parent block header"))?;
let next_ghostdata = self.dag().verify_and_ghostdata(uncles, header)?;

let (pruning_depth, pruning_finality) = self.get_pruning_config();
if self.status().head().pruning_point() != HashValue::zero() {
let previous_ghostdata = if previous_header.pruning_point() == HashValue::zero() {
let genesis = self
Expand All @@ -1409,6 +1410,8 @@ impl ChainReader for BlockChain {
previous_ghostdata.as_ref(),
header.pruning_point(),
&next_ghostdata,
pruning_depth,
pruning_finality,
)?;
}

Expand All @@ -1422,6 +1425,18 @@ impl ChainReader for BlockChain {
fn get_pruning_height(&self) -> BlockNumber {
self.get_pruning_height()
}

fn get_pruning_config(&self) -> (u64, u64) {
let reader = AccountStateReader::new(&self.statedb);
let FlexiDagConfigV2 {
pruning_depth,
pruning_finality,
} = reader
.get_dag_config()
.unwrap_or_default()
.unwrap_or_default();
(pruning_depth, pruning_finality)
}
Comment on lines +1430 to +1439
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider handling errors explicitly in get_pruning_config

The method get_pruning_config uses multiple unwrap_or_default() calls, which may suppress errors and return default values unintentionally. Consider handling errors explicitly to ensure any issues are caught and addressed appropriately.

Refactor the method to handle errors properly:

-fn get_pruning_config(&self) -> (u64, u64) {
-    let reader = AccountStateReader::new(&self.statedb);
-    let FlexiDagConfigV2 {
-        pruning_depth,
-        pruning_finality,
-    } = reader
-        .get_dag_config()
-        .unwrap_or_default()
-        .unwrap_or_default();
-    (pruning_depth, pruning_finality)
-}
+fn get_pruning_config(&self) -> Result<(u64, u64)> {
+    let reader = AccountStateReader::new(&self.statedb);
+    if let Some(config) = reader.get_dag_config()? {
+        Ok((config.pruning_depth, config.pruning_finality))
+    } else {
+        Err(format_err!("Failed to retrieve DAG configuration"))
+    }
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let reader = AccountStateReader::new(&self.statedb);
let FlexiDagConfigV2 {
pruning_depth,
pruning_finality,
} = reader
.get_dag_config()
.unwrap_or_default()
.unwrap_or_default();
(pruning_depth, pruning_finality)
}
fn get_pruning_config(&self) -> Result<(u64, u64)> {
let reader = AccountStateReader::new(&self.statedb);
if let Some(config) = reader.get_dag_config()? {
Ok((config.pruning_depth, config.pruning_finality))
} else {
Err(format_err!("Failed to retrieve DAG configuration"))
}
}

}

impl BlockChain {
Expand Down
2 changes: 1 addition & 1 deletion chain/tests/test_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashSet;

#[stest::test]
fn test_block_chain_prune() -> anyhow::Result<()> {
let mut mock_chain = MockChain::new_with_params(ChainNetwork::new_test(), 3, 4, 3)?;
let mut mock_chain = MockChain::new_with_params(ChainNetwork::new_test(), 3)?;
let genesis = mock_chain.head().status().head.clone();

// blue blocks
Expand Down
35 changes: 13 additions & 22 deletions flexidag/src/blockdag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::ghostdag::protocol::GhostdagManager;
use crate::prune::pruning_point_manager::PruningPointManagerT;
use crate::{process_key_already_error, reachability};
use anyhow::{bail, ensure, Ok};
use starcoin_config::genesis_config::{G_PRUNING_DEPTH, G_PRUNING_FINALITY};
use starcoin_config::temp_dir;
use starcoin_crypto::{HashValue as Hash, HashValue};
use starcoin_logger::prelude::{debug, info, warn};
Expand All @@ -30,8 +29,6 @@ use std::ops::DerefMut;
use std::sync::Arc;

pub const DEFAULT_GHOSTDAG_K: KType = 8u16;
pub const DEFAULT_PRUNING_DEPTH: u64 = 185798;
pub const DEFAULT_FINALITY_DEPTH: u64 = 86400;

pub type DbGhostdagManager = GhostdagManager<
DbGhostdagStore,
Expand All @@ -57,15 +54,10 @@ pub struct BlockDAG {

impl BlockDAG {
pub fn create_blockdag(dag_storage: FlexiDagStorage) -> Self {
Self::new(
DEFAULT_GHOSTDAG_K,
dag_storage,
G_PRUNING_DEPTH,
G_PRUNING_FINALITY,
)
Self::new(DEFAULT_GHOSTDAG_K, dag_storage)
}

pub fn new(k: KType, db: FlexiDagStorage, pruning_depth: u64, pruning_finality: u64) -> Self {
pub fn new(k: KType, db: FlexiDagStorage) -> Self {
let ghostdag_store = db.ghost_dag_store.clone();
let header_store = db.header_store.clone();
let relations_store = db.relations_store.clone();
Expand All @@ -78,12 +70,7 @@ impl BlockDAG {
header_store,
reachability_service.clone(),
);
let pruning_point_manager = PruningPointManager::new(
reachability_service,
ghostdag_store,
pruning_depth,
pruning_finality,
);
let pruning_point_manager = PruningPointManager::new(reachability_service, ghostdag_store);

Self {
ghostdag_manager,
Expand All @@ -101,14 +88,10 @@ impl BlockDAG {
Ok(Self::create_blockdag(dag_storage))
}

pub fn create_for_testing_with_parameters(
k: KType,
pruning_depth: u64,
pruning_finality: u64,
) -> anyhow::Result<Self> {
pub fn create_for_testing_with_parameters(k: KType) -> anyhow::Result<Self> {
let dag_storage =
FlexiDagStorage::create_from_path(temp_dir(), FlexiDagStorageConfig::default())?;
Ok(Self::new(k, dag_storage, pruning_depth, pruning_finality))
Ok(Self::new(k, dag_storage))
}

pub fn has_dag_block(&self, hash: Hash) -> anyhow::Result<bool> {
Expand Down Expand Up @@ -492,6 +475,8 @@ impl BlockDAG {
&self,
previous_pruning_point: HashValue,
previous_ghostdata: &GhostdagData,
pruning_depth: u64,
pruning_finality: u64,
) -> anyhow::Result<MineNewDagBlockInfo> {
info!("start to calculate the mergeset and tips, previous pruning point: {:?}, previous ghostdata: {:?}", previous_pruning_point, previous_ghostdata);
let dag_state = self.get_dag_state(previous_pruning_point)?;
Expand All @@ -504,6 +489,8 @@ impl BlockDAG {
previous_pruning_point,
previous_ghostdata,
&next_ghostdata,
pruning_depth,
pruning_finality,
)?;
info!(
"the next pruning point is: {:?}, and the previous pruning point is: {:?}",
Expand Down Expand Up @@ -545,11 +532,15 @@ impl BlockDAG {
previous_ghostdata: &GhostdagData,
next_pruning_point: HashValue,
next_ghostdata: &GhostdagData,
pruning_depth: u64,
pruning_finality: u64,
) -> anyhow::Result<()> {
let inside_next_pruning_point = self.pruning_point_manager().next_pruning_point(
previous_pruning_point,
previous_ghostdata,
next_ghostdata,
pruning_depth,
pruning_finality,
)?;

if next_pruning_point != inside_next_pruning_point {
Expand Down
25 changes: 10 additions & 15 deletions flexidag/src/prune/pruning_point_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,25 @@ use crate::{
pub struct PruningPointManagerT<T: ReachabilityStoreReader + Clone> {
reachability_service: MTReachabilityService<T>,
ghost_dag_store: DbGhostdagStore,
pruning_depth: u64,
pruning_finality: u64,
}

impl<T: ReachabilityStoreReader + Clone> PruningPointManagerT<T> {
pub fn new(
reachability_service: MTReachabilityService<T>,
ghost_dag_store: DbGhostdagStore,
pruning_depth: u64,
pruning_finality: u64,
) -> Self {
Self {
reachability_service,
ghost_dag_store,
pruning_depth,
pruning_finality,
}
}

pub fn reachability_service(&self) -> MTReachabilityService<T> {
self.reachability_service.clone()
}

pub fn finality_score(&self, blue_score: u64) -> u64 {
blue_score / self.pruning_finality
pub(crate) fn finality_score(&self, blue_score: u64, pruning_finality: u64) -> u64 {
blue_score / pruning_finality
Comment on lines +35 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent potential division by zero in finality_score

The finality_score function divides blue_score by pruning_finality, but there is no check to ensure pruning_finality is not zero. This could lead to a division by zero error. Consider adding a check to prevent this scenario.

Apply this diff to add a validation check:

 pub(crate) fn finality_score(&self, blue_score: u64, pruning_finality: u64) -> u64 {
+    if pruning_finality == 0 {
+        // Handle the error appropriately, e.g., return an error or default value
+        return 0; // or consider returning an error
+    }
     blue_score / pruning_finality
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub(crate) fn finality_score(&self, blue_score: u64, pruning_finality: u64) -> u64 {
blue_score / pruning_finality
pub(crate) fn finality_score(&self, blue_score: u64, pruning_finality: u64) -> u64 {
if pruning_finality == 0 {
// Handle the error appropriately, e.g., return an error or default value
return 0; // or consider returning an error
}
blue_score / pruning_finality
}

}

pub fn prune(
Expand Down Expand Up @@ -69,17 +63,20 @@ impl<T: ReachabilityStoreReader + Clone> PruningPointManagerT<T> {
previous_pruning_point: HashValue,
previous_ghostdata: &GhostdagData,
next_ghostdata: &GhostdagData,
pruning_depth: u64,
pruning_finality: u64,
) -> anyhow::Result<HashValue> {
let min_required_blue_score_for_next_pruning_point =
(self.finality_score(previous_ghostdata.blue_score) + 1) * self.pruning_finality;
(self.finality_score(previous_ghostdata.blue_score, pruning_finality) + 1)
* pruning_finality;
Comment on lines +66 to +71
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Validate pruning_depth and pruning_finality parameters

The next_pruning_point function now accepts pruning_depth and pruning_finality as parameters. To ensure robust operation, validate that these parameters are greater than zero to prevent potential runtime errors such as division by zero or incorrect logical comparisons.

Consider adding validation at the beginning of the function:

 pub(crate) fn next_pruning_point(
     &self,
     previous_pruning_point: HashValue,
     previous_ghostdata: &GhostdagData,
     next_ghostdata: &GhostdagData,
     pruning_depth: u64,
     pruning_finality: u64,
 ) -> anyhow::Result<HashValue> {
+    if pruning_depth == 0 || pruning_finality == 0 {
+        return Err(anyhow::anyhow!("pruning_depth and pruning_finality must be greater than zero"));
+    }
     let min_required_blue_score_for_next_pruning_point =
         (self.finality_score(previous_ghostdata.blue_score, pruning_finality) + 1)
             * pruning_finality;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pruning_depth: u64,
pruning_finality: u64,
) -> anyhow::Result<HashValue> {
let min_required_blue_score_for_next_pruning_point =
(self.finality_score(previous_ghostdata.blue_score) + 1) * self.pruning_finality;
(self.finality_score(previous_ghostdata.blue_score, pruning_finality) + 1)
* pruning_finality;
pub(crate) fn next_pruning_point(
&self,
previous_pruning_point: HashValue,
previous_ghostdata: &GhostdagData,
next_ghostdata: &GhostdagData,
pruning_depth: u64,
pruning_finality: u64,
) -> anyhow::Result<HashValue> {
if pruning_depth == 0 || pruning_finality == 0 {
return Err(anyhow::anyhow!("pruning_depth and pruning_finality must be greater than zero"));
}
let min_required_blue_score_for_next_pruning_point =
(self.finality_score(previous_ghostdata.blue_score, pruning_finality) + 1)
* pruning_finality;


debug!(
"min_required_blue_score_for_next_pruning_point: {:?}",
min_required_blue_score_for_next_pruning_point
);

let mut latest_pruning_ghost_data = previous_ghostdata.to_compact();
if min_required_blue_score_for_next_pruning_point + self.pruning_depth
if min_required_blue_score_for_next_pruning_point + pruning_depth
<= next_ghostdata.blue_score
{
for child in self.reachability_service().forward_chain_iterator(
Expand All @@ -92,13 +89,11 @@ impl<T: ReachabilityStoreReader + Clone> PruningPointManagerT<T> {
"child: {:?}, observer2.blue_score: {:?}, next_pruning_ghostdata.blue_score: {:?}",
child, next_ghostdata.blue_score, next_pruning_ghostdata.blue_score
);
if next_ghostdata.blue_score - next_pruning_ghostdata.blue_score
< self.pruning_depth
{
if next_ghostdata.blue_score - next_pruning_ghostdata.blue_score < pruning_depth {
break;
Comment on lines +92 to 93
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent potential underflow in blue score subtraction

In the condition:

if next_ghostdata.blue_score - next_pruning_ghostdata.blue_score < pruning_depth {
    break;
}

There is a potential for underflow if next_pruning_ghostdata.blue_score is greater than next_ghostdata.blue_score, which could cause unexpected behavior due to wrapping of unsigned integers. Consider adjusting the logic to prevent underflow.

Modify the condition to ensure next_pruning_ghostdata.blue_score is not greater than next_ghostdata.blue_score:

+if next_pruning_ghostdata.blue_score > next_ghostdata.blue_score {
+    break;
+}
 if next_ghostdata.blue_score - next_pruning_ghostdata.blue_score < pruning_depth {
     break;
 }

}
if self.finality_score(next_pruning_ghostdata.blue_score)
> self.finality_score(latest_pruning_ghost_data.blue_score)
if self.finality_score(next_pruning_ghostdata.blue_score, pruning_finality)
> self.finality_score(latest_pruning_ghost_data.blue_score, pruning_finality)
{
latest_pruning_ghost_data = CompactGhostdagData {
blue_score: next_pruning_ghostdata.blue_score,
Expand Down
23 changes: 14 additions & 9 deletions flexidag/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::{bail, format_err, Ok, Result};
use starcoin_config::genesis_config::{G_PRUNING_DEPTH, G_PRUNING_FINALITY};
use starcoin_crypto::HashValue as Hash;
use starcoin_dag::{
blockdag::{BlockDAG, MineNewDagBlockInfo},
Expand Down Expand Up @@ -890,8 +889,7 @@ fn test_prune() -> anyhow::Result<()> {
let pruning_depth = 4;
let pruning_finality = 3;

let mut dag =
BlockDAG::create_for_testing_with_parameters(k, pruning_depth, pruning_finality).unwrap();
let mut dag = BlockDAG::create_for_testing_with_parameters(k).unwrap();

let origin = BlockHeaderBuilder::random().with_number(0).build();
let genesis = BlockHeader::dag_genesis_random_with_parent(origin)?;
Expand Down Expand Up @@ -1008,13 +1006,17 @@ fn test_prune() -> anyhow::Result<()> {
block_main_5.pruning_point(),
)
};

// test the pruning point calculation
let MineNewDagBlockInfo {
tips,
blue_blocks: _,
pruning_point,
} = dag.calc_mergeset_and_tips(previous_pruning_point, previous_ghostdata.as_ref())?;
} = dag.calc_mergeset_and_tips(
previous_pruning_point,
previous_ghostdata.as_ref(),
pruning_depth,
pruning_finality,
)?;

assert_eq!(pruning_point, block_main_2.id());
assert_eq!(tips.len(), 1);
Expand Down Expand Up @@ -1050,7 +1052,12 @@ fn test_prune() -> anyhow::Result<()> {
tips,
blue_blocks: _,
pruning_point,
} = dag.calc_mergeset_and_tips(previous_pruning_point, previous_ghostdata.as_ref())?;
} = dag.calc_mergeset_and_tips(
previous_pruning_point,
previous_ghostdata.as_ref(),
pruning_depth,
pruning_finality,
)?;

assert_eq!(pruning_point, block_main_2.id());
assert_eq!(tips.len(), 2);
Expand All @@ -1067,9 +1074,7 @@ fn test_verification_blue_block() -> anyhow::Result<()> {
// initialzie the dag firstly
let k = 5;

let mut dag =
BlockDAG::create_for_testing_with_parameters(k, G_PRUNING_DEPTH, G_PRUNING_FINALITY)
.unwrap();
let mut dag = BlockDAG::create_for_testing_with_parameters(k).unwrap();

let origin = BlockHeaderBuilder::random().with_number(0).build();
let genesis = BlockHeader::dag_genesis_random_with_parent(origin)?;
Expand Down
4 changes: 1 addition & 3 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,11 @@ impl Genesis {
pub fn init_storage_for_test_with_param(
net: &ChainNetwork,
k: KType,
pruning_depth: u64,
pruning_finality: u64,
) -> Result<(Arc<Storage>, ChainInfo, Self, BlockDAG)> {
debug!("init storage by genesis for test. {net:?}");
let storage = Arc::new(Storage::new(StorageInstance::new_cache_instance())?);
let genesis = Self::load_or_build(net)?;
let dag = BlockDAG::create_for_testing_with_parameters(k, pruning_depth, pruning_finality)?;
let dag = BlockDAG::create_for_testing_with_parameters(k)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Update all instances of init_storage_for_test_with_param to match the new signature.

The function init_storage_for_test_with_param has been modified to remove the pruning_depth and pruning_finality parameters in genesis/src/lib.rs. However, there is at least one other usage in chain/mock/src/mock_chain.rs that still includes these parameters. All call sites must be updated to ensure consistency and prevent potential issues.

  • File: chain/mock/src/mock_chain.rs

    Update the function call to remove the deprecated parameters:

    - let (storage, chain_info, _, dag) = Genesis::init_storage_for_test_with_param(&net, k, pruning_depth, pruning_finality)?;
    + let (storage, chain_info, _, dag) = Genesis::init_storage_for_test_with_param(&net, k)?;

Ensure that any additional call sites are similarly updated to align with the new function signature.

🔗 Analysis chain

Update function signature to match the new usage.

The BlockDAG::create_for_testing_with_parameters call has been modified to remove the pruning_depth and pruning_finality parameters. However, the function signature of init_storage_for_test_with_param still includes these parameters. This inconsistency should be addressed.

Consider updating the function signature to match the new usage:

-    pub fn init_storage_for_test_with_param(
-        net: &ChainNetwork,
-        k: KType,
-        pruning_depth: u64,
-        pruning_finality: u64,
-    ) -> Result<(Arc<Storage>, ChainInfo, Self, BlockDAG)> {
+    pub fn init_storage_for_test_with_param(
+        net: &ChainNetwork,
+        k: KType,
+    ) -> Result<(Arc<Storage>, ChainInfo, Self, BlockDAG)> {

Also, ensure that all calls to this function throughout the codebase are updated accordingly.

To verify the impact of this change, let's search for other occurrences of this function:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of init_storage_for_test_with_param
rg "init_storage_for_test_with_param" --type rust

Length of output: 239

let chain_info = genesis.execute_genesis_block(net, storage.clone(), dag.clone())?;
Ok((storage, chain_info, genesis, dag))
}
Expand Down
2 changes: 0 additions & 2 deletions node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ impl NodeService {
let dag = starcoin_dag::blockdag::BlockDAG::new(
KType::try_from(G_BASE_MAX_UNCLES_PER_BLOCK)?,
dag_storage.clone(),
config.base().net().genesis_config().pruning_depth,
config.base().net().genesis_config().pruning_finality,
);
registry.put_shared(dag.clone()).await?;
let (chain_info, genesis) = Genesis::init_and_check_storage(
Expand Down
5 changes: 5 additions & 0 deletions state/api/src/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use starcoin_types::{
};
use starcoin_vm_types::account_config::TABLE_HANDLE_ADDRESS_LIST;
use starcoin_vm_types::genesis_config::ChainId;
use starcoin_vm_types::on_chain_config::FlexiDagConfigV2;
use starcoin_vm_types::on_chain_resource::{Epoch, EpochInfo, GlobalTimeOnChain};
use starcoin_vm_types::state_store::table::{TableHandle, TableInfo};
use starcoin_vm_types::token::token_code::TokenCode;
Expand Down Expand Up @@ -200,6 +201,10 @@ where
self.reader.get_balance(*address)
}

pub fn get_dag_config(&self) -> Result<Option<FlexiDagConfigV2>> {
self.get_on_chain_config::<FlexiDagConfigV2>()
}

/// Get balance by address and coin type
pub fn get_balance_by_type(
&self,
Expand Down
Loading
Loading