mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Fix duplicate initial headers sync
This commit is contained in:
parent
f585450062
commit
753ed61fb3
@ -98,8 +98,9 @@ class BIP68_112_113Test(ComparisonTestFramework):
|
||||
|
||||
def setup_network(self):
|
||||
# Must set the blockversion for this test
|
||||
# Must also set '-maxtipage=600100' to allow syncing from very old blocks
|
||||
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
|
||||
extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=4']],
|
||||
extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=4', '-maxtipage=600100']],
|
||||
binary=[self.options.testbinary])
|
||||
|
||||
def run_test(self):
|
||||
|
@ -91,7 +91,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
||||
def setup_network(self):
|
||||
# Start a node with maxuploadtarget of 200 MB (/24h)
|
||||
self.nodes = []
|
||||
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-maxuploadtarget=200", "-blockmaxsize=999000"]))
|
||||
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-maxuploadtarget=200", "-blockmaxsize=999000", "-maxtipage="+str(2*60*60*24*7)]))
|
||||
|
||||
def run_test(self):
|
||||
# Advance all nodes 2 weeks in the future
|
||||
@ -205,7 +205,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
||||
#stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1
|
||||
print("Restarting nodes with -whitelist=127.0.0.1")
|
||||
stop_node(self.nodes[0], 0)
|
||||
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-whitelist=127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000"])
|
||||
self.nodes[0] = start_node(0, self.options.tmpdir, ["-debug", "-whitelist=127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000", "-maxtipage="+str(2*60*60*24*7)])
|
||||
|
||||
#recreate/reconnect 3 test nodes
|
||||
test_nodes = []
|
||||
|
@ -1682,7 +1682,24 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||
|
||||
if (inv.type == MSG_BLOCK) {
|
||||
UpdateBlockAvailability(pfrom->GetId(), inv.hash);
|
||||
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
|
||||
|
||||
if (fAlreadyHave || fImporting || fReindex || mapBlocksInFlight.count(inv.hash)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CNodeState *state = State(pfrom->id);
|
||||
if (!state) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Download if this is a nice peer, or we have no nice peers and this one might do.
|
||||
bool fFetch = state->fPreferredDownload || (nPreferredDownload == 0 && !pfrom->fOneShot);
|
||||
// Only actively request headers from a single peer, unless we're close to end of initial download.
|
||||
if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - nMaxTipAge) {
|
||||
// Make sure to mark this peer as the one we are currently syncing with etc.
|
||||
state->fSyncStarted = true;
|
||||
state->nHeadersSyncTimeout = GetTimeMicros() + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (GetAdjustedTime() - pindexBestHeader->GetBlockTime())/(chainparams.GetConsensus().nPowTargetSpacing);
|
||||
nSyncStarted++;
|
||||
// We used to request the full block here, but since headers-announcements are now the
|
||||
// primary method of announcement on the network, and since, in the case that a node
|
||||
// fell back to inv we probably have a reorg which we should get the headers for first,
|
||||
@ -3099,7 +3116,7 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interr
|
||||
bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do.
|
||||
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
|
||||
// Only actively request headers from a single peer, unless we're close to end of initial download.
|
||||
if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 6 * 60 * 60) { // NOTE: was "close to today" and 24h in Bitcoin
|
||||
if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - nMaxTipAge) {
|
||||
state.fSyncStarted = true;
|
||||
state.nHeadersSyncTimeout = GetTimeMicros() + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (GetAdjustedTime() - pindexBestHeader->GetBlockTime())/(consensusParams.nPowTargetSpacing);
|
||||
nSyncStarted++;
|
||||
@ -3418,7 +3435,7 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic<bool>& interr
|
||||
// Check for headers sync timeouts
|
||||
if (state.fSyncStarted && state.nHeadersSyncTimeout < std::numeric_limits<int64_t>::max()) {
|
||||
// Detect whether this is a stalling initial-headers-sync peer
|
||||
if (pindexBestHeader->GetBlockTime() <= GetAdjustedTime() - 6*60*60) { // was 24*60*60 in bitcoin
|
||||
if (pindexBestHeader->GetBlockTime() <= GetAdjustedTime() - nMaxTipAge) {
|
||||
if (nNow > state.nHeadersSyncTimeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1)) {
|
||||
// Disconnect a (non-whitelisted) peer if it is our only sync peer,
|
||||
// and we have others we could be using instead.
|
||||
|
Loading…
Reference in New Issue
Block a user