From e6f1b4a33538ee8706782e43d4ccec8d81148d34 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 7 Oct 2023 23:51:28 +0300 Subject: [PATCH 1/2] fix: Let CDeterministicMN::ToJson() return correct `collateralAddress` for spent collaterals --- src/evo/deterministicmns.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index e99c711055fe4..87df855cae1cc 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -50,12 +50,17 @@ UniValue CDeterministicMN::ToJson() const obj.pushKV("collateralHash", collateralOutpoint.hash.ToString()); obj.pushKV("collateralIndex", (int)collateralOutpoint.n); - Coin coin; - if (GetUTXOCoin(collateralOutpoint, coin)) { - CTxDestination dest; - if (ExtractDestination(coin.out.scriptPubKey, dest)) { - obj.pushKV("collateralAddress", EncodeDestination(dest)); - } + CScript scriptPubKey; + if (Coin coin; GetUTXOCoin(collateralOutpoint, coin)) { + scriptPubKey = coin.out.scriptPubKey; + } else { + uint256 tmpHashBlock; + CTransactionRef collateralTx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, collateralOutpoint.hash, Params().GetConsensus(), tmpHashBlock); + scriptPubKey = collateralTx->vout[collateralOutpoint.n].scriptPubKey; + } + CTxDestination dest; + if (ExtractDestination(scriptPubKey, dest)) { + obj.pushKV("collateralAddress", EncodeDestination(dest)); } obj.pushKV("operatorReward", (double)nOperatorReward / 100); From f613b43931cc3ce9787c51a9270b011d3dc89faa Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 8 Oct 2023 13:58:58 +0300 Subject: [PATCH 2/2] test: check `protx listdiff` on spent mns --- test/functional/feature_dip3_deterministicmns.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/functional/feature_dip3_deterministicmns.py b/test/functional/feature_dip3_deterministicmns.py index 9a39ab1040a5e..357901121b63d 100755 --- a/test/functional/feature_dip3_deterministicmns.py +++ b/test/functional/feature_dip3_deterministicmns.py @@ -112,6 +112,8 @@ def run_test(self): spend_mns_count = 3 mns_tmp = [] + mns dummy_txins = [] + old_tip = self.nodes[0].getblockcount() + old_listdiff = self.nodes[0].protx("listdiff", 1, old_tip) for i in range(spend_mns_count): dummy_txin = self.spend_mn_collateral(mns[i], with_dummy_input_output=True) dummy_txins.append(dummy_txin) @@ -119,6 +121,8 @@ def run_test(self): self.sync_all() mns_tmp.remove(mns[i]) self.assert_mnlists(mns_tmp) + new_listdiff = self.nodes[0].protx("listdiff", 1, old_tip) + assert_equal(new_listdiff, old_listdiff) self.log.info("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):