Skip to content

dpow_haveutxo: fix bug if only one "iguana" UTXO#186

Merged
ca333 merged 1 commit intoKomodoPlatform:devfrom
phm87:FixBugIfOnlyOneUTXO
Aug 24, 2020
Merged

dpow_haveutxo: fix bug if only one "iguana" UTXO#186
ca333 merged 1 commit intoKomodoPlatform:devfrom
phm87:FixBugIfOnlyOneUTXO

Conversation

@phm87
Copy link
Copy Markdown
Contributor

@phm87 phm87 commented Jul 9, 2020

This code change is not consensus change, it is a utxo selection improvement.
It was tested prior to the Bible rules existence.
I hope that enhancing iguana during S4 is not forbidden, can you clarify about how to test code improvements/changes without breaking Bible rules?

This code change was discussed on discord with blackjok3r who said that it will fix one problem of this loop but the utxo selection loop needs a complete rewrite.

I had a bug on the main Notary Node (NN) but it didn't happen on the 3P NN on KMD.
If there is only one "iguana" UTXO and no other UTXO (*), no notarization happens and the following error happens:
no (%s -> %s) utxo: need to fund address.(%s) or wait for splitfund to confirm\n

(*) Such case can be encountered if the node is running out of assetchain balance and there is only one "iguana" UTXO left. it can also happens if playing with distant coin split and/or advanced use of wallet filters.

In such a case, the loop inside dpow_haveutxo will have n = cJSON_GetArraySize(unspents) = 1 because listunspent returns only one UTXO. As j variable is initialized at 0 before the loop and incremented at the beginning of the loop, j = 1 at the first iteration of the loop so j = n and the loop will exit. By moving the j incrementation at the end of the loop, it will execute the code within the loop if there is only one UTXO.

To test/analyse:

  • add more logs and analyze iguana TV on main NN and 3P NN.

To test:

Changelog for NN operators:
The number of the chosen UTXO will be decreased by 1, meaning the UTXO "numbering" in the log will start at UTXO 0 instead of starting from UTXO 1:
[%s] : chosen = %d out of %d loop.(%d)\n

I had a bug on the main Notary Node (NN) but it didn't happen on the 3P NN on KMD.
If there is only one "iguana" UTXO and no other UTXO (*), no notarization happens and the following error happens:
```no (%s -> %s) utxo: need to fund address.(%s) or wait for splitfund to confirm\n```

(*) Such case can be encountered if the node is running out of assetchain balance and there is only one "iguana" UTXO left. it can also happens if playing with distant coin split and/or advanced use of wallet filters.


In such a case, the loop inside dpow_haveutxo will have ``n = cJSON_GetArraySize(unspents) = 1`` because listunspent returns only one UTXO. As ``j`` variable is initialized at 0 before the loop and incremented at the beginning of the loop, j = 1 at the first iteration of the loop so j = n and the loop will exit. By moving the j incrementation at the end of the loop, it will execute the code within the loop if there is only one UTXO.

To test/analyse:
- add more logs and analyze iguana TV on main NN and 3P NN.

To test:
- Test with different coinsplit scripts,
- Test with distant coinsplit (e.g. with https://github.com/DeckerSU/komodo_scripts/blob/master/split_nn_sapling.sh) with/without wallet filters
- Test on main NN and 3P NN in different situations (no coin left, only one big utxo not splitted, same tests without sapling (OOT)).

Changelog for NN operators:
The number of the chosen UTXO will be decreased by 1, meaning the UTXO "numbering" in the log will start at UTXO 0 instead of starting from UTXO 1:
[%s] : chosen = %d  out of %d loop.(%d)\n
@ca333 ca333 changed the base branch from master to dev August 21, 2020 18:44
@ca333 ca333 requested review from Alrighttt and DeckerSU August 21, 2020 18:45
Copy link
Copy Markdown
Contributor

@DeckerSU DeckerSU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This commit really should fix "only one" utxo issue, despite the fact that this issue is kind of rarely met edge case.

@ca333 ca333 merged commit b4b1c03 into KomodoPlatform:dev Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants