-
Notifications
You must be signed in to change notification settings - Fork 102
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
First idea of "confirmation layer" #25
base: master
Are you sure you want to change the base?
Conversation
Can this be accomplished by providing a specialized sort function, before handling We could then offer the different options to that function, such as |
The algorithms have no guarantee of choosing utxos in the order given, right? A-ha, they actually all do. I have confused it with the algorithms in |
@Runn1ng they do, maybe that should be documented better than "UTXOs order"? |
Related to #24 discussion Should there be another layer of algorithms, that have type (Rich Inputs | (Rich inputs -> Inputs) | Outputs | Fee Rate | Maybe Outputs) -> Nothing | Fee | (Fee | Inputs | Outputs)
Or the underlyng algorithm another input (as in the PR)? The algorigthm in |
@Runn1ng I actually played with that function prototype initially, but ruled against it because it didn't easily lend itself to composition, and the method used would only use Easier to have users do that themselves using a provided comparator TBH.
The default export was optimized to provide the best results for users, if they were composing the algorithms themselves, the idea was they might know what they were doing. |
I did some changes, combining the ideas from here and from the #24 discussion, don't want to make another PR https://github.com/runn1ng/coinselect/tree/reorg Adding the various sorting function and utils.algorithmBackup simplified simulation code somewhat, the index.js is shorter and the composition is easier, but the function-returning-functions are slightly harder to read and understand. You can comment on the commit directly, or I can make it as a PR |
@Runn1ng I commented on the commit directly. Nice work! Mostly nits. I think we're going to have 3 user-choices.
Algorithms like BIP126 don't offer a choice, but some algorithms are entirely composable. Example let coinselect = require('coinselect')
let utils = require('coinselect/utils')
let accumulative = require('coinselect/u_accumulative')
let blackjack = require('coinselect/u_blackjack')
let feeRate = 10
utxos = utxos.sort(utils.BY_DESCENDING_VALUE) // no issue with copies now
let { inputs, outputs } = utils.bestOf(blackjack, accumulative)(utxos, desiredOutputs, feeRate)
if (!inputs) return
... That is a bit lame, but, it puts it all out on the table. |
Maybe also add an example of how BNB fits into this |
Hm, now I realized how just sorting the utxos won't be sufficient for BnB (or blackjack). BnB and blackjack will try to find an exact match, from any of the inputs. However, if a non-exact match is possible from 6+ confirmed utxos (or 1+ confirmed utxos for own change utxos), they should be used instead of exact match with little confirmed utxos. Just sorting the UTXOs won't cut it. I will need some logic as I made in this PR - first try [6,1] - and try first exact match, then accumulative - and then repeatedly loosen the restrictions. |
I have updated the Hm. I will update this PR with the new confirmation filtering |
...updated (tests check, but the new file is not covered :)) |
What should I do to move this forward. To be more concrete - do you think the multiple trials, with the confirmation restriction being loosened in every trial, be included in this library? Or should it be in another layer / another library, if the user wants it? In my case - I am adding it to Trezor Web Wallet and I will want that logic there one way or the other. |
I simply haven't had time to review/discuss this yet 😦 - apologies @Runn1ng |
No problem, I want to help, not overwhelm. :) |
@karel-3d reading this again, I still don't know if this is the right space. Isn't the optimal behaviour around confirmations entirely contextually dependent? |
The fuction is optional (is just another layer above current selection algorithms) and whoever calls the library can set how much confirmations he wants; can be 0 for both "own" utxos and "other" utxos |
This is a first idea for #23
The function would get "rich utxos", which include not just input with script+value, but also information about confirmations, and whether it is "own" utxo or not.
The point is - we want to allow the user to make a transaction on unconfirmed utxos, but only when utxos with more confirmations fail.
The API is not yet ideal; but I would like to hear your thoughts now