forked from Qortal/qortal
Require a complete sync in syncToPeerChain()
We have gone backwards and forwards on this one a lot recently, but now that stability has returned, it is best to tighten this up. Previously it was loosened to help reduce network load, but that is no longer a problem. With this stricter approach, it should prevent a node ending up in an incomplete state after syncing, which is the main cause of the shorter re-orgs we are seeing.
This commit is contained in:
parent
92d8c37d7d
commit
66711c2e9d
@ -785,19 +785,13 @@ public class Synchronizer {
|
|||||||
if (cachedCommonBlockData != null)
|
if (cachedCommonBlockData != null)
|
||||||
cachedCommonBlockData.setBlockSummariesAfterCommonBlock(null);
|
cachedCommonBlockData.setBlockSummariesAfterCommonBlock(null);
|
||||||
|
|
||||||
// If we have already received recent or newer blocks from this peer, go ahead and apply them
|
// If we have already received newer blocks from this peer that what we have already, go ahead and apply them
|
||||||
if (peerBlocks.size() > 0) {
|
if (peerBlocks.size() > 0) {
|
||||||
final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock();
|
final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock();
|
||||||
final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1);
|
final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1);
|
||||||
final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp();
|
final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp();
|
||||||
if (ourLatestBlockData != null && peerLatestBlock != null && minLatestBlockTimestamp != null) {
|
if (ourLatestBlockData != null && peerLatestBlock != null && minLatestBlockTimestamp != null) {
|
||||||
|
|
||||||
// If we have received at least one recent block, we can apply them
|
|
||||||
if (peerLatestBlock.getBlockData().getTimestamp() > minLatestBlockTimestamp) {
|
|
||||||
LOGGER.debug("Newly received blocks are recent, so we will apply them");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If our latest block is very old....
|
// If our latest block is very old....
|
||||||
if (ourLatestBlockData.getTimestamp() < minLatestBlockTimestamp) {
|
if (ourLatestBlockData.getTimestamp() < minLatestBlockTimestamp) {
|
||||||
// ... and we have received a block that is more recent than our latest block ...
|
// ... and we have received a block that is more recent than our latest block ...
|
||||||
@ -813,7 +807,7 @@ public class Synchronizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, give up and move on to the next peer, to avoid putting our chain into an outdated state
|
// Otherwise, give up and move on to the next peer, to avoid putting our chain into an outdated or incomplete state
|
||||||
return SynchronizationResult.NO_REPLY;
|
return SynchronizationResult.NO_REPLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,20 +831,13 @@ public class Synchronizer {
|
|||||||
nextHeight, Base58.encode(nextPeerSignature)));
|
nextHeight, Base58.encode(nextPeerSignature)));
|
||||||
|
|
||||||
if (retryCount >= maxRetries) {
|
if (retryCount >= maxRetries) {
|
||||||
|
// If we have already received newer blocks from this peer that what we have already, go ahead and apply them
|
||||||
// If we have already received recent or newer blocks from this peer, go ahead and apply them
|
|
||||||
if (peerBlocks.size() > 0) {
|
if (peerBlocks.size() > 0) {
|
||||||
final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock();
|
final BlockData ourLatestBlockData = repository.getBlockRepository().getLastBlock();
|
||||||
final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1);
|
final Block peerLatestBlock = peerBlocks.get(peerBlocks.size() - 1);
|
||||||
final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp();
|
final Long minLatestBlockTimestamp = Controller.getMinimumLatestBlockTimestamp();
|
||||||
if (ourLatestBlockData != null && peerLatestBlock != null && minLatestBlockTimestamp != null) {
|
if (ourLatestBlockData != null && peerLatestBlock != null && minLatestBlockTimestamp != null) {
|
||||||
|
|
||||||
// If we have received at least one recent block, we can apply them
|
|
||||||
if (peerLatestBlock.getBlockData().getTimestamp() > minLatestBlockTimestamp) {
|
|
||||||
LOGGER.debug("Newly received blocks are recent, so we will apply them");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If our latest block is very old....
|
// If our latest block is very old....
|
||||||
if (ourLatestBlockData.getTimestamp() < minLatestBlockTimestamp) {
|
if (ourLatestBlockData.getTimestamp() < minLatestBlockTimestamp) {
|
||||||
// ... and we have received a block that is more recent than our latest block ...
|
// ... and we have received a block that is more recent than our latest block ...
|
||||||
@ -866,7 +853,7 @@ public class Synchronizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, give up and move on to the next peer, to avoid putting our chain into an outdated state
|
// Otherwise, give up and move on to the next peer, to avoid putting our chain into an outdated or incomplete state
|
||||||
return SynchronizationResult.NO_REPLY;
|
return SynchronizationResult.NO_REPLY;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user