Skip to content

Commit

Permalink
update try_connect function to process dag block
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Nov 10, 2023
1 parent 22b3d6a commit 48e1d72
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 144 deletions.
15 changes: 13 additions & 2 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ use starcoin_open_block::OpenedBlock;
use starcoin_state_api::{AccountStateReader, ChainStateReader, ChainStateWriter};
use starcoin_statedb::ChainStateDB;
use starcoin_storage::flexi_dag::SyncFlexiDagSnapshot;
use starcoin_storage::storage::CodecKVStore;
use starcoin_storage::Store;
use starcoin_time_service::TimeService;
use starcoin_types::block::BlockIdAndNumber;
use starcoin_types::contract_event::ContractEventInfo;
use starcoin_types::filter::Filter;
use starcoin_types::header::DagHeader;
use starcoin_types::startup_info::{ChainInfo, ChainStatus};
use starcoin_types::transaction::RichTransactionInfo;
use starcoin_types::{
Expand All @@ -55,6 +53,19 @@ pub struct ChainStatusWithBlock {
pub head: Block,
}

impl ChainStatusWithBlock {
pub fn new(head_block: Block, block_info: BlockInfo, dag_tips: Vec<HashValue>) -> Self {
Self {
status: ChainStatus::new(head_block.header.clone(), block_info, Some(dag_tips)),
head: head_block,
}
}

pub fn dag_tips(&self) -> Option<&Vec<HashValue>> {
self.status.tips_hash.as_ref()
}
}

pub struct BlockChain {
genesis_hash: HashValue,
txn_accumulator: MerkleAccumulator,
Expand Down
2 changes: 1 addition & 1 deletion chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#![deny(clippy::integer_arithmetic)]
mod chain;
pub mod verifier;
pub use chain::BlockChain;
pub use chain::{BlockChain, ChainStatusWithBlock};
pub use starcoin_chain_api::{ChainReader, ChainWriter};
3 changes: 2 additions & 1 deletion sync/src/block_connector/block_connector_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::tasks::{BlockConnectedEvent, BlockConnectedFinishEvent, BlockDiskChec
use anyhow::bail;
use anyhow::{format_err, Ok, Result};
use network_api::PeerProvider;
use parking_lot::Mutex;
use starcoin_chain_api::{ChainReader, ConnectBlockError, WriteableChainService};
use starcoin_config::{NodeConfig, G_CRATE_VERSION};
use starcoin_consensus::BlockDAG;
Expand All @@ -29,7 +30,7 @@ use starcoin_txpool_mock_service::MockTxPoolService;
use starcoin_types::block::ExecutedBlock;
use starcoin_types::sync_status::SyncStatus;
use starcoin_types::system_events::{MinedBlock, SyncStatusChangeEvent, SystemShutdown};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use sysinfo::{DiskExt, System, SystemExt};

const DISK_CHECKPOINT_FOR_PANIC: u64 = 1024 * 1024 * 1024 * 3;
Expand Down
5 changes: 2 additions & 3 deletions sync/src/block_connector/test_write_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
#![allow(clippy::integer_arithmetic)]
use crate::block_connector::WriteBlockChainService;
use parking_lot::Mutex;
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_consensus::{BlockDAG, Consensus, FlexiDagStorage, FlexiDagStorageConfig};
use starcoin_crypto::HashValue;
use starcoin_genesis::Genesis as StarcoinGenesis;
use starcoin_service_registry::bus::BusService;
use starcoin_service_registry::{RegistryAsyncService, RegistryService};
use starcoin_storage::Store;
Expand All @@ -19,7 +18,7 @@ use starcoin_types::block::Block;
use starcoin_types::blockhash::ORIGIN;
use starcoin_types::header::Header;
use starcoin_types::startup_info::StartupInfo;
use std::sync::{Arc, Mutex};
use std::sync::Arc;

pub async fn create_writeable_block_chain() -> (
WriteBlockChainService<MockTxPoolService>,
Expand Down
Loading

0 comments on commit 48e1d72

Please sign in to comment.