@ -9,7 +9,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger ;
import org.qora.block.Block ;
import org.qora.block.Block.ValidationResult ;
import org.qora.block.BlockChain ;
import org.qora.data.block.BlockData ;
import org.qora.data.network.BlockSummaryData ;
import org.qora.data.transaction.TransactionData ;
@ -28,7 +27,6 @@ import org.qora.repository.Repository;
import org.qora.repository.RepositoryManager ;
import org.qora.transaction.Transaction ;
import org.qora.transaction.Transaction.ApprovalStatus ;
import org.qora.utils.NTP ;
public class Synchronizer {
@ -38,8 +36,6 @@ public class Synchronizer {
private static final int MAXIMUM_BLOCK_STEP = 500 ;
private static final int MAXIMUM_HEIGHT_DELTA = 300 ; // XXX move to blockchain config?
private static final int MAXIMUM_COMMON_DELTA = 60 ; // XXX move to blockchain config?
/** Maximum age for our latest block before we consider ditching our fork. */
private static final long MAXIMUM_TIP_AGE = BlockChain . getInstance ( ) . getMaxBlockTime ( ) * 1000L * 10 ; // XXX move to blockchain config?
private static final int SYNC_BATCH_SIZE = 200 ;
private static Synchronizer instance ;
@ -103,9 +99,9 @@ public class Synchronizer {
byte [ ] peersLastBlockSignature = peer . getPeerData ( ) . getLastBlockSignature ( ) ;
byte [ ] ourLastBlockSignature = ourLatestBlockData . getSignature ( ) ;
if ( peerHeight = = ourHeight & & ( peersLastBlockSignature = = null | | ! Arrays . equals ( peersLastBlockSignature , ourLastBlockSignature ) ) )
LOGGER . info ( String . format ( "Synchronizing with peer %s at height %d, our height %d, signatures differ" , peer , peerHeight , ourHeight ) ) ;
LOGGER . debug ( String . format ( "Synchronizing with peer %s at height %d, our height %d, signatures differ" , peer , peerHeight , ourHeight ) ) ;
else
LOGGER . info ( String . format ( "Synchronizing with peer %s at height %d, our height %d" , peer , peerHeight , ourHeight ) ) ;
LOGGER . debug ( String . format ( "Synchronizing with peer %s at height %d, our height %d" , peer , peerHeight , ourHeight ) ) ;
List < byte [ ] > signatures = findSignaturesFromCommonBlock ( peer , ourHeight ) ;
if ( signatures = = null ) {
@ -134,9 +130,9 @@ public class Synchronizer {
// If common block is peer's latest block then we simply have the same, or longer, chain to peer, so exit now
if ( commonBlockHeight = = peerHeight ) {
if ( peerHeight = = ourHeight )
LOGGER . info ( String . format ( "We have the same blockchain as peer %s" , peer ) ) ;
LOGGER . debug ( String . format ( "We have the same blockchain as peer %s" , peer ) ) ;
else
LOGGER . info ( String . format ( "We have the same blockchain as peer %s, but longer" , peer ) ) ;
LOGGER . debug ( String . format ( "We have the same blockchain as peer %s, but longer" , peer ) ) ;
return SynchronizationResult . NOTHING_TO_DO ;
}
@ -151,9 +147,9 @@ public class Synchronizer {
// If we have blocks after common block then decide whether we want to sync (lowest block signature wins)
int highestMutualHeight = Math . min ( peerHeight , ourHeight ) ;
// XXX This might be obsolete now
// If our latest block is very old, we're very behind and should ditch our fork.
if ( ourInitialHeight > commonBlockHeight & & ourLatestBlockData . getTimestamp ( ) < NTP . getTime ( ) - MAXIMUM_TIP_AGE ) {
final long minLatestBlockTimestamp = Controller . getMinimumLatestBlockTimestamp ( ) ;
if ( ourInitialHeight > commonBlockHeight & & ourLatestBlockData . getTimestamp ( ) < minLatestBlockTimestamp ) {
LOGGER . info ( String . format ( "Ditching our chain after height %d as our latest block is very old" , commonBlockHeight ) ) ;
highestMutualHeight = commonBlockHeight ;
}