Skip to content

Commit fd09130

Browse files
committed
Merge branch 'fg-flexidag' of github.com:starcoinorg/starcoin into fg-flexidag
2 parents 514b0fb + 07dd80c commit fd09130

25 files changed

+275
-194
lines changed

chain/api/src/chain.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2
33

44
use anyhow::Result;
5-
use starcoin_accumulator::accumulator_info::AccumulatorInfo;
65
use starcoin_config::ChainNetworkID;
76
use starcoin_crypto::HashValue;
87
use starcoin_state_api::ChainStateReader;

chain/service/src/chain_service.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) The Starcoin Core Contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use anyhow::{bail, format_err, Error, Ok, Result};
5-
use starcoin_accumulator::node::AccumulatorStoreType;
6-
use starcoin_accumulator::{Accumulator, MerkleAccumulator};
4+
use anyhow::{format_err, Error, Ok, Result};
75
use starcoin_chain::BlockChain;
86
use starcoin_chain_api::message::{ChainRequest, ChainResponse};
97
use starcoin_chain_api::{
@@ -12,10 +10,10 @@ use starcoin_chain_api::{
1210
use starcoin_config::NodeConfig;
1311
use starcoin_consensus::BlockDAG;
1412
use starcoin_crypto::HashValue;
15-
use starcoin_flexidag::flexidag_service::{
16-
GetDagAccumulatorLeafDetail, GetDagBlockParents, UpdateDagTips,
13+
use starcoin_flexidag::{
14+
flexidag_service::{self, GetDagAccumulatorLeafDetail, UpdateDagTips},
15+
FlexidagService,
1716
};
18-
use starcoin_flexidag::{flexidag_service, FlexidagService};
1917
use starcoin_logger::prelude::*;
2018
use starcoin_network_rpc_api::dag_protocol::{
2119
GetDagAccumulatorLeaves, GetTargetDagAccumulatorLeafDetail, TargetDagAccumulatorLeaf,
@@ -78,7 +76,14 @@ impl ServiceFactory<Self> for ChainReaderService {
7876
let dag = ctx.get_shared_opt::<BlockDAG>()?;
7977
let vm_metrics = ctx.get_shared_opt::<VMMetrics>()?;
8078
let flexidag_service = ctx.service_ref::<FlexidagService>()?.clone();
81-
Self::new(config, startup_info, storage, flexidag_service, dag, vm_metrics)
79+
Self::new(
80+
config,
81+
startup_info,
82+
storage,
83+
flexidag_service,
84+
dag,
85+
vm_metrics,
86+
)
8287
}
8388
}
8489

@@ -95,10 +100,15 @@ impl ActorService for ChainReaderService {
95100
}
96101

97102
impl EventHandler<Self, NewHeadBlock> for ChainReaderService {
98-
fn handle_event(&mut self, event: NewHeadBlock, ctx: &mut ServiceContext<ChainReaderService>) {
103+
fn handle_event(&mut self, event: NewHeadBlock, _ctx: &mut ServiceContext<ChainReaderService>) {
99104
let new_head = event.executed_block.block().header().clone();
100-
if let Err(e) = if self.inner.get_main().can_connect(&event.executed_block.as_ref()) {
101-
self.inner.update_chain_head(event.executed_block.as_ref().clone())
105+
if let Err(e) = if self
106+
.inner
107+
.get_main()
108+
.can_connect(event.executed_block.as_ref())
109+
{
110+
self.inner
111+
.update_chain_head(event.executed_block.as_ref().clone())
102112
} else {
103113
self.inner.switch_main(new_head.id())
104114
} {
@@ -111,7 +121,7 @@ impl ServiceHandler<Self, ChainRequest> for ChainReaderService {
111121
fn handle(
112122
&mut self,
113123
msg: ChainRequest,
114-
ctx: &mut ServiceContext<ChainReaderService>,
124+
_ctx: &mut ServiceContext<ChainReaderService>,
115125
) -> Result<ChainResponse> {
116126
match msg {
117127
ChainRequest::CurrentHeader() => Ok(ChainResponse::BlockHeader(Box::new(

chain/src/chain.rs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use crate::verifier::{BlockVerifier, FullVerifier};
5-
use anyhow::{anyhow, bail, ensure, format_err, Ok, Result};
5+
use anyhow::{bail, ensure, format_err, Ok, Result};
66
use bcs_ext::BCSCodec;
77
use sp_utils::stop_watch::{watch, CHAIN_WATCH_NAME};
88
use starcoin_accumulator::inmemory::InMemoryAccumulator;
@@ -22,8 +22,6 @@ use starcoin_logger::prelude::*;
2222
use starcoin_open_block::OpenedBlock;
2323
use starcoin_state_api::{AccountStateReader, ChainStateReader, ChainStateWriter};
2424
use starcoin_statedb::ChainStateDB;
25-
use starcoin_storage::flexi_dag::SyncFlexiDagSnapshot;
26-
use starcoin_storage::storage::CodecKVStore;
2725
use starcoin_storage::Store;
2826
use starcoin_time_service::TimeService;
2927
use starcoin_types::block::BlockIdAndNumber;
@@ -53,8 +51,8 @@ pub struct ChainStatusWithBlock {
5351
pub status: ChainStatus,
5452
pub head: Block,
5553
}
56-
impl ChainStatusWithBlock{
57-
pub fn dag_tips(&self,)->&Option<Vec<HashValue>>{
54+
impl ChainStatusWithBlock {
55+
pub fn dag_tips(&self) -> &Option<Vec<HashValue>> {
5856
&self.status.tips_hash
5957
}
6058
}
@@ -109,7 +107,6 @@ impl BlockChain {
109107
let genesis = storage
110108
.get_genesis()?
111109
.ok_or_else(|| format_err!("Can not find genesis hash in storage."))?;
112-
let head_id = head_block.id();
113110
watch(CHAIN_WATCH_NAME, "n1253");
114111
let mut chain = Self {
115112
genesis_hash: genesis,
@@ -125,7 +122,7 @@ impl BlockChain {
125122
storage.as_ref(),
126123
),
127124
status: ChainStatusWithBlock {
128-
status: ChainStatus::new(head_block.header.clone(), block_info,None), //FIXME:read from snapshot
125+
status: ChainStatus::new(head_block.header.clone(), block_info, None), //FIXME:read from snapshot
129126
head: head_block,
130127
},
131128
statedb: chain_state,
@@ -188,10 +185,17 @@ impl BlockChain {
188185
head_block_id: genesis_id,
189186
total_difficulty: executed_block.block_info().get_total_difficulty(),
190187
}]
191-
.into_iter()
192-
.collect(),
188+
.into_iter()
189+
.collect(),
193190
)?;
194-
Self::new(time_service, executed_block.block.id(), storage, net, None, None)
191+
Self::new(
192+
time_service,
193+
executed_block.block.id(),
194+
storage,
195+
net,
196+
None,
197+
None,
198+
)
195199
}
196200

197201
pub fn current_epoch_uncles_size(&self) -> u64 {
@@ -370,15 +374,15 @@ impl BlockChain {
370374
}
371375

372376
pub fn verify_with_verifier<V>(&mut self, block: Block) -> Result<VerifiedBlock>
373-
where
374-
V: BlockVerifier,
377+
where
378+
V: BlockVerifier,
375379
{
376380
V::verify_block(self, block)
377381
}
378382

379383
pub fn apply_with_verifier<V>(&mut self, block: Block) -> Result<ExecutedBlock>
380-
where
381-
V: BlockVerifier,
384+
where
385+
V: BlockVerifier,
382386
{
383387
let verified_block = self.verify_with_verifier::<V>(block)?;
384388
watch(CHAIN_WATCH_NAME, "n1");
@@ -755,9 +759,17 @@ impl BlockChain {
755759

756760
impl ChainReader for BlockChain {
757761
fn info(&self) -> ChainInfo {
758-
let (dag_accumulator, k_total_difficulties) = self.storage.get_lastest_snapshot().unwrap_or(None).map(|snapshot| {
759-
(Some(snapshot.accumulator_info), Some(snapshot.k_total_difficulties))
760-
}).unwrap_or((None, None));
762+
let (dag_accumulator, k_total_difficulties) = self
763+
.storage
764+
.get_lastest_snapshot()
765+
.unwrap_or(None)
766+
.map(|snapshot| {
767+
(
768+
Some(snapshot.accumulator_info),
769+
Some(snapshot.k_total_difficulties),
770+
)
771+
})
772+
.unwrap_or((None, None));
761773
ChainInfo::new(
762774
self.status.head.header().chain_id(),
763775
self.genesis_hash,
@@ -779,10 +791,6 @@ impl ChainReader for BlockChain {
779791
self.status.status.head().clone()
780792
}
781793

782-
fn net_id(&self) -> ChainNetworkID {
783-
self.net.clone()
784-
}
785-
786794
fn get_header(&self, hash: HashValue) -> Result<Option<BlockHeader>> {
787795
self.storage
788796
.get_block_header_by_hash(hash)
@@ -1110,6 +1118,10 @@ impl ChainReader for BlockChain {
11101118
state_proof,
11111119
}))
11121120
}
1121+
1122+
fn net_id(&self) -> ChainNetworkID {
1123+
self.net.clone()
1124+
}
11131125
}
11141126

11151127
impl BlockChain {
@@ -1214,11 +1226,14 @@ impl BlockChain {
12141226
Ok(event_with_infos)
12151227
}
12161228

1229+
#[allow(dead_code)]
12171230
fn connect_dag(&mut self, executed_block: ExecutedBlock) -> Result<ExecutedBlock> {
12181231
let dag = self.dag.clone().expect("dag should init with blockdag");
12191232
let (new_tip_block, _) = (executed_block.block(), executed_block.block_info());
12201233
let mut tips = self
1221-
.status.dag_tips().as_ref()
1234+
.status
1235+
.dag_tips()
1236+
.as_ref()
12221237
.expect("Tips should exist on dag")
12231238
.clone();
12241239
let parents = executed_block
@@ -1278,18 +1293,18 @@ impl BlockChain {
12781293
impl ChainWriter for BlockChain {
12791294
fn can_connect(&self, executed_block: &ExecutedBlock) -> bool {
12801295
if executed_block.block.header().parent_hash() == self.status.status.head().id() {
1281-
return true;
1296+
true
12821297
} else {
1283-
return Self::calculate_dag_accumulator_key(
1298+
Self::calculate_dag_accumulator_key(
12841299
self.status
12851300
.status
12861301
.tips_hash
12871302
.as_ref()
12881303
.expect("dag blocks must have tips")
12891304
.clone(),
12901305
)
1291-
.expect("failed to calculate the tips hash")
1292-
== executed_block.block().header().parent_hash();
1306+
.expect("failed to calculate the tips hash")
1307+
== executed_block.block().header().parent_hash()
12931308
}
12941309
}
12951310

consensus/src/consensusdb/access.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ where
6363
}
6464
}
6565

66+
#[allow(dead_code)]
6667
pub fn iterator(
6768
&self,
6869
) -> Result<impl Iterator<Item = Result<(Box<[u8]>, S::Value), Box<dyn Error>>> + '_, StoreError>
@@ -96,6 +97,7 @@ where
9697
Ok(())
9798
}
9899

100+
#[allow(dead_code)]
99101
pub fn write_many(
100102
&self,
101103
mut writer: impl DbWriter,
@@ -109,6 +111,7 @@ where
109111
}
110112

111113
/// Write directly from an iterator and do not cache any data. NOTE: this action also clears the cache
114+
#[allow(dead_code)]
112115
pub fn write_many_without_cache(
113116
&self,
114117
mut writer: impl DbWriter,
@@ -122,12 +125,14 @@ where
122125
Ok(())
123126
}
124127

128+
#[allow(dead_code)]
125129
pub fn delete(&self, mut writer: impl DbWriter, key: S::Key) -> Result<(), StoreError> {
126130
self.cache.remove(&key);
127131
writer.delete::<S>(&key)?;
128132
Ok(())
129133
}
130134

135+
#[allow(dead_code)]
131136
pub fn delete_many(
132137
&self,
133138
mut writer: impl DbWriter,
@@ -141,6 +146,7 @@ where
141146
Ok(())
142147
}
143148

149+
#[allow(dead_code)]
144150
pub fn delete_all(&self, mut writer: impl DbWriter) -> Result<(), StoreError> {
145151
self.cache.remove_all();
146152
let keys = self
@@ -164,6 +170,7 @@ where
164170

165171
/// A dynamic iterator that can iterate through a specific prefix, and from a certain start point.
166172
//TODO: loop and chain iterators for multi-prefix iterator.
173+
#[allow(dead_code)]
167174
pub fn seek_iterator(
168175
&self,
169176
seek_from: Option<S::Key>, // iter whole range if None

consensus/src/consensusdb/consensus_ghostdag.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl From<GhostdagData> for GhostDagDataWrapper {
5757

5858
impl GhostDagDataWrapper {
5959
/// Returns an iterator to the mergeset in ascending blue work order (tie-breaking by hash)
60+
#[allow(dead_code)]
6061
pub fn ascending_mergeset_without_selected_parent<'a>(
6162
&'a self,
6263
store: &'a (impl GhostdagStoreReader + ?Sized),
@@ -91,6 +92,7 @@ impl GhostDagDataWrapper {
9192
}
9293

9394
/// Returns an iterator to the mergeset in descending blue work order (tie-breaking by hash)
95+
#[allow(dead_code)]
9496
pub fn descending_mergeset_without_selected_parent<'a>(
9597
&'a self,
9698
store: &'a (impl GhostdagStoreReader + ?Sized),
@@ -129,6 +131,7 @@ impl GhostDagDataWrapper {
129131
/// Returns an iterator to the mergeset in topological consensus order -- starting with the selected parent,
130132
/// and adding the mergeset in increasing blue work order. Note that this is a topological order even though
131133
/// the selected parent has highest blue work by def -- since the mergeset is in its anticone.
134+
#[allow(dead_code)]
132135
pub fn consensus_ordered_mergeset<'a>(
133136
&'a self,
134137
store: &'a (impl GhostdagStoreReader + ?Sized),
@@ -140,6 +143,7 @@ impl GhostDagDataWrapper {
140143
}
141144

142145
/// Returns an iterator to the mergeset in topological consensus order without the selected parent
146+
#[allow(dead_code)]
143147
pub fn consensus_ordered_mergeset_without_selected_parent<'a>(
144148
&'a self,
145149
store: &'a (impl GhostdagStoreReader + ?Sized),

consensus/src/consensusdb/consensus_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use starcoin_crypto::HashValue as Hash;
1111
use starcoin_types::block::BlockHeader;
1212
use starcoin_types::{
1313
blockhash::BlockLevel,
14-
consensus_header::{CompactHeaderData, ConsensusHeader, HeaderWithBlockLevel},
14+
consensus_header::{CompactHeaderData, HeaderWithBlockLevel},
1515
U256,
1616
};
1717
use std::sync::Arc;

consensus/src/consensusdb/consensus_reachability.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub struct StagingReachabilityStore<'a> {
240240
}
241241

242242
impl<'a> StagingReachabilityStore<'a> {
243+
#[allow(dead_code)]
243244
pub fn new(store_read: RwLockUpgradableReadGuard<'a, DbReachabilityStore>) -> Self {
244245
Self {
245246
store_read,
@@ -248,6 +249,7 @@ impl<'a> StagingReachabilityStore<'a> {
248249
}
249250
}
250251

252+
#[allow(dead_code)]
251253
pub fn commit(
252254
self,
253255
batch: &mut WriteBatch,
@@ -269,6 +271,7 @@ impl<'a> StagingReachabilityStore<'a> {
269271
}
270272

271273
impl ReachabilityStore for StagingReachabilityStore<'_> {
274+
#[allow(dead_code)]
272275
fn init(&mut self, origin: Hash, capacity: Interval) -> Result<(), StoreError> {
273276
self.insert(origin, Hash::new(blockhash::NONE), capacity, 0)?;
274277
self.set_reindex_root(origin)?;

consensus/src/consensusdb/consensus_relations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ mod tests {
195195
test_relations_store(db.relations_store);
196196
}
197197

198-
fn test_relations_store<T: RelationsStore>(mut store: T) {
198+
fn test_relations_store<T: RelationsStore>(store: T) {
199199
let parents = [
200200
(1, vec![]),
201201
(2, vec![1]),

0 commit comments

Comments
 (0)