@@ -264,7 +264,7 @@ impl PruningProofManager {
264264 Err ( e) => return Err ( e) ,
265265 } ;
266266
267- let root = if self . reachability_service . is_dag_ancestor_of ( block_at_depth_2m, block_at_depth_m_at_next_level) {
267+ let mut root = if self . reachability_service . is_dag_ancestor_of ( block_at_depth_2m, block_at_depth_m_at_next_level) {
268268 block_at_depth_2m
269269 } else if self . reachability_service . is_dag_ancestor_of ( block_at_depth_m_at_next_level, block_at_depth_2m) {
270270 block_at_depth_m_at_next_level
@@ -304,6 +304,28 @@ impl PruningProofManager {
304304 if has_required_block
305305 && ( root == self . genesis_hash || ghostdag_store. get_blue_score ( selected_tip) . unwrap ( ) >= required_level_depth)
306306 {
307+ if root != self . genesis_hash {
308+ // Try to adjust the root forward with the new known block_at_depth_2m_buffered
309+ let block_at_depth_2m_buffered =
310+ self . block_at_depth ( & * ghostdag_store, selected_tip, required_level_depth + 100 ) . unwrap ( ) ;
311+
312+ root = if self . reachability_service . is_dag_ancestor_of ( block_at_depth_2m_buffered, block_at_depth_m_at_next_level)
313+ {
314+ block_at_depth_2m_buffered
315+ } else if self . reachability_service . is_dag_ancestor_of ( block_at_depth_m_at_next_level, block_at_depth_2m_buffered)
316+ {
317+ block_at_depth_m_at_next_level
318+ } else {
319+ self . find_common_ancestor_in_chain_of_a (
320+ & * ghostdag_store,
321+ block_at_depth_m_at_next_level,
322+ block_at_depth_2m_buffered,
323+ )
324+ . map_err ( |err| format ! ( "level: {}, err: {}" , level, err) )
325+ . unwrap ( )
326+ } ;
327+ }
328+
307329 break Ok ( ( ghostdag_store, selected_tip, root) ) ;
308330 }
309331
0 commit comments