Commit Graph

89 Commits

Author SHA1 Message Date
Jon Griffiths 5e63e55b99 psbt: use wally_map_get instead of wally_map_find
Changelog-None

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2024-01-16 15:47:03 +01:00
Jon Griffiths 16ac5cf085 psbt: use wally_map_replace instead of coding our own
Changelog-None

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2024-01-16 15:47:03 +01:00
Dusty Daemon a6a9e5b1e3 splice: Reestablish when commit or sig sends fail
Adds tests for when the connection fails during
1) splice tx_signature
2) splice commitment_signed

Fleshed out the reestablish flow for these two cases and implemented the fixes to make these reestablish flows work.

Part of this work required changing commit process for splices: Now we send a single commit_part for the splice where previously we sent all commits, and accordingly, we no longer revoke in response.

Changelog-Fixed: Implemented splicing restart logic for tx_signature and commitment_signed. Splice commitments are reworked in a manner incompatible with the last version.
2023-11-20 07:35:22 +01:00
Ken Sedgwick 39e17ff83b Restore any missing psbt metadata that resource constrained signers strip
Fixes ([#6764])
Changelog-Fixed: Restore any missing metadata that resource constrained signers stripped
2023-10-25 11:33:07 +02:00
Vincenzo Palazzo 843fae7caf psbt: fix PSBT mutation in the changeset
During the changeset calculation after the `openchannel2_sign`
hook.

So this commit patch the problem with the following change:

- Addressed an issue where `psbt_get_changeset` was modifying the original PSBT unnecessarily.
- This modification led to problems with a different hsmd, as referenced in [Issue #6672](https://github.com/ElementsProject/lightning/issues/6672).
- Noted a potential optimization where only a subpart of the PSBT
needs to be cloned, as the mutation is specific to inputs.

Link: https://github.com/ElementsProject/lightning/issues/6672
Reported-by: @devrandom
Suggested-by: Ken Sedgwick <ken@bonsai.com>
Co-Developed-by: Ken Sedgwick <ken@bonsai.com>
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-10-24 12:57:45 +10:30
Rusty Russell 91b5a3b323 bitcoin: remove DEVELOPER options.
Mainly removing the PSBT re-marshalling which hasn't had any issues in
recent libwally, and making dev_no_grind into the clearer
dev_no_signature_grind.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
Dusty Daemon 4628e3ace8 channeld: Code to implement splicing
Update the lightningd <-> channeld interface with lots of new commands to needed to facilitate spicing.

Implement the channeld splicing protocol leveraging the interactivetx protocol.

Implement lightningd’s channel_control to support channeld in its splicing efforts.

Changelog-Added: Added the features to enable splicing & resizing of active channels.
2023-07-31 21:00:22 +09:30
Dusty Daemon 50fe819f47 splicing: Add channel state AWAITING_SPLICE
Update gossip routiens and various other hecks on the channel state to consider AWAITING_SPLICE to be routable and treated similar to CHANNELD_NORMAL.

Small updates to psbt interface

Changelog-None
2023-07-31 21:00:22 +09:30
niftynei 388f27edce varint: make helper public 2023-07-13 19:34:47 +09:30
Greg Sanders 0097e2c666 psbt_input_add_pubkey: support taproot 2023-07-11 11:41:15 +09:30
Rusty Russell 313354329d bitcoin/psbt: handle anchor spends.
Turns out it's a single sig, identical to the already-handled
case where we spend a to_remote output.

We also close a temporary memleak: stack was unused, but
tallocated off the psbt, so it lives as long as the PSBT.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-29 11:28:47 -04:00
Jon Griffiths 14e942298a psbt: remove redundant re-setting of tx modification flags.
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2023-05-30 13:56:56 +09:30
Jon Griffiths b2b8722a14 psbt: replace init/create_psbt with just create_psbt, and simplify it.
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2023-05-30 13:56:56 +09:30
Jon Griffiths 909f911ff7 psbt: implement psbt_append_output using psbt_insert_output.
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2023-05-30 13:56:56 +09:30
Greg Sanders cc7d9f39be Update libwally to 0.8.9
Changelog-Changed: Update libwally to 0.8.9
2023-04-15 10:32:42 -07:00
Greg Sanders e30f2cb4a4 have towire_wally_psbt and fromwire_wally_psbt set safe psbt version 2023-04-11 11:23:17 +09:30
Rusty Russell 2fb942d21c bitcoin: rename confusing functions.
1. anchor_to_remote_redeem => bitcoin_wscript_to_remote_anchored,
   which matches other witness script producing functions and makes
   it clear that it's a to_remote variant.
2. is_anchor_witness_script => is_to_remote_anchored_witness_script
   makes it clear that it's about a to_remote output (as altered
   when anchors are enabled) not an anchor output!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Greg Sanders 908f834d66 Update libwally to 0.8.8, support PSBTv2
Libwally update breaks compatibility, so
we do this in one large step.

Changelog-Changed: JSON-RPC: elements network PSET now only supports PSETv2.
Changelog-Added: JSON-RPC: PSBTv2 supported for fundchannel_complete, openchannel_update, reserveinputs, sendpsbt, signpsbt, withdraw and unreserveinputs parameter psbt, openchannel_init and openchannel_bump parameter initialpsbt, openchannel_signed parameter signed_psbt and utxopsbt parameter utxopsbt
2023-03-23 16:10:55 +10:30
niftynei 49ed0a4b9e psbt: wipe global tx scriptSig/witness data after saved to PSBT
The global tx should be "free from sin" (no scriptSig data, no witness
stacks).
2022-10-18 12:46:45 -05:00
Rusty Russell b17db120b1 bitcoin: add to check-source-bolt, and (minor) quotes fixup.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-18 13:45:09 +09:30
Jon Griffiths 572942c783 psbt: use DER encoded + sighash byte for PSBT_IN_PARTIAL_SIG items
Per BIP-0171, the signature map is of pubkey to "The signature as would
be pushed to the stack from a scriptSig or witness".

Fixes 5298

Changelog-Fixed: PSBT: Fix signature encoding to comply with BIP-0171.

Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2022-06-09 18:28:35 +02:00
Rusty Russell 65be18d355 memleak: handle libwally allocations better.
Things allocated by libwally all get the tal_name "wally_tal",
which cost me a few hours trying to find a leak.

In the case where we're making one of the allocations the parent
of the others (e.g. a wally_psbt), we can do better: supply a name
for the tal_wally_end().

So I add a new tal_wally_end_onto() which does the standard
tal_steal() trick, and also changes the (typechecked!) name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-21 10:19:50 +10:30
Rusty Russell d9968bbc0c bitcoin: remove unused functions, or make static.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30
Rusty Russell c503232cde common: use bitcoin_outpoint.
I started pulling this thread, and the entire codebase got unravelled.

Oh well, it's done now!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-15 12:09:36 +02:00
Rusty Russell 7401b26824 cleanup: remove unneeded includes in C files.
Before:
 Ten builds, laptop -j5, no ccache:

```
real	0m36.686000-38.956000(38.608+/-0.65)s
user	2m32.864000-42.253000(40.7545+/-2.7)s
sys	0m16.618000-18.316000(17.8531+/-0.48)s
```

 Ten builds, laptop -j5, ccache (warm):

```
real	0m8.212000-8.577000(8.39989+/-0.13)s
user	0m12.731000-13.212000(12.9751+/-0.17)s
sys	0m3.697000-3.902000(3.83722+/-0.064)s
```

After:
 Ten builds, laptop -j5, no ccache: 8% faster

```
real	0m33.802000-35.773000(35.468+/-0.54)s
user	2m19.073000-27.754000(26.2542+/-2.3)s
sys	0m15.784000-17.173000(16.7165+/-0.37)s
```

 Ten builds, laptop -j5, ccache (warm): 1% faster

```
real	0m8.200000-8.485000(8.30138+/-0.097)s
user	0m12.485000-13.100000(12.7344+/-0.19)s
sys	0m3.702000-3.889000(3.78787+/-0.056)s
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
niftynei 3c4c8d4fa0 libwally: update to release_0.8.3
Remove hacks to get around empty PSBT deserialization bug
2021-06-03 11:24:33 +09:30
niftynei de854fa9d4 psbt: really hacky patch over libwally's 0-input txs parse fail
Issue being tracked at https://github.com/ElementsProject/libwally-core/pull/273
2021-05-12 11:25:41 +09:30
niftynei ff164cf8b3 psbt: temporarily patch over failure to parse the empty tx
libwally has a bug which results in it failing to parse the 'empty tx'
cHNidP8BAAoAAAAAAAAAAAAAAA==. While we wait for the patch to land in
libwally, we patch over it.

Fix at: https://github.com/ElementsProject/libwally-core/pull/273
2021-04-16 15:33:44 +09:30
niftynei cca6e8db03 psbt: mark psbt arg as const for `psbt_compute_fee` 2021-03-09 14:55:05 +10:30
niftynei 5a11c8aa7a psbt: method to calculate fee paid on PSBT 2021-02-24 10:06:42 -06:00
niftynei 10fce07d96 psbt: method to clone a PSBT onto a context
wally offers up `wally_clone_psbt` but it's a bit clunky (requires
checking return value, starting/stopping the wally_allocation context)

Helper method wraps this all up nice + neat!
2021-02-24 10:06:42 -06:00
Rusty Russell 06a54606a3 check-includes: allow redundant "config.h"
We should actually be including this (as it may define _GNU_SOURCE
etc) before any system headers.  But where we include <assert.h> we
often didn't, because check-includes would complain that the headers
included it too.

Weaken that check, and include config.h in C files before assert.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-04 12:02:36 +10:30
Jon Griffiths 5c2fc4c1cb wally: remove wally casts that are no longer needed
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
2020-11-30 10:28:04 +10:30
niftynei 4034d0c306 psbt: have the unknown map 'add' be a 'set' instead 2020-10-20 14:27:19 +10:30
niftynei 93045945be psbt: add helper to set the non-witness utxo for an input
We need this info for every dual-funded open
2020-10-20 12:50:31 +10:30
Rusty Russell d5cb0d85b5 utils: use a cleaner pattern to capture wally allocations.
We force use of tal_wally_start/tal_wally_end around every wally
allocation, and with "end" make the caller choose where to reparent
everything.

This is particularly powerful where we allocate a tx or a psbt: we
want that tx or psbt to be the parent of the other allocations, so
this way we can reparent the tx or psbt, then reparent everything
else onto it.

Implementing psbt_finalize (which uses a behavior flag antipattern)
was tricky, so I ended up splitting that into 'psbt_finalize' and
'psbt_final_tx', which I think also makes the callers clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 14:45:53 +02:00
Rusty Russell 66ffd7a73f bitcoin/: neaten use of libwally base58 and bas64 routines.
Now libwally uses tal, we don't need to make copies.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 14:45:53 +02:00
niftynei 1f165c00ae psbt_txid: it's possible a psbt may already have the finalized scriptsig
If we've already got a scriptSig field filled out for a PSBT input, we
use that instead of 'deriving' the scriptSig from the redeemscript
(finalizing a PSBT removes the redeemscript field)
2020-09-23 15:51:13 +09:30
Rusty Russell c23001d508 bitcoin: use tal_gather_wally() so we don't leave unattached allocations.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
Rusty Russell 3c8049f32c bitcoin/psbt: psbt_input_add_unknown/psbt_output_add_unknown needs a tal ctx.
Since it allocates something, it needs a context (used in the next patch!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
Rusty Russell 77b62d9e42 bitcoin/psbt: psbt_finalize needs a tal ctx.
Since it returns a wally_tx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
Rusty Russell 607075a3d4 bitcoin/psbt: wallt_tx_output needs a tal ctx.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
Rusty Russell 480f671e91 bitcoin/psbt: psbt_txid needs a tal ctx.
It returns a wally_tx; it's an anti-pattern not to hand in a tal context.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
Rusty Russell 11ebb84e7d bitcoin/psbt: attach destructors to wally allocations to avoid leaks.
This covers the obvious ones, but the later patches fix this more
seriously.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Some memory leaks in transaction and PSBT manipulate closed.
2020-09-23 13:52:49 +09:30
Rusty Russell 80c705d528 bitcoin/psbt: more const pointers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
niftynei 165d039f6c elements: consolidate fee outputs into a single fee output
In the case that you've got more than one fee output already on a
psbt, we consolidate them into a single fee output (the first)
2020-09-10 12:31:36 +09:30
niftynei 4c28e7b362 txprepare: elements requires inclusion of an accurate fee output
so we add an accurate one
2020-09-10 12:31:36 +09:30
niftynei 24578c7fea elementsd: use the elements version of a 'witness utxo'
Elements requires the witness utxo to include the asset and value info,
in order for the signing hash to be constructed correctly

Changelog-Fixed: elementsd: PSBTs include correct witness_utxo struct for elements transactions
2020-09-10 12:31:36 +09:30
ZmnSCPxj jxPCSnmZ 5d7178d488 bitcoin/psbt.c: Add psbt_insert_output function. 2020-09-09 20:36:08 +09:30
niftynei 303263d381 psbt: clean up interface for setting metadata on PSBT inputs
it's just neater if it's not all wrapped up together, simplifies the
interface a smidge
2020-09-09 19:54:20 +09:30