Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getmasternodeblocks #704

Merged
merged 2 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/masternodes/rpc_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,17 +498,29 @@ UniValue getmasternodeblocks(const JSONRPCRequest& request) {

UniValue ret(UniValue::VOBJ);

pcustomcsview->ForEachMinterNode([&](MNBlockTimeKey const & key, CLazySerialize<int64_t>) {
if (key.masternodeID != mn_id) {
auto masternodeBlocks = [&](const uint256& masternodeID, uint32_t blockHeight) {
if (masternodeID != mn_id) {
return false;
}

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<int64_t>){
return masternodeBlocks(key.masternodeID, key.blockHeight);
}, SubNodeBlockTimeKey{mn_id, 0, std::numeric_limits<uint32_t>::max()});

pcustomcsview->ForEachMinterNode([&](MNBlockTimeKey const & key, CLazySerialize<int64_t>) {
return masternodeBlocks(key.masternodeID, key.blockHeight);
}, MNBlockTimeKey{mn_id, std::numeric_limits<uint32_t>::max()});

auto tip = ::ChainActive()[std::min(lastHeight, uint64_t(Params().GetConsensus().DakotaCrescentHeight)) - 1];
Expand Down Expand Up @@ -675,7 +687,7 @@ UniValue listanchors(const JSONRPCRequest& request)
}

static const CRPCCommand commands[] =
{
{
// category name actor (function) params
// --------------- ---------------------- --------------------- ----------
{"masternodes", "createmasternode", &createmasternode, {"ownerAddress", "operatorAddress", "inputs"}},
Expand Down
18 changes: 14 additions & 4 deletions test/functional/rpc_mn_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")

Expand All @@ -198,6 +199,15 @@ def run_test(self):
self.nodes[0].generate(1)
assert_equal(self.nodes[0].listmasternodes({}, False)[mnTx], "ENABLED")

blocks = self.nodes[0].getmasternodeblocks({'ownerAddress': mnAddress})
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)
self.nodes[0].generate(1)
Expand Down