diff --git a/qa/rpc-tests/dip3-deterministicmns.py b/qa/rpc-tests/dip3-deterministicmns.py index 09ed89207582..92c2a3337e07 100755 --- a/qa/rpc-tests/dip3-deterministicmns.py +++ b/qa/rpc-tests/dip3-deterministicmns.py @@ -56,217 +56,82 @@ def run_test(self): self.nodes[0].generate(1) # generate enough for collaterals print("controller node has {} dash".format(self.nodes[0].getbalance())) - # Make sure we're below block 143 (which activates dip3) + # Make sure we're below block 432 (which activates dip3) print("testing rejection of ProTx before dip3 activation") - assert(self.nodes[0].getblockchaininfo()['blocks'] < 143) - dip3_deployment = self.nodes[0].getblockchaininfo()['bip9_softforks']['dip0003'] - assert_equal(dip3_deployment['status'], 'defined') - - self.test_fail_create_protx(self.nodes[0]) + assert(self.nodes[0].getblockchaininfo()['blocks'] < 432) mns = [] - mn_idx = 1 - for i in range(self.num_initial_mn): - mn = self.create_mn(self.nodes[0], mn_idx, 'mn-%d' % (mn_idx)) - mn_idx += 1 - mns.append(mn) - - # mature collaterals - for i in range(3): - self.nodes[0].generate(1) - time.sleep(1) - - self.write_mnconf(mns) - - self.restart_controller_node() - for mn in mns: - self.start_mn(mn) - self.sync_all() - - # force finishing of mnsync - for node in self.nodes: - self.force_finish_mnsync(node) - - # start MNs - print("start mns") - for mn in mns: - self.start_alias(self.nodes[0], mn.alias) - print("wait for MNs to appear in MN lists") - self.wait_for_mnlists(mns, True, False) - - print("testing MN payment votes") - self.test_mn_votes(10) - - print("testing instant send") - self.test_instantsend(10, 5) - - print("testing rejection of ProTx before dip3 activation (in states defined, started and locked_in)") - while self.nodes[0].getblockchaininfo()['bip9_softforks']['dip0003']['status'] == 'defined': - self.nodes[0].generate(1) - self.test_fail_create_protx(self.nodes[0]) - while self.nodes[0].getblockchaininfo()['bip9_softforks']['dip0003']['status'] == 'started': - self.nodes[0].generate(1) - self.test_fail_create_protx(self.nodes[0]) # prepare mn which should still be accepted later when dip3 activates print("creating collateral for mn-before-dip3") - before_dip3_mn = self.create_mn(self.nodes[0], mn_idx, 'mn-before-dip3') - mn_idx += 1 + before_dip3_mn = self.prepare_mn(self.nodes[0], 1, 'mn-before-dip3') + self.create_mn_collateral(self.nodes[0], before_dip3_mn) + mns.append(before_dip3_mn) - while self.nodes[0].getblockchaininfo()['bip9_softforks']['dip0003']['status'] == 'locked_in': + # block 500 starts enforcing DIP3 MN payments + while self.nodes[0].getblockcount() < 498: self.nodes[0].generate(1) + print("mining final block for DIP3 activation") + self.nodes[0].generate(1) + # We have hundreds of blocks to sync here, give it more time print("syncing blocks for all nodes") sync_blocks(self.nodes, timeout=120) # DIP3 has activated here - print("testing rejection of ProTx right before dip3 activation") - best_block = self.nodes[0].getbestblockhash() - self.nodes[0].invalidateblock(best_block) - self.test_fail_create_protx(self.nodes[0]) - self.nodes[0].reconsiderblock(best_block) - - # Now it should be possible to mine ProTx - self.sync_all() - self.test_success_create_protx(self.nodes[0]) - - print("creating collateral for mn-after-dip3") - after_dip3_mn = self.create_mn(self.nodes[0], mn_idx, 'mn-after-dip3') - # mature collaterals - for i in range(3): - self.nodes[0].generate(1) - time.sleep(1) - - print("testing if we can start a mn which was created before dip3 activation") - self.write_mnconf(mns + [before_dip3_mn, after_dip3_mn]) - self.restart_controller_node() - self.force_finish_mnsync(self.nodes[0]) - - print("start MN %s" % before_dip3_mn.alias) - mns.append(before_dip3_mn) + self.register_mn(self.nodes[0], before_dip3_mn) self.start_mn(before_dip3_mn) - self.wait_for_sporks() - self.force_finish_mnsync_list(before_dip3_mn.node) - self.start_alias(self.nodes[0], before_dip3_mn.alias) - self.wait_for_mnlists(mns) - self.wait_for_mnlists_same() + print("registering MNs") + for i in range(0, self.num_initial_mn): + mn = self.prepare_mn(self.nodes[0], i + 2, "mn-%d" % i) + mns.append(mn) - # Test if nodes still allow creating new non-ProTx MNs now - print("testing if MN start succeeds when using collateral which was created after dip3 activation") - print("start MN %s" % after_dip3_mn.alias) - mns.append(after_dip3_mn) - self.start_mn(after_dip3_mn) - self.wait_for_sporks() - self.force_finish_mnsync_list(after_dip3_mn.node) - self.start_alias(self.nodes[0], after_dip3_mn.alias) - - self.wait_for_mnlists(mns) - self.wait_for_mnlists_same() - - first_upgrade_count = 5 - mns_after_upgrade = [] - mns_to_restart = [] - mns_to_restart_later = [] - mns_protx = [] - print("upgrading first %d MNs to use ProTx (but not deterministic MN lists)" % first_upgrade_count) - for i in range(first_upgrade_count): - # let a few of the protx MNs refer to the old collaterals - fund = (i % 2) == 0 - mns[i] = self.upgrade_mn_protx(mns[i], fund) - self.nodes[0].generate(1) + # start a few MNs before they are registered and a few after they are registered + start = (i % 3) == 0 + if start: + self.start_mn(mn) + # let a few of the protx MNs refer to the existing collaterals + fund = (i % 2) == 0 if fund: - # collateral has moved, so we need to start it again - mns_to_restart.append(mns[i]) + print("register_fund %s" % mn.alias) + self.register_fund_mn(self.nodes[0], mn) else: - # collateral has not moved, so it should still be in the masternode list even after upgrade - mns_after_upgrade.append(mns[i]) - mns_to_restart_later.append(mns[i]) - mns_protx.append(mns[i]) - for i in range(first_upgrade_count, len(mns)): - mns_after_upgrade.append(mns[i]) - self.write_mnconf(mns) - - print("wait for freshly funded and upgraded MNs to disappear from MN lists (their collateral was spent)") - self.wait_for_mnlists(mns_after_upgrade, check=True) - self.wait_for_mnlists_same() - - print("restarting controller and upgraded MNs") - self.restart_controller_node() - self.force_finish_mnsync_list(self.nodes[0]) - for mn in mns_to_restart: - print("restarting MN %s" % mn.alias) - self.stop_node(mn.idx) - self.start_mn(mn) - self.force_finish_mnsync_list(mn.node) - print('start-alias on upgraded nodes') - for mn in mns_to_restart: - self.start_alias(self.nodes[0], mn.alias) - - print("wait for upgraded MNs to appear in MN list") - self.wait_for_mnlists(mns) - self.wait_for_mnlists_same() - - print("testing MN payment votes (with mixed ProTx and legacy nodes)") - self.test_mn_votes(10, test_enforcement=True) + print("create_collateral %s" % mn.alias) + self.create_mn_collateral(self.nodes[0], mn) + print("register %s" % mn.alias) + self.register_mn(self.nodes[0], mn) - print("testing instant send (with mixed ProTx and legacy nodes)") - self.test_instantsend(10, 3) - - # We still need to restart them as otherwise they won't have the BLS operator key loaded - print("restart upgraded nodes which refer to old collaterals") - for mn in mns_to_restart_later: - print("restarting MN %s" % mn.alias) - self.stop_node(mn.idx) - self.start_mn(mn) - self.force_finish_mnsync_list(mn.node) - - print("activating spork15") - height = self.nodes[0].getblockchaininfo()['blocks'] - spork15_offset = 10 - self.nodes[0].spork('SPORK_15_DETERMINISTIC_MNS_ENABLED', height + spork15_offset) - self.wait_for_sporks() - - print("test that MN list does not change before final spork15 activation") - for i in range(spork15_offset - 1): self.nodes[0].generate(1) - self.sync_all() - self.wait_for_mnlists(mns) - self.wait_for_mnlists_same() - - print("mining final block which should switch network to deterministic lists") - self.nodes[0].generate(1) - self.sync_all() - ##### WOW...we made it...we are in deterministic MN lists mode now. - ##### From now on, we don't wait for mnlists to become correct anymore, we always assert that they are correct immediately + if not start: + self.start_mn(mn) - print("assert that not upgraded MNs disappeared from MN list") - self.assert_mnlists(mns_protx) + self.sync_all() + self.assert_mnlists(mns) - # enable enforcement and keep it on from now on - self.nodes[0].spork('SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT', 0) - self.wait_for_sporks() + print("testing instant send") + self.test_instantsend(10, 3) print("test that MNs disappear from the list when the ProTx collateral is spent") spend_mns_count = 3 - mns_tmp = [] + mns_protx + mns_tmp = [] + mns dummy_txins = [] for i in range(spend_mns_count): - dummy_txin = self.spend_mn_collateral(mns_protx[i], with_dummy_input_output=True) + dummy_txin = self.spend_mn_collateral(mns[i], with_dummy_input_output=True) dummy_txins.append(dummy_txin) self.nodes[0].generate(1) self.sync_all() - mns_tmp.remove(mns_protx[i]) + mns_tmp.remove(mns[i]) self.assert_mnlists(mns_tmp) print("test that reverting the blockchain on a single node results in the mnlist to be reverted as well") for i in range(spend_mns_count): self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) - mns_tmp.append(mns_protx[spend_mns_count - 1 - i]) + mns_tmp.append(mns[spend_mns_count - 1 - i]) self.assert_mnlist(self.nodes[0], mns_tmp) print("cause a reorg with a double spend and check that mnlists are still correct on all nodes") @@ -275,21 +140,6 @@ def run_test(self): self.sync_all() self.assert_mnlists(mns_tmp) - print("upgrade remaining MNs to ProTx") - for i in range(first_upgrade_count, len(mns)): - mns[i] = self.upgrade_mn_protx(mns[i], True) - mn = mns[i] - self.nodes[0].generate(1) - mns_protx.append(mn) - print("restarting MN %s" % mn.alias) - self.stop_node(mn.idx) - self.start_mn(mn) - self.sync_all() - self.force_finish_mnsync(mn.node) - self.assert_mnlists(mns_protx) - - self.assert_mnlists(mns_protx) - print("test mn payment enforcement with deterministic MNs") for i in range(20): node = self.nodes[i % len(self.nodes)] @@ -297,18 +147,15 @@ def run_test(self): node.generate(1) self.sync_all() - print("testing instant send with deterministic MNs") - self.test_instantsend(10, 5, timeout=20) - print("testing ProUpServTx") - for mn in mns_protx: + for mn in mns: self.test_protx_update_service(mn) print("testing P2SH/multisig for payee addresses") multisig = self.nodes[0].createmultisig(1, [self.nodes[0].getnewaddress(), self.nodes[0].getnewaddress()])['address'] - self.update_mn_payee(mns_protx[0], multisig) + self.update_mn_payee(mns[0], multisig) found_multisig_payee = False - for i in range(len(mns_protx)): + for i in range(len(mns)): bt = self.nodes[0].getblocktemplate() expected_payee = bt['masternode'][0]['payee'] expected_amount = bt['masternode'][0]['amount'] @@ -325,24 +172,29 @@ def run_test(self): print("testing reusing of collaterals for replaced MNs") for i in range(0, 5): - mn = mns_protx[i] + mn = mns[i] # a few of these will actually refer to old ProRegTx internal collaterals, # which should work the same as external collaterals - mn = self.create_mn_protx(self.nodes[0], mn.idx, 'mn-protx-%d' % mn.idx, mn.collateral_txid, mn.collateral_vout) - mns_protx[i] = mn + new_mn = self.prepare_mn(self.nodes[0], mn.idx, mn.alias) + new_mn.collateral_address = mn.collateral_address + new_mn.collateral_txid = mn.collateral_txid + new_mn.collateral_vout = mn.collateral_vout + + self.register_mn(self.nodes[0], new_mn) + mns[i] = new_mn self.nodes[0].generate(1) self.sync_all() - self.assert_mnlists(mns_protx) - print("restarting MN %s" % mn.alias) - self.stop_node(mn.idx) - self.start_mn(mn) + self.assert_mnlists(mns) + print("restarting MN %s" % new_mn.alias) + self.stop_node(new_mn.idx) + self.start_mn(new_mn) self.sync_all() print("testing instant send with replaced MNs") self.test_instantsend(10, 3, timeout=20) print("testing simple PoSe") - self.assert_mnlists(mns_protx) + self.assert_mnlists(mns) self.nodes[0].spork('SPORK_17_QUORUM_DKG_ENABLED', 0) self.wait_for_sporks() @@ -351,9 +203,9 @@ def run_test(self): if skip_count != 0: self.nodes[0].generate(skip_count) - for i in range(len(mns_protx), len(mns_protx) - 2, -1): - mn = mns_protx[len(mns_protx) - 1] - mns_protx.remove(mn) + for i in range(len(mns), len(mns) - 2, -1): + mn = mns[len(mns) - 1] + mns.remove(mn) self.stop_node(mn.idx) self.nodes.remove(mn.node) @@ -382,56 +234,42 @@ def run_test(self): self.sync_all() assert(punished and banned) - def create_mn(self, node, idx, alias): + def prepare_mn(self, node, idx, alias): mn = Masternode() mn.idx = idx mn.alias = alias - mn.is_protx = False + mn.is_protx = True mn.p2p_port = p2p_port(mn.idx) blsKey = node.bls('generate') - mn.legacyMnkey = node.masternode('genkey') + mn.fundsAddr = node.getnewaddress() + mn.ownerAddr = node.getnewaddress() + mn.operatorAddr = blsKey['public'] + mn.votingAddr = mn.ownerAddr mn.blsMnkey = blsKey['secret'] + + return mn + + def create_mn_collateral(self, node, mn): mn.collateral_address = node.getnewaddress() mn.collateral_txid = node.sendtoaddress(mn.collateral_address, 1000) - rawtx = node.getrawtransaction(mn.collateral_txid, 1) - mn.collateral_vout = -1 + node.generate(1) + + rawtx = node.getrawtransaction(mn.collateral_txid, 1) for txout in rawtx['vout']: if txout['value'] == Decimal(1000): mn.collateral_vout = txout['n'] break assert(mn.collateral_vout != -1) - lock = node.lockunspent(False, [{'txid': mn.collateral_txid, 'vout': mn.collateral_vout}]) - - return mn - - def create_mn_protx_base(self, node, idx, alias, legacy_mn_key): - mn = Masternode() - mn.idx = idx - mn.alias = alias - mn.is_protx = True - mn.p2p_port = p2p_port(mn.idx) - - blsKey = node.bls('generate') - mn.fundsAddr = node.getnewaddress() - mn.ownerAddr = node.getnewaddress() - mn.operatorAddr = blsKey['public'] - mn.votingAddr = mn.ownerAddr - mn.legacyMnkey = node.masternode('genkey') if legacy_mn_key is None else legacy_mn_key - mn.blsMnkey = blsKey['secret'] - - return mn - - # create a protx MN and also fund it (using collateral inside ProRegTx) - def create_mn_protx_fund(self, node, idx, alias, legacy_mn_key=None): - mn = self.create_mn_protx_base(node, idx, alias, legacy_mn_key=legacy_mn_key) + # register a protx MN and also fund it (using collateral inside ProRegTx) + def register_fund_mn(self, node, mn): node.sendtoaddress(mn.fundsAddr, 1000.001) - mn.collateral_address = node.getnewaddress() + mn.rewards_address = node.getnewaddress() - mn.protx_hash = node.protx('register_fund', mn.collateral_address, '127.0.0.1:%d' % mn.p2p_port, mn.ownerAddr, mn.operatorAddr, mn.votingAddr, 0, mn.collateral_address, mn.fundsAddr) + mn.protx_hash = node.protx('register_fund', mn.collateral_address, '127.0.0.1:%d' % mn.p2p_port, mn.ownerAddr, mn.operatorAddr, mn.votingAddr, 0, mn.rewards_address, mn.fundsAddr) mn.collateral_txid = mn.protx_hash mn.collateral_vout = -1 @@ -442,25 +280,18 @@ def create_mn_protx_fund(self, node, idx, alias, legacy_mn_key=None): break assert(mn.collateral_vout != -1) - return mn - # create a protx MN which refers to an existing collateral - def create_mn_protx(self, node, idx, alias, collateral_txid, collateral_vout, legacy_mn_key=None): - mn = self.create_mn_protx_base(node, idx, alias, legacy_mn_key=legacy_mn_key) + def register_mn(self, node, mn): node.sendtoaddress(mn.fundsAddr, 0.001) - mn.rewards_address = node.getnewaddress() - mn.protx_hash = node.protx('register', collateral_txid, collateral_vout, '127.0.0.1:%d' % mn.p2p_port, mn.ownerAddr, mn.operatorAddr, mn.votingAddr, 0, mn.rewards_address, mn.fundsAddr) - mn.collateral_txid = collateral_txid - mn.collateral_vout = collateral_vout - - return mn + mn.protx_hash = node.protx('register', mn.collateral_txid, mn.collateral_vout, '127.0.0.1:%d' % mn.p2p_port, mn.ownerAddr, mn.operatorAddr, mn.votingAddr, 0, mn.rewards_address, mn.fundsAddr) + node.generate(1) def start_mn(self, mn): while len(self.nodes) <= mn.idx: self.nodes.append(None) - extra_args = ['-masternode=1', '-masternodeprivkey=%s' % mn.legacyMnkey, '-masternodeblsprivkey=%s' % mn.blsMnkey] + extra_args = ['-masternode=1', '-masternodeblsprivkey=%s' % mn.blsMnkey] n = start_node(mn.idx, self.options.tmpdir, self.extra_args + extra_args, redirect_stderr=True) self.nodes[mn.idx] = n for i in range(0, self.num_nodes): @@ -468,18 +299,11 @@ def start_mn(self, mn): connect_nodes_bi(self.nodes, mn.idx, i) mn.node = self.nodes[mn.idx] self.sync_all() + self.force_finish_mnsync(mn.node) def spend_mn_collateral(self, mn, with_dummy_input_output=False): return self.spend_input(mn.collateral_txid, mn.collateral_vout, 1000, with_dummy_input_output) - def upgrade_mn_protx(self, mn, refund): - if refund: - self.spend_mn_collateral(mn) - mn = self.create_mn_protx_fund(self.nodes[0], mn.idx, 'mn-protx-%d' % mn.idx, legacy_mn_key=mn.legacyMnkey) - else: - mn = self.create_mn_protx(self.nodes[0], mn.idx, 'mn-protx-%d' % mn.idx, mn.collateral_txid, mn.collateral_vout, legacy_mn_key=mn.legacyMnkey) - return mn - def update_mn_payee(self, mn, payee): self.nodes[0].sendtoaddress(mn.fundsAddr, 0.001) self.nodes[0].protx('update_registrar', mn.protx_hash, '', '', payee, mn.fundsAddr) @@ -522,90 +346,6 @@ def force_finish_mnsync_list(self, node): return time.sleep(0.1) - def write_mnconf_line(self, mn, f): - conf_line = "%s %s:%d %s %s %d\n" % (mn.alias, '127.0.0.1', mn.p2p_port, mn.legacyMnkey, mn.collateral_txid, mn.collateral_vout) - f.write(conf_line) - - def write_mnconf(self, mns): - mnconf_file = os.path.join(self.options.tmpdir, "node0/regtest/masternode.conf") - with open(mnconf_file, 'w') as f: - for mn in mns: - self.write_mnconf_line(mn, f) - - def start_alias(self, node, alias, should_fail=False): - # When generating blocks very fast, the logic in miner.cpp:UpdateTime might result in block times ahead of the real time - # This can easily accumulate to 30 seconds or more, which results in start-alias to fail as it expects the sigTime - # to be less or equal to the confirmation block time - # Solution is to sleep in this case. - lastblocktime = node.getblock(node.getbestblockhash())['time'] - sleeptime = lastblocktime - time.time() - if sleeptime > 0: - time.sleep(sleeptime + 1) # +1 to be extra sure - - start_result = node.masternode('start-alias', alias) - if not should_fail: - assert_equal(start_result, {'result': 'successful', 'alias': alias}) - else: - assert_equal(start_result, {'result': 'failed', 'alias': alias, 'errorMessage': 'Failed to verify MNB'}) - - def generate_blocks_until_winners(self, node, count, timeout=60): - # Winner lists are pretty much messed up when too many blocks were generated in a short time - # To allow proper testing of winners list, we need to slowly generate a few blocks until the list stabilizes - good_count = 0 - st = time.time() - while time.time() < st + timeout: - height = node.getblockchaininfo()['blocks'] + 10 - winners = node.masternode('winners') - if str(height) in winners: - if re.match('[0-9a-zA-Z]*:10', winners[str(height)]): - good_count += 1 - if good_count >= count: - return - else: - good_count = 0 - node.generate(1) - self.sync_all() - time.sleep(1) - raise AssertionError("generate_blocks_until_winners timed out: {}".format(node.masternode('winners'))) - - def test_mn_votes(self, block_count, test_enforcement=False): - self.generate_blocks_until_winners(self.nodes[0], self.num_nodes) - - if test_enforcement: - self.nodes[0].spork('SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT', 0) - self.wait_for_sporks() - self.test_invalid_mn_payment(self.nodes[0]) - - cur_block = 0 - while cur_block < block_count: - for n1 in self.nodes: - if cur_block >= block_count: - break - if n1 is None: - continue - - if test_enforcement: - self.test_invalid_mn_payment(n1) - - n1.generate(1) - cur_block += 1 - self.sync_all() - - height = n1.getblockchaininfo()['blocks'] - winners = self.wait_for_winners(n1, height + 10) - - for n2 in self.nodes: - if n1 is n2 or n2 is None: - continue - winners2 = self.wait_for_winners(n2, height + 10) - if winners[str(height + 10)] != winners2[str(height + 10)]: - print("winner1: " + str(winners[str(height + 10)])) - print("winner2: " + str(winners2[str(height + 10)])) - raise AssertionError("winners did not match") - - if test_enforcement: - self.nodes[0].spork('SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT', 4070908800) - def test_instantsend(self, tx_count, repeat, timeout=20): self.nodes[0].spork('SPORK_2_INSTANTSEND_ENABLED', 0) self.wait_for_sporks() @@ -657,30 +397,6 @@ def wait_for_instant_lock(self, node, node_idx, txid, timeout=10): time.sleep(0.5) raise AssertionError("wait_for_instant_lock timed out for: {} on node {}".format(txid, node_idx)) - def wait_for_winners(self, node, height, timeout=5): - st = time.time() - while time.time() < st + timeout: - winners = node.masternode('winners') - if str(height) in winners: - if re.match('[0-9a-zA-Z]*:10', winners[str(height)]): - return winners - time.sleep(0.5) - raise AssertionError("wait_for_winners for height {} timed out: {}".format(height, node.masternode('winners'))) - - def wait_for_mnlists(self, mns, timeout=30, check=False): - for node in self.nodes: - self.wait_for_mnlist(node, mns, timeout, check=check) - - def wait_for_mnlist(self, node, mns, timeout=30, check=False): - st = time.time() - while time.time() < st + timeout: - if check: - node.masternode('check') - if self.compare_mnlist(node, mns): - return - time.sleep(0.5) - raise AssertionError("wait_for_mnlist timed out") - def assert_mnlists(self, mns): for node in self.nodes: self.assert_mnlist(node, mns) @@ -722,63 +438,32 @@ def compare_mnlist(self, node, mns): return False return True - def wait_for_mnlists_same(self, timeout=30): - st = time.time() - while time.time() < st + timeout: - mnlist = self.nodes[0].masternode('list', 'status') - all_match = True - for node in self.nodes[1:]: - mnlist2 = node.masternode('list', 'status') - if mnlist != mnlist2: - all_match = False - break - if all_match: - return - time.sleep(0.5) - raise AssertionError("wait_for_mnlists_same timed out") - - def test_fail_create_protx(self, node): - # Try to create ProTx (should still fail) - fund_address = node.getnewaddress() - address = node.getnewaddress() - node.sendtoaddress(fund_address, 1000.001) # +0.001 for fees - key = node.getnewaddress() - blsKey = node.bls('generate') - assert_raises_jsonrpc(None, "bad-tx-type", node.protx, 'register_fund', address, '127.0.0.1:10000', key, blsKey['public'], key, 0, address, fund_address) - - def test_success_create_protx(self, node): - fund_address = node.getnewaddress() - address = node.getnewaddress() - txid = node.sendtoaddress(fund_address, 1000.001) # +0.001 for fees - key = node.getnewaddress() - blsKey = node.bls('generate') - node.protx('register_fund', address, '127.0.0.1:10000', key, blsKey['public'], key, 0, address, fund_address) - rawtx = node.getrawtransaction(txid, 1) - self.mine_double_spend(node, rawtx['vin'], address, use_mnmerkleroot_from_tip=True) - self.sync_all() - def spend_input(self, txid, vout, amount, with_dummy_input_output=False): # with_dummy_input_output is useful if you want to test reorgs with double spends of the TX without touching the actual txid/vout address = self.nodes[0].getnewaddress() - target = {address: amount} + + txins = [ + {'txid': txid, 'vout': vout} + ] + targets = {address: amount} + + dummy_txin = None if with_dummy_input_output: dummyaddress = self.nodes[0].getnewaddress() - target[dummyaddress] = 1 - rawtx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': vout}], target) + unspent = self.nodes[0].listunspent(20) + for u in unspent: + if u['amount'] > Decimal(1): + dummy_txin = {'txid': u['txid'], 'vout': u['vout']} + txins.append(dummy_txin) + targets[dummyaddress] = float(u['amount'] - Decimal(0.0001)) + break + + rawtx = self.nodes[0].createrawtransaction(txins, targets) rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex'] rawtx = self.nodes[0].signrawtransaction(rawtx)['hex'] new_txid = self.nodes[0].sendrawtransaction(rawtx) - if with_dummy_input_output: - decoded = self.nodes[0].decoderawtransaction(rawtx) - for i in range(len(decoded['vout'])): - # make sure this one can only be spent when explicitely creating a rawtx with these outputs as inputs - # this ensures that no other TX is chaining on top of this TX - lock = self.nodes[0].lockunspent(False, [{'txid': new_txid, 'vout': i}]) - for txin in decoded['vin']: - if txin['txid'] != txid or txin['vout'] != vout: - return txin - return None + return dummy_txin def mine_block(self, node, vtx=[], miner_address=None, mn_payee=None, mn_amount=None, use_mnmerkleroot_from_tip=False, expected_error=None): bt = node.getblocktemplate() diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index e57bbbb229f9..bc80f0ec2a66 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -63,7 +63,7 @@ void CActiveDeterministicMasternodeManager::Init() if (!fMasternodeMode) return; - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) return; + if (!deterministicMNManager->IsDIP3Active()) return; // Check that our local network configuration is correct if (!fListen) { @@ -133,7 +133,7 @@ void CActiveDeterministicMasternodeManager::UpdatedBlockTip(const CBlockIndex* p if (!fMasternodeMode) return; - if (!deterministicMNManager->IsDeterministicMNsSporkActive(pindexNew->nHeight)) return; + if (!deterministicMNManager->IsDIP3Active(pindexNew->nHeight)) return; if (state == MASTERNODE_READY) { auto mnList = deterministicMNManager->GetListForBlock(pindexNew->GetBlockHash()); @@ -190,7 +190,7 @@ bool CActiveDeterministicMasternodeManager::GetLocalAddress(CService& addrRet) void CActiveLegacyMasternodeManager::ManageState(CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) return; + if (deterministicMNManager->IsDIP3Active()) return; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- Start\n"); if (!fMasternodeMode) { @@ -272,7 +272,7 @@ std::string CActiveLegacyMasternodeManager::GetTypeString() const bool CActiveLegacyMasternodeManager::SendMasternodePing(CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) return false; + if (deterministicMNManager->IsDIP3Active()) return false; if (!fPingerEnabled) { LogPrint("masternode", "CActiveLegacyMasternodeManager::SendMasternodePing -- %s: masternode ping service is disabled, skipping...\n", GetStateString()); @@ -326,7 +326,7 @@ void CActiveLegacyMasternodeManager::DoMaintenance(CConnman& connman) void CActiveLegacyMasternodeManager::ManageStateInitial(CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) return; + if (deterministicMNManager->IsDIP3Active()) return; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); @@ -409,7 +409,7 @@ void CActiveLegacyMasternodeManager::ManageStateInitial(CConnman& connman) void CActiveLegacyMasternodeManager::ManageStateRemote() { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) return; + if (deterministicMNManager->IsDIP3Active()) return; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateRemote -- Start status = %s, type = %s, pinger enabled = %d, keyIDOperator = %s\n", GetStatus(), GetTypeString(), fPingerEnabled, activeMasternodeInfo.legacyKeyIDOperator.ToString()); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index ad695bc62d36..74fbc0f51b4d 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -197,6 +197,8 @@ class CMainParams : public CChainParams { consensus.BIP65Height = 619382; // 00000000000076d8fcea02ec0963de4abfd01e771fec0863f960c2c64fe6f357 consensus.BIP66Height = 245817; // 00000000000b1fa2dfa312863570e13fae9ca7b5566cb27e55422620b469aefa consensus.DIP0001Height = 782208; + consensus.DIP0003Height = 1000000000; // TODO update after DIP3 is deployed + consensus.DIP0003Hash = uint256(); // TODO update after DIP3 is deployed consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 20 consensus.nPowTargetTimespan = 24 * 60 * 60; // Dash: 1 day consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes @@ -359,6 +361,8 @@ class CTestNetParams : public CChainParams { consensus.BIP65Height = 2431; // 0000039cf01242c7f921dcb4806a5994bc003b48c1973ae0c89b67809c2bb2ab consensus.BIP66Height = 2075; // 0000002acdd29a14583540cb72e1c5cc83783560e38fa7081495d474fe1671f7 consensus.DIP0001Height = 5500; + consensus.DIP0003Height = 7300; + consensus.DIP0003Hash = uint256S("00000055ebc0e974ba3a3fb785c5ad4365a39637d4df168169ee80d313612f8f"); consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 20 consensus.nPowTargetTimespan = 24 * 60 * 60; // Dash: 1 day consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes @@ -504,6 +508,8 @@ class CDevNetParams : public CChainParams { consensus.BIP65Height = 1; // BIP65 activated immediately on devnet consensus.BIP66Height = 1; // BIP66 activated immediately on devnet consensus.DIP0001Height = 2; // DIP0001 activated immediately on devnet + consensus.DIP0003Height = 2; // DIP0003 activated immediately on devnet + consensus.DIP0003Hash = uint256(); consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 1 consensus.nPowTargetTimespan = 24 * 60 * 60; // Dash: 1 day consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes @@ -654,6 +660,8 @@ class CRegTestParams : public CChainParams { consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests) consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests) consensus.DIP0001Height = 2000; + consensus.DIP0003Height = 500; + consensus.DIP0003Hash = uint256(); consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 1 consensus.nPowTargetTimespan = 24 * 60 * 60; // Dash: 1 day consensus.nPowTargetSpacing = 2.5 * 60; // Dash: 2.5 minutes diff --git a/src/consensus/params.h b/src/consensus/params.h index c6dc9d5f40e8..aeca8e519207 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -129,6 +129,9 @@ struct Params { int BIP66Height; /** Block height at which DIP0001 becomes active */ int DIP0001Height; + /** Block height at which DIP0003 becomes active */ + int DIP0003Height; + uint256 DIP0003Hash; /** * Minimum blocks including miner confirmation of the total of nMinerConfirmationWindow blocks in a retargeting period, * (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments. diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index ba0f7d0190aa..8f1140fd97ab 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -9,7 +9,6 @@ #include "chainparams.h" #include "core_io.h" #include "script/standard.h" -#include "spork.h" #include "validation.h" #include "validationinterface.h" @@ -465,8 +464,14 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde __func__, nHeight, newList.GetAllMNsCount()); } - if (nHeight == GetSpork15Value()) { - LogPrintf("CDeterministicMNManager::%s -- spork15 is active now. nHeight=%d\n", __func__, nHeight); + const auto& consensusParams = Params().GetConsensus(); + if (nHeight == consensusParams.DIP0003Height) { + if (!consensusParams.DIP0003Hash.IsNull() && consensusParams.DIP0003Hash != pindex->GetBlockHash()) { + LogPrintf("CDeterministicMNManager::%s -- DIP3 activation block has wrong hash: hash=%s, expected=%s, nHeight=%d\n", __func__, + pindex->GetBlockHash().ToString(), consensusParams.DIP0003Hash.ToString(), nHeight); + return _state.DoS(100, false, REJECT_INVALID, "bad-dip3-block"); + } + LogPrintf("CDeterministicMNManager::%s -- DIP3 is active now. nHeight=%d\n", __func__, nHeight); } CleanupCache(nHeight); @@ -485,8 +490,9 @@ bool CDeterministicMNManager::UndoBlock(const CBlock& block, const CBlockIndex* evoDb.Erase(std::make_pair(DB_LIST_SNAPSHOT, blockHash)); mnListsCache.erase(blockHash); - if (nHeight == GetSpork15Value()) { - LogPrintf("CDeterministicMNManager::%s -- spork15 is not active anymore. nHeight=%d\n", __func__, nHeight); + const auto& consensusParams = Params().GetConsensus(); + if (nHeight == consensusParams.DIP0003Height) { + LogPrintf("CDeterministicMNManager::%s -- DIP3 is not active anymore. nHeight=%d\n", __func__, nHeight); } return true; @@ -834,11 +840,6 @@ bool CDeterministicMNManager::HasMNCollateralAtChainTip(const COutPoint& outpoin return dmn != nullptr; } -int64_t CDeterministicMNManager::GetSpork15Value() -{ - return sporkManager.GetSporkValue(SPORK_15_DETERMINISTIC_MNS_ENABLED); -} - bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n) { if (tx->nVersion != 3 || tx->nType != TRANSACTION_PROVIDER_REGISTER) { @@ -861,7 +862,7 @@ bool CDeterministicMNManager::IsProTxWithCollateral(const CTransactionRef& tx, u return true; } -bool CDeterministicMNManager::IsDeterministicMNsSporkActive(int nHeight) +bool CDeterministicMNManager::IsDIP3Active(int nHeight) { LOCK(cs); @@ -869,8 +870,7 @@ bool CDeterministicMNManager::IsDeterministicMNsSporkActive(int nHeight) nHeight = tipHeight; } - int64_t spork15Value = GetSpork15Value(); - return nHeight >= spork15Value; + return nHeight >= Params().GetConsensus().DIP0003Height; } void CDeterministicMNManager::CleanupCache(int nHeight) diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index ba0d1fa8541c..48729c0b9247 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -486,10 +486,9 @@ class CDeterministicMNManager // Test if given TX is a ProRegTx which also contains the collateral at index n bool IsProTxWithCollateral(const CTransactionRef& tx, uint32_t n); - bool IsDeterministicMNsSporkActive(int nHeight = -1); + bool IsDIP3Active(int nHeight = -1); private: - int64_t GetSpork15Value(); void CleanupCache(int nHeight); }; diff --git a/src/evo/providertx.cpp b/src/evo/providertx.cpp index b4a045cd99d6..a75efcba76dc 100644 --- a/src/evo/providertx.cpp +++ b/src/evo/providertx.cpp @@ -186,7 +186,7 @@ bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValid return state.DoS(10, false, REJECT_DUPLICATE, "bad-protx-dup-key"); } - if (!deterministicMNManager->IsDeterministicMNsSporkActive(pindexPrev->nHeight)) { + if (!deterministicMNManager->IsDIP3Active(pindexPrev->nHeight)) { if (ptx.keyIDOwner != ptx.keyIDVoting) { return state.DoS(10, false, REJECT_INVALID, "bad-protx-key-not-same"); } @@ -330,7 +330,7 @@ bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVal } } - if (!deterministicMNManager->IsDeterministicMNsSporkActive(pindexPrev->nHeight)) { + if (!deterministicMNManager->IsDIP3Active(pindexPrev->nHeight)) { if (dmn->pdmnState->keyIDOwner != ptx.keyIDVoting) { return state.DoS(10, false, REJECT_INVALID, "bad-protx-key-not-same"); } diff --git a/src/governance-object.cpp b/src/governance-object.cpp index 06608d663a51..5eaba3c54e22 100644 --- a/src/governance-object.cpp +++ b/src/governance-object.cpp @@ -572,7 +572,7 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast } // Check that we have a valid MN signature - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { if (!CheckSignature(infoMn.blsPubKeyOperator)) { strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey id = " + infoMn.blsPubKeyOperator.ToString(); return false; diff --git a/src/governance-vote.cpp b/src/governance-vote.cpp index 15a145df12c4..64ea6479739d 100644 --- a/src/governance-vote.cpp +++ b/src/governance-vote.cpp @@ -265,7 +265,7 @@ bool CGovernanceVote::IsValid(bool useVotingKey) const if (useVotingKey) { return CheckSignature(infoMn.keyIDVoting); } else { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return CheckSignature(infoMn.blsPubKeyOperator); } else { return CheckSignature(infoMn.legacyKeyIDOperator); diff --git a/src/governance.cpp b/src/governance.cpp index e2917a07131c..496427a40962 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -579,7 +579,7 @@ void CGovernanceManager::DoMaintenance(CConnman& connman) { if (fLiteMode || !masternodeSync.IsSynced() || ShutdownRequested()) return; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { ClearPreDIP3Votes(); RemoveInvalidProposalVotes(); } @@ -1302,7 +1302,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex, CConnman& co nCachedBlockHeight = pindex->nHeight; LogPrint("gobject", "CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n", nCachedBlockHeight); - if (deterministicMNManager->IsDeterministicMNsSporkActive(pindex->nHeight)) { + if (deterministicMNManager->IsDIP3Active(pindex->nHeight)) { ClearPreDIP3Votes(); RemoveInvalidProposalVotes(); } @@ -1401,10 +1401,10 @@ void CGovernanceManager::RemoveInvalidProposalVotes() unsigned int CGovernanceManager::GetMinVoteTime() { LOCK(cs_main); - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { return 0; } - int64_t dip3SporkHeight = sporkManager.GetSporkValue(SPORK_15_DETERMINISTIC_MNS_ENABLED); + int64_t dip3SporkHeight = Params().GetConsensus().DIP0003Height; return chainActive[dip3SporkHeight]->nTime; } diff --git a/src/init.cpp b/src/init.cpp index 92e94a383ec2..c94451be4060 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1947,7 +1947,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf(" keyIDOperator: %s\n", CBitcoinAddress(activeMasternodeInfo.legacyKeyIDOperator).ToString()); } else { - return InitError(_("You must specify a masternodeprivkey in the configuration. Please see documentation for help.")); + //return InitError(_("You must specify a masternodeprivkey in the configuration. Please see documentation for help.")); } std::string strMasterNodeBLSPrivKey = GetArg("-masternodeblsprivkey", ""); diff --git a/src/instantx.cpp b/src/instantx.cpp index 49bd568528aa..db2e2cc0eab4 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -250,7 +250,7 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman) LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternodeInfo.outpoint.ToStringShort()); continue; } - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { // not used until spork15 activation quorumModifierHash = uint256(); } @@ -1043,7 +1043,7 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const LogPrint("instantsend", "CTxLockVote::IsValid -- invalid masternodeProTxHash %s\n", masternodeProTxHash.ToString()); return false; } - } else if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + } else if (deterministicMNManager->IsDIP3Active()) { LogPrint("instantsend", "CTxLockVote::IsValid -- missing masternodeProTxHash while DIP3 is active\n"); return false; } @@ -1069,7 +1069,7 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const LogPrint("instantsend", "CTxLockVote::IsValid -- invalid quorumModifierHash %s, expected %s\n", quorumModifierHash.ToString(), expectedQuorumModifierHash.ToString()); return false; } - } else if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + } else if (deterministicMNManager->IsDIP3Active()) { LogPrint("instantsend", "CTxLockVote::IsValid -- missing quorumModifierHash while DIP3 is active\n"); return false; } @@ -1112,7 +1112,7 @@ bool CTxLockVote::CheckSignature() const return false; } - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { uint256 hash = GetSignatureHash(); CBLSSignature sig; @@ -1148,7 +1148,7 @@ bool CTxLockVote::Sign() { std::string strError; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { uint256 hash = GetSignatureHash(); CBLSSignature sig = activeMasternodeInfo.blsKeyOperator->Sign(hash); diff --git a/src/instantx.h b/src/instantx.h index 81f18c23b66c..633901adc45f 100644 --- a/src/instantx.h +++ b/src/instantx.h @@ -272,7 +272,7 @@ class CTxLockVote READWRITE(txHash); READWRITE(outpoint); READWRITE(outpointMasternode); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { // Starting with spork15 activation, the proTxHash and quorumModifierHash is included. When we bump to >= 70214, we can remove // the surrounding if. We might also remove outpointMasternode as well later READWRITE(quorumModifierHash); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index b3b00e0270bd..aca4b632b416 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -194,7 +194,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc if(CSuperblockManager::IsValid(txNew, nBlockHeight, blockReward)) { LogPrint("gobject", "%s -- Valid superblock at height %d: %s", __func__, nBlockHeight, txNew.ToString()); // only allow superblock and masternode payments in the same block after spork15 activation - if (!deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) + if (!deterministicMNManager->IsDIP3Active(nBlockHeight)) return true; // continue validation, should also pay MN } else { @@ -216,7 +216,7 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc return true; } - if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + if (deterministicMNManager->IsDIP3Active(nBlockHeight)) { // always enforce masternode payments when spork15 is active LogPrintf("%s -- ERROR: Invalid masternode payment detected at height %d: %s", __func__, nBlockHeight, txNew.ToString()); return false; @@ -241,7 +241,7 @@ void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blo CSuperblockManager::GetSuperblockPayments(nBlockHeight, voutSuperblockPaymentsRet); } - bool allowSuperblockAndMNReward = deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight); + bool allowSuperblockAndMNReward = deterministicMNManager->IsDIP3Active(nBlockHeight); // don't allow payments to superblocks AND masternodes before spork15 activation if (!voutSuperblockPaymentsRet.empty() && !allowSuperblockAndMNReward) { @@ -304,7 +304,7 @@ std::map GetRequiredPaymentsStrings(int nStartHeight, int nEnd bool doProjection = false; for(int h = nStartHeight; h < nEndHeight; h++) { - if (deterministicMNManager->IsDeterministicMNsSporkActive(h)) { + if (deterministicMNManager->IsDIP3Active(h)) { if (h <= nChainTipHeight) { auto payee = deterministicMNManager->GetListForBlock(chainActive[h - 1]->GetBlockHash()).GetMNPayee(); mapPayments.emplace(h, GetRequiredPaymentsString(h, payee)); @@ -337,7 +337,7 @@ void CMasternodePayments::Clear() bool CMasternodePayments::UpdateLastVote(const CMasternodePaymentVote& vote) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return false; LOCK(cs_mapMasternodePaymentVotes); @@ -367,7 +367,7 @@ bool CMasternodePayments::GetMasternodeTxOuts(int nBlockHeight, CAmount blockRew voutMasternodePaymentsRet.clear(); if(!GetBlockTxOuts(nBlockHeight, blockReward, voutMasternodePaymentsRet)) { - if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + if (deterministicMNManager->IsDIP3Active(nBlockHeight)) { LogPrintf("CMasternodePayments::%s -- deterministic masternode lists enabled and no payee\n", __func__); return false; } @@ -405,7 +405,7 @@ int CMasternodePayments::GetMinMasternodePaymentsProto() const { void CMasternodePayments::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; if(fLiteMode) return; // disable all Dash specific functionality @@ -592,7 +592,7 @@ bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, CAmount blockReward, CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward); - if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + if (deterministicMNManager->IsDIP3Active(nBlockHeight)) { uint256 blockHash; { LOCK(cs_main); @@ -645,7 +645,7 @@ bool CMasternodePayments::IsScheduled(const masternode_info_t& mnInfo, int nNotB { LOCK(cs_mapMasternodeBlocks); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto projectedPayees = deterministicMNManager->GetListAtChainTip().GetProjectedMNPayees(8); for (const auto &dmn : projectedPayees) { if (dmn->collateralOutpoint == mnInfo.outpoint) { @@ -830,7 +830,7 @@ std::string CMasternodePayments::GetRequiredPaymentsString(int nBlockHeight) con bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward) const { - if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + if (deterministicMNManager->IsDIP3Active(nBlockHeight)) { std::vector voutMasternodePayments; if (!GetBlockTxOuts(nBlockHeight, blockReward, voutMasternodePayments)) { LogPrintf("CMasternodePayments::%s -- ERROR failed to get payees for block at height %s\n", __func__, nBlockHeight); @@ -863,7 +863,7 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, int nBlo void CMasternodePayments::CheckAndRemove() { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return; } @@ -948,7 +948,7 @@ bool CMasternodePaymentVote::IsValid(CNode* pnode, int nValidationHeight, std::s bool CMasternodePayments::ProcessBlock(int nBlockHeight, CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + if (deterministicMNManager->IsDIP3Active(nBlockHeight)) { return true; } @@ -1087,7 +1087,7 @@ void CMasternodePayments::CheckBlockVotes(int nBlockHeight) void CMasternodePaymentVote::Relay(CConnman& connman) const { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return; } @@ -1292,7 +1292,7 @@ void CMasternodePayments::UpdatedBlockTip(const CBlockIndex *pindex, CConnman& c { if(!pindex) return; - if (deterministicMNManager->IsDeterministicMNsSporkActive(pindex->nHeight)) { + if (deterministicMNManager->IsDIP3Active(pindex->nHeight)) { return; } diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index b5cf4dc950fe..b165918dda12 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -67,7 +67,7 @@ void CMasternodeSync::SwitchToNextAsset(CConnman& connman) break; case(MASTERNODE_SYNC_WAITING): LogPrintf("CMasternodeSync::SwitchToNextAsset -- Completed %s in %llds\n", GetAssetName(), GetTime() - nTimeAssetSyncStarted); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { nCurrentAsset = MASTERNODE_SYNC_GOVERNANCE; } else { nCurrentAsset = MASTERNODE_SYNC_LIST; @@ -76,7 +76,7 @@ void CMasternodeSync::SwitchToNextAsset(CConnman& connman) break; case(MASTERNODE_SYNC_LIST): LogPrintf("CMasternodeSync::SwitchToNextAsset -- Completed %s in %llds\n", GetAssetName(), GetTime() - nTimeAssetSyncStarted); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { nCurrentAsset = MASTERNODE_SYNC_GOVERNANCE; } else { nCurrentAsset = MASTERNODE_SYNC_MNW; @@ -200,12 +200,12 @@ void CMasternodeSync::ProcessTick(CConnman& connman) connman.PushMessage(pnode, msgMaker.Make(NetMsgType::GETSPORKS)); //get current network sporks SwitchToNextAsset(connman); } else if (nCurrentAsset == MASTERNODE_SYNC_LIST) { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { mnodeman.DsegUpdate(pnode, connman); } SwitchToNextAsset(connman); } else if (nCurrentAsset == MASTERNODE_SYNC_MNW) { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { connman.PushMessage(pnode, msgMaker.Make(NetMsgType::MASTERNODEPAYMENTSYNC)); //sync payment votes } SwitchToNextAsset(connman); @@ -256,7 +256,7 @@ void CMasternodeSync::ProcessTick(CConnman& connman) // MNLIST : SYNC MASTERNODE LIST FROM OTHER CONNECTED CLIENTS if(nCurrentAsset == MASTERNODE_SYNC_LIST) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { SwitchToNextAsset(connman); connman.ReleaseNodeVector(vNodesCopy); return; @@ -300,7 +300,7 @@ void CMasternodeSync::ProcessTick(CConnman& connman) // MNW : SYNC MASTERNODE PAYMENT VOTES FROM OTHER CONNECTED CLIENTS if(nCurrentAsset == MASTERNODE_SYNC_MNW) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { SwitchToNextAsset(connman); connman.ReleaseNodeVector(vNodesCopy); return; diff --git a/src/masternode.cpp b/src/masternode.cpp index e89e49d6c8e2..f6fe9bd035c5 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -329,7 +329,7 @@ void CMasternode::UpdateLastPaid(const CBlockIndex *pindex, int nMaxBlocksToScan if(!pindex) return; - if (deterministicMNManager->IsDeterministicMNsSporkActive(pindex->nHeight)) { + if (deterministicMNManager->IsDIP3Active(pindex->nHeight)) { auto dmn = deterministicMNManager->GetListForBlock(pindex->GetBlockHash()).GetMNByCollateral(outpoint); if (!dmn || dmn->pdmnState->nLastPaidHeight == -1) { LogPrint("masternode", "CMasternode::UpdateLastPaidBlock -- searching for block with payment to %s -- not found\n", outpoint.ToStringShort()); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index b118b3839f54..42bf3301b0f1 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -82,7 +82,7 @@ bool CMasternodeMan::Add(CMasternode &mn) { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return false; if (Has(mn.outpoint)) return false; @@ -100,7 +100,7 @@ void CMasternodeMan::AskForMN(CNode* pnode, const COutPoint& outpoint, CConnman& CNetMsgMaker msgMaker(pnode->GetSendVersion()); LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; CService addrSquashed = Params().AllowMultiplePorts() ? (CService)pnode->addr : CService(pnode->addr, 0); @@ -157,7 +157,7 @@ bool CMasternodeMan::PoSeBan(const COutPoint &outpoint) { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return true; CMasternode* pmn = Find(outpoint); @@ -173,7 +173,7 @@ void CMasternodeMan::Check() { LOCK2(cs_main, cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; for (auto& mnpair : mapMasternodes) { @@ -185,7 +185,7 @@ void CMasternodeMan::Check() void CMasternodeMan::CheckAndRemove(CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; if(!masternodeSync.IsMasternodeListSynced()) return; @@ -372,7 +372,7 @@ void CMasternodeMan::CheckAndRemove(CConnman& connman) void CMasternodeMan::AddDeterministicMasternodes() { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) + if (!deterministicMNManager->IsDIP3Active()) return; bool added = false; @@ -407,7 +407,7 @@ void CMasternodeMan::AddDeterministicMasternodes() void CMasternodeMan::RemoveNonDeterministicMasternodes() { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) + if (!deterministicMNManager->IsDIP3Active()) return; bool erased = false; @@ -453,7 +453,7 @@ int CMasternodeMan::CountMasternodes(int nProtocolVersion) int nCount = 0; nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto mnList = deterministicMNManager->GetListAtChainTip(); nCount = (int)mnList.GetAllMNsCount(); } else { @@ -472,7 +472,7 @@ int CMasternodeMan::CountEnabled(int nProtocolVersion) int nCount = 0; nProtocolVersion = nProtocolVersion == -1 ? mnpayments.GetMinMasternodePaymentsProto() : nProtocolVersion; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto mnList = deterministicMNManager->GetListAtChainTip(); nCount = (int)mnList.GetValidMNsCount(); } else { @@ -507,7 +507,7 @@ void CMasternodeMan::DsegUpdate(CNode* pnode, CConnman& connman) CNetMsgMaker msgMaker(pnode->GetSendVersion()); LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; CService addrSquashed = Params().AllowMultiplePorts() ? (CService)pnode->addr : CService(pnode->addr, 0); @@ -533,7 +533,7 @@ CMasternode* CMasternodeMan::Find(const COutPoint &outpoint) { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { // This code keeps compatibility to old code depending on the non-deterministic MN lists // When deterministic MN lists get activated, we stop relying on the MNs we encountered due to MNBs and start // using the MNs found in the deterministic MN manager. To keep compatibility, we create CMasternode entries @@ -592,7 +592,7 @@ bool CMasternodeMan::GetMasternodeInfo(const COutPoint& outpoint, masternode_inf bool CMasternodeMan::GetMasternodeInfo(const CKeyID& keyIDOperator, masternode_info_t& mnInfoRet) { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return false; } else { for (const auto& mnpair : mapMasternodes) { @@ -607,7 +607,7 @@ bool CMasternodeMan::GetMasternodeInfo(const CKeyID& keyIDOperator, masternode_i bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { // we can't reliably search by payee as there might be duplicates. Also, keyIDCollateralAddress is not // always the payout address as DIP3 allows using different keys for collateral and payouts // this method is only used from ComputeBlockVersion, which has a different logic for deterministic MNs @@ -632,7 +632,7 @@ bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& bool CMasternodeMan::Has(const COutPoint& outpoint) { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return deterministicMNManager->HasValidMNCollateralAtChainTip(outpoint); } else { return mapMasternodes.find(outpoint) != mapMasternodes.end(); @@ -649,7 +649,7 @@ bool CMasternodeMan::GetNextMasternodeInQueueForPayment(bool fFilterSigTime, int bool CMasternodeMan::GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet) { - if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + if (deterministicMNManager->IsDIP3Active(nBlockHeight)) { return false; } @@ -761,7 +761,7 @@ masternode_info_t CMasternodeMan::FindRandomNotInVec(const std::vectorIsDeterministicMNsSporkActive() && !deterministicMNManager->HasValidMNCollateralAtChainTip(pmn->outpoint)) + if (deterministicMNManager->IsDIP3Active() && !deterministicMNManager->HasValidMNCollateralAtChainTip(pmn->outpoint)) continue; // found the one not in vecToExclude LogPrint("masternode", "CMasternodeMan::FindRandomNotInVec -- found, masternode=%s\n", pmn->outpoint.ToStringShort()); @@ -776,7 +776,7 @@ std::map CMasternodeMan::GetFullMasternodeMap() { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { std::map result; auto mnList = deterministicMNManager->GetListAtChainTip(); for (const auto &p : mapMasternodes) { @@ -797,7 +797,7 @@ bool CMasternodeMan::GetMasternodeScores(const uint256& nBlockHash, CMasternodeM vecMasternodeScoresRet.clear(); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto mnList = deterministicMNManager->GetListAtChainTip(); auto scores = mnList.CalculateScores(nBlockHash); for (const auto& p : scores) { @@ -917,7 +917,7 @@ void CMasternodeMan::ProcessMasternodeConnections(CConnman& connman) std::pair > CMasternodeMan::PopScheduledMnbRequestConnection() { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return std::make_pair(CService(), std::set()); } if(listScheduledMnbRequestConnections.empty()) { @@ -946,7 +946,7 @@ std::pair > CMasternodeMan::PopScheduledMnbRequestCo void CMasternodeMan::ProcessPendingMnbRequests(CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; std::pair > p = PopScheduledMnbRequestConnection(); @@ -988,7 +988,7 @@ void CMasternodeMan::ProcessPendingMnbRequests(CConnman& connman) void CMasternodeMan::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; if(fLiteMode) return; // disable all Dash specific functionality @@ -1189,7 +1189,7 @@ void CMasternodeMan::PushDsegInvs(CNode* pnode, const CMasternode& mn) void CMasternodeMan::DoFullVerificationStep(CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; if(activeMasternodeInfo.outpoint.IsNull()) return; @@ -1269,7 +1269,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) void CMasternodeMan::CheckSameAddr() { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; if(!masternodeSync.IsSynced() || mapMasternodes.empty()) return; @@ -1325,7 +1325,7 @@ void CMasternodeMan::CheckSameAddr() bool CMasternodeMan::CheckVerifyRequestAddr(const CAddress& addr, CConnman& connman) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return false; if(netfulfilledman.HasFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) { @@ -1351,7 +1351,7 @@ void CMasternodeMan::ProcessPendingMnvRequests(CConnman& connman) { LOCK(cs_mapPendingMNV); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; std::map >::iterator itPendingMNV = mapPendingMNV.begin(); @@ -1383,7 +1383,7 @@ void CMasternodeMan::SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv, { AssertLockHeld(cs_main); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; // only masternodes can sign this, why would someone ask regular node? @@ -1443,7 +1443,7 @@ void CMasternodeMan::ProcessVerifyReply(CNode* pnode, CMasternodeVerification& m { AssertLockHeld(cs_main); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; std::string strError; @@ -1582,7 +1582,7 @@ void CMasternodeMan::ProcessVerifyBroadcast(CNode* pnode, const CMasternodeVerif { AssertLockHeld(cs_main); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; std::string strError; @@ -1706,7 +1706,7 @@ std::string CMasternodeMan::ToString() const { std::ostringstream info; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { info << "Masternodes: masternode object count: " << (int)mapMasternodes.size() << ", deterministic masternode count: " << deterministicMNManager->GetListAtChainTip().GetAllMNsCount() << ", nDsqCount: " << (int)nDsqCount; @@ -1725,7 +1725,7 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CNode* pfrom, CMasternodeBr // Need to lock cs_main here to ensure consistent locking order because the SimpleCheck call below locks cs_main LOCK(cs_main); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return false; { @@ -1840,7 +1840,7 @@ void CMasternodeMan::UpdateLastPaid(const CBlockIndex* pindex) void CMasternodeMan::UpdateLastSentinelPingTime() { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; nLastSentinelPingTime = GetTime(); } @@ -1874,7 +1874,7 @@ void CMasternodeMan::RemoveGovernanceObject(uint256 nGovernanceObjectHash) void CMasternodeMan::CheckMasternode(const CKeyID& keyIDOperator, bool fForce) { LOCK2(cs_main, cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; for (auto& mnpair : mapMasternodes) { if (mnpair.second.legacyKeyIDOperator == keyIDOperator) { @@ -1894,7 +1894,7 @@ bool CMasternodeMan::IsMasternodePingedWithin(const COutPoint& outpoint, int nSe void CMasternodeMan::SetMasternodeLastPing(const COutPoint& outpoint, const CMasternodePing& mnp) { LOCK(cs); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) return; CMasternode* pmn = Find(outpoint); if(!pmn) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 3010fbd78108..699a3244dc69 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1189,7 +1189,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam } if (!push && inv.type == MSG_MASTERNODE_PAYMENT_VOTE) { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { if (mnpayments.HasVerifiedPaymentVote(inv.hash)) { connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MASTERNODEPAYMENTVOTE, mnpayments.mapMasternodePaymentVotes[inv.hash])); push = true; @@ -1198,7 +1198,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam } if (!push && inv.type == MSG_MASTERNODE_PAYMENT_BLOCK) { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { BlockMap::iterator mi = mapBlockIndex.find(inv.hash); LOCK(cs_mapMasternodeBlocks); if (mi != mapBlockIndex.end() && mnpayments.mapMasternodeBlocks.count(mi->second->nHeight)) { @@ -1216,7 +1216,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam } if (!push && inv.type == MSG_MASTERNODE_ANNOUNCE) { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { if (mnodeman.mapSeenMasternodeBroadcast.count(inv.hash)) { connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MNANNOUNCE, mnodeman.mapSeenMasternodeBroadcast[inv.hash].second)); push = true; @@ -1225,7 +1225,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam } if (!push && inv.type == MSG_MASTERNODE_PING) { - if (!deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (!deterministicMNManager->IsDIP3Active()) { if (mnodeman.mapSeenMasternodePing.count(inv.hash)) { connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::MNPING, mnodeman.mapSeenMasternodePing[inv.hash])); push = true; @@ -1806,7 +1806,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr static std::set allowWhileInIBDObjs = { MSG_SPORK }; - if (legacyMNObjs.count(inv.type) && deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (legacyMNObjs.count(inv.type) && deterministicMNManager->IsDIP3Active()) { LogPrint("net", "ignoring (%s) inv of legacy type %d peer=%d\n", inv.hash.ToString(), inv.type, pfrom->id); continue; } diff --git a/src/privatesend.cpp b/src/privatesend.cpp index b6189e424813..01db2b1cc61a 100644 --- a/src/privatesend.cpp +++ b/src/privatesend.cpp @@ -52,7 +52,7 @@ bool CPrivateSendQueue::Sign() std::string strError = ""; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { uint256 hash = GetSignatureHash(); CBLSSignature sig = activeMasternodeInfo.blsKeyOperator->Sign(hash); if (!sig.IsValid()) { @@ -94,7 +94,7 @@ bool CPrivateSendQueue::Sign() bool CPrivateSendQueue::CheckSignature(const CKeyID& keyIDOperator, const CBLSPublicKey& blsPubKey) const { std::string strError = ""; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { uint256 hash = GetSignatureHash(); CBLSSignature sig; @@ -147,7 +147,7 @@ bool CPrivateSendBroadcastTx::Sign() std::string strError = ""; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { uint256 hash = GetSignatureHash(); CBLSSignature sig = activeMasternodeInfo.blsKeyOperator->Sign(hash); @@ -188,7 +188,7 @@ bool CPrivateSendBroadcastTx::CheckSignature(const CKeyID& keyIDOperator, const { std::string strError = ""; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { uint256 hash = GetSignatureHash(); CBLSSignature sig; diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp index fba28e4210c2..b8b086613c12 100644 --- a/src/qt/masternodelist.cpp +++ b/src/qt/masternodelist.cpp @@ -277,7 +277,7 @@ void MasternodeList::updateMyNodeList(bool fForce) if (ShutdownRequested()) { return; } - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { return; } @@ -321,7 +321,7 @@ void MasternodeList::updateNodeList() return; } - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { // we misuse the fact that updateNodeList is called regularely here and remove both tabs if (ui->tabWidget->indexOf(ui->tabDIP3Masternodes) != 0) { // remove "My Masternode" and "All Masternodes" tabs @@ -356,7 +356,7 @@ void MasternodeList::updateNodeList() ui->tableWidgetMasternodes->clearContents(); ui->tableWidgetMasternodes->setRowCount(0); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { ui->countLabel->setText(QString::number(0)); return; } @@ -405,7 +405,7 @@ void MasternodeList::updateDIP3List() return; } - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { ui->dip3NoteLabel->setVisible(false); } diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index 441f7453d6d8..f6733db99824 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -313,7 +313,7 @@ UniValue gobject_submit(const JSONRPCRequest& request) if (govobj.GetObjectType() == GOVERNANCE_OBJECT_TRIGGER) { if (fMnFound) { govobj.SetMasternodeOutpoint(activeMasternodeInfo.outpoint); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { govobj.Sign(*activeMasternodeInfo.blsKeyOperator); } else { govobj.Sign(activeMasternodeInfo.legacyKeyOperator, activeMasternodeInfo.legacyKeyIDOperator); @@ -428,7 +428,7 @@ UniValue gobject_vote_conf(const JSONRPCRequest& request) CGovernanceVote vote(mn.outpoint, hash, eVoteSignal, eVoteOutcome); bool signSuccess = false; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { if (govObjType == GOVERNANCE_OBJECT_PROPOSAL && eVoteSignal == VOTE_SIGNAL_FUNDING) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Can't use vote-conf for proposals when deterministic masternodes are active"); } @@ -520,7 +520,7 @@ UniValue VoteWithMasternodeList(const std::vectorIsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { if (govObjType == GOVERNANCE_OBJECT_PROPOSAL && mn.keyIDVoting != pubKeyOperator.GetID()) { nFailed++; statusObj.push_back(Pair("result", "failed")); @@ -600,7 +600,7 @@ UniValue gobject_vote_many(const JSONRPCRequest& request) // This allows voting on proposals when you have the MN voting key in your wallet // We can remove this when we remove support for masternode.conf and only support wallet based masternode // management - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { if (!pwalletMain) { throw JSONRPCError(RPC_INVALID_PARAMETER, "vote-many not supported when wallet is disabled."); } @@ -634,7 +634,7 @@ UniValue gobject_vote_many(const JSONRPCRequest& request) }); } #else - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "vote-many not supported when wallet is disabled."); } #endif @@ -678,7 +678,7 @@ UniValue gobject_vote_alias(const JSONRPCRequest& request) std::vector entries; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { #ifdef ENABLE_WALLET if (!pwalletMain) { throw JSONRPCError(RPC_INVALID_PARAMETER, "vote-alias not supported when wallet is disabled"); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index f443a0527c00..5e8281648d60 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -226,7 +226,7 @@ UniValue masternode_count(const JSONRPCRequest& request) int nCount; int total = mnodeman.CountMasternodes(0); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { nCount = mnodeman.CountEnabled(); } else { masternode_info_t mnInfo; @@ -283,7 +283,7 @@ UniValue GetNextMasternodeForPayment(int heightShift) mnodeman.UpdateLastPaid(pindex); CScript payeeScript; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto payee = deterministicMNManager->GetListAtChainTip().GetMNPayee(); if (!payee || !mnodeman.GetMasternodeInfo(payee->proTxHash, mnInfo)) return "unknown"; @@ -359,7 +359,7 @@ UniValue masternode_start_alias(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 2) masternode_start_alias_help(); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) throw JSONRPCError(RPC_MISC_ERROR, "start-alias is not supported when deterministic masternode list is active (DIP3)"); if (!EnsureWalletIsAvailable(request.fHelp)) @@ -461,7 +461,7 @@ UniValue masternode_start_all(const JSONRPCRequest& request) { if (request.fHelp) masternode_start_all_help(); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) + if (deterministicMNManager->IsDIP3Active()) throw JSONRPCError(RPC_MISC_ERROR, strprintf("start-all is not supported when deterministic masternode list is active (DIP3)")); if (!EnsureWalletIsAvailable(request.fHelp)) @@ -662,7 +662,7 @@ UniValue masternode_status(const JSONRPCRequest& request) mnObj.push_back(Pair("outpoint", activeMasternodeInfo.outpoint.ToStringShort())); mnObj.push_back(Pair("service", activeMasternodeInfo.service.ToString())); - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto dmn = activeMasternodeManager->GetDMN(); if (dmn) { mnObj.push_back(Pair("proTxHash", dmn->proTxHash.ToString())); @@ -887,7 +887,7 @@ UniValue masternodelist(const JSONRPCRequest& request) std::string strOutpoint = mnpair.first.ToStringShort(); CScript payeeScript; - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto dmn = deterministicMNManager->GetListAtChainTip().GetMNByCollateral(mn.outpoint); if (dmn) { payeeScript = dmn->pdmnState->scriptPayout; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 43522360d6d5..49c5e500a164 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -722,7 +722,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) result.push_back(Pair("masternode", masternodeObj)); result.push_back(Pair("masternode_payments_started", pindexPrev->nHeight + 1 > consensusParams.nMasternodePaymentsStartBlock)); - result.push_back(Pair("masternode_payments_enforced", deterministicMNManager->IsDeterministicMNsSporkActive() || sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))); + result.push_back(Pair("masternode_payments_enforced", deterministicMNManager->IsDIP3Active() || sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))); UniValue superblockObjArray(UniValue::VARR); if(pblocktemplate->voutSuperblockPayments.size()) { diff --git a/src/spork.cpp b/src/spork.cpp index c5ed4a94cae4..1872263c61a2 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -27,7 +27,6 @@ std::map mapSporkDefaults = { {SPORK_10_MASTERNODE_PAY_UPDATED_NODES, 4070908800ULL}, // OFF {SPORK_12_RECONSIDER_BLOCKS, 0}, // 0 BLOCKS {SPORK_14_REQUIRE_SENTINEL_FLAG, 4070908800ULL}, // OFF - {SPORK_15_DETERMINISTIC_MNS_ENABLED, 4070908800ULL}, // OFF {SPORK_16_INSTANTSEND_AUTOLOCKS, 4070908800ULL}, // OFF {SPORK_17_QUORUM_DKG_ENABLED, 4070908800ULL}, // OFF }; @@ -290,7 +289,6 @@ int CSporkManager::GetSporkIDByName(const std::string& strName) if (strName == "SPORK_10_MASTERNODE_PAY_UPDATED_NODES") return SPORK_10_MASTERNODE_PAY_UPDATED_NODES; if (strName == "SPORK_12_RECONSIDER_BLOCKS") return SPORK_12_RECONSIDER_BLOCKS; if (strName == "SPORK_14_REQUIRE_SENTINEL_FLAG") return SPORK_14_REQUIRE_SENTINEL_FLAG; - if (strName == "SPORK_15_DETERMINISTIC_MNS_ENABLED") return SPORK_15_DETERMINISTIC_MNS_ENABLED; if (strName == "SPORK_16_INSTANTSEND_AUTOLOCKS") return SPORK_16_INSTANTSEND_AUTOLOCKS; if (strName == "SPORK_17_QUORUM_DKG_ENABLED") return SPORK_17_QUORUM_DKG_ENABLED; @@ -310,7 +308,6 @@ std::string CSporkManager::GetSporkNameByID(int nSporkID) case SPORK_10_MASTERNODE_PAY_UPDATED_NODES: return "SPORK_10_MASTERNODE_PAY_UPDATED_NODES"; case SPORK_12_RECONSIDER_BLOCKS: return "SPORK_12_RECONSIDER_BLOCKS"; case SPORK_14_REQUIRE_SENTINEL_FLAG: return "SPORK_14_REQUIRE_SENTINEL_FLAG"; - case SPORK_15_DETERMINISTIC_MNS_ENABLED: return "SPORK_15_DETERMINISTIC_MNS_ENABLED"; case SPORK_16_INSTANTSEND_AUTOLOCKS: return "SPORK_16_INSTANTSEND_AUTOLOCKS"; case SPORK_17_QUORUM_DKG_ENABLED: return "SPORK_17_QUORUM_DKG_ENABLED"; default: diff --git a/src/spork.h b/src/spork.h index f2baecf6a19b..2764b21266f3 100644 --- a/src/spork.h +++ b/src/spork.h @@ -26,7 +26,6 @@ static const int SPORK_9_SUPERBLOCKS_ENABLED = 10008; static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009; static const int SPORK_12_RECONSIDER_BLOCKS = 10011; static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013; -static const int SPORK_15_DETERMINISTIC_MNS_ENABLED = 10014; static const int SPORK_16_INSTANTSEND_AUTOLOCKS = 10015; static const int SPORK_17_QUORUM_DKG_ENABLED = 10016; diff --git a/src/test/evo_deterministicmns_tests.cpp b/src/test/evo_deterministicmns_tests.cpp index ca0eb0bcd0e1..782d386890ae 100644 --- a/src/test/evo_deterministicmns_tests.cpp +++ b/src/test/evo_deterministicmns_tests.cpp @@ -279,8 +279,8 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChainDIP3Setup) nHeight++; } - // activate spork15 - sporkManager.UpdateSpork(SPORK_15_DETERMINISTIC_MNS_ENABLED, chainActive.Height() + 1, *g_connman); + int DIP0003HeightBackup = Params().GetConsensus().DIP0003Height; + const_cast(Params().GetConsensus()).DIP0003Height = chainActive.Height() + 1; CreateAndProcessBlock({}, coinbaseKey); deterministicMNManager->UpdatedBlockTip(chainActive.Tip()); nHeight++; @@ -398,5 +398,7 @@ BOOST_FIXTURE_TEST_CASE(dip3_protx, TestChainDIP3Setup) nHeight++; } BOOST_ASSERT(foundRevived); + + const_cast(Params().GetConsensus()).DIP0003Height = DIP0003HeightBackup; } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/validation.cpp b/src/validation.cpp index 18136074e6fe..786c68fbebd6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1828,7 +1828,7 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para ThresholdState state = VersionBitsState(pindexPrev, params, pos, versionbitscache); const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos]; if (vbinfo.check_mn_protocol && state == THRESHOLD_STARTED && fCheckMasternodesUpgraded) { - if (deterministicMNManager->IsDeterministicMNsSporkActive()) { + if (deterministicMNManager->IsDIP3Active()) { auto mnList = deterministicMNManager->GetListForBlock(pindexPrev->GetBlockHash()); auto payee = mnList.GetMNPayee(); if (!payee) {