Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sanlee42 committed Jan 4, 2024
1 parent d86f271 commit 0a74e92
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
10 changes: 7 additions & 3 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) The Starcoin Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::verifier::{BlockVerifier, FullVerifier};
use crate::verifier::{BlockVerifier, DagVerifier, FullVerifier};
use anyhow::{bail, ensure, format_err, Ok, Result};
use sp_utils::stop_watch::{watch, CHAIN_WATCH_NAME};
use starcoin_accumulator::inmemory::InMemoryAccumulator;
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl ChainWriter for BlockChain {
info!(
"connect a dag block, {:?}, number: {:?}",
executed_block.block.id(),
executed_block.block.header().number()
executed_block.block.header().number(),
);
return self.connect_dag(executed_block);
}
Expand Down Expand Up @@ -1346,7 +1346,11 @@ impl ChainWriter for BlockChain {
}

fn apply(&mut self, block: Block) -> Result<ExecutedBlock> {
self.apply_with_verifier::<FullVerifier>(block)
if !block.is_dag() {
self.apply_with_verifier::<FullVerifier>(block)
} else {
self.apply_with_verifier::<DagVerifier>(block)
}
}

fn chain_state(&mut self) -> &ChainStateDB {
Expand Down
32 changes: 30 additions & 2 deletions chain/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ impl BlockVerifier for FullVerifier {
where
R: ChainReader,
{
//TODO: FIXME: Vefify block number logic should refactor
//BasicVerifier::verify_header(current_chain, new_block_header)?;
BasicVerifier::verify_header(current_chain, new_block_header)?;
ConsensusVerifier::verify_header(current_chain, new_block_header)
}
}
Expand Down Expand Up @@ -322,3 +321,32 @@ impl BlockVerifier for NoneVerifier {
Ok(())
}
}

//TODO: Implement it.
pub struct DagVerifier;
impl BlockVerifier for DagVerifier {
fn verify_header<R>(current_chain: &R, new_block_header: &BlockHeader) -> Result<()>
where
R: ChainReader,
{
ConsensusVerifier::verify_header(current_chain, new_block_header)
}

fn verify_block<R>(_current_chain: &R, new_block: Block) -> Result<VerifiedBlock>
where
R: ChainReader,
{
Ok(VerifiedBlock(new_block))
}

fn verify_uncles<R>(
_current_chain: &R,
_uncles: &[BlockHeader],
_header: &BlockHeader,
) -> Result<()>
where
R: ChainReader,
{
Ok(())
}
}
1 change: 0 additions & 1 deletion sync/src/block_connector/test_illegal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ async fn test_verify_timestamp_failed() {
error!("apply failed : {:?}", apply_err);
}
}

async fn test_verify_future_timestamp(succ: bool) -> Result<()> {
let (mut new_block, mut main) = new_block_and_main().await;
if !succ {
Expand Down
10 changes: 2 additions & 8 deletions sync/src/block_connector/test_write_dag_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
#![allow(clippy::integer_arithmetic)]
use crate::block_connector::test_write_block_chain::create_writeable_block_chain;
use crate::block_connector::WriteBlockChainService;
use async_std::path::Path;
use starcoin_account_api::AccountInfo;
use starcoin_chain::{BlockChain, ChainReader};
use starcoin_chain_service::WriteableChainService;
use starcoin_config::NodeConfig;
use starcoin_consensus::Consensus;
use starcoin_crypto::HashValue;
use starcoin_dag::consensusdb::prelude::FlexiDagStorageConfig;
use starcoin_dag::blockdag::BlockDAG;
use starcoin_time_service::TimeService;
use starcoin_txpool_mock_service::MockTxPoolService;
use starcoin_types::block::Block;
Expand Down Expand Up @@ -105,12 +104,7 @@ fn gen_fork_dag_block_chain(
writeable_block_chain_service: &mut WriteBlockChainService<MockTxPoolService>,
) -> Option<HashValue> {
let miner_account = AccountInfo::random();
let dag_storage = starcoin_dag::consensusdb::prelude::FlexiDagStorage::create_from_path(
Path::new("dag/db/starcoindb"),
FlexiDagStorageConfig::new(),
)
.expect("create dag storage fail");
let dag = starcoin_dag::blockdag::BlockDAG::new(8, dag_storage);
let dag = BlockDAG::create_for_testing().unwrap();
if let Some(block_header) = writeable_block_chain_service
.get_main()
.get_header_by_number(fork_number)
Expand Down
3 changes: 2 additions & 1 deletion types/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub static PROXIMA_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000;
pub static HALLEY_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000;
pub static BARNARD_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000;
pub static MAIN_FLEXIDAG_FORK_HEIGHT: BlockNumber = 1000000;
pub static CUSTOM_FLEXIDAG_FORK_HEIGHT: BlockNumber = 3;
pub static CUSTOM_FLEXIDAG_FORK_HEIGHT: BlockNumber = 100000;

/// Type for block header extra
#[derive(Clone, Default, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, JsonSchema)]
Expand Down Expand Up @@ -354,6 +354,7 @@ impl BlockHeader {
}

pub fn is_dag(&self) -> bool {
println!("fuck:{},{}", self.number, self.dag_fork_height());
self.number > self.dag_fork_height()
}
pub fn is_legacy(&self) -> bool {
Expand Down

0 comments on commit 0a74e92

Please sign in to comment.