mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-30 00:55:54 +00:00
Added "maxRetries" setting.
This controls the maximum number of retry attempts if a peer fails to respond with the requested data.
This commit is contained in:
parent
0c3597f757
commit
fe4ae61552
@ -35,6 +35,7 @@ import org.qortal.network.message.Message.MessageType;
|
|||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
import org.qortal.repository.RepositoryManager;
|
import org.qortal.repository.RepositoryManager;
|
||||||
|
import org.qortal.settings.Settings;
|
||||||
import org.qortal.transaction.Transaction;
|
import org.qortal.transaction.Transaction;
|
||||||
import org.qortal.utils.Base58;
|
import org.qortal.utils.Base58;
|
||||||
import org.qortal.utils.NTP;
|
import org.qortal.utils.NTP;
|
||||||
@ -57,9 +58,6 @@ 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?
|
||||||
|
|
||||||
/** Number of retry attempts if a peer fails to respond with the requested data */
|
|
||||||
private static final int MAXIMUM_RETRIES = 2; // XXX move to Settings?
|
|
||||||
|
|
||||||
|
|
||||||
private static Synchronizer instance;
|
private static Synchronizer instance;
|
||||||
|
|
||||||
@ -748,6 +746,7 @@ public class Synchronizer {
|
|||||||
|
|
||||||
LOGGER.debug(() -> String.format("Fetching peer %s chain from height %d, sig %.8s", peer, commonBlockHeight, commonBlockSig58));
|
LOGGER.debug(() -> String.format("Fetching peer %s chain from height %d, sig %.8s", peer, commonBlockHeight, commonBlockSig58));
|
||||||
|
|
||||||
|
final int maxRetries = Settings.getInstance().getMaxRetries();
|
||||||
|
|
||||||
// Overall plan: fetch peer's blocks first, then orphan, then apply
|
// Overall plan: fetch peer's blocks first, then orphan, then apply
|
||||||
|
|
||||||
@ -837,7 +836,7 @@ public class Synchronizer {
|
|||||||
LOGGER.info(String.format("Peer %s failed to respond with block for height %d, sig %.8s", peer,
|
LOGGER.info(String.format("Peer %s failed to respond with block for height %d, sig %.8s", peer,
|
||||||
nextHeight, Base58.encode(nextPeerSignature)));
|
nextHeight, Base58.encode(nextPeerSignature)));
|
||||||
|
|
||||||
if (retryCount >= MAXIMUM_RETRIES) {
|
if (retryCount >= maxRetries) {
|
||||||
|
|
||||||
// If we have already received recent or newer blocks from this peer, 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) {
|
||||||
@ -875,9 +874,9 @@ public class Synchronizer {
|
|||||||
peerBlockSignatures.clear();
|
peerBlockSignatures.clear();
|
||||||
numberSignaturesRequired = peerHeight - height;
|
numberSignaturesRequired = peerHeight - height;
|
||||||
|
|
||||||
// Retry until retryCount reaches MAXIMUM_RETRIES
|
// Retry until retryCount reaches maxRetries
|
||||||
retryCount++;
|
retryCount++;
|
||||||
int triesRemaining = MAXIMUM_RETRIES - retryCount;
|
int triesRemaining = maxRetries - retryCount;
|
||||||
LOGGER.info(String.format("Re-issuing request to peer %s (%d attempt%s remaining)", peer, triesRemaining, (triesRemaining != 1 ? "s" : "")));
|
LOGGER.info(String.format("Re-issuing request to peer %s (%d attempt%s remaining)", peer, triesRemaining, (triesRemaining != 1 ? "s" : "")));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,8 @@ public class Settings {
|
|||||||
private int maxNetworkThreadPoolSize = 20;
|
private int maxNetworkThreadPoolSize = 20;
|
||||||
/** Maximum number of threads for network proof-of-work compute, used during handshaking. */
|
/** Maximum number of threads for network proof-of-work compute, used during handshaking. */
|
||||||
private int networkPoWComputePoolSize = 2;
|
private int networkPoWComputePoolSize = 2;
|
||||||
|
/** Maximum number of retry attempts if a peer fails to respond with the requested data */
|
||||||
|
private int maxRetries = 2;
|
||||||
|
|
||||||
// Which blockchains this node is running
|
// Which blockchains this node is running
|
||||||
private String blockchainConfig = null; // use default from resources
|
private String blockchainConfig = null; // use default from resources
|
||||||
@ -408,6 +410,8 @@ public class Settings {
|
|||||||
return this.networkPoWComputePoolSize;
|
return this.networkPoWComputePoolSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxRetries() { return this.maxRetries; }
|
||||||
|
|
||||||
public String getBlockchainConfig() {
|
public String getBlockchainConfig() {
|
||||||
return this.blockchainConfig;
|
return this.blockchainConfig;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user