Commit Graph

249 Commits

Author SHA1 Message Date
Greg Sanders 4b70736d13 Support p2tr deposit addresses
Changelog-Added: JSON-RPC: newaddr: p2tr option to create taproot addresses.
Changelog-Changed: Wallet: we now use taproot change addresses.
2023-07-11 11:41:15 +09:30
Rusty Russell af6d7c0779 global: thread zero fee option everywhere.
In most cases, it's the same as option_anchor_outputs, but for
fees it's different.  This transformation is the simplest:
pass it as a pair, and test it explicitly.

In future we could rationalize some paths, but this was nice
and mechanical.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-29 11:28:47 -04:00
Rusty Russell 6087decec3 dualopend: use a lower feerate for first commitment tx for anchors.
We need to know both, because in theory we could negotiate a
non-anchor channel even if they support it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-29 11:28:47 -04:00
Rusty Russell 5c6e706026 lightningd: initialize channel_type field on dualopend channel creation.
Otherwise a badly-timed listpeerchannels will crash.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-29 11:28:47 -04:00
Rusty Russell a6772e9dec common: add new internal type for websockets.
Now it's not a public type, we need a way to refer to it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-01 09:28:39 +09:30
Rusty Russell 1b6ff0b2fc staticbackup: don't use wireaddr_internal.
This is an internal type: it has no API guarantees (indeed, I'm about
to change it, which is how I discovered scb was using it).

Fortunately for every case we care about, it is actually a wireaddr
(in theory the peer can connect locally using a local socket, but this
is mostly for testing and is a very strange setup, and so simply don't
do scb for those).

In this case, the wire encoding is a single byte followed by the
wireaddr, so open-code that in scb_wire.csv for compatibility.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-01 09:28:39 +09:30
Rusty Russell cfa33ce362 lightningd: fix incorrect reuse of dualopend, leading to dev_queryfeerates race
CI hit this issue where it would get a tx_abort in fundchannel.  This
happens when the dualopend we use to query the feerates has not exited
yet (it waits for the tx_abort reply), and we mistakenly reuse it.

With multi-channel support, this is wrong: just run another one and it
all Just Works.

This means we need to rework our dual_open_control.c logic, since it
would previously create an unsaved channel then not clean up if
something went wrong.

Most people will never try to negotiate opening multiple channels to
the same peer at the same time (vs. having an established channel and
opening a new one), so this case is a bit weird.

```
         rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
     
         # l1 leases a channel from l2
         l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
                            feerate='{}perkw'.format(feerate),
 >                          compact_lease=rates['compact_lease'])
 
 tests/test_opening.py:1611: 
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 contrib/pyln-client/pyln/client/lightning.py:833: in fundchannel
     return self.call("fundchannel", payload)
 contrib/pyln-testing/pyln/testing/utils.py:721: in call
     res = LightningRpc.call(self, method, payload, cmdprefix, filter)

 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 
 self = <pyln.testing.utils.PrettyPrintingLightningRpc object at 0x7f6cbcd97950>
 method = 'fundchannel'
 payload = {'amount': 500000, 'announce': True, 'compact_lease': '029a00640064000000644c4b40', 'feerate': '2000perkw', ...}
 cmdprefix = None, filter = None
 
     def call(self, method, payload=None, cmdprefix=None, filter=None):
         """Generic call API: you can set cmdprefix here, or set self.cmdprefix
...
         if not isinstance(resp, dict):
             raise ValueError("Malformed response, response is not a dictionary %s." % resp)
         elif "error" in resp:
 >           raise RpcError(method, payload, resp['error'])
 E           pyln.client.lightning.RpcError: RPC call failed: method: fundchannel, payload: {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'amount': 500000, 'feerate': '2000perkw', 'announce': True, 'request_amt': 500000, 'compact_lease': '029a00640064000000644c4b40'}, error: {'code': -1, 'message': 'Abort requested', 'data': {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'method': 'openchannel_init'}}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-05-29 13:46:21 +09:30
Rusty Russell ba46849ee2 lightningd: fix DF crash from libwally update.
Broken prior to 23.05 in 908f834d66218b52132c22af78a7ff87ad7ddec1:

```
lightningd: FATAL SIGNAL 11 (version d1cf88c)
0x56135ea0f865 send_backtrace
	common/daemon.c:33
0x56135ea0fa50 crashdump
	common/daemon.c:75
0x7f00d263bcef ???
	./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x56135e9887d9 validate_input_unspent
	lightningd/dual_open_control.c:2632
0x56135e989a55 handle_validate_inputs
	lightningd/dual_open_control.c:3026
0x56135e98a9a3 dual_opend_msg
	lightningd/dual_open_control.c:3357
0x56135e9df230 sd_msg_read
	lightningd/subd.c:557
0x56135eb0b6aa next_plan
	ccan/ccan/io/io.c:59
0x56135eb0c2d9 do_plan
	ccan/ccan/io/io.c:407
0x56135eb0c31b io_ready
	ccan/ccan/io/io.c:417
0x56135eb0e6b5 io_loop
	ccan/ccan/io/poll.c:453
0x56135e99b682 io_loop_with_timers
	lightningd/io_loop_with_timers.c:22
0x56135e9a230c main
	lightningd/lightningd.c:1231
0x7f00d262350f __libc_start_call_main
	../sysdeps/nptl/libc_start_call_main.h:58
0x7f00d26235c8 __libc_start_main_impl
	../csu/libc-start.c:381
0x56135e96ff24 ???
	???:0
0xffffffffffffffff ???
	???:0
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: Fixed crash in dual-funding.
2023-05-29 13:46:21 +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
Rusty Russell 9366e6b39f cleanup: rename json_add_amount_msat_only to json_add_amount_msat
Now there's no compat variant, we can rename this function.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-03-18 15:55:49 +10:30
Rusty Russell 780f32dfc6 global: remove deprecated non-msat-named msat fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: JSON-RPC: all the non-msat-named millisatoshi fields deprecated in v0.12.0.
2023-03-18 15:55:49 +10:30
Vincenzo Palazzo dd9400df99 fix: compilation error on armv7l 32 bit
This fixes the following compilation error
and allow rebuilding again on 32-bit platform.

```
lightningd/dual_open_control.c: In function 'validate_input_unspent':
lightningd/dual_open_control.c:2627:43: error: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
 2627 |                         err = tal_fmt(pv, "PSBT input at index %"PRIu64
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~
 2628 |                                       " missing serial id", i);
      |                                                             ~
      |                                                             |
      |                                                             size_t {aka unsigned int}
ccan/ccan/tal/str/str.h:43:46: note: in definition of macro 'tal_fmt'
   43 |         tal_fmt_(ctx, TAL_LABEL(char, "[]"), __VA_ARGS__)
      |                                              ^~~~~~~~~~~

```

PS: apparently I'm the only remaining people that ran cln on an old raspberry pi 2?

Changelog-None
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-02-10 16:26:06 -06:00
niftynei beec517910 df: persist our setting to disk, read back to dualopend at reinit
It's not likely but possible that the node's settings will shift btw a
start and an RBF; we persist the setting to the database so we don't
lose it.

Right now holding onto it forever is kind of extra but maybe we'll
reuse the setting for splices? idk.

Should this be a channel type??
2023-02-07 21:03:36 -06:00
niftynei fa80f15f85 dualopend: if required, validate inputs rcvd from peer
Pass in the "validate inputs confirmed" flag from lightningd; use flag
to determine whether or not to validate the inputs we've recieved from
peer.
2023-02-07 21:03:36 -06:00
niftynei abb50c4627 df: reuse psbt validation for the psbts incoming from dualopend
Add callback methods to extant psbt validator, and expand usage to
include the handling psbt validation requests from dualopend.
2023-02-07 21:03:36 -06:00
niftynei 0da2729ce6 df: for dryruns, inform on requires-confirmation value 2023-02-07 21:03:36 -06:00
niftynei cea7fe3f05 df: push back psbt to validate iff peer requests confirmed inputs
`openchannel_init` takes a psbt, which we pipe over to dualopend
process.

If the peer requests that they'll only accept confirmed inputs, we need
to go validate those before we continue.

This wires up the harness for this (validation check yet tc)
2023-02-07 21:03:36 -06:00
niftynei 9f53e3c7f5 df: wire up peer's "require-confirmed-inputs"
We push this info out to the various RPCs/hooks.
2023-02-07 21:03:36 -06:00
niftynei f05d450098 df: persist channel open preference to database
technically we don't need this info after the channel opens, but for any
subsequent RBF (and maybe splice?) we need to remember what the
open/accept peer signaled
2023-02-07 21:03:36 -06:00
niftynei 739d3c7b47 v2 open: if flagged, check that all our inputs are confirmed
not amazing, since we'll probably call openchannel_update multiple
times per open, but this is the simplest way to confirm that we're
not sending unconfirmed outputs to peer.
2023-02-07 21:03:36 -06:00
niftynei 195a2cf44b dual-open: use tx-abort instead of warning/errors
When a channel open fails, we use tx-abort instead of warning/error.

This means that the peer won't disconnect! And instead when a new
message arrives, we'll need to rebuild the dualopend subd (if missing).

Makes opens a bit easer to retry (no reconnect needed), as well as keeps
the connection alive for other channels we may have with that peer.

Changelog-Changed: Experimental-Dual-Fund: open failures don't disconnect, but instead fail the opening process
2023-02-05 10:02:46 +01:00
niftynei 4c46750001 dual-open-rbf: remember the requested lease amount btw restarts
Don't forget the requested lease across restarts.
2023-02-04 15:31:16 +10:30
niftynei df4bd6287a dual-fund: patch in channel_type logic
There's no reason not to use the channel-types (same as v1s) for v2
opens.

Brings us into compliance with ACINQ's implementation afaict
2023-02-04 15:31:16 +10:30
niftynei c9c367d770 dual-fund: remove anchor assumption for all dual-funded channels
Only add the anchor channel_type if it's negotiated separately!
2023-02-04 15:31:16 +10:30
niftynei efe66f9689 dual-fund: check features to print (anchors not assumed) 2023-02-04 15:31:16 +10:30
Rusty Russell 611795beee listtransactions: get rid of per-tx type annotations.
We didn't actually populate them properly, and the real annotations
are on inputs and outputs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: JSON-RPC: `listtransactions` `channel` and `type` field removed at top level.
2023-01-30 15:15:41 -06:00
Rusty Russell 1d8b899551 lightningd: prepare internal json routines for listpeerchannels.
We're soon going to call json_add_unsaved_channel and
json_add_uncommitted_channel from a new place, where we want the peer
state directly included.

Based on patch by @vincenzopalazzo.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-01-13 10:42:42 +10:30
Rusty Russell 66bde4bd9f lightningd: only allow closing to native segwit
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: JSON-RPC: `close` `destination` no longer allows p2pkh or p2sh addresses (deprecated v0.11.0)
2022-12-13 08:28:12 +10:30
Christian Decker adf14151fa wallet: Use boolean to determine whether an output is coinbase 2022-11-09 11:55:25 +01:00
niftynei 26f5dcd2a5 wallet: mark coinbase outputs as 'immature' until spendable
Changelog-Changed: JSON-RPC: `listfunds` now lists coinbase outputs as 'immature' until they're spendable
Changelog-Changed: JSON-RPC: UTXOs aren't spendable while immature
2022-11-09 11:55:25 +01:00
niftynei 85039d4f4e df: pass lease data back to funder for rbfs
let's let RBFs know about our lease info!
2022-10-20 13:42:41 +02:00
niftynei d3066ab7f9 openchannel2: may re-use rates
If more than one plugin calls `openchannel2`, the payload will get
re-freshed/re-parsed.
2022-10-20 13:42:41 +02:00
niftynei fa987f2344 df: put requested_lease onto state, so it persists
We're gonna need it for rbf requests/re-negotiations
2022-10-20 13:42:41 +02:00
niftynei 250b190e5f chainparams/dual-open: set max_supply; use for max on wumbo channels
We were leaving out the `channel_max_msat` for `openchannel2` when
channels are 'wumbo' (the conversion to msat in the json helper
overflowed, which resulted in the field not being printed)

Changelog-Changed: Plugins: `openchannel2` now always includes the `channel_max_msat`
2022-10-20 13:42:41 +02:00
Rusty Russell e8ef42b741 plugin: wire JSON id for commands which caused hooks to fire.
Most obvious one is the "connect" hook.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-09-16 12:31:45 +09:30
Rusty Russell ea7903f69a lightningd: trace JSON id prefixes through sendrawtx.
First, merge the _ahf_ and non-ahf interfaces.
Second, remove the always-NULL txs->cmd field.

Then, add optional id_prefix for bitcoind_sendrawx, so if it's
triggered by a command (e.g. "withdraw") it's shown correctly in logs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-09-16 12:31:45 +09:30
Rusty Russell 5b7f14a7cb channeld/dualopend/lightningd: use channel_ready everywhere.
This alters the billboard, but that's a human-readable thing so not
noted in CHANGELOG.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `listpeers` `status` now refers to "channel ready" rather than "funding locked" (BOLT language change for zeroconf channels)
Changelog-Added: JSON-RPC: `channel_opened` notification `channel_ready` flag.
Changelog-Deprecated: JSON-RPC: `channel_opened` notification `funding_locked` flag (use `channel_ready`: BOLTs namechange).
2022-09-12 09:34:52 +09:30
Rusty Russell 1b30ea4b82 doc: update BOLTs to bc86304b4b0af5fd5ce9d24f74e2ebbceb7e2730
This contains the zeroconf stuff, with funding_locked renamed to
channel_ready.  I change that everywhere, and try to fix up the
comments.

Also the `alias` field is called `short_channel_id`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: `funding_locked` is now called `channel_ready` as per latest BOLTs.
2022-09-12 09:34:52 +09:30
Rusty Russell 645b1b505b lightningd: fix funding_locked in channel_opened notification.
Previously, "funding_locked" was always "true"!

(It's actually been wrong since its introduction in v0.7.3!)

Changelog-Fixed: Plugins: `channel_opened` notification `funding_locked` field is now accurate: was always `true`.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-08-04 13:08:25 +09:30
Rusty Russell 22ff007d64 connectd: control connect backoff from lightningd.
We used to tell connectd to remember our connect delay, and hand it
back (increased if necessary).

Instead, simply record when we last tried to connect.  If it was less
than 10 minutes ago, double delay (up to 5 minutes max), otherwise
reset delay to 1 second.

This covers all scenarios: whether we reconnect then immediately
disconnect, or never successfully connect, it doesn't matter.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #5453
2022-07-28 15:08:44 +09:30
niftynei 30aa1d79fb bkpr: for zerconfs, we still wanna know you're opening a channel
We need a record of the channel account before you start sending
payments through it. Normally we don't start allowing payments to be
sent until after the channel has locked in but zeroconf does away with
this assumption.

Instead we push out a "channel_proposed" event, which should only show
up for zeroconfs.
2022-07-28 12:08:18 +09:30
niftynei d87bdeeace coin_mvt: log channel_open for channels that close before they're locked
We don't push out a coin_move for a channel open until it's locked in,
but this causes problems for channels that close before they're locked.

So if we go the "close before locked in" route, we push out a channel
open event.

These will get a blockheight of 0, if we haven't seen the
funding transaction in a block yet.
2022-07-28 12:08:18 +09:30
Rusty Russell 02e169fd27 lightningd: drive all reconnections out of disconnections.
The only places which should call try_reconnect now are the "connect"
command, and the disconnect path when it decides there's still an
active channel.

This introduces one subtlety: if we disconnect when there's no active
channel, but then the subd makes one, we have to catch that case!

This temporarily reverts "slow" reconnections to fast ones: see next
patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell d31420211a connectd: add counters to each peer connection.
This allows us to detect when lightningd hasn't seen our latest
disconnect/reconnect; in particular, we would hit the following pattern:

1. lightningd says to connect a subd.
2. connectd disconnects and reconnects.
3. connectd reads message, connects subd.
4. lightningd reads disconnect and reconnect, sends msg to connect to subd again.
5. connectd asserts because subd is alreacy connected.

This way connectd can tell if lightningd is talking about the previous
connection, and ignoere it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 41b379ed89 lightningd: hand fds to connectd, not receive them from connectd.
Before this patch:
1. connectd says it's connected (peer_connected)
2. we tell connectd we want to talk about each channel (peer_make_active)
3. connectd gives us an fd for each channel, and we connect it to a subd (peer_active)
4. OR, connectd says it sent something about a channel we didn't tell it about, with an fd (peer_active)

Now:
1. connectd says it's connected (peer_connected)
2. we start all appropriate subds and tell connectd to what channels/fds (peer_connect_subd).
3. if connectd says it sent something about a channel we didn't tell it about, we either tell
   it to hang up (peer_final_msg), or connect a new opening daemon (peer_connect_subd).

This is the minimal-size patch, which is why we create socket pairs in
so many places to use the existing functions.  Many cleanups are
possible, since the new flow is so simple.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell eff53495db lightningd: make "is peer connected" a tristate.
First, connectd tells us the peer has connected, and we call the connected hook,
and if it says it's fine, we are actually connected and we fire off notifications.

Of course, we could be disconnected while in the connected hook, and that would
mean we tell people about a connection which is no longer current.

Make this clear with a tristate: if we're not marked disconnected by
the time the hooks finish, we're good.  It also gives us a cleaner
"connect" command return when we connected but disconnected before
processing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 912ac25270 lightningd: remove 'connected' flag from channel structure.
It's directly a product of "does it have a current owner subdaemon"
and "does that subdaemon talk to peers", so create a helper function
which just evaluates that instead.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 36a29fbfbc lightningd/json.h: remove.
There are hardly any lightningd-specific JSON functions: all that's left
are the feerate ones, and there's already a comment that we should have
a lightningd/feerate.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 12:24:00 -05:00
Rusty Russell 401f1debc5 common: clean up json routine locations.
We have them split over common/param.c, common/json.c,
common/json_helpers.c, common/json_tok.c and common/json_stream.c.

Change that to:
* common/json_parse (all the json_to_xxx routines)
* common/json_parse_simple (simplest the json parsing routines, for cli too)
* common/json_stream (all the json_add_xxx routines)
* common/json_param (all the param and param_xxx routines)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 12:24:00 -05:00
adi2011 eca844eb36 channel: Add struct scb_chan in channel and making last tx optional. 2022-07-14 12:24:48 -05:00