From c2be96ad093d2c61c4d7024acdfba3b356f90ec1 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 6 Dec 2018 11:26:55 +0100 Subject: [PATCH 1/3] Fix spork syncing issue in sporks tests https://github.com/dashpay/dash/pull/2522 caused an issue with sporks syncing in tests. The introduced time check in CMasternodeSync::ProcessTick causes masternode sync to never start when mocktime is enabled, so this commit disables mocktime for sporks.py. Disabling mocktime however leads to fInitialDownload never becoming false in CMasternodeSync::UpdatedBlockTip, so mnsync is never started. To fix this, the tests now create a block before connecting the last node. This however doesn't work because node1 will ignore the "getheaders" request from node2 as it has not finished mnsync yet...so we also have to force finish mnsync for node1. --- qa/rpc-tests/sporks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qa/rpc-tests/sporks.py b/qa/rpc-tests/sporks.py index ceae32914d2f..1d5b9a10cc65 100755 --- a/qa/rpc-tests/sporks.py +++ b/qa/rpc-tests/sporks.py @@ -19,6 +19,7 @@ def __init__(self): self.is_network_split = False def setup_network(self): + disable_mocktime() self.nodes = [] self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-sporkkey=cP4EKFyJsHT39LDqgdcB43Y3YXjNyjb5Fuas1GQSeAtjnZWmZEQK"])) @@ -69,6 +70,16 @@ def run_test(self): assert(not self.get_test_spork_state(self.nodes[0])) assert(not self.get_test_spork_state(self.nodes[1])) + # Force finish mnsync node as otherwise it will never send out headers to other peers + while True: + s = self.nodes[1].mnsync('next') + if s == 'sync updated to MASTERNODE_SYNC_FINISHED': + break + sleep(0.1) + + # Generate one block to kick off masternode sync, which also starts sporks syncing for node2 + self.nodes[1].generate(1) + # connect new node and check spork propagation after restoring from cache connect_nodes(self.nodes[1], 2) start = time() From e9520428efd6e2c10ea26ec2ca5decfda22ac558 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 6 Dec 2018 11:28:57 +0100 Subject: [PATCH 2/3] Also respond with getdata for announced sporks while in IBD There was never a good reason to ignore spork announcements while in IBD. At the same time, this poses the risk of missing out on sporks while in IBD. This also fixes an issue in sporks testing, as nodes did not request for announced sporks. --- src/net_processing.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 71fc8e0b77f5..bc506e8da008 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1793,16 +1793,24 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr MSG_MASTERNODE_PING, MSG_MASTERNODE_VERIFY, }; + static std::set allowWhileInIBDObjs = { + MSG_SPORK + }; if (legacyMNObjs.count(inv.type) && deterministicMNManager->IsDeterministicMNsSporkActive()) { LogPrint("net", "ignoring (%s) inv of legacy type %d peer=%d\n", inv.hash.ToString(), inv.type, pfrom->id); continue; } pfrom->AddInventoryKnown(inv); - if (fBlocksOnly) - LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->id); - else if (!fAlreadyHave && !fImporting && !fReindex && !IsInitialBlockDownload()) - pfrom->AskFor(inv); + if (fBlocksOnly) { + LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), + pfrom->id); + } else if (!fAlreadyHave) { + bool allowWhileInIBD = allowWhileInIBDObjs.count(inv.type); + if (allowWhileInIBD || (!fImporting && !fReindex && !IsInitialBlockDownload())) { + pfrom->AskFor(inv); + } + } } // Track requests for our stuff From 170cfb98bb62b1ad13e60c39084c507386030e41 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 6 Dec 2018 12:24:54 +0100 Subject: [PATCH 3/3] Use wait_to_sync instead of custom loop --- qa/rpc-tests/sporks.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/qa/rpc-tests/sporks.py b/qa/rpc-tests/sporks.py index 1d5b9a10cc65..f556468df08e 100755 --- a/qa/rpc-tests/sporks.py +++ b/qa/rpc-tests/sporks.py @@ -71,11 +71,7 @@ def run_test(self): assert(not self.get_test_spork_state(self.nodes[1])) # Force finish mnsync node as otherwise it will never send out headers to other peers - while True: - s = self.nodes[1].mnsync('next') - if s == 'sync updated to MASTERNODE_SYNC_FINISHED': - break - sleep(0.1) + wait_to_sync(self.nodes[1], fast_mnsync=True) # Generate one block to kick off masternode sync, which also starts sporks syncing for node2 self.nodes[1].generate(1)