Skip to content

Commit 97c6911

Browse files
committed
fix compile error
1 parent a2bf25c commit 97c6911

File tree

18 files changed

+234
-237
lines changed

18 files changed

+234
-237
lines changed

chain/chain-notify/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ impl EventHandler<Self, NewHeadBlock> for ChainNotifyHandlerService {
5252
item: NewHeadBlock,
5353
ctx: &mut ServiceContext<ChainNotifyHandlerService>,
5454
) {
55-
let NewHeadBlock(block_detail) = item;
56-
let block = block_detail.block();
55+
let block = item.executed_block.block();
5756
// notify header.
5857
self.notify_new_block(block, ctx);
5958
// notify events

chain/service/src/chain_service.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use starcoin_types::{
3939
};
4040
use starcoin_vm_runtime::metrics::VMMetrics;
4141
use starcoin_vm_types::access_path::AccessPath;
42-
use std::sync::{Arc, Mutex};
42+
use std::sync::Arc;
4343

4444
/// A Chain reader service to provider Reader API.
4545
pub struct ChainReaderService {
@@ -52,6 +52,7 @@ impl ChainReaderService {
5252
startup_info: StartupInfo,
5353
storage: Arc<dyn Store>,
5454
flexidag_service: ServiceRef<FlexidagService>,
55+
dag: Option<BlockDAG>,
5556
vm_metrics: Option<VMMetrics>,
5657
) -> Result<Self> {
5758
Ok(Self {
@@ -60,6 +61,7 @@ impl ChainReaderService {
6061
startup_info,
6162
storage.clone(),
6263
flexidag_service,
64+
dag,
6365
vm_metrics.clone(),
6466
)?,
6567
})
@@ -73,9 +75,10 @@ impl ServiceFactory<Self> for ChainReaderService {
7375
let startup_info = storage
7476
.get_startup_info()?
7577
.ok_or_else(|| format_err!("StartupInfo should exist at service init."))?;
78+
let dag = ctx.get_shared_opt::<BlockDAG>()?;
7679
let vm_metrics = ctx.get_shared_opt::<VMMetrics>()?;
7780
let flexidag_service = ctx.service_ref::<FlexidagService>()?.clone();
78-
Self::new(config, startup_info, storage, flexidag_service, vm_metrics)
81+
Self::new(config, startup_info, storage, flexidag_service, dag, vm_metrics)
7982
}
8083
}
8184

@@ -93,12 +96,9 @@ impl ActorService for ChainReaderService {
9396

9497
impl EventHandler<Self, NewHeadBlock> for ChainReaderService {
9598
fn handle_event(&mut self, event: NewHeadBlock, ctx: &mut ServiceContext<ChainReaderService>) {
96-
let new_head = event.0.block().header().clone();
97-
if let Err(e) = if self.inner.get_main().can_connect(event.0.as_ref()) {
98-
match self.inner.update_chain_head(event.0.as_ref().clone()) {
99-
std::result::Result::Ok(_) => (),
100-
Err(e) => Err(e),
101-
}
99+
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())
102102
} else {
103103
self.inner.switch_main(new_head.id())
104104
} {
@@ -286,6 +286,7 @@ pub struct ChainReaderServiceInner {
286286
main: BlockChain,
287287
storage: Arc<dyn Store>,
288288
flexidag_service: ServiceRef<FlexidagService>,
289+
dag: Option<BlockDAG>,
289290
vm_metrics: Option<VMMetrics>,
290291
}
291292

@@ -295,6 +296,7 @@ impl ChainReaderServiceInner {
295296
startup_info: StartupInfo,
296297
storage: Arc<dyn Store>,
297298
flexidag_service: ServiceRef<FlexidagService>,
299+
dag: Option<BlockDAG>,
298300
vm_metrics: Option<VMMetrics>,
299301
) -> Result<Self> {
300302
let net = config.net();
@@ -304,13 +306,15 @@ impl ChainReaderServiceInner {
304306
storage.clone(),
305307
config.net().id().clone(),
306308
vm_metrics.clone(),
309+
dag.clone(),
307310
)?;
308311
Ok(Self {
309312
config,
310313
startup_info,
311314
main,
312315
storage,
313316
flexidag_service,
317+
dag,
314318
vm_metrics,
315319
})
316320
}
@@ -332,6 +336,7 @@ impl ChainReaderServiceInner {
332336
self.storage.clone(),
333337
self.config.net().id().clone(),
334338
self.vm_metrics.clone(),
339+
self.dag.clone(),
335340
)?;
336341
Ok(())
337342
}
@@ -510,6 +515,8 @@ impl ReadableChainService for ChainReaderServiceInner {
510515
.map(|detail| TargetDagAccumulatorLeafDetail {
511516
accumulator_root: detail.accumulator_root,
512517
tips: detail.tips,
518+
head_block_id: detail.accumulator_root,
519+
k_total_difficulties: todo!(),
513520
})
514521
.collect())
515522
}

chain/src/chain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ impl BlockChain {
747747
pub fn get_block_accumulator(&self) -> &MerkleAccumulator {
748748
&self.block_accumulator
749749
}
750+
751+
pub fn dag(&self) -> &Option<BlockDAG> {
752+
&self.dag
753+
}
750754
}
751755

752756
impl ChainReader for BlockChain {

flexidag/src/flexidag_service.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub struct GetDagAccumulatorLeafDetail {
6464
pub struct DagAccumulatorLeafDetail {
6565
pub accumulator_root: HashValue,
6666
pub tips: Vec<HashValue>,
67+
pub head_block_id: HashValue,
68+
pub k_total_difficulties: BTreeSet<KTotalDifficulty>,
6769
}
6870

6971
impl ServiceRequest for GetDagAccumulatorLeafDetail {
@@ -501,6 +503,9 @@ impl ServiceHandler<Self, GetDagAccumulatorLeafDetail> for FlexidagService {
501503
details.push(DagAccumulatorLeafDetail {
502504
accumulator_root: snapshot.accumulator_info.accumulator_root,
503505
tips: snapshot.child_hashes,
506+
head_block_id: snapshot.head_block_id,
507+
k_total_difficulties: snapshot.k_total_difficulties,
508+
504509
});
505510
}
506511
Ok(details)

network-rpc/api/src/dag_protocol.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use std::collections::BTreeSet;
2+
13
use network_p2p_core::PeerId;
24
use serde::{Deserialize, Serialize};
35
use starcoin_crypto::HashValue;
4-
use starcoin_types::block::Block;
6+
use starcoin_types::{block::Block, dag_block::KTotalDifficulty};
57

68
#[derive(Clone, Debug, Hash, Eq, PartialOrd, Ord, PartialEq, Serialize, Deserialize)]
79
pub struct RelationshipPair {
@@ -31,6 +33,8 @@ pub struct GetTargetDagAccumulatorLeafDetail {
3133
pub struct TargetDagAccumulatorLeafDetail {
3234
pub accumulator_root: HashValue,
3335
pub tips: Vec<HashValue>,
36+
pub head_block_id: HashValue,
37+
pub k_total_difficulties: BTreeSet<KTotalDifficulty>
3438
}
3539

3640
#[derive(Debug, Serialize, Deserialize, Clone)]

network/src/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ impl Inner {
559559
peer_info.peer_info.update_chain_status(ChainStatus::new(
560560
block_header.clone(),
561561
compact_block_message.block_info.clone(),
562+
compact_block_message.compact_block.tips.clone(),
562563
));
563564

564565
if self.self_peer.known_blocks.contains(&block_id) {
@@ -717,7 +718,7 @@ impl Inner {
717718
//2. Sync status change.
718719
// may be update by repeat message, but can not find a more good way.
719720
self.network_service.update_business_status(
720-
ChainStatus::new(msg.compact_block.header.clone(), msg.block_info.clone())
721+
ChainStatus::new(msg.compact_block.header.clone(), msg.block_info.clone(), msg.compact_block.tips.clone())
721722
.encode()
722723
.expect(
723724
"Encoding the compact_block.header and block_info must be successful",

state/service/src/service.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ impl ServiceHandler<Self, StateRequest> for ChainStateService {
131131

132132
impl EventHandler<Self, NewHeadBlock> for ChainStateService {
133133
fn handle_event(&mut self, msg: NewHeadBlock, _ctx: &mut ServiceContext<ChainStateService>) {
134-
let NewHeadBlock(block) = msg;
135-
136-
let state_root = block.header().state_root();
134+
let state_root = msg.executed_block.header().state_root();
137135
debug!("ChainStateActor change StateRoot to : {:?}", state_root);
138136
self.service.change_root(state_root);
139137
}

sync/src/block_connector/block_connector_service.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use network_api::PeerProvider;
1414
use parking_lot::Mutex;
1515
use starcoin_chain_api::{ChainReader, ConnectBlockError, WriteableChainService};
1616
use starcoin_config::{NodeConfig, G_CRATE_VERSION};
17-
use starcoin_consensus::dag::blockdag::InitDagState;
1817
use starcoin_consensus::BlockDAG;
1918
use starcoin_crypto::HashValue;
2019
use starcoin_executor::VMMetrics;
@@ -34,7 +33,7 @@ use starcoin_types::block::ExecutedBlock;
3433
use starcoin_types::sync_status::SyncStatus;
3534
use starcoin_types::system_events::{MinedBlock, SyncStatusChangeEvent, SystemShutdown};
3635
use std::result;
37-
use std::sync::{Arc, Mutex};
36+
use std::sync::Arc;
3837
use sysinfo::{DiskExt, System, SystemExt};
3938

4039
const DISK_CHECKPOINT_FOR_PANIC: u64 = 1024 * 1024 * 1024 * 3;
@@ -137,7 +136,7 @@ where
137136
.get_startup_info()?
138137
.ok_or_else(|| format_err!("Startup info should exist."))?;
139138
let vm_metrics = ctx.get_shared_opt::<VMMetrics>()?;
140-
let dag = ctx.get_shared::<BlockDAG>()?;
139+
let dag = ctx.get_shared_opt::<BlockDAG>()?;
141140
let chain_service = WriteBlockChainService::new(
142141
config.clone(),
143142
startup_info,
@@ -146,6 +145,7 @@ where
146145
bus,
147146
vm_metrics,
148147
ctx.service_ref::<FlexidagService>()?.clone(),
148+
dag,
149149
)?;
150150

151151
Ok(Self::new(chain_service, config))
@@ -271,11 +271,8 @@ where
271271
debug!("try connect mined block: {}", id);
272272

273273
match self.chain_service.try_connect(new_block.as_ref().clone()) {
274-
std::result::Result::Ok(ConnectOk::DagConnected) => {
275-
match self.chain_service.dump_tips(block_header) {
276-
std::result::Result::Ok(_) => (),
277-
Err(e) => error!("failed to dump tips to dag accumulator: {}", e),
278-
}
274+
std::result::Result::Ok(()) => {
275+
self.chain_service.dump_tips(block_header);
279276
}
280277
Err(e) => {
281278
warn!("Process mined block {} fail, error: {:?}", id, e);
@@ -310,8 +307,8 @@ where
310307
std::result::Result::Ok(connect_error) => {
311308
match connect_error {
312309
ConnectBlockError::FutureBlock(block) => {
313-
self.chain_service
314-
.update_tips(msg.get_block().header().clone())?;
310+
let _ = self.chain_service
311+
.update_tips(msg.get_block().header().clone());
315312
//TODO cache future block
316313
if let std::result::Result::Ok(sync_service) =
317314
ctx.service_ref::<SyncService>()

0 commit comments

Comments
 (0)