Skip to content

Commit

Permalink
Showing 5 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion chain/tests/test_txn_info_and_proof.rs
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@ pub fn gen_txns(seq_num: &mut u64) -> Result<Vec<SignedUserTransaction>> {
}

#[stest::test(timeout = 480)]
#[ignore = "set dag block height to 2 for passing"]
fn test_transaction_info_and_proof_1() -> Result<()> {
starcoin_types::block::set_test_flexidag_fork_height(2);
// generate 5 block
let config = Arc::new(NodeConfig::random_for_test());
let mut block_chain = test_helper::gen_blockchain_for_test(config.net())?;
@@ -105,6 +105,7 @@ fn test_transaction_info_and_proof_1() -> Result<()> {
block_chain.current_header().id(),
block_chain.get_block_by_number(6).unwrap().unwrap().id()
);
starcoin_types::block::reset_test_custom_fork_height();
Ok(())
}

12 changes: 7 additions & 5 deletions sync/tests/test_rpc_client.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ struct DagBlockInfo {

#[stest::test]
fn test_verified_client_for_dag() {
starcoin_types::block::set_test_flexidag_fork_height(2);
let (local_handle, target_handle, target_peer_id) =
init_two_node().expect("failed to initalize the local and target node");

@@ -47,7 +48,7 @@ fn test_verified_client_for_dag() {
.into_iter()
.all(|child| { target_dag_block.children.contains(&child) }));
});

starcoin_types::block::reset_test_custom_fork_height();
target_handle.stop().unwrap();
local_handle.stop().unwrap();
}
@@ -82,12 +83,13 @@ fn generate_dag_block(handle: &NodeHandle, count: i32) -> Result<Vec<DagBlockInf
result.push(block);
}
}
Ok(result.into_iter().map(|block| {
DagBlockInfo {
Ok(result
.into_iter()
.map(|block| DagBlockInfo {
header: block.header().clone(),
children: dag.get_children(block.header().id()).unwrap(),
}
}).collect::<Vec<DagBlockInfo>>())
})
.collect::<Vec<DagBlockInfo>>())
}

fn gen_chain_env(config: NodeConfig) -> Result<NodeHandle> {
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ starcoin-crypto = { workspace = true }
starcoin-uint = { workspace = true }
starcoin-vm-types = { workspace = true }
thiserror = { workspace = true }

lazy_static= { workspace = true }
[features]
default = []
fuzzing = ["proptest", "proptest-derive", "starcoin-vm-types/fuzzing"]
53 changes: 39 additions & 14 deletions types/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ use crate::language_storage::CORE_CODE_ADDRESS;
use crate::transaction::SignedUserTransaction;
use crate::U256;
use bcs_ext::Sample;
use lazy_static::lazy_static;
pub use legacy::{
Block as LegacyBlock, BlockBody as LegacyBlockBody, BlockHeader as LegacyBlockHeader,
};
@@ -28,20 +29,45 @@ use starcoin_vm_types::account_config::genesis_address;
use starcoin_vm_types::transaction::authenticator::AuthenticationKey;
use std::fmt::Formatter;
use std::hash::Hash;

use std::sync::Mutex;
/// Type for block number.
pub type BlockNumber = u64;

//TODO: make sure height
pub type ParentsHash = Option<Vec<HashValue>>;
//TODO: make sure height
static DEV_FLEXIDAG_FORK_HEIGHT: BlockNumber = 2;
static PROXIMA_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000;
static HALLEY_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000;
static BARNARD_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000;
static MAIN_FLEXIDAG_FORK_HEIGHT: BlockNumber = 1000000;

lazy_static! {
static ref TEST_FLEXIDAG_FORK_HEIGHT: Mutex<BlockNumber> = Mutex::new(10000);
static ref CUSTOM_FLEXIDAG_FORK_HEIGHT: Mutex<BlockNumber> = Mutex::new(10000);
}

pub fn get_test_flexidag_fork_height() -> BlockNumber {
*TEST_FLEXIDAG_FORK_HEIGHT.lock().unwrap()
}

pub static DEV_FLEXIDAG_FORK_HEIGHT: BlockNumber = 2;
pub static TEST_FLEXIDAG_FORK_HEIGHT: BlockNumber = 10000; //keep it for the old tests passing
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 = 100000;
pub fn get_custom_flexidag_fork_height() -> BlockNumber {
*CUSTOM_FLEXIDAG_FORK_HEIGHT.lock().unwrap()
}

// TODO: support a macro such as #[cfg(test:consensus=dag)] to set fork height for testing customly and reset after executing.
pub fn set_test_flexidag_fork_height(value: BlockNumber) {
let mut num = TEST_FLEXIDAG_FORK_HEIGHT.lock().unwrap();
*num = value;
}

pub fn set_customm_flexidag_fork_height(value: BlockNumber) {
let mut num = TEST_FLEXIDAG_FORK_HEIGHT.lock().unwrap();
*num = value;
}

pub fn reset_test_custom_fork_height() {
*TEST_FLEXIDAG_FORK_HEIGHT.lock().unwrap() = 10000;
*CUSTOM_FLEXIDAG_FORK_HEIGHT.lock().unwrap() = 10000;
}

/// Type for block header extra
#[derive(Clone, Default, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, JsonSchema)]
@@ -337,7 +363,7 @@ impl BlockHeader {
}
pub fn dag_fork_height(&self) -> BlockNumber {
if self.chain_id.is_test() {
TEST_FLEXIDAG_FORK_HEIGHT
get_test_flexidag_fork_height()
} else if self.chain_id.is_halley() {
HALLEY_FLEXIDAG_FORK_HEIGHT
} else if self.chain_id.is_proxima() {
@@ -349,12 +375,11 @@ impl BlockHeader {
} else if self.chain_id.is_dev() {
DEV_FLEXIDAG_FORK_HEIGHT
} else {
CUSTOM_FLEXIDAG_FORK_HEIGHT
get_custom_flexidag_fork_height()
}
}

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 {
@@ -394,7 +419,7 @@ impl BlockHeader {
pub fn dag_genesis_random() -> Self {
let mut header = Self::random();
header.parents_hash = Some(vec![header.parent_hash]);
header.number = TEST_FLEXIDAG_FORK_HEIGHT;
header.number = get_test_flexidag_fork_height();
header
}

0 comments on commit 44932a6

Please sign in to comment.