Skip to content

Commit

Permalink
Fix spork propagation while in IBD and fix spork integration tests (#…
Browse files Browse the repository at this point in the history
…2533)

* Fix spork syncing issue in sporks tests

#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.

* 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.

* Use wait_to_sync instead of custom loop
  • Loading branch information
codablock authored Dec 6, 2018
1 parent 9100c69 commit d94092b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions qa/rpc-tests/sporks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand Down Expand Up @@ -69,6 +70,12 @@ 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
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)

# connect new node and check spork propagation after restoring from cache
connect_nodes(self.nodes[1], 2)
start = time()
Expand Down
16 changes: 12 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,16 +1793,24 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
MSG_MASTERNODE_PING,
MSG_MASTERNODE_VERIFY,
};
static std::set<int> 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
Expand Down

0 comments on commit d94092b

Please sign in to comment.