Browse Source

Use MAXIMUM_BLOCKS_REQUEST_SIZE for GetBlocksMessage and BlockMessage, instead of MAXIMUM_REQUEST_SIZE.

Currently set to 1, as serialization of the BlocksMessage data on mainnet is too slow to use this for any significant number of blocks right now. Hopefully we can find a way to optimise this process, which will allow us to use this for multiple block syncing.

Until then, sticking with single blocks should still be enough to help solve the network congestion and re-orgs we are seeing, because it gives us the ability to request the next block based on the previous block's signature, which was unavailable using GET_BLOCK. This removes the requirement to fetch all block signatures upfront, and therefore it shouldn't matter if the peer does a partial re-org whilst a node is syncing to it.
sync-multiple-blocks
CalDescent 4 years ago
parent
commit
f22f954ae3
  1. 7
      src/main/java/org/qortal/controller/Synchronizer.java

7
src/main/java/org/qortal/controller/Synchronizer.java

@ -56,6 +56,9 @@ public class Synchronizer {
/** Maximum number of block signatures we ask from peer in one go */ /** Maximum number of block signatures we ask from peer in one go */
private static final int MAXIMUM_REQUEST_SIZE = 200; // XXX move to Settings? private static final int MAXIMUM_REQUEST_SIZE = 200; // XXX move to Settings?
/** Maximum number of blocks we ask from peer in one go */
private static final int MAXIMUM_BLOCKS_REQUEST_SIZE = 1; // XXX move to Settings?
/** Number of retry attempts if a peer fails to respond with the requested data */ /** Number of retry attempts if a peer fails to respond with the requested data */
private static final int MAXIMUM_RETRIES = 1; // XXX move to Settings? private static final int MAXIMUM_RETRIES = 1; // XXX move to Settings?
@ -383,7 +386,7 @@ public class Synchronizer {
byte[] latestPeerSignature = peerBlocks.isEmpty() ? commonBlockSig : peerBlocks.get(peerBlocks.size() - 1).getSignature(); byte[] latestPeerSignature = peerBlocks.isEmpty() ? commonBlockSig : peerBlocks.get(peerBlocks.size() - 1).getSignature();
int lastPeerHeight = commonBlockHeight + peerBlocks.size(); int lastPeerHeight = commonBlockHeight + peerBlocks.size();
int numberOfBlocksToRequest = Math.min(numberBlocksRequired, MAXIMUM_REQUEST_SIZE); int numberOfBlocksToRequest = Math.min(numberBlocksRequired, MAXIMUM_BLOCKS_REQUEST_SIZE);
LOGGER.trace(String.format("Requesting %d block%s after height %d, sig %.8s", LOGGER.trace(String.format("Requesting %d block%s after height %d, sig %.8s",
numberOfBlocksToRequest, (numberOfBlocksToRequest != 1 ? "s" : ""), lastPeerHeight, Base58.encode(latestPeerSignature))); numberOfBlocksToRequest, (numberOfBlocksToRequest != 1 ? "s" : ""), lastPeerHeight, Base58.encode(latestPeerSignature)));
@ -600,7 +603,7 @@ public class Synchronizer {
if (Controller.isStopping()) if (Controller.isStopping())
return SynchronizationResult.SHUTTING_DOWN; return SynchronizationResult.SHUTTING_DOWN;
int numberRequested = Math.min(maxBatchHeight - ourHeight, MAXIMUM_REQUEST_SIZE); int numberRequested = Math.min(maxBatchHeight - ourHeight, MAXIMUM_BLOCKS_REQUEST_SIZE);
LOGGER.trace(String.format("Fetching %d blocks after height %d, sig %.8s from %s", numberRequested, ourHeight, Base58.encode(latestPeerSignature), peer)); LOGGER.trace(String.format("Fetching %d blocks after height %d, sig %.8s from %s", numberRequested, ourHeight, Base58.encode(latestPeerSignature), peer));
List<Block> blocks = this.fetchBlocks(repository, peer, latestPeerSignature, numberRequested); List<Block> blocks = this.fetchBlocks(repository, peer, latestPeerSignature, numberRequested);

Loading…
Cancel
Save