hsd
hsd copied to clipboard
MTX.fund - Fixes
This is alternative implementation of #639 that solves issue in the CoinSelector
.
Separate existing
and preferred
inputs:
- existing are the inputs that are present in the mtx.
- preferred now refers to inputs passed by
options.inputs
. - Use
CoinView
to resolvecoins
.
Closes #639
Test is just repeat of the matrix, it can be rewritten and shortened as a function..
Pull Request Test Coverage Report for Build 1957546736
- 60 of 61 (98.36%) changed or added relevant lines in 1 file are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage decreased (-14.6%) to 62.844%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
lib/primitives/mtx.js | 60 | 61 | 98.36% |
<!-- | Total: | 60 | 61 |
Totals | |
---|---|
Change from base Build 1947977808: | -14.6% |
Covered Lines: | 21401 |
Relevant Lines: | 31870 |
💛 - Coveralls
Another thing I noticed is that in the worst case scenario, we will loop through this.coins
twice and then iterate through a third time to fill the remaining inputs -- do you think it makes any sense to merge the existing & preferred loops? This will also get a lot better when we refactor txdb and not pull ALL COINS out for every tx...
The anyone can renew test can also be updated:
https://github.com/handshake-org/hsd/blob/06aabfffe6a26b9c5c1417d80691a8e943a48f1e/test/anyone-can-renew-test.js#L309-L312
@nodech checking in on this?
One thing that users will have to consider with these changes is that, coinview should always be supplied with coin information when using preferred inputs
and existing inputs
. If you don't add coins to the coinview, the code will try to fill them in from the coin list it gets, but if the coin list is big that will hit the performance. - That feature is there to help users just in case.
As for double spend question: It's not job of the CoinSelector to resolve double spents that happen because of the existing
and preferred
inputs. The coinselector itself wont double spend the coins if they are correctly applied to the coinview.