@ -41,7 +41,6 @@ class FullSyncTargetManager<C> extends SyncTargetManager<C> {
private final SynchronizerConfiguration config ;
private final SynchronizerConfiguration config ;
private final ProtocolContext < C > protocolContext ;
private final ProtocolContext < C > protocolContext ;
private final EthContext ethContext ;
private final EthContext ethContext ;
private final SyncState syncState ;
FullSyncTargetManager (
FullSyncTargetManager (
final SynchronizerConfiguration config ,
final SynchronizerConfiguration config ,
@ -54,7 +53,6 @@ class FullSyncTargetManager<C> extends SyncTargetManager<C> {
this . config = config ;
this . config = config ;
this . protocolContext = protocolContext ;
this . protocolContext = protocolContext ;
this . ethContext = ethContext ;
this . ethContext = ethContext ;
this . syncState = syncState ;
}
}
@Override
@Override
@ -82,10 +80,7 @@ class FullSyncTargetManager<C> extends SyncTargetManager<C> {
return completedFuture ( Optional . empty ( ) ) ;
return completedFuture ( Optional . empty ( ) ) ;
} else {
} else {
final EthPeer bestPeer = maybeBestPeer . get ( ) ;
final EthPeer bestPeer = maybeBestPeer . get ( ) ;
final long peerHeight = bestPeer . chainState ( ) . getEstimatedHeight ( ) ;
if ( isSyncTargetReached ( bestPeer ) ) {
final UInt256 peerTd = bestPeer . chainState ( ) . getBestBlock ( ) . getTotalDifficulty ( ) ;
if ( peerTd . compareTo ( syncState . chainHeadTotalDifficulty ( ) ) < = 0
& & peerHeight < = syncState . chainHeadNumber ( ) ) {
// We're caught up to our best peer, try again when a new peer connects
// We're caught up to our best peer, try again when a new peer connects
LOG . debug ( "Caught up to best peer: " + bestPeer . chainState ( ) . getEstimatedHeight ( ) ) ;
LOG . debug ( "Caught up to best peer: " + bestPeer . chainState ( ) . getEstimatedHeight ( ) ) ;
return completedFuture ( Optional . empty ( ) ) ;
return completedFuture ( Optional . empty ( ) ) ;
@ -94,6 +89,15 @@ class FullSyncTargetManager<C> extends SyncTargetManager<C> {
}
}
}
}
@Override
public boolean isSyncTargetReached ( final EthPeer peer ) {
final long peerHeight = peer . chainState ( ) . getEstimatedHeight ( ) ;
final UInt256 peerTd = peer . chainState ( ) . getBestBlock ( ) . getTotalDifficulty ( ) ;
return peerTd . compareTo ( syncState . chainHeadTotalDifficulty ( ) ) < = 0
& & peerHeight < = syncState . chainHeadNumber ( ) ;
}
@Override
@Override
public boolean shouldSwitchSyncTarget ( final SyncTarget currentTarget ) {
public boolean shouldSwitchSyncTarget ( final SyncTarget currentTarget ) {
final EthPeer currentPeer = currentTarget . peer ( ) ;
final EthPeer currentPeer = currentTarget . peer ( ) ;