From 838d354b4e8ce3df1d65e573b3b4d67430611a36 Mon Sep 17 00:00:00 2001 From: simonjiao Date: Fri, 17 Nov 2023 19:12:37 +0800 Subject: [PATCH] fix starcoin-storage compilation --- Cargo.lock | 35 +------------------------------- cmd/db-exporter/src/main.rs | 2 +- flexidag/Cargo.toml | 1 - genesis/src/lib.rs | 4 ++-- network/api/src/peer_provider.rs | 1 - storage/src/lib.rs | 32 ++++++++++++++++++----------- types/src/block.rs | 11 +--------- types/src/startup_info.rs | 1 - types/src/sync_status.rs | 2 +- 9 files changed, 26 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81ff007b28..c2b978862e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2837,40 +2837,7 @@ dependencies = [ "starcoin-chain-api", "starcoin-config", "starcoin-crypto", - "starcoin-logger", - "starcoin-state-api", - "starcoin-storage", - "starcoin-time-service", - "starcoin-types", - "starcoin-vm-types", - "thiserror", -] - -[[package]] -name = "flexidag-service" -version = "1.13.7" -dependencies = [ - "anyhow", - "bcs-ext", - "bincode", - "byteorder", - "flexidag", - "futures 0.3.26", - "hex", - "itertools", - "once_cell", - "parking_lot 0.12.1", - "proptest", - "proptest-derive", - "rand 0.8.5", - "rand_core 0.6.4", - "rocksdb", - "rust-argon2", - "serde 1.0.152", - "sha3", - "starcoin-chain-api", - "starcoin-config", - "starcoin-crypto", + "starcoin-flexidag", "starcoin-logger", "starcoin-state-api", "starcoin-storage", diff --git a/cmd/db-exporter/src/main.rs b/cmd/db-exporter/src/main.rs index 0accc3b51c..71c0a193f1 100644 --- a/cmd/db-exporter/src/main.rs +++ b/cmd/db-exporter/src/main.rs @@ -779,7 +779,7 @@ pub fn apply_block( let use_time = SystemTime::now().duration_since(start_time)?; println!("apply block use time: {:?}", use_time.as_secs()); let chain_info = storage - .get_chain_info(net.id().clone())? + .get_chain_info()? .ok_or_else(|| format_err!("{}", "get chain_info error"))?; println!("chain_info {}", chain_info); Ok(()) diff --git a/flexidag/Cargo.toml b/flexidag/Cargo.toml index 00e042c08b..999bca15f4 100644 --- a/flexidag/Cargo.toml +++ b/flexidag/Cargo.toml @@ -23,7 +23,6 @@ rand = { workspace = true } rand_core = { default-features = false, workspace = true } rust-argon2 = { workspace = true } sha3 = { workspace = true } -starcoin-config = { workspace = true } starcoin-chain-api = { workspace = true } starcoin-crypto = { workspace = true } starcoin-logger = { workspace = true } diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index 4683b286d8..ee8ec9983d 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -266,7 +266,7 @@ impl Genesis { let startup_info = StartupInfo::new(genesis_chain.current_header().id()); storage.save_startup_info(startup_info)?; storage - .get_chain_info(net.id().clone())? + .get_chain_info()? .ok_or_else(|| format_err!("ChainInfo should exist after genesis block executed.")) } @@ -319,7 +319,7 @@ impl Genesis { data_dir: &Path, ) -> Result<(ChainInfo, Genesis)> { debug!("load startup_info."); - let (chain_info, genesis) = match storage.get_chain_info(net.id().clone()) { + let (chain_info, genesis) = match storage.get_chain_info() { Ok(Some(chain_info)) => { debug!("Get chain info {:?} from db", chain_info); info!("Check genesis file."); diff --git a/network/api/src/peer_provider.rs b/network/api/src/peer_provider.rs index 52ef7d8271..15d3f03e4f 100644 --- a/network/api/src/peer_provider.rs +++ b/network/api/src/peer_provider.rs @@ -7,7 +7,6 @@ use anyhow::Result; use futures::channel::oneshot::Receiver; use futures::future::BoxFuture; use itertools::Itertools; -use network_p2p_types::peer_id; use network_p2p_types::{peer_id::PeerId, ReputationChange}; use parking_lot::Mutex; use rand::prelude::IteratorRandom; diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 9902e9f564..ab6ea414ca 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -21,19 +21,18 @@ use network_p2p_types::peer_id::PeerId; use num_enum::{IntoPrimitive, TryFromPrimitive}; use once_cell::sync::Lazy; use starcoin_accumulator::{ - accumulator_info::{self, AccumulatorInfo}, - node::AccumulatorStoreType, - AccumulatorTreeStore, MerkleAccumulator, Accumulator, + accumulator_info::AccumulatorInfo, node::AccumulatorStoreType, Accumulator, + AccumulatorTreeStore, MerkleAccumulator, }; use starcoin_config::ChainNetworkID; use starcoin_crypto::HashValue; use starcoin_state_store_api::{StateNode, StateNodeStore}; +use starcoin_types::block::BlockNumber; use starcoin_types::{ block::{Block, BlockBody, BlockHeader, BlockInfo}, contract_event::ContractEvent, dag_block::KTotalDifficulty, - header, - startup_info::{self, ChainInfo, ChainStatus, SnapshotRange, StartupInfo}, + startup_info::{ChainInfo, ChainStatus, SnapshotRange, StartupInfo}, transaction::{RichTransactionInfo, Transaction}, }; use starcoin_vm_types::{ @@ -226,7 +225,7 @@ pub trait BlockStore { fn save_genesis(&self, genesis_hash: HashValue) -> Result<()>; - fn get_chain_info(&self, id: ChainNetworkID) -> Result>; + fn get_chain_info(&self) -> Result>; fn get_block(&self, block_id: HashValue) -> Result>; @@ -439,7 +438,7 @@ impl BlockStore for Storage { self.chain_info_storage.save_genesis(genesis_hash) } - fn get_chain_info(&self, id: ChainNetworkID) -> Result> { + fn get_chain_info(&self) -> Result> { let genesis_hash = match self.get_genesis()? { Some(genesis_hash) => genesis_hash, None => return Ok(None), @@ -454,11 +453,13 @@ impl BlockStore for Storage { let head_block_info = self.get_block_info(head_block.id())?.ok_or_else(|| { format_err!("Startup block info {:?} should exist", startup_info.main) })?; - let snapshot = self.get_lastest_snapshot()?.ok_or_else(|| anyhow!("latest snapshot is none"))?; + let snapshot = self + .get_lastest_snapshot()? + .ok_or_else(|| anyhow!("latest snapshot is none"))?; let chain_info = ChainInfo::new( head_block.chain_id(), genesis_hash, - ChainStatus::new(head_block.clone(), head_block_info), + ChainStatus::new(head_block, head_block_info), Some(snapshot.accumulator_info), Some(snapshot.k_total_difficulties), ); @@ -674,9 +675,16 @@ impl SyncFlexiDagStore for Storage { } fn get_lastest_snapshot(&self) -> Result> { - let info = self.get_dag_accumulator_info()?.ok_or_else(|| anyhow!("dag startup info is none"))?; - let merkle_tree = MerkleAccumulator::new_with_info(info, self.get_accumulator_store(AccumulatorStoreType::SyncDag)); - let key = merkle_tree.get_leaf(merkle_tree.num_leaves() - 1)?.ok_or_else(|| anyhow!("faile to get the key since it is none"))?; + let info = self + .get_dag_accumulator_info()? + .ok_or_else(|| anyhow!("dag startup info is none"))?; + let merkle_tree = MerkleAccumulator::new_with_info( + info, + self.get_accumulator_store(AccumulatorStoreType::SyncDag), + ); + let key = merkle_tree + .get_leaf(merkle_tree.num_leaves() - 1)? + .ok_or_else(|| anyhow!("faile to get the key since it is none"))?; self.query_by_hash(key) } diff --git a/types/src/block.rs b/types/src/block.rs index 0c010cea14..5d205dd8d8 100644 --- a/types/src/block.rs +++ b/types/src/block.rs @@ -8,7 +8,7 @@ use crate::language_storage::CORE_CODE_ADDRESS; use crate::transaction::SignedUserTransaction; use crate::U256; use anyhow::format_err; -use bcs_ext::{BCSCodec, Sample}; +use bcs_ext::Sample; use schemars::{self, JsonSchema}; use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -1011,15 +1011,6 @@ impl BlockTemplate { } } - fn generate_parent_header(&self) -> HashValue { - if self.parents_hash.is_none() { - return self.parent_hash; - } - let mut tips = self.parents_hash.as_ref().unwrap().clone(); - tips.sort(); - HashValue::sha3_256_of(&tips.encode().expect("dag parent must encode successfully")) - } - pub fn as_raw_block_header_single_chain(&self) -> RawBlockHeader { RawBlockHeader { parent_hash: self.parent_hash, diff --git a/types/src/startup_info.rs b/types/src/startup_info.rs index 4e08226411..c4137040e9 100644 --- a/types/src/startup_info.rs +++ b/types/src/startup_info.rs @@ -8,7 +8,6 @@ use bcs_ext::{BCSCodec, Sample}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use starcoin_accumulator::accumulator_info::AccumulatorInfo; -use starcoin_accumulator::MerkleAccumulator; use starcoin_crypto::HashValue; use starcoin_uint::U256; use starcoin_vm_types::genesis_config::ChainId; diff --git a/types/src/sync_status.rs b/types/src/sync_status.rs index 1fb3b97e9e..813b872a67 100644 --- a/types/src/sync_status.rs +++ b/types/src/sync_status.rs @@ -5,7 +5,7 @@ use crate::block::BlockIdAndNumber; use crate::startup_info::ChainStatus; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use starcoin_accumulator::{accumulator_info::AccumulatorInfo, Accumulator}; +use starcoin_accumulator::accumulator_info::AccumulatorInfo; use starcoin_uint::U256; #[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug, JsonSchema)] pub enum SyncState {