Skip to content

Commit

Permalink
fix: Let CDeterministicMN::ToJson() return correct `collateralAddress…
Browse files Browse the repository at this point in the history
…` for spent collaterals (#5607)

## Issue being fixed or feature implemented
Historical masternode data returned via rpcs like `protx listdiff` can
be broken because some collaterals might be spent already and
`GetUTXOCoin` wasn't able to get any info.

## What was done?
Use `GetTransaction` as a fallback.

## How Has This Been Tested?
run tests

## Breaking Changes
n/a

## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone _(for repository
code-owners and collaborators only)_
  • Loading branch information
UdjinM6 authored Oct 9, 2023
1 parent 2004a85 commit 30f3f50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions test/functional/feature_dip3_deterministicmns.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ 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)
self.nodes[0].generate(1)
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):
Expand Down

0 comments on commit 30f3f50

Please sign in to comment.