Skip to content

Commit

Permalink
fix starcoin-storage compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Nov 17, 2023
1 parent 1cef501 commit 838d354
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 63 deletions.
35 changes: 1 addition & 34 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cmd/db-exporter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
1 change: 0 additions & 1 deletion flexidag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
}

Expand Down Expand Up @@ -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.");
Expand Down
1 change: 0 additions & 1 deletion network/api/src/peer_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 20 additions & 12 deletions storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -226,7 +225,7 @@ pub trait BlockStore {

fn save_genesis(&self, genesis_hash: HashValue) -> Result<()>;

fn get_chain_info(&self, id: ChainNetworkID) -> Result<Option<ChainInfo>>;
fn get_chain_info(&self) -> Result<Option<ChainInfo>>;

fn get_block(&self, block_id: HashValue) -> Result<Option<Block>>;

Expand Down Expand Up @@ -439,7 +438,7 @@ impl BlockStore for Storage {
self.chain_info_storage.save_genesis(genesis_hash)
}

fn get_chain_info(&self, id: ChainNetworkID) -> Result<Option<ChainInfo>> {
fn get_chain_info(&self) -> Result<Option<ChainInfo>> {
let genesis_hash = match self.get_genesis()? {
Some(genesis_hash) => genesis_hash,
None => return Ok(None),
Expand All @@ -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),
);
Expand Down Expand Up @@ -674,9 +675,16 @@ impl SyncFlexiDagStore for Storage {
}

fn get_lastest_snapshot(&self) -> Result<Option<SyncFlexiDagSnapshot>> {
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)
}

Expand Down
11 changes: 1 addition & 10 deletions types/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion types/src/startup_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion types/src/sync_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 838d354

Please sign in to comment.