Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
no check uncle number if it is a dag block
  • Loading branch information
jackzhhuang committed Mar 21, 2024
1 parent f6d6390 commit 7cfddb8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
12 changes: 7 additions & 5 deletions chain/src/verifier/mod.rs
Expand Up @@ -407,11 +407,13 @@ impl BlockVerifier for DagVerifier {
header.id()
);

verify_block!(
VerifyBlockField::Uncle,
uncle.number() < header.number() ,
"uncle block number bigger than or equal to current block ,uncle block number is {} , current block number is {}", uncle.number(), header.number()
);
if !header.is_dag() {
verify_block!(
VerifyBlockField::Uncle,
uncle.number() < header.number() ,
"uncle block number bigger than or equal to current block ,uncle block number is {} , current block number is {}", uncle.number(), header.number()
);
}

verify_block!(
VerifyBlockField::Uncle,
Expand Down
4 changes: 4 additions & 0 deletions flexidag/dag/src/reachability/inquirer.rs
Expand Up @@ -10,6 +10,10 @@ pub fn init(store: &mut (impl ReachabilityStore + ?Sized), origin: HashValue) ->
init_with_params(store, origin, Interval::maximal())
}

pub fn init_for_test(store: &mut (impl ReachabilityStore + ?Sized), origin: HashValue, capacity: Interval) -> Result<()> {
init_with_params(store, origin, capacity)
}

pub(super) fn init_with_params(
store: &mut (impl ReachabilityStore + ?Sized),
origin: Hash,
Expand Down
2 changes: 0 additions & 2 deletions flexidag/dag/src/types/interval.rs
@@ -1,5 +1,4 @@
use serde::{Deserialize, Serialize};
use starcoin_logger::prelude::info;
use std::fmt::{Display, Formatter};

#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
Expand Down Expand Up @@ -77,7 +76,6 @@ impl Interval {
}

pub fn decrease_end(&self, offset: u64) -> Self {
info!("jacktest: self.start: {}, self.end: {}, offset: {}", self.start, self.end, offset);
Self::new(self.start, self.end.checked_sub(offset).unwrap())
}

Expand Down
67 changes: 65 additions & 2 deletions flexidag/dag/tests/tests.rs
Expand Up @@ -4,9 +4,9 @@
mod tests {
use anyhow::{bail, Ok};
use starcoin_config::RocksdbConfig;
use starcoin_dag::{blockdag::BlockDAG, consensusdb::{consenses_state::{DagState, DagStateReader, DagStateStore}, prelude::{FlexiDagStorage, FlexiDagStorageConfig}, schemadb::ReachabilityStoreReader}, reachability::{inquirer, reachability_service::ReachabilityService, ReachabilityError}};
use starcoin_dag::{blockdag::BlockDAG, consensusdb::{consenses_state::{DagState, DagStateReader, DagStateStore}, prelude::{FlexiDagStorage, FlexiDagStorageConfig}, schemadb::{DbReachabilityStore, ReachabilityStore, ReachabilityStoreReader}}, reachability::{inquirer, reachability_service::ReachabilityService, ReachabilityError}, types::interval::{self, Interval}};
use starcoin_types::{block::{set_test_flexidag_fork_height, BlockHeader, BlockHeaderBuilder}, blockhash::KType};
use std::{env, fs};
use std::{env, fs, process::ChildStdin};
use starcoin_crypto::{hash, HashValue as Hash};

fn build_block_dag(k: KType) -> BlockDAG {
Expand Down Expand Up @@ -390,4 +390,67 @@ mod tests {

Ok(())
}

fn print_reachability_data(reachability: &DbReachabilityStore, key: &[Hash]) {
println!("**********************");
for k in key {
let height = reachability.get_height(*k).unwrap();
let parent = reachability.get_parent(*k).unwrap();
let children = reachability.get_children(*k).unwrap();
let interval = reachability.get_interval(*k).unwrap();

println!("key: {:?}, height: {:?}, parent: {:?}, children: {:?}, interval: {:?}", k, height, parent, children, interval);
}
println!("**********************");
}

#[test]
fn test_reachability_algorighm() -> anyhow::Result<()> {
let dag = BlockDAG::create_for_testing().unwrap();
let mut reachability_store = dag.storage.reachability_store.clone();

let origin = Hash::random();

inquirer::init_for_test(&mut reachability_store, origin, Interval::new(1, 16))?;

let mut hashes = vec![origin];
print_reachability_data(&reachability_store, &hashes);

let child1 = Hash::random();
inquirer::add_block(&mut reachability_store, child1, origin, &mut vec![origin].into_iter())?;
hashes.push(child1);
print_reachability_data(&reachability_store, &hashes);

let child2 = Hash::random();
hashes.push(child2);
inquirer::add_block(&mut reachability_store, child2, origin, &mut vec![origin].into_iter())?;
print_reachability_data(&reachability_store, &hashes);

let child3 = Hash::random();
inquirer::add_block(&mut reachability_store, child3, origin, &mut vec![origin].into_iter())?;
hashes.push(child3);
print_reachability_data(&reachability_store, &hashes);

let child4 = Hash::random();
inquirer::add_block(&mut reachability_store, child4, origin, &mut vec![origin].into_iter())?;
hashes.push(child4);
print_reachability_data(&reachability_store, &hashes);

let child5 = Hash::random();
inquirer::add_block(&mut reachability_store, child5, origin, &mut vec![origin].into_iter())?;
hashes.push(child5);
print_reachability_data(&reachability_store, &hashes);

// let mut count = 6;
// loop {
// let child = Hash::random();
// inquirer::add_block(&mut reachability_store, child, origin, &mut vec![origin].into_iter())?;
// hashes.push(child);
// print!("{count:?}");
// print_reachability_data(&reachability_store, &hashes);
// count += 1;
// }

Ok(())
}
}

0 comments on commit 7cfddb8

Please sign in to comment.