mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-15 03:35:49 +00:00
Include "size" value in the "Synchronized with peer" logs.
This indicates the size of the re-org/rollback that was required in order to perform this sync operation. It is only included if it's greater than 0 blocks.
This commit is contained in:
parent
280f7814aa
commit
4cff03e7fe
@ -59,6 +59,9 @@ public class Synchronizer {
|
|||||||
private static final int MAXIMUM_REQUEST_SIZE = 200; // XXX move to Settings?
|
private static final int MAXIMUM_REQUEST_SIZE = 200; // XXX move to Settings?
|
||||||
|
|
||||||
|
|
||||||
|
// Keep track of the size of the last re-org, so it can be logged
|
||||||
|
private int lastReorgSize;
|
||||||
|
|
||||||
private static Synchronizer instance;
|
private static Synchronizer instance;
|
||||||
|
|
||||||
public enum SynchronizationResult {
|
public enum SynchronizationResult {
|
||||||
@ -510,6 +513,9 @@ public class Synchronizer {
|
|||||||
peerHeight, Base58.encode(peersLastBlockSignature), peer.getChainTipData().getLastBlockTimestamp(),
|
peerHeight, Base58.encode(peersLastBlockSignature), peer.getChainTipData().getLastBlockTimestamp(),
|
||||||
ourInitialHeight, Base58.encode(ourLastBlockSignature), ourLatestBlockData.getTimestamp()));
|
ourInitialHeight, Base58.encode(ourLastBlockSignature), ourLatestBlockData.getTimestamp()));
|
||||||
|
|
||||||
|
// Reset last re-org size as we are starting a new sync round
|
||||||
|
this.lastReorgSize = 0;
|
||||||
|
|
||||||
List<BlockSummaryData> peerBlockSummaries = new ArrayList<>();
|
List<BlockSummaryData> peerBlockSummaries = new ArrayList<>();
|
||||||
SynchronizationResult findCommonBlockResult = fetchSummariesFromCommonBlock(repository, peer, ourInitialHeight, force, peerBlockSummaries, true);
|
SynchronizationResult findCommonBlockResult = fetchSummariesFromCommonBlock(repository, peer, ourInitialHeight, force, peerBlockSummaries, true);
|
||||||
if (findCommonBlockResult != SynchronizationResult.OK) {
|
if (findCommonBlockResult != SynchronizationResult.OK) {
|
||||||
@ -567,10 +573,19 @@ public class Synchronizer {
|
|||||||
// Commit
|
// Commit
|
||||||
repository.saveChanges();
|
repository.saveChanges();
|
||||||
|
|
||||||
|
// Create string for logging
|
||||||
final BlockData newLatestBlockData = repository.getBlockRepository().getLastBlock();
|
final BlockData newLatestBlockData = repository.getBlockRepository().getLastBlock();
|
||||||
LOGGER.info(String.format("Synchronized with peer %s to height %d, sig %.8s, ts: %d", peer,
|
String syncLog = String.format("Synchronized with peer %s to height %d, sig %.8s, ts: %d", peer,
|
||||||
newLatestBlockData.getHeight(), Base58.encode(newLatestBlockData.getSignature()),
|
newLatestBlockData.getHeight(), Base58.encode(newLatestBlockData.getSignature()),
|
||||||
newLatestBlockData.getTimestamp()));
|
newLatestBlockData.getTimestamp());
|
||||||
|
|
||||||
|
// Append re-org info
|
||||||
|
if (this.lastReorgSize > 0) {
|
||||||
|
syncLog = syncLog.concat(String.format(", size: %d", this.lastReorgSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sync info
|
||||||
|
LOGGER.info(syncLog);
|
||||||
|
|
||||||
return SynchronizationResult.OK;
|
return SynchronizationResult.OK;
|
||||||
} finally {
|
} finally {
|
||||||
@ -924,6 +939,7 @@ public class Synchronizer {
|
|||||||
// Unwind to common block (unless common block is our latest block)
|
// Unwind to common block (unless common block is our latest block)
|
||||||
int ourHeight = ourInitialHeight;
|
int ourHeight = ourInitialHeight;
|
||||||
LOGGER.debug(String.format("Orphaning blocks back to common block height %d, sig %.8s. Our height: %d", commonBlockHeight, commonBlockSig58, ourHeight));
|
LOGGER.debug(String.format("Orphaning blocks back to common block height %d, sig %.8s. Our height: %d", commonBlockHeight, commonBlockSig58, ourHeight));
|
||||||
|
int reorgSize = ourHeight - commonBlockHeight;
|
||||||
|
|
||||||
BlockData orphanBlockData = repository.getBlockRepository().fromHeight(ourInitialHeight);
|
BlockData orphanBlockData = repository.getBlockRepository().fromHeight(ourInitialHeight);
|
||||||
while (ourHeight > commonBlockHeight) {
|
while (ourHeight > commonBlockHeight) {
|
||||||
@ -972,6 +988,7 @@ public class Synchronizer {
|
|||||||
Controller.getInstance().onNewBlock(newBlock.getBlockData());
|
Controller.getInstance().onNewBlock(newBlock.getBlockData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.lastReorgSize = reorgSize;
|
||||||
return SynchronizationResult.OK;
|
return SynchronizationResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user