doc: correct weight numbers for fundpsbt

This commit is contained in:
niftynei
2020-09-14 14:56:17 -05:00
committed by Rusty Russell
parent 9f006fdf03
commit 53ba34fe3a
3 changed files with 12 additions and 12 deletions

View File

@@ -50,10 +50,10 @@ Let's assume the caller is trying to produce a 100,000 satoshi output\.
First, the caller estimates the weight of the core (typically 42) and First, the caller estimates the weight of the core (typically 42) and
known outputs of the transaction (typically (9 + scriptlen) * 4)\. For known outputs of the transaction (typically (9 + scriptlen) * 4)\. For
a simple P2WPKH it's a 22 byte scriptpubkey, so that's 164 weight\. a simple P2WPKH it's a 22 byte scriptpubkey, so that's 124 weight\.
It calls "\fIfundpsbt\fR 100000sat slow 206", which succeeds, and returns It calls "\fIfundpsbt\fR 100000sat slow 166", which succeeds, and returns
the \fIpsbt\fR and \fIfeerate_per_kw\fR it used, the \fIestimated_final_weight\fR the \fIpsbt\fR and \fIfeerate_per_kw\fR it used, the \fIestimated_final_weight\fR
and any \fIexcess_msat\fR\. and any \fIexcess_msat\fR\.
@@ -61,9 +61,9 @@ and any \fIexcess_msat\fR\.
If \fIexcess_msat\fR is greater than the cost of adding a change output, If \fIexcess_msat\fR is greater than the cost of adding a change output,
the caller adds a change output randomly to position 0 or 1 in the the caller adds a change output randomly to position 0 or 1 in the
PSBT\. Say \fIfeerate_per_kw\fR is 253, and the change output is a P2WPKH PSBT\. Say \fIfeerate_per_kw\fR is 253, and the change output is a P2WPKH
(weight 164), that would cost the cost is around 41 sats\. With the (weight 124), the cost is around 31 sats\. With the dust limit disallowing
dust limit disallowing payments below 546 satoshis, we would only create payments below 546 satoshis, we would only create a change output
a change output if \fIexcess_msat\fR was greater or equal to 41 + 546\. if \fIexcess_msat\fR was greater or equal to 31 + 546\.
.SH RETURN VALUE .SH RETURN VALUE
@@ -104,4 +104,4 @@ Rusty Russell \fI<rusty@rustcorp.com.au\fR> is mainly responsible\.
Main web site: \fIhttps://github.com/ElementsProject/lightning\fR Main web site: \fIhttps://github.com/ElementsProject/lightning\fR
\" SHA256STAMP:0a80505110887fe165580fd6420d681b7cdcdae89d5c45d863510f1405d70040 \" SHA256STAMP:8eb6970e2d625198db9b8e5ab7f90f9fb141744a837f58ee68ef54d28c7066b0

View File

@@ -46,18 +46,18 @@ Let's assume the caller is trying to produce a 100,000 satoshi output.
First, the caller estimates the weight of the core (typically 42) and First, the caller estimates the weight of the core (typically 42) and
known outputs of the transaction (typically (9 + scriptlen) * 4). For known outputs of the transaction (typically (9 + scriptlen) * 4). For
a simple P2WPKH it's a 22 byte scriptpubkey, so that's 164 weight. a simple P2WPKH it's a 22 byte scriptpubkey, so that's 124 weight.
It calls "*fundpsbt* 100000sat slow 206", which succeeds, and returns It calls "*fundpsbt* 100000sat slow 166", which succeeds, and returns
the *psbt* and *feerate_per_kw* it used, the *estimated_final_weight* the *psbt* and *feerate_per_kw* it used, the *estimated_final_weight*
and any *excess_msat*. and any *excess_msat*.
If *excess_msat* is greater than the cost of adding a change output, If *excess_msat* is greater than the cost of adding a change output,
the caller adds a change output randomly to position 0 or 1 in the the caller adds a change output randomly to position 0 or 1 in the
PSBT. Say *feerate_per_kw* is 253, and the change output is a P2WPKH PSBT. Say *feerate_per_kw* is 253, and the change output is a P2WPKH
(weight 164), that would cost the cost is around 41 sats. With the (weight 124), the cost is around 31 sats. With the dust limit disallowing
dust limit disallowing payments below 546 satoshis, we would only create payments below 546 satoshis, we would only create a change output
a change output if *excess_msat* was greater or equal to 41 + 546. if *excess_msat* was greater or equal to 31 + 546.
RETURN VALUE RETURN VALUE
------------ ------------

View File

@@ -56,7 +56,7 @@ def on_openchannel(openchannel2, plugin, **kwargs):
psbt_obj = psbt_from_base64(funding['psbt']) psbt_obj = psbt_from_base64(funding['psbt'])
excess = Millisatoshi(funding['excess_msat']) excess = Millisatoshi(funding['excess_msat'])
change_cost = Millisatoshi(164 * feerate // 1000 * 1000) change_cost = Millisatoshi(124 * feerate // 1000 * 1000)
dust_limit = Millisatoshi(253 * 1000) dust_limit = Millisatoshi(253 * 1000)
if excess > (dust_limit + change_cost): if excess > (dust_limit + change_cost):
addr = plugin.rpc.newaddr()['bech32'] addr = plugin.rpc.newaddr()['bech32']