-
Notifications
You must be signed in to change notification settings - Fork 974
Reserve/unreserve/fundpsbt #3825
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
Merged
rustyrussell
merged 12 commits into
ElementsProject:master
from
rustyrussell:reserve-unreserve-fundpsbt
Jul 15, 2020
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9e7c0d9
utxos: add a 'reserved_til' marker for utxos
niftynei 9c7a374
wallet: explicit routines to reserve/unreserve a UTXO.
rustyrussell 4f9fd46
wallet: add wallet_find_utxo().
rustyrussell 5611246
wallet: new JSON commands reserveinputs and unreserveinputs.
rustyrussell ba86cdc
reserveinputs: add exclusive flag.
rustyrussell 1056eba
pytest: test reserve and unreserve.
rustyrussell 78fcaac
fundpsbt: new JSON API to gather UTXOs.
rustyrussell 32c7dbb
fundpsbt: add reserve arg.
rustyrussell 42d6013
doc: document fundpsbt.
rustyrussell 1ce1209
pytest: test fundpsbt.
rustyrussell 5a93794
pytest: restore test_sign_and_send_psbt.
rustyrussell d162739
txprepare: revert 1fb9a078b620a65a2802bc8b1303970914cfb4cb (`psbt` fi…
rustyrussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| lightning-fundpsbt -- Command to populate PSBT inputs from the wallet | ||
| ================================================================ | ||
|
|
||
| SYNOPSIS | ||
| -------- | ||
|
|
||
| **fundpsbt** *satoshi* *feerate* \[*minconf*\] \[*reserve*\] | ||
|
|
||
| DESCRIPTION | ||
| ----------- | ||
|
|
||
| `fundpsbt` is a low-level RPC command which creates a PSBT using unreserved | ||
| inputs in the wallet, optionally reserving them as well. | ||
|
|
||
| *satoshi* is the minimum satoshi value of the output(s) needed (or the | ||
| string "all" meaning use all unreserved inputs). If a value, it can | ||
| be a whole number, a whole number ending in *sat*, a whole number | ||
| ending in *000msat*, or a number with 1 to 8 decimal places ending in | ||
| *btc*. | ||
|
|
||
| You calculate the value by starting with the amount you want to pay | ||
| and adding the fee which will be needed to pay for the base of the | ||
| transaction plus that output, and any other outputs and inputs you | ||
| will add to the final transaction. | ||
|
|
||
| *feerate* is a number, with an optional suffix: *perkw* means the | ||
| number is interpreted as satoshi-per-kilosipa (weight), and *perkb* | ||
| means it is interpreted bitcoind-style as | ||
| satoshi-per-kilobyte. Omitting the suffix is equivalent to *perkb*. | ||
|
|
||
| *minconf* specifies the minimum number of confirmations that used | ||
| outputs should have. Default is 1. | ||
|
|
||
| *reserve* is a boolean: if true (the default), then *reserveinputs* is | ||
| called (successfully, with *exclusive* true) on the returned PSBT. | ||
|
|
||
| RETURN VALUE | ||
| ------------ | ||
|
|
||
| On success, returns the *psbt* containing the inputs, and | ||
| *excess_msat* containing the amount above *satoshi* which is | ||
| available. This could be zero, or dust. If *satoshi* was "all", | ||
| then *excess_msat* is the entire amount once fees are subtracted | ||
| for the weights of the inputs. | ||
|
|
||
| If *reserve* was true, then a *reservations* array is returned, | ||
| exactly like *reserveinputs*. | ||
|
|
||
| On error the returned object will contain `code` and `message` properties, | ||
| with `code` being one of the following: | ||
|
|
||
| - -32602: If the given parameters are wrong. | ||
| - -1: Catchall nonspecific error. | ||
| - 301: Insufficient UTXOs to meet *satoshi* value. | ||
|
|
||
| AUTHOR | ||
| ------ | ||
|
|
||
| Rusty Russell <<rusty@rustcorp.com.au>> is mainly responsible. | ||
|
|
||
| SEE ALSO | ||
| -------- | ||
|
|
||
| lightning-reserveinputs(7), lightning-unreserveinputs(7). | ||
|
|
||
| RESOURCES | ||
| --------- | ||
|
|
||
| Main web site: <https://github.com/ElementsProject/lightning> | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably mention that:
fundpsbtfactors in the fees needed for each input it proposes to add.satoshivalue should include the fee for the outputs, plus the fee for the common parts (nLockTime,nVersionetc) of the transaction.The latter point implies that plugins need access to the fee estimates. While plugins can call the
bcliestimatefeesdirectly, I think it is best iflightningd/chaintopologyalso exposes the actual feerates it would use, especially sinceestimatefeesis allowed to returnnullandchaintopology, to my understanding, papers over that case. (I think? @darosior )Alternately, since e.g. Liquid apparently has explicit fee outputs, maybe we can add another parameter,
outputs, which is an array of strings ornulls:fundpsbtallocates fees enough for an output going to that address.fundpsbtallocates fees enough for an output going to that kind of address:p2pkhp2pk- or not who uses this nowadaysp2shp2wpkhp2wshop-return-#where # is a number from 0 to 64 (or whatever theOP_RETURNmax is).null, in which casefundpsbtwill allocate fees for the largest known valid address typescriptPubKey..Then
fundpsbtcan consider whether there is some excess and see if it is large enough to (1) pay for its existence as a change output and (2) remains large enough to keep itself above the dust limit. If not, it adds the excess to fees (which it adds as an explicit output for Liquid txes).With this
outputsparameter we can also havefundpsbtconsider the common parts of the transaction (nLockTimeand friends). This removes any remaining reasons that a robust plugin would want to loop aroundfundpsbt.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, better to use the
feeratecommand which returns a human error in case of estimation failure and smoothed estimation otherwise.estimatefeescould fail (and we allow it to), whilefeerateswould still return a result based on our cached history (if we have one, ie not startup).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right,
feerates. Will go document it for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next paragraph does exactly this:
You calculate the value by starting with the amount you want to pay
and adding the fee which will be needed to pay for the base of the
transaction plus that output, and any other outputs and inputs you
will add to the final transaction.
Indeed. My draft
txprepare-as-pluginpatch does exactly this, and it's pretty simple (now we have the helpers in place!).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the code in
txprepareor infundpsbt? I cannot findtxprepare-as-pluginbranch in your repo or in the ElementsProject repo. My concern is that I believe you mentioned deprecation oftxprepare, and in any casefundchannel/multifundchannelwill want to move away fromtxprepareanyway. So a command which wrapsfundpsbtand handles as well the common and output weight fees would be quite convenient; iftxpreparewill be deprecated later, it would be useful for bothwithdrawandfundchannel(and theirmultiversions) to use that rather than the existing basefundpsbt.