Merge #6287: test: fixes and improvements for feature_llmq_simplepose.py

a656d2f14f feat: more logging (UdjinM6)
cedd3d52be refactor: make expected_connections optional (UdjinM6)
fd2fbe06a3 fix: check mn state after each mined quorum (UdjinM6)
cce87a662a fix: should have at least 2 connections when testing isolate_mn (UdjinM6)
793f4b739f fix: connect repaired mns only (UdjinM6)
8597acd0dc fix: remember mns that don't listen and avoid them (UdjinM6)
2069625759 fix: calculate expected_complaints correctly (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented
  Fix some general mistakes and also `connect_nodes` related issues discovered while debugging #6276. Add some logging to make debugging a bit easier.

  ~NOTE: builds on top of #6278 to avoid conflicts, will rebase~ done

  ## What was done?
  pls see individual commits

  ## How Has This Been Tested?
  run tests

  ## Breaking Changes
  n/a

  ## Checklist:
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  kwvg:
    LGTM, ACK a656d2f14f
  knst:
    ACK a656d2f14f
  PastaPastaPasta:
    utACK a656d2f14f

Tree-SHA512: 30f657218ce0338f9a5a09d9a839cca9c4605740265d2182a1e143ec6ece739fecf748f7b60ccec065c17d9f6d893c0c47893be05c44bb8d34624fb4bf3c2a58
This commit is contained in:
Konstantin Akimov 2024-09-26 23:34:53 +07:00
commit 67b5d86d8c
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524

View File

@ -23,6 +23,7 @@ class LLMQSimplePoSeTest(DashTestFramework):
def run_test(self): def run_test(self):
self.deaf_mns = []
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
self.wait_for_sporks_same() self.wait_for_sporks_same()
@ -30,7 +31,7 @@ class LLMQSimplePoSeTest(DashTestFramework):
self.test_no_banning() self.test_no_banning()
# Now lets isolate MNs one by one and verify that punishment/banning happens # Now lets isolate MNs one by one and verify that punishment/banning happens
self.test_banning(self.isolate_mn, 1) self.test_banning(self.isolate_mn, 2)
self.repair_masternodes(False) self.repair_masternodes(False)
@ -44,7 +45,8 @@ class LLMQSimplePoSeTest(DashTestFramework):
self.test_no_banning() self.test_no_banning()
# Lets restart masternodes with closed ports and verify that they get banned even though they are connected to other MNs (via outbound connections) # Lets restart masternodes with closed ports and verify that they get banned even though they are connected to other MNs (via outbound connections)
self.test_banning(self.close_mn_port, 3) self.test_banning(self.close_mn_port)
self.deaf_mns.clear()
self.repair_masternodes(True) self.repair_masternodes(True)
self.reset_probe_timeouts() self.reset_probe_timeouts()
@ -61,6 +63,7 @@ class LLMQSimplePoSeTest(DashTestFramework):
self.repair_masternodes(True) self.repair_masternodes(True)
self.close_mn_port(self.mninfo[0]) self.close_mn_port(self.mninfo[0])
self.deaf_mns.clear()
self.test_no_banning(3) self.test_no_banning(3)
def isolate_mn(self, mn): def isolate_mn(self, mn):
@ -69,12 +72,13 @@ class LLMQSimplePoSeTest(DashTestFramework):
return True, True return True, True
def close_mn_port(self, mn): def close_mn_port(self, mn):
self.deaf_mns.append(mn)
self.stop_node(mn.node.index) self.stop_node(mn.node.index)
self.start_masternode(mn, ["-listen=0", "-nobind"]) self.start_masternode(mn, ["-listen=0", "-nobind"])
self.connect_nodes(mn.node.index, 0) self.connect_nodes(mn.node.index, 0)
# Make sure the to-be-banned node is still connected well via outbound connections # Make sure the to-be-banned node is still connected well via outbound connections
for mn2 in self.mninfo: for mn2 in self.mninfo:
if mn2 is not mn: if self.deaf_mns.count(mn2) == 0:
self.connect_nodes(mn.node.index, mn2.node.index) self.connect_nodes(mn.node.index, mn2.node.index)
self.reset_probe_timeouts() self.reset_probe_timeouts()
return False, False return False, False
@ -87,10 +91,11 @@ class LLMQSimplePoSeTest(DashTestFramework):
return False, True return False, True
def test_no_banning(self, expected_connections=None): def test_no_banning(self, expected_connections=None):
for _ in range(3): for i in range(3):
self.log.info(f"Testing no PoSe banning in normal conditions {i + 1}/3")
self.mine_quorum(expected_connections=expected_connections) self.mine_quorum(expected_connections=expected_connections)
for mn in self.mninfo: for mn in self.mninfo:
assert not self.check_punished(mn) and not self.check_banned(mn) assert not self.check_punished(mn) and not self.check_banned(mn)
def mine_quorum_less_checks(self, expected_good_nodes, mninfos_online): def mine_quorum_less_checks(self, expected_good_nodes, mninfos_online):
# Unlike in mine_quorum we skip most of the checks and only care about # Unlike in mine_quorum we skip most of the checks and only care about
@ -154,13 +159,15 @@ class LLMQSimplePoSeTest(DashTestFramework):
return new_quorum return new_quorum
def test_banning(self, invalidate_proc, expected_connections): def test_banning(self, invalidate_proc, expected_connections=None):
mninfos_online = self.mninfo.copy() mninfos_online = self.mninfo.copy()
mninfos_valid = self.mninfo.copy() mninfos_valid = self.mninfo.copy()
expected_contributors = len(mninfos_online) expected_contributors = len(mninfos_online)
for _ in range(2): for i in range(2):
self.log.info(f"Testing PoSe banning due to {invalidate_proc.__name__} {i + 1}/2")
mn = mninfos_valid.pop() mn = mninfos_valid.pop()
went_offline, instant_ban = invalidate_proc(mn) went_offline, instant_ban = invalidate_proc(mn)
expected_complaints = expected_contributors - 1
if went_offline: if went_offline:
mninfos_online.remove(mn) mninfos_online.remove(mn)
expected_contributors -= 1 expected_contributors -= 1
@ -168,12 +175,16 @@ class LLMQSimplePoSeTest(DashTestFramework):
# NOTE: Min PoSe penalty is 100 (see CDeterministicMNList::CalcMaxPoSePenalty()), # NOTE: Min PoSe penalty is 100 (see CDeterministicMNList::CalcMaxPoSePenalty()),
# so nodes are PoSe-banned in the same DKG they misbehave without being PoSe-punished first. # so nodes are PoSe-banned in the same DKG they misbehave without being PoSe-punished first.
if instant_ban: if instant_ban:
assert expected_connections is not None
self.log.info("Expecting instant PoSe banning")
self.reset_probe_timeouts() self.reset_probe_timeouts()
self.mine_quorum(expected_connections=expected_connections, expected_members=expected_contributors, expected_contributions=expected_contributors, expected_complaints=expected_contributors-1, expected_commitments=expected_contributors, mninfos_online=mninfos_online, mninfos_valid=mninfos_valid) self.mine_quorum(expected_connections=expected_connections, expected_members=expected_contributors, expected_contributions=expected_contributors, expected_complaints=expected_complaints, expected_commitments=expected_contributors, mninfos_online=mninfos_online, mninfos_valid=mninfos_valid)
else: else:
# It's ok to miss probes/quorum connections up to 5 times. # It's ok to miss probes/quorum connections up to 5 times.
# 6th time is when it should be banned for sure. # 6th time is when it should be banned for sure.
for _ in range(6): assert expected_connections is None
for j in range(6):
self.log.info(f"Accumulating PoSe penalty {j + 1}/6")
self.reset_probe_timeouts() self.reset_probe_timeouts()
self.mine_quorum_less_checks(expected_contributors - 1, mninfos_online) self.mine_quorum_less_checks(expected_contributors - 1, mninfos_online)
@ -184,7 +195,7 @@ class LLMQSimplePoSeTest(DashTestFramework):
expected_contributors -= 1 expected_contributors -= 1
def repair_masternodes(self, restart): def repair_masternodes(self, restart):
# Repair all nodes self.log.info("Repairing all banned and punished masternodes")
for mn in self.mninfo: for mn in self.mninfo:
if self.check_banned(mn) or self.check_punished(mn): if self.check_banned(mn) or self.check_punished(mn):
addr = self.nodes[0].getnewaddress() addr = self.nodes[0].getnewaddress()
@ -195,7 +206,7 @@ class LLMQSimplePoSeTest(DashTestFramework):
self.start_masternode(mn) self.start_masternode(mn)
else: else:
mn.node.setnetworkactive(True) mn.node.setnetworkactive(True)
self.connect_nodes(mn.node.index, 0) self.connect_nodes(mn.node.index, 0)
# syncing blocks only since node 0 has txes waiting to be mined # syncing blocks only since node 0 has txes waiting to be mined
self.sync_blocks() self.sync_blocks()