Commit 0dae1d5 1 parent adb8d21 commit 0dae1d5 Copy full SHA for 0dae1d5
File tree 3 files changed +14
-7
lines changed
3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -1340,9 +1340,10 @@ impl Chain {
1340
1340
let mut segm_header_pmmr_backend: VecBackend < Hash > = VecBackend :: new ( ) ;
1341
1341
let mut segm_header_pmmr = PMMR :: new ( & mut segm_header_pmmr_backend) ;
1342
1342
1343
- for i in ( 0 ..header. height ) . step_by ( HEADERS_PER_BATCH as usize ) {
1343
+ let hash_num = txhashset:: calc_header_hashes_from_target_height ( header. height ) ;
1344
+ for i in 0 ..hash_num {
1344
1345
let data = self
1345
- . get_header_hash_by_height ( i)
1346
+ . get_header_hash_by_height ( i * HEADERS_PER_BATCH as u64 )
1346
1347
. expect ( "Header data is expected below horizon" ) ;
1347
1348
segm_header_pmmr. push ( & data) . map_err ( |s| {
1348
1349
Error :: SyncError ( format ! ( "Unable to create Headers hash MMR, {}" , s) )
Original file line number Diff line number Diff line change @@ -47,6 +47,12 @@ pub struct HeaderHashesDesegmenter {
47
47
pibd_params : Arc < PibdParams > ,
48
48
}
49
49
50
+ /// This formula must be the same for segmenter and desegmenter
51
+ /// Both party needs to be onthe same page regarding the size of the data
52
+ pub fn calc_header_hashes_from_target_height ( target_height : u64 ) -> u64 {
53
+ target_height / HEADERS_PER_BATCH as u64 + 1
54
+ }
55
+
50
56
impl HeaderHashesDesegmenter {
51
57
/// Create a new segmenter based on the provided txhashset and the specified block header
52
58
pub fn new (
@@ -55,7 +61,7 @@ impl HeaderHashesDesegmenter {
55
61
headers_root_hash : Hash , // target height and headers_root_hash must be get as a result of handshake process.
56
62
pibd_params : Arc < PibdParams > ,
57
63
) -> Self {
58
- let n_leaves = target_height / HEADERS_PER_BATCH as u64 + 1 ;
64
+ let n_leaves = calc_header_hashes_from_target_height ( target_height) ;
59
65
let header_pmmr_size = pmmr:: insertion_to_pmmr_index ( n_leaves) ;
60
66
let header_segments = Desegmenter :: generate_segments (
61
67
Hash :: LEN ,
Original file line number Diff line number Diff line change @@ -378,8 +378,8 @@ impl DesegmenterRequestor {
378
378
}
379
379
}
380
380
fn test_pibd_copy_impl ( src_root_dir : & str , dest_root_dir : & str ) {
381
- global:: set_global_chain_type ( global:: ChainTypes :: Mainnet ) ;
382
- let genesis = genesis:: genesis_main ( ) ;
381
+ global:: set_global_chain_type ( global:: ChainTypes :: Floonet ) ;
382
+ let genesis = genesis:: genesis_floo ( ) ;
383
383
384
384
let src_responder = Arc :: new ( SegmenterResponder :: new ( src_root_dir, genesis. clone ( ) ) ) ;
385
385
@@ -432,8 +432,8 @@ fn test_pibd_copy_real() {
432
432
util:: init_test_logger ( ) ;
433
433
434
434
// if testing against a real chain, insert location here
435
- let src_root_dir = format ! ( "/Users/bay/.mwc/main_orig/chain_data " ) ;
436
- let dest_root_dir = format ! ( "/Users/bay/.mwc/main_copy/chain_data " ) ;
435
+ let src_root_dir = format ! ( "/Users/bay/.mwc/floo_orig " ) ;
436
+ let dest_root_dir = format ! ( "/Users/bay/.mwc/floo_copy " ) ;
437
437
438
438
//self::chain_test_helper::clean_output_dir(&dest_root_dir);
439
439
test_pibd_copy_impl ( & src_root_dir, & dest_root_dir) ;
You can’t perform that action at this time.
0 commit comments