From 1260e002f62c72da78de4ca82c3fbb2af5213936 Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Thu, 13 May 2021 07:34:15 +0100 Subject: [PATCH] Remove backwards compatible anchor code --- src/masternodes/anchors.cpp | 103 +++++-------------- src/masternodes/anchors.h | 1 - src/masternodes/rpc_masternodes.cpp | 19 +--- src/spv/spv_rpc.cpp | 8 +- src/test/anchor_tests.cpp | 4 +- src/validation.cpp | 66 +++++-------- test/functional/feature_anchor_rewards.py | 64 +++++++++++- test/functional/feature_anchorauths.py | 110 --------------------- test/functional/feature_anchors.py | 115 ---------------------- test/functional/test_runner.py | 2 - 10 files changed, 123 insertions(+), 369 deletions(-) delete mode 100755 test/functional/feature_anchorauths.py delete mode 100755 test/functional/feature_anchors.py diff --git a/src/masternodes/anchors.cpp b/src/masternodes/anchors.cpp index e6110c9cb4..b7ce1c55ce 100644 --- a/src/masternodes/anchors.cpp +++ b/src/masternodes/anchors.cpp @@ -127,8 +127,6 @@ bool CAnchorAuthIndex::ValidateAuth(const CAnchorAuthIndex::Auth & auth) const { AssertLockHeld(cs_main); - bool newAnchorLogic{::ChainActive().Height() >= Params().GetConsensus().DakotaHeight}; - // 1. Prev and top checks // Skip checks if no SPV as panchors will be empty (allows non-SPV nodes to relay auth messages) @@ -154,20 +152,16 @@ bool CAnchorAuthIndex::ValidateAuth(const CAnchorAuthIndex::Auth & auth) const return false; } - // Add extra checks to make sure we are forming an anchor chain - if (newAnchorLogic) - { - // Top anchor should chain from previous anchor if it exists - if (auth.previousAnchor.IsNull()) { - LogPrint(BCLog::ANCHORING, "%s: anchor does not have previous anchor set to top anchor\n", __func__); - return false; - } + // Top anchor should chain from previous anchor if it exists + if (auth.previousAnchor.IsNull()) { + LogPrint(BCLog::ANCHORING, "%s: anchor does not have previous anchor set to top anchor\n", __func__); + return false; + } - // Previous anchor should link to top anchor - if (auth.previousAnchor != topAnchor->txHash) { - LogPrint(BCLog::ANCHORING, "%s: anchor previousAnchor does not match top anchor\n", __func__); - return false; - } + // Previous anchor should link to top anchor + if (auth.previousAnchor != topAnchor->txHash) { + LogPrint(BCLog::ANCHORING, "%s: anchor previousAnchor does not match top anchor\n", __func__); + return false; } } } @@ -181,25 +175,16 @@ bool CAnchorAuthIndex::ValidateAuth(const CAnchorAuthIndex::Auth & auth) const // 3. Full anchor validation and team context CTeam team; - if (newAnchorLogic) { - uint64_t anchorCreationHeight; - CBlockIndex block; - if (!ContextualValidateAnchor(auth, block, anchorCreationHeight)) { - return false; - } - - // Let's try and get the team that set this anchor - auto anchorTeam = pcustomcsview->GetAuthTeam(anchorCreationHeight); - if (anchorTeam) { - team = *anchorTeam; - } - } else { - team = panchors->GetNextTeam(auth.previousAnchor); + uint64_t anchorCreationHeight; + CBlockIndex anchorBlock; + if (!ContextualValidateAnchor(auth, anchorBlock, anchorCreationHeight)) { + return false; + } - if (auth.nextTeam != pcustomcsview->CalcNextTeam(block->stakeModifier)) { - LogPrint(BCLog::ANCHORING, "%s: Wrong nextTeam for auth %s\n", __func__, auth.GetHash().ToString()); - return false; - } + // Let's try and get the team that set this anchor + auto anchorTeam = pcustomcsview->GetAuthTeam(anchorCreationHeight); + if (anchorTeam) { + team = *anchorTeam; } if (team.empty()) { @@ -258,8 +243,7 @@ CAnchor CAnchorAuthIndex::CreateBestAnchor(CTxDestination const & rewardDest) co KList const & list = auths.get(); auto const topAnchor = panchors->GetActiveAnchor(); - auto const topTeam = panchors->GetCurrentTeam(topAnchor); - uint32_t quorum = GetMinAnchorQuorum(topTeam); + uint32_t quorum = 1 + (Params().GetConsensus().mn.anchoringTeamSize * 2) / 3; auto const topHeight = topAnchor ? topAnchor->anchor.height : 0; LogPrint(BCLog::ANCHORING, "auths size: %d quorum: %d\n", list.size(), quorum); @@ -278,8 +262,7 @@ CAnchor CAnchorAuthIndex::CreateBestAnchor(CTxDestination const & rewardDest) co curHeight = it->height; curSignHash = it->GetSignHash(); - // Post fork anchor auth only have one team member. Check it is present here before reading from it! - if (ChainActive().Height() >= Params().GetConsensus().DakotaHeight && it->nextTeam.size() == 1) + if (it->nextTeam.size() == 1) { // Team data reference const CKeyID& teamData = *it->nextTeam.begin(); @@ -295,9 +278,6 @@ CAnchor CAnchorAuthIndex::CreateBestAnchor(CTxDestination const & rewardDest) co if (team) { // Now we can set the appropriate quorum size quorum = GetMinAnchorQuorum(*team); - } else { - // Should not get here but set max size if we do - quorum = 1 + (Params().GetConsensus().mn.anchoringTeamSize * 2) / 3; } } } @@ -460,16 +440,6 @@ CAnchorData::CTeam CAnchorIndex::GetNextTeam(const uint256 & btcPrevTx) const return prev->anchor.nextTeam; } -CAnchorData::CTeam CAnchorIndex::GetCurrentTeam(const CAnchorIndex::AnchorRec * anchor) const -{ - AssertLockHeld(cs_main); - - if (!anchor) - return Params().GetGenesisTeam(); - - return GetNextTeam(anchor->anchor.previousAnchor); -} - CAnchorIndex::AnchorRec const * CAnchorIndex::GetAnchorByBtcTx(uint256 const & txHash) const { AssertLockHeld(cs_main); @@ -600,14 +570,13 @@ void CAnchorIndex::CheckActiveAnchor(bool forced) // Only continue with context of chain if (ShutdownRequested()) return; - bool topChanged{false}; { // fix spv height to avoid datarace while choosing best anchor uint32_t const tmp = spv::pspv ? spv::pspv->GetLastBlockHeight() : 0; LOCK(cs_main); spvLastHeight = tmp; - topChanged = panchors->ActivateBestAnchor(forced); + panchors->ActivateBestAnchor(forced); // prune auths older than anchor with 6 confirmations. Warning! This constant are using for start confirming reward too! auto it = panchors->GetActiveAnchor(); @@ -622,22 +591,6 @@ void CAnchorIndex::CheckActiveAnchor(bool forced) panchorAwaitingConfirms->ReVote(); } } - - // Get height - int height{0}; - { - LOCK(cs_main); - height = ::ChainActive().Height(); - } - - // Pre-fork only, anchors for manual checking only after fork. - if (height < Params().GetConsensus().DakotaHeight) { - CValidationState state; - if (topChanged && !ActivateBestChain(state, Params())) { - throw std::runtime_error(strprintf("%s: ActivateBestChain failed. (%s)", __func__, FormatStateMessage(state))); - } - } - } void CAnchorIndex::UpdateLastHeight(uint32_t height) @@ -1086,15 +1039,11 @@ void CAnchorAwaitingConfirms::ReVote() const auto height = ::ChainActive().Height(); CTeamView::CTeam currentTeam; - if (height >= Params().GetConsensus().DakotaHeight) { - auto team = pcustomcsview->GetConfirmTeam(height); - if (team) { - currentTeam = *team; - } else if (!team || team->empty()) { - return; - } - } else { - currentTeam = pcustomcsview->GetCurrentTeam(); + auto team = pcustomcsview->GetConfirmTeam(height); + if (team) { + currentTeam = *team; + } else if (!team || team->empty()) { + return; } const auto operatorDetails = AmISignerNow(currentTeam); diff --git a/src/masternodes/anchors.h b/src/masternodes/anchors.h index 8e580e2910..c48ca84f08 100644 --- a/src/masternodes/anchors.h +++ b/src/masternodes/anchors.h @@ -238,7 +238,6 @@ class CAnchorIndex bool DeleteAnchorByBtcTx(uint256 const & btcTxHash); CAnchorData::CTeam GetNextTeam(uint256 const & btcPrevTx) const; - CAnchorData::CTeam GetCurrentTeam(AnchorRec const * anchor) const; AnchorRec const * GetAnchorByBtcTx(uint256 const & txHash) const; diff --git a/src/masternodes/rpc_masternodes.cpp b/src/masternodes/rpc_masternodes.cpp index 36dced54b0..0a9ce97241 100644 --- a/src/masternodes/rpc_masternodes.cpp +++ b/src/masternodes/rpc_masternodes.cpp @@ -652,23 +652,12 @@ UniValue listanchors(const JSONRPCRequest& request) CTxDestination rewardDest = item.rewardKeyType == 1 ? CTxDestination(PKHash(item.rewardKeyID)) : CTxDestination(WitnessV0KeyHash(item.rewardKeyID)); UniValue entry(UniValue::VOBJ); entry.pushKV("anchorHeight", static_cast(item.anchorHeight)); - if (item.dfiBlockHash != uint256()) { - entry.pushKV("anchorHash", item.dfiBlockHash.ToString()); - } + entry.pushKV("anchorHash", item.dfiBlockHash.ToString()); entry.pushKV("rewardAddress", EncodeDestination(rewardDest)); - if (defiHash) { - entry.pushKV("dfiRewardHash", defiHash->ToString()); - } - if (item.btcTxHeight != 0) { - entry.pushKV("btcAnchorHeight", static_cast(item.btcTxHeight)); - } + entry.pushKV("dfiRewardHash", defiHash->ToString()); + entry.pushKV("btcAnchorHeight", static_cast(item.btcTxHeight)); entry.pushKV("btcAnchorHash", item.btcTxHash.ToString()); - - if (item.dfiBlockHash != uint256() && item.btcTxHeight != 0) { - entry.pushKV("confirmSignHash", item.GetSignHash().ToString()); - } else { - entry.pushKV("confirmSignHash", static_cast(item).GetSignHash().ToString()); - } + entry.pushKV("confirmSignHash", item.GetSignHash().ToString()); result.push_back(entry); } diff --git a/src/spv/spv_rpc.cpp b/src/spv/spv_rpc.cpp index 0f17c4f23c..1e52e28a38 100644 --- a/src/spv/spv_rpc.cpp +++ b/src/spv/spv_rpc.cpp @@ -553,9 +553,7 @@ UniValue spv_listanchorauths(const JSONRPCRequest& request) item.pushKV("previousAnchor", prev->previousAnchor.ToString()); item.pushKV("blockHeight", static_cast(prev->height)); item.pushKV("blockHash", prev->blockHash.ToString()); - if (anchorCreationHeight != 0) { - item.pushKV("creationHeight", static_cast(anchorCreationHeight)); - } + item.pushKV("creationHeight", static_cast(anchorCreationHeight)); item.pushKV("signers", (uint64_t)signers.size()); UniValue signees(UniValue::VARR); @@ -606,9 +604,7 @@ UniValue spv_listanchorauths(const JSONRPCRequest& request) item.pushKV("previousAnchor", prev->previousAnchor.ToString()); item.pushKV("blockHeight", static_cast(prev->height)); item.pushKV("blockHash", prev->blockHash.ToString()); - if (anchorCreationHeight != 0) { - item.pushKV("creationHeight", static_cast(anchorCreationHeight)); - } + item.pushKV("creationHeight", static_cast(anchorCreationHeight)); item.pushKV("signers", (uint64_t)signers.size()); UniValue signees(UniValue::VARR); diff --git a/src/test/anchor_tests.cpp b/src/test/anchor_tests.cpp index 9ffefca4f2..a5151ecb7c 100644 --- a/src/test/anchor_tests.cpp +++ b/src/test/anchor_tests.cpp @@ -109,7 +109,7 @@ BOOST_AUTO_TEST_CASE(best_anchor_activation_logic) auto top = panchors->GetActiveAnchor(); BOOST_CHECK(top == nullptr); - auto team0 = panchors->GetCurrentTeam(panchors->GetActiveAnchor()); + CAnchorData::CTeam team0; // Stage 1. Same btc height. The very first, no prevs (btc height = 1) // create first anchor @@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(Test_GetLatestAnchorUpToDeFiHeight) auto top = panchors->GetActiveAnchor(); BOOST_CHECK(top == nullptr); - auto team0 = panchors->GetCurrentTeam(panchors->GetActiveAnchor()); + CAnchorData::CTeam team0; // no anchors yet. call the GetMostLatestAtDeFiHeight() at DeFi height 20 // should return nullptr diff --git a/src/validation.cpp b/src/validation.cpp index 6f3ea48dfc..918c0f78eb 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4468,19 +4468,13 @@ void ProcessAuthsIfTipChanged(CBlockIndex const * oldTip, CBlockIndex const * ti CTeamView::CTeam team; int teamChange = tip->nHeight; auto const teamDakota = pcustomcsview->GetAuthTeam(tip->height); - - bool newAnchorLogic{tip->height >= static_cast(consensus.DakotaHeight)}; - if (newAnchorLogic) { - if (!teamDakota || teamDakota->empty()) { - return; - } - team = *teamDakota; - - // Calc how far back team changes, do not generate auths below that height. - teamChange = teamChange % Params().GetConsensus().mn.anchoringTeamChange; - } else { - team = panchors->GetCurrentTeam(topAnchor); + if (!teamDakota || teamDakota->empty()) { + return; } + team = *teamDakota; + + // Calc how far back team changes, do not generate auths below that height. + teamChange = teamChange % Params().GetConsensus().mn.anchoringTeamChange; uint64_t topAnchorHeight = topAnchor ? static_cast(topAnchor->anchor.height) : 0; // we have no need to ask for auths at all if we have topAnchor higher than current chain @@ -4518,16 +4512,14 @@ void ProcessAuthsIfTipChanged(CBlockIndex const * oldTip, CBlockIndex const * ti int anchorHeight = static_cast(pindex->height) - consensus.mn.anchoringFrequency; - if (newAnchorLogic) { - // Get anchor block from specified time depth - while (anchorHeight > 0 && ::ChainActive()[anchorHeight]->nTime + consensus.mn.anchoringTimeDepth > pindex->nTime) { - --anchorHeight; - } + // Get anchor block from specified time depth + while (anchorHeight > 0 && ::ChainActive()[anchorHeight]->nTime + consensus.mn.anchoringTimeDepth > pindex->nTime) { + --anchorHeight; + } - // Rollback to height consistent with anchoringFrequency - while (anchorHeight > 0 && anchorHeight % consensus.mn.anchoringFrequency != 0) { - --anchorHeight; - } + // Rollback to height consistent with anchoringFrequency + while (anchorHeight > 0 && anchorHeight % consensus.mn.anchoringFrequency != 0) { + --anchorHeight; } if (anchorHeight <= 0 || (topAnchor && topAnchor->anchor.height >= (THeight)anchorHeight)) { // important to check prev anchor height! @@ -4536,25 +4528,21 @@ void ProcessAuthsIfTipChanged(CBlockIndex const * oldTip, CBlockIndex const * ti auto const anchorBlock = ::ChainActive()[anchorHeight]; - // Create next team or data to find team if new logic + // Create team data CTeamView::CTeam team; - if (newAnchorLogic) { - std::vector teamDetailsVector; - - // Embed height and partial hash into CKeyID to find team later and validate chain - size_t prefixLength{CKeyID().size() - spv::BtcAnchorMarker.size() - sizeof(uint64_t)}; - std::vector hashPrefix{pindex->GetBlockHash().begin(), pindex->GetBlockHash().begin() + prefixLength}; - teamDetailsVector.insert(teamDetailsVector.end(), spv::BtcAnchorMarker.begin(), spv::BtcAnchorMarker.end()); // 3 Bytes - uint64_t anchorCreationHeight = pindex->height; - teamDetailsVector.insert(teamDetailsVector.end(), reinterpret_cast(&anchorCreationHeight), - reinterpret_cast(&anchorCreationHeight) + sizeof(uint64_t)); // 8 Bytes - teamDetailsVector.insert(teamDetailsVector.end(), hashPrefix.begin(), hashPrefix.end()); // 9 Bytes - - CKeyID teamDetails{uint160{teamDetailsVector}}; - team.insert(teamDetails); - } else { - team = pcustomcsview->CalcNextTeam(anchorBlock->stakeModifier); - } + std::vector teamDetailsVector; + + // Embed height and partial hash into CKeyID to find team later and validate chain + size_t prefixLength{CKeyID().size() - spv::BtcAnchorMarker.size() - sizeof(uint64_t)}; + std::vector hashPrefix{pindex->GetBlockHash().begin(), pindex->GetBlockHash().begin() + prefixLength}; + teamDetailsVector.insert(teamDetailsVector.end(), spv::BtcAnchorMarker.begin(), spv::BtcAnchorMarker.end()); // 3 Bytes + uint64_t anchorCreationHeight = pindex->height; + teamDetailsVector.insert(teamDetailsVector.end(), reinterpret_cast(&anchorCreationHeight), + reinterpret_cast(&anchorCreationHeight) + sizeof(uint64_t)); // 8 Bytes + teamDetailsVector.insert(teamDetailsVector.end(), hashPrefix.begin(), hashPrefix.end()); // 9 Bytes + + CKeyID teamDetails{uint160{teamDetailsVector}}; + team.insert(teamDetails); // trying to create and sign new auth CAnchorAuthMessage auth({topAnchor ? topAnchor->txHash : uint256(), static_cast(anchorHeight), anchorBlock->GetBlockHash(), team}); diff --git a/test/functional/feature_anchor_rewards.py b/test/functional/feature_anchor_rewards.py index be1947e5fb..c93b98b370 100755 --- a/test/functional/feature_anchor_rewards.py +++ b/test/functional/feature_anchor_rewards.py @@ -10,8 +10,8 @@ from test_framework.test_framework import DefiTestFramework -from test_framework.util import assert_equal, \ - connect_nodes_bi, disconnect_nodes, wait_until +from test_framework.util import assert_equal, connect_nodes_bi, \ + disconnect_nodes, wait_until, assert_raises_rpc_error from decimal import Decimal import time @@ -120,6 +120,65 @@ def run_test(self): self.nodes[0].spv_setlastheight(1) self.nodes[1].spv_setlastheight(1) + # Check errors + assert_raises_rpc_error(None, "Not enough money", self.nodes[1].spv_createanchor, + [{ + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", + 'vout': 3, + 'amount': 1000, + 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") + + # Check some params: + assert_raises_rpc_error(None, "Expected type array, got object", self.nodes[1].spv_createanchor, + { + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", + 'vout': 3, + 'amount': 2262303, + 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }, "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") + + assert_raises_rpc_error(None, "txid must be of length 64", self.nodes[1].spv_createanchor, + [{ + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963aa", + 'vout': 3, + 'amount': 2262303, + 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") + + assert_raises_rpc_error(None, "value is not an integer", self.nodes[1].spv_createanchor, + [{ + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", + 'vout': "aa", + 'amount': 2262303, + 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") + + assert_raises_rpc_error(None, "Can't parse WIF privkey", self.nodes[1].spv_createanchor, + [{ + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", + 'vout': 3, + 'amount': 2262303, + 'privkey': "1_cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") + + assert_raises_rpc_error(None, "does not refer to a P2PKH or P2WPKH address", self.nodes[1].spv_createanchor, + [{ + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", + 'vout': 3, + 'amount': 2262303, + 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }], "__mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") + + assert_raises_rpc_error(None, "does not refer to a P2PKH or P2WPKH address", self.nodes[1].spv_createanchor, + [{ + 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", + 'vout': 3, + 'amount': 2262303, + 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" + }], "") + + # Test anchor creations rewardAddress0 = self.nodes[0].getnewaddress("", "legacy") rewardAddress1 = self.nodes[0].getnewaddress("", "legacy") @@ -200,6 +259,7 @@ def run_test(self): self.nodes[1].spv_setlastheight(6) anchors = self.nodes[0].spv_listanchors() + print(anchors) assert_equal(anchors[0]['confirmations'], 6) # Bitcoin confirmations if anchors[0]['active']: activeAnc = anchors[0] diff --git a/test/functional/feature_anchorauths.py b/test/functional/feature_anchorauths.py deleted file mode 100755 index df3a0a848e..0000000000 --- a/test/functional/feature_anchorauths.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2014-2019 The Bitcoin Core developers -# Copyright (c) DeFi Blockchain Developers -# Distributed under the MIT software license, see the accompanying -# file LICENSE or http://www.opensource.org/licenses/mit-license.php. -"""Test the masternodes RPC. - -- verify basic MN creation and resign -""" - -import time - -from test_framework.test_framework import DefiTestFramework - -from test_framework.util import assert_equal, \ - connect_nodes_bi - -class AnchorAuthsTest (DefiTestFramework): - def set_test_params(self): - self.num_nodes = 3 - self.extra_args = [ - [ "-dummypos=1", "-spv=1", "-clarkequayheight=0"], - [ "-dummypos=1", "-spv=1", "-clarkequayheight=0"], - [ "-dummypos=1", "-spv=1", "-clarkequayheight=0"], - ] - self.setup_clean_chain = True - - def setup_network(self): - self.setup_nodes() - - # 0 | 1 = 2 - connect_nodes_bi(self.nodes, 1, 2) - - def dumphashes(self, nodes=None, block = None): - if nodes is None: - nodes = range(self.num_nodes - 1) - for i in nodes: - bl = self.nodes[i].getblockcount() if block is None else block - print ("Node%d: [%d] %s" % (i, bl, self.nodes[i].getblockhash(bl))) - - def dumpheights(self): - print ("Heights:", self.nodes[0].getblockcount(), "\t", self.nodes[1].getblockcount(), "\t", self.nodes[2].getblockcount()) - # pass - - def dumpauths(self, nodes=None, block = None): - if nodes is None: - nodes = range(self.num_nodes - 1) - for i in nodes: - print ("Node%d: %s" % (i, self.nodes[i].spv_listanchorauths())) - - def run_test(self): - assert_equal(len(self.nodes[0].listmasternodes()), 8) - - # no auths yet - print ("Node0:") - self.nodes[0].generate(29) - auths = self.nodes[0].spv_listanchorauths() - assert_equal(len(auths), 0) - - # auth should appear - self.nodes[0].generate(1) - auths = self.nodes[0].spv_listanchorauths() - assert_equal(len(auths), 1) - assert_equal(auths[0]['blockHeight'], 15) - assert_equal(auths[0]['blockHash'], self.nodes[0].getblockhash(15)) - assert_equal(auths[0]['signers'], 1) - - self.nodes[0].generate(1) # to be longer than chain of Node1 - - self.dumpheights() - self.dumphashes() - self.dumpauths() - - print ("Node1:") - assert_equal(len(self.nodes[1].spv_listanchorauths()), 0) - self.nodes[1].generate(30) - time.sleep(1) - self.dumphashes() - self.dumpauths() - - assert_equal(len(self.nodes[1].spv_listanchorauths()), 1) - - self.dumpheights() - self.dumpauths() - - connect_nodes_bi(self.nodes, 0, 1) - - self.nodes[0].generate(1) - self.sync_all() - - print ("After connect 0 + 1/2:") - time.sleep(1) - - self.dumpheights() - self.dumphashes() - self.dumphashes(None, 15) - self.dumpauths() - - auths = self.nodes[1].spv_listanchorauths() - assert_equal(len(auths), 2) - assert_equal(auths[0]['blockHeight'], auths[1]['blockHeight']) - assert(auths[0]['blockHash'] != auths[1]['blockHash']) - if auths[0]['signers'] == 2: - assert_equal(auths[1]['signers'], 3) - else: - assert_equal(auths[0]['signers'], 3) - assert_equal(auths[1]['signers'], 2) - -if __name__ == '__main__': - AnchorAuthsTest ().main () diff --git a/test/functional/feature_anchors.py b/test/functional/feature_anchors.py deleted file mode 100755 index e6f608d4fa..0000000000 --- a/test/functional/feature_anchors.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2014-2019 The Bitcoin Core developers -# Copyright (c) DeFi Blockchain Developers -# Distributed under the MIT software license, see the accompanying -# file LICENSE or http://www.opensource.org/licenses/mit-license.php. -"""Test the masternodes RPC. - -- verify basic MN creation and resign -""" - -from test_framework.test_framework import DefiTestFramework - -from test_framework.util import assert_equal, \ - connect_nodes_bi, assert_raises_rpc_error - -class AnchorsTest (DefiTestFramework): - def set_test_params(self): - self.num_nodes = 3 - self.extra_args = [ - [ "-dummypos=1", "-spv=1", "-clarkequayheight=0"], - [ "-dummypos=1", "-spv=1", "-clarkequayheight=0"], - [ "-dummypos=1", "-spv=1", "-clarkequayheight=0"], - ] - self.setup_clean_chain = True - - def setup_network(self): - self.setup_nodes() - - for i in range(self.num_nodes - 1): - connect_nodes_bi(self.nodes, i, i + 1) - self.sync_all() - - def check_rpc_fails(self): - print ("Node0: Check fails") - assert_raises_rpc_error(None, "Not enough money", self.nodes[0].spv_createanchor, - [{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': 3, - 'amount': 1000, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") - - # Check some params: - assert_raises_rpc_error(None, "Expected type array, got object", self.nodes[0].spv_createanchor, - { - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': 3, - 'amount': 2262303, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }, "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") - - assert_raises_rpc_error(None, "txid must be of length 64", self.nodes[0].spv_createanchor, - [{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963aa", - 'vout': 3, - 'amount': 2262303, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") - - assert_raises_rpc_error(None, "value is not an integer", self.nodes[0].spv_createanchor, - [{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': "aa", - 'amount': 2262303, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") - - assert_raises_rpc_error(None, "Can't parse WIF privkey", self.nodes[0].spv_createanchor, - [{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': 3, - 'amount': 2262303, - 'privkey': "1_cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }], "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") - - assert_raises_rpc_error(None, "does not refer to a P2PKH or P2WPKH address", self.nodes[0].spv_createanchor, - [{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': 3, - 'amount': 2262303, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }], "__mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu") - - assert_raises_rpc_error(None, "does not refer to a P2PKH or P2WPKH address", self.nodes[0].spv_createanchor, - [{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': 3, - 'amount': 2262303, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP" - }], "") - - # all is Ok, but don't send! - self.nodes[0].spv_createanchor([{ - 'txid': "a0d5a294be3cde6a8bddab5815b8c4cb1b2ebf2c2b8a4018205d6f8c576e8963", - 'vout': 3, - 'amount': 2262303, - 'privkey': "cStbpreCo2P4nbehPXZAAM3gXXY1sAphRfEhj7ADaLx8i2BmxvEP"}], - "mgsE1SqrcfUhvuYuRjqy6rQCKmcCVKNhMu", False) - assert_equal(len(self.nodes[0].spv_listanchors()), 0) - - - def run_test(self): - assert_equal(len(self.nodes[0].listmasternodes()), 8) - - chain0 = 17+15 - self.nodes[0].generate(chain0) - assert_equal(len(self.nodes[0].spv_listanchors()), 0) - - self.check_rpc_fails() - - # This test only checks spv_createanchor failures. New anchor checks are handled - # by feature_anchor_rewards.py and feature_anchor_dakota.py. - -if __name__ == '__main__': - AnchorsTest ().main () diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 27c90dd79b..e18cd9f7d3 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -116,8 +116,6 @@ 'feature_fee_estimation.py', 'feature_dip1.py', 'feature_dfip8_communitybalances.py', - 'feature_anchors.py', - 'feature_anchorauths.py', 'feature_anchor_rewards.py', 'feature_anchorauths_pruning.py', 'feature_autoauth.py',