@ -66,7 +66,6 @@ import org.slf4j.LoggerFactory;
public class BlockPropagationManager {
public class BlockPropagationManager {
private static final Logger LOG = LoggerFactory . getLogger ( BlockPropagationManager . class ) ;
private static final Logger LOG = LoggerFactory . getLogger ( BlockPropagationManager . class ) ;
private final SynchronizerConfiguration config ;
private final SynchronizerConfiguration config ;
private final ProtocolSchedule protocolSchedule ;
private final ProtocolSchedule protocolSchedule ;
private final ProtocolContext protocolContext ;
private final ProtocolContext protocolContext ;
@ -364,6 +363,25 @@ public class BlockPropagationManager {
return getBlockFromPeers ( Optional . of ( peer ) , blockHash . number ( ) , Optional . of ( blockHash . hash ( ) ) ) ;
return getBlockFromPeers ( Optional . of ( peer ) , blockHash . number ( ) , Optional . of ( blockHash . hash ( ) ) ) ;
}
}
private void requestParentBlock ( final BlockHeader blockHeader ) {
if ( requestedBlocks . add ( blockHeader . getParentHash ( ) ) ) {
retrieveParentBlock ( blockHeader ) ;
} else {
LOG . trace ( "Parent block with hash {} was already requested" , blockHeader . getParentHash ( ) ) ;
}
}
private CompletableFuture < Block > retrieveParentBlock ( final BlockHeader blockHeader ) {
final long targetParentBlockNumber = blockHeader . getNumber ( ) - 1L ;
final Hash targetParentBlockHash = blockHeader . getParentHash ( ) ;
LOG . info (
"Retrieving parent {} of block #{} from peers" ,
targetParentBlockHash ,
blockHeader . getNumber ( ) ) ;
return getBlockFromPeers (
Optional . empty ( ) , targetParentBlockNumber , Optional . of ( targetParentBlockHash ) ) ;
}
private CompletableFuture < Block > getBlockFromPeers (
private CompletableFuture < Block > getBlockFromPeers (
final Optional < EthPeer > preferredPeer ,
final Optional < EthPeer > preferredPeer ,
final long blockNumber ,
final long blockNumber ,
@ -421,6 +439,10 @@ public class BlockPropagationManager {
if ( pendingBlocksManager . registerPendingBlock ( block , nodeId ) ) {
if ( pendingBlocksManager . registerPendingBlock ( block , nodeId ) ) {
LOG . info ( "Saving announced block {} for future import" , block . toLogString ( ) ) ;
LOG . info ( "Saving announced block {} for future import" , block . toLogString ( ) ) ;
}
}
// Request parent of the lowest announced block
pendingBlocksManager . lowestAnnouncedBlock ( ) . ifPresent ( this : : requestParentBlock ) ;
return CompletableFuture . completedFuture ( block ) ;
return CompletableFuture . completedFuture ( block ) ;
}
}
}
}