From a7dbd9b5257c12fe5b222414dacfe3bd9fed04fc Mon Sep 17 00:00:00 2001 From: Diego del Corral Tercero Date: Wed, 1 Sep 2021 09:23:46 +0200 Subject: [PATCH 1/2] - fix getmasternodeblocks (WIP) --- src/masternodes/rpc_masternodes.cpp | 15 ++++++++++++++- test/functional/rpc_mn_basic.py | 8 +++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/masternodes/rpc_masternodes.cpp b/src/masternodes/rpc_masternodes.cpp index 106799dc01..054e1741f7 100644 --- a/src/masternodes/rpc_masternodes.cpp +++ b/src/masternodes/rpc_masternodes.cpp @@ -498,6 +498,19 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { UniValue ret(UniValue::VOBJ); + pcustomcsview->ForEachSubNode([&](const SubNodeBlockTimeKey &key, CLazySerialize){ + if (key.masternodeID != mn_id) { + return false; + } + + if (auto tip = ::ChainActive()[key.blockHeight]) { + lastHeight = tip->height; + ret.pushKV(std::to_string(tip->height), tip->GetBlockHash().ToString()); + } + + return true; + },SubNodeBlockTimeKey{mn_id, 0, std::numeric_limits::max()}); + pcustomcsview->ForEachMinterNode([&](MNBlockTimeKey const & key, CLazySerialize) { if (key.masternodeID != mn_id) { return false; @@ -675,7 +688,7 @@ UniValue listanchors(const JSONRPCRequest& request) } static const CRPCCommand commands[] = -{ +{ // category name actor (function) params // --------------- ---------------------- --------------------- ---------- {"masternodes", "createmasternode", &createmasternode, {"ownerAddress", "operatorAddress", "inputs"}}, diff --git a/test/functional/rpc_mn_basic.py b/test/functional/rpc_mn_basic.py index c35fb69fff..24df88e113 100755 --- a/test/functional/rpc_mn_basic.py +++ b/test/functional/rpc_mn_basic.py @@ -179,7 +179,8 @@ def run_test(self): assert_raises_rpc_error(-26, 'masternode creation needs owner auth', self.nodes[0].sendrawtransaction, signedTx['hex']) # Test new register delay - mnTx = self.nodes[0].createmasternode(self.nodes[0].getnewaddress("", "legacy")) + mnAddress = self.nodes[0].getnewaddress("", "legacy") + mnTx = self.nodes[0].createmasternode(mnAddress) self.nodes[0].generate(1) assert_equal(self.nodes[0].listmasternodes({}, False)[mnTx], "PRE_ENABLED") @@ -198,6 +199,11 @@ def run_test(self): self.nodes[0].generate(1) assert_equal(self.nodes[0].listmasternodes({}, False)[mnTx], "ENABLED") + # test getmasternodeblocks + self.nodes[0].generate(1, address=mnAddress) + blocks = self.nodes[0].getmasternodeblocks({'ownerAddress': mnAddress}) + assert_equal(len(blocks), 1) # not working correctly only mints block 141 + # Test new resign delay self.nodes[0].resignmasternode(mnTx) self.nodes[0].generate(1) From ab34021b439d1a2b5d2f411bafd9698d5f202dac Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Wed, 1 Sep 2021 14:01:02 +0300 Subject: [PATCH 2/2] Do not include masternode creation height in minted blocks Signed-off-by: Anthony Fieroni --- src/masternodes/rpc_masternodes.cpp | 25 ++++++++++++------------- test/functional/rpc_mn_basic.py | 16 ++++++++++------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/masternodes/rpc_masternodes.cpp b/src/masternodes/rpc_masternodes.cpp index 054e1741f7..cbc65b7ad3 100644 --- a/src/masternodes/rpc_masternodes.cpp +++ b/src/masternodes/rpc_masternodes.cpp @@ -498,30 +498,29 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) { UniValue ret(UniValue::VOBJ); - pcustomcsview->ForEachSubNode([&](const SubNodeBlockTimeKey &key, CLazySerialize){ - if (key.masternodeID != mn_id) { + auto masternodeBlocks = [&](const uint256& masternodeID, uint32_t blockHeight) { + if (masternodeID != mn_id) { return false; } - if (auto tip = ::ChainActive()[key.blockHeight]) { - lastHeight = tip->height; - ret.pushKV(std::to_string(tip->height), tip->GetBlockHash().ToString()); - } - - return true; - },SubNodeBlockTimeKey{mn_id, 0, std::numeric_limits::max()}); - - pcustomcsview->ForEachMinterNode([&](MNBlockTimeKey const & key, CLazySerialize) { - if (key.masternodeID != mn_id) { + if (blockHeight <= creationHeight) { return false; } - if (auto tip = ::ChainActive()[key.blockHeight]) { + if (auto tip = ::ChainActive()[blockHeight]) { lastHeight = tip->height; ret.pushKV(std::to_string(tip->height), tip->GetBlockHash().ToString()); } return true; + }; + + pcustomcsview->ForEachSubNode([&](const SubNodeBlockTimeKey &key, CLazySerialize){ + return masternodeBlocks(key.masternodeID, key.blockHeight); + }, SubNodeBlockTimeKey{mn_id, 0, std::numeric_limits::max()}); + + pcustomcsview->ForEachMinterNode([&](MNBlockTimeKey const & key, CLazySerialize) { + return masternodeBlocks(key.masternodeID, key.blockHeight); }, MNBlockTimeKey{mn_id, std::numeric_limits::max()}); auto tip = ::ChainActive()[std::min(lastHeight, uint64_t(Params().GetConsensus().DakotaCrescentHeight)) - 1]; diff --git a/test/functional/rpc_mn_basic.py b/test/functional/rpc_mn_basic.py index 24df88e113..b5e86d726d 100755 --- a/test/functional/rpc_mn_basic.py +++ b/test/functional/rpc_mn_basic.py @@ -21,9 +21,9 @@ class MasternodesRpcBasicTest (DefiTestFramework): def set_test_params(self): self.num_nodes = 3 self.setup_clean_chain = True - self.extra_args = [['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=136', '-eunosheight=140', '-eunospayaheight=140'], - ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=136', '-eunosheight=140', '-eunospayaheight=140'], - ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=136', '-eunosheight=140', '-eunospayaheight=140']] + self.extra_args = [['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=136', '-eunosheight=140', '-eunospayaheight=140'], + ['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=136', '-eunosheight=140', '-eunospayaheight=140'], + ['-dummypos=0', '-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=136', '-eunosheight=140', '-eunospayaheight=140']] def run_test(self): assert_equal(len(self.nodes[0].listmasternodes()), 8) @@ -199,10 +199,14 @@ def run_test(self): self.nodes[0].generate(1) assert_equal(self.nodes[0].listmasternodes({}, False)[mnTx], "ENABLED") - # test getmasternodeblocks - self.nodes[0].generate(1, address=mnAddress) blocks = self.nodes[0].getmasternodeblocks({'ownerAddress': mnAddress}) - assert_equal(len(blocks), 1) # not working correctly only mints block 141 + assert_equal(len(blocks), 0) # there is no minted blocks yet + + # test getmasternodeblocks + self.nodes[0].generate(1) + node0_keys = self.nodes[0].get_genesis_keys() + blocks = self.nodes[0].getmasternodeblocks({'operatorAddress': node0_keys.operatorAuthAddress}) + assert_equal(list(blocks.keys())[0], '162') # Test new resign delay self.nodes[0].resignmasternode(mnTx)