@@ -4,7 +4,7 @@ use std::{
4
4
} ;
5
5
6
6
use anyhow:: { anyhow, bail, Error , Ok , Result } ;
7
- use starcoin_accumulator:: { accumulator_info:: AccumulatorInfo , Accumulator , MerkleAccumulator } ;
7
+ use starcoin_accumulator:: { accumulator_info:: AccumulatorInfo , Accumulator , MerkleAccumulator , node :: AccumulatorStoreType } ;
8
8
use starcoin_config:: { NodeConfig , TimeService } ;
9
9
use starcoin_consensus:: { dag:: types:: ghostdata:: GhostdagData , BlockDAG } ;
10
10
use starcoin_crypto:: HashValue ;
@@ -14,7 +14,7 @@ use starcoin_service_registry::{
14
14
use starcoin_storage:: {
15
15
flexi_dag:: { KTotalDifficulty , SyncFlexiDagSnapshot , SyncFlexiDagSnapshotHasher } ,
16
16
storage:: CodecKVStore ,
17
- BlockStore , Storage , SyncFlexiDagStore , block_info:: BlockInfoStore ,
17
+ BlockStore , Storage , SyncFlexiDagStore , block_info:: BlockInfoStore , Store ,
18
18
} ;
19
19
use starcoin_types:: { block:: BlockHeader , header:: DagHeader , startup_info} ;
20
20
@@ -127,6 +127,15 @@ impl ServiceRequest for ForkDagAccumulator {
127
127
type Response = anyhow:: Result < AccumulatorInfo > ;
128
128
}
129
129
130
+ #[ derive( Debug , Clone ) ]
131
+ pub struct FinishSync {
132
+ pub dag_accumulator_info : AccumulatorInfo ,
133
+ }
134
+
135
+ impl ServiceRequest for FinishSync {
136
+ type Response = anyhow:: Result < ( ) > ;
137
+ }
138
+
130
139
pub struct TipInfo {
131
140
tips : Option < Vec < HashValue > > , // some is for dag or the state of the chain is still in old version
132
141
k_total_difficulties : BTreeSet < KTotalDifficulty > ,
@@ -536,8 +545,28 @@ impl ServiceHandler<Self, ForkDagAccumulator> for FlexidagService {
536
545
} else {
537
546
self . merge_from_small_dag ( msg)
538
547
}
539
-
540
-
541
- // append the ForkDagAccumulator.new_blocks and the fetched blocks above into the forked dag accumulator
542
548
}
543
549
}
550
+
551
+ impl ServiceHandler < Self , FinishSync > for FlexidagService {
552
+ fn handle (
553
+ & mut self ,
554
+ msg : FinishSync ,
555
+ _ctx : & mut ServiceContext < FlexidagService > ,
556
+ ) -> Result < ( ) > {
557
+ let dag_accumulator = self . dag_accumulator . ok_or_else ( || anyhow ! ( "the dag_accumulator is none when sync finish" ) ) ?;
558
+ let local_info = dag_accumulator. get_info ( ) ;
559
+ if msg. dag_accumulator_info . get_num_leaves ( ) < local_info. get_num_leaves ( ) {
560
+ let mut new_dag_accumulator = MerkleAccumulator :: new_with_info ( msg. dag_accumulator_info , self . storage . get_accumulator_store ( AccumulatorStoreType :: SyncDag ) ) ;
561
+ for index in msg. dag_accumulator_info . get_num_leaves ( ) ..local_info. get_num_leaves ( ) {
562
+ let key = dag_accumulator. get_leaf ( index) ?. ok_or_else ( || anyhow ! ( "the dag_accumulator leaf is none when sync finish" ) ) ?;
563
+ new_dag_accumulator. append ( & [ key] ) ?;
564
+ }
565
+ self . dag_accumulator = Some ( new_dag_accumulator) ;
566
+ Ok ( ( ) )
567
+ } else {
568
+ self . dag_accumulator = Some ( MerkleAccumulator :: new_with_info ( msg. dag_accumulator_info , self . storage . get_accumulator_store ( AccumulatorStoreType :: SyncDag ) ) ) ;
569
+ Ok ( ( ) )
570
+ }
571
+ }
572
+ }
0 commit comments