mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
Make stall threshold configurable and reset parameters to be more appropriate for most wallets.
This commit is contained in:
parent
f693d88620
commit
ed3ef7d15e
@ -1464,12 +1464,33 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GuardedBy("lock") private int stallPeriodSeconds = 10;
|
||||||
|
@GuardedBy("lock") private int stallMinSpeed = 15;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the stall speed: the speed at which a peer is considered to be serving us the block chain
|
||||||
|
* unacceptably slowly. Once a peer has served us slower than the given "blocks per second" for the given
|
||||||
|
* number of seconds, it is considered stalled and will be disconnected, forcing the chain download to be
|
||||||
|
* restarted from a different peer. The defaults are chosen to work well for regular wallets and platforms,
|
||||||
|
* but if you are running on a platform that is CPU constrained the default settings may need adjustment to
|
||||||
|
* avoid false stalls.
|
||||||
|
*
|
||||||
|
* @param periodSecs How many seconds the download speed must be below blocksPerSec, defaults to 10.
|
||||||
|
* @param blocksPerSec How many blocks per second the speed must be consistently below, defaults to 10.
|
||||||
|
*/
|
||||||
|
public void setStallThreshold(int periodSecs, int blocksPerSec) {
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
stallPeriodSeconds = periodSecs;
|
||||||
|
stallMinSpeed = blocksPerSec;
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ChainDownloadSpeedCalculator extends AbstractPeerEventListener implements Runnable {
|
private class ChainDownloadSpeedCalculator extends AbstractPeerEventListener implements Runnable {
|
||||||
private int blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, stallWarning;
|
private int blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, stallWarning;
|
||||||
|
|
||||||
private static final int STALL_PERIOD_SECONDS = 15;
|
|
||||||
private static final int STALL_MIN_SPEED = 5;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
|
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
|
||||||
blocksInLastSecond++;
|
blocksInLastSecond++;
|
||||||
@ -1483,24 +1504,37 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void run() {
|
public void run() {
|
||||||
if (blocksInLastSecond > 0) {
|
int period;
|
||||||
log.info("{} blocks/sec, {} tx/sec, {} pre-filtered tx/sec", blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond);
|
int minSpeed;
|
||||||
if (blocksInLastSecond >= STALL_MIN_SPEED)
|
|
||||||
stallWarning = 0;
|
lock.lock();
|
||||||
|
try {
|
||||||
|
period = stallPeriodSeconds;
|
||||||
|
minSpeed = stallMinSpeed;
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (chain != null && chain.getBestChainHeight() < getMostCommonChainHeight() && blocksInLastSecond < STALL_MIN_SPEED && stallWarning > -1) {
|
|
||||||
stallWarning++;
|
synchronized (this) {
|
||||||
if (stallWarning == STALL_PERIOD_SECONDS) {
|
if (blocksInLastSecond > 0) {
|
||||||
stallWarning = -1;
|
log.info("{} blocks/sec, {} tx/sec, {} pre-filtered tx/sec", blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond);
|
||||||
Peer peer = getDownloadPeer();
|
if (blocksInLastSecond >= period)
|
||||||
log.warn("Chain download stalled: slow progress for {} seconds, disconnecting {}", STALL_PERIOD_SECONDS, peer);
|
stallWarning = 0;
|
||||||
peer.close();
|
|
||||||
}
|
}
|
||||||
|
if (chain != null && chain.getBestChainHeight() < getMostCommonChainHeight() && blocksInLastSecond < minSpeed && stallWarning > -1) {
|
||||||
|
stallWarning++;
|
||||||
|
if (stallWarning == minSpeed) {
|
||||||
|
stallWarning = -1;
|
||||||
|
Peer peer = getDownloadPeer();
|
||||||
|
log.warn("Chain download stalled: slow progress for {} seconds, disconnecting {}", period, peer);
|
||||||
|
peer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
blocksInLastSecond = 0;
|
||||||
|
txnsInLastSecond = 0;
|
||||||
|
origTxnsInLastSecond = 0;
|
||||||
}
|
}
|
||||||
blocksInLastSecond = 0;
|
|
||||||
txnsInLastSecond = 0;
|
|
||||||
origTxnsInLastSecond = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Nullable private ChainDownloadSpeedCalculator chainDownloadSpeedCalculator;
|
@Nullable private ChainDownloadSpeedCalculator chainDownloadSpeedCalculator;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user