Commit Graph

497 Commits

Author SHA1 Message Date
Rusty Russell 2526e804f7 doc: big BOLT update to incorporate warnings language.
We do this (send warnings) in almost all cases anyway, so mainly this
is a textual update, but there are some changes:

1. Send ERROR not WARNING if they send a malformed commitment secret.
2. Send WARNING not ERROR if they get the shutdown_scriptpubkey wrong (vs upfront)
3. Send WARNING not ERROR if they send a bad shutdown_scriptpubkey (e.g. p2pkh in future)
4. Rename some vars 'err' to 'warn' to make it clear we send a warning.

This means test_option_upfront_shutdown_script can be made reliable, too,
and it now warns and doesn't automatically close channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:40:18 +10:30
Rusty Russell 9f06a59e3c shutdown: don't allow shutdown to p2pkh or p2sh addresses for anchor outputs.
This doesn't have an effect now (except in experimental mode), but it
will when we support anchors.  So we deprecate the use of those in the
close command too.

For experimental mode we have to avoid using p2pkh; adapt that test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `shutdown` no longer allows p2pkh or p2sh addresses.
2022-04-02 09:40:18 +10:30
Rusty Russell a770f51d0e tools/generate_wire.py: make functions allocate the TLV.
Requiring the caller to allocate them is ugly, and differs from
other types.

This means we need a context arg if we don't have one already.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-25 13:55:44 +10:30
Rusty Russell 2bc58e2327 lightningd: always tell connectd the channel id.
This means lightningd needs to create the temporary one and tell it to
openingd/dualopend, rather than the other way around.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 57263a3eb2 lightningd: handle reestablish directly from connectd.
We don't need to hand it to channeld: it will read it!  We simply
need to tell it to expect it.

Similarly, openingd/dualopend will never see it, so remove that logic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 2424b7dea8 connectd: hold peer until we're interested.
Either because lightningd tells us it wants to talk, or because the peer
says something about a channel.

We also introduce a behavior change: we disconnect after a failed open.
We might want to modify this later, but we it's a side-effect of openingd
not holding onto idle connections.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 10e36e073c openingd: disconnect from peer when an error occurs.
openingd currently holds the connection to idle peers, but we're about
to change that: it will only look after peers which are actively
opening a connection.  We can start this process by disconnecting
whenever we have a negotiation failure.

We could stay connected if we wanted to, but that would be up to
connectd to decide.  Right now it's easier if we disconnect from any
idle peer once it's been active.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Ken Sedgwick 8994b8dade hsmd: Add validate_commitment_tx 2022-03-20 13:06:16 +10:30
Ken Sedgwick 36466af3eb hsmd: Add fields to hsmd_sign_{,remote_}commitment_tx for validating signers 2022-03-16 12:06:21 +10:30
Rusty Russell d7ffb712e5 dualopend: restore memleak calls.
And implement a timeout (20 seconds) just in case it's not listening.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-10 09:40:09 +10:30
Rusty Russell 84e0e743eb dualopend: fix memleak reports.
Next patch re-enables runtime leak checking for dualopend, so fix those
leak reports.

In some cases, this menas allocating off tmpctx or state->channel
(which gets reset on failure), not state.  The problem with tmpctx is
that there are event loops in the *middle* of some functions, which
free it.  So for RBF functions we use a rbf_ctx temporary (with leak
detection suppressed, like it is for tmpctx), then be careful to free
it on all exits!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-10 09:40:09 +10:30
Dustin Dettmer bdeeaab631 Clean up outdated comments about gossipd 2022-02-23 10:11:33 +10:30
Michael Schmoock 38e2abf68a peer_exchange: set, read and log remote_addr
Changelog-Added: Protocol: set remote_addr on init tlvs
2022-02-22 05:45:47 +10:30
Rusty Russell 3c5d27e3e9 subdaemons: remove gossipd fd from per-peer daemons.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell 1c71c9849b connectd: handle custom messages.
This is neater than what we had before, and slightly more general.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON_RPC: `sendcustommsg` now works with any connected peer, even when shutting down a channel.
2022-02-08 11:15:52 +10:30
Rusty Russell 4dc72dd829 dualopend: tell lightningd about new channel as soon as it's locked in.
Once we send funding_locked, gossipd could start seeing channel_updates
from the peer (which get sent so we can use the channel in routehints
even before it's announcable).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell f6847f44f6 subds: remove "ignore error" from old LND nodes.
This was put in late 2019, and @t-bast says Eclair doesn't ignore their
errors and has had no issues.

It also conflicts with https://github.com/lightning/bolts/pull/932
which suggests you *should* fail when you receive an error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-25 06:26:52 +10:30
Rusty Russell 6115ed02e8 subdaemons: don't stream gossip_store at all.
We now let gossipd do it.

This also means there's nothing left in 'struct per_peer_state' to
send across the wire (the fds are sent separately), so that gets
removed from wire messages too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 7a514112ec connectd: do dev_disconnect logic.
As connectd handles more packets itself, or diverts them to/from gossipd,
it's the only place we can implement the dev_disconnect logic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 9c0bb444b7 per_peer_state: remove struct crypto_state
Now that connectd does the crypto, no need to hand around crypto_state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell ce8b69401c peer_io: replace crypto_sync in daemons, use normal wire messages.
Now connectd is doing the crypto, we can use normal wire io.  We
create helper functions to clearly differentiate between "peer" comms
and intra-daemon comms though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 35e3c1866e common: generalize extract_channel_id().
connectd is going to end up using this do demux; make it fast and complete.

Fixing this reveals a problem in openingd: it now extracts the channel_id
from funding_signed (which is where we transition off the temporary), and
gets upset.  So fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-30 09:50:40 +10:30
niftynei 8225a9decf coin_mvt: log events for pushes/lease_fees for leased channels
We need to stash/save the amount of the lease fees on a leased channel,
we do this by re-using the 'push' amount field on channel (which is
technically correct, since we're essentially pushing the fee amount to
the peer).

Also updates a bit of how the pushes are accounted for (pushed to now
has an event; their channel will open at zero but then they'll
immediately register a push event).

Leases fees are treated exactly the same as pushes, except labeled
differently.

Required adding a 'lease_fee' field to the inflights so we keep track of
the fee for the lease until the open happens.
2021-12-28 04:42:42 +10:30
Ken Sedgwick 335ef3fb69 hsmd: Add hsmd_ready_channel 2021-12-14 11:24:52 +10:30
Rusty Russell 4ffda340d3 check: make sure all files outside contrib/ include "config.h" first.
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30
Rusty Russell b3af5f5a2c spec: import latest onionmessage spec, based on routeblinding.
This is from 6e99c5feaf60cb797507d181fe583224309318e9

We renamed the enctlv field to encrypted_recipient_data in the spec, and the
new onion_message is message 513.  We don't handle it until the next patch.

Two renames:
1. blinding_seed -> blinding_point.
2. enctlv -> encrypted_recipient_data.

We don't do a compat cycle for our JSON APIs for these experimental
features only used by our own plugins, we just rename.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-01 05:44:28 +10:30
Rusty Russell 1ec6346f3d common: rename current onion message structures to obs2_.
Yes, we changed the spec again.  Hopefully for the last time!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-01 05:44:28 +10:30
Rusty Russell b74848f6f6 common: remove support for pre v0.10.2 onionmessages.
Temporarily disable sendpay_blinding test which uses obsolete onionmsg;
there's still some debate on the PR about how blinded HTLCs will work.

Changelog-EXPERIMENTAL: onionmessage: removed support for v0.10.1 onion messages.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-01 05:44:28 +10:30
niftynei 1fe829c546 lightningd: new option for htlc dust limit
To reduce the surface area of amount of a channel balance that can be
eaten up as htlc dust, we introduce a new config
'--max-dust-htlc-exposure-msat', which sets the max amount that any
channel's balance can be added as dust

Changelog-Added: config: new option --max-dust-htlc-exposure-msat, which limits the total amount of sats to be allowed as dust on a channel
2021-10-23 12:59:13 +02:00
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
Vincenzo Palazzo 015627cdee Fixes msat and sat convention in the error message
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-10-14 10:09:20 +10:30
Rusty Russell c394fd5db2 common/read_peer_msg: handle pings in handle_peer_gossip_or_error().
This is a noop for now, since gossipd handles them.  But that
will change in the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-10 15:32:57 +02:00
Rusty Russell 79e09b92ef Makefile: remove generated files.
By popular merge-hell demand.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Build: Python is now required to build, as generated files are no longer checked into the repository.
2021-09-22 15:25:14 +02:00
Rusty Russell f2a4bd6ad8 wire: import new onion message spec.
One change from the obsolete version handling, gossipd will no longer send
forwarding onion msgs to lightningd, but will forward it directly.
That was the effect before, anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-22 09:10:34 +09:30
Rusty Russell e3ae7883bb channeld: rename onion_message to obs_onion_message.
This splits the existing old-spec pathways to prepare for the
new ones.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-22 06:44:26 +09:30
Rusty Russell 24536c5561 common/autodata: use instead of ccan/autodata
This means it needs to be linked ~everywhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-21 18:04:43 +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
Rusty Russell ea30c34d82 cleanup: remove unneeded includes in header files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Rusty Russell 00a0d09340 tools/check-includes.sh: test that c files include their .h files.
This is best-practice (to ensure prototypes match up), but there were a
few places we didn't (at least, directly).  Make it a requirement,
either of form "foo.h" or <dir/foo.h>.

The noise is the change to our print templates.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Rusty Russell 88adbbd20e openingd: clean up state properly when a hook says to reject opening.
This was just a minor leak, found by CI for
test_openchannel_hook_chaining.  We didn't call negotiation_aborted
which frees various fields: negotiation_failed() does that for us.

```
 MEMLEAK: 0x55b0f2d5f3c8
   label=common/channel_type.c:19:struct channel_type
   backtrace:
     ccan/ccan/tal/tal.c:442 (tal_alloc_)
     common/channel_type.c:19 (channel_type_none)
     common/channel_type.c:27 (channel_type_static_remotekey)
     common/channel_type.c:136 (channel_type_accept)
     openingd/openingd.c:844 (fundee_channel)
     openingd/openingd.c:1240 (handle_peer_in)
     openingd/openingd.c:1510 (main)
   parents:
     openingd/openingd.c:1414:struct state
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell acef45d02e common/channel_type: fix up bolt quotes now channel-types is merged.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 6e075d2dbb openingd: tell them channel_type if signature is bad.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell b985cd774d openingd: allow channel_type to *downgrade* from default.
e.g. you can negotiate anchor_outputs, but still ask for a
non-anchor-output channel.

If/when we make those features compulsory, downgrade will
not be allowed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 65290c02ba openingd: channel_type TLV no longer experimental.
It was merged (but this doesn't update the BOLT quotes, that's in another patch).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: We now send and support channel_type in channel open (not dual-funding though).
2021-09-13 15:53:23 +02:00
Rusty Russell c121fc9fcf openingd: EXPERIMENTAL_FEATURES provide and use channel_types.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 12f298d830 openingd: tell lightningd what channel type we negotiated.
Currently we actually insist it's the default, but in future it could be
different.

We also need to tell openingd what the channel_type was, if we resume
via openingd_funder_complete().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 183fe107e8 lightningd: use channel_type, pass to-and-from channeld.
Instead of explicit option_static_remotekey and option_anchor_outputs flags.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 740afb822c common/initial_channel: use channel_type instead of individual option bools.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell cb22015b2a common/channel_type: wrapper for generated 'struct channel_type'.
We make it a first-class citizen internally, even though we won't use
it over the wire (at least, non-experimental builds).  This scheme
follows the latest draft, in which features are flagged compulsory.

We also add several helper functions.

Since uses the *even* bits (as per latest spec), not the *odd* bits,
we have some other fixups.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 1b8551923d tools: handle generating print templates for CSV without tlvs, messages
We want to use this to handle the simple description for channel_type.

It also needs to handle variable-size types (just like subtypes).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell d12a2ec76a openingd: don't hand redundant feature flags.
Openingd can query them itself (as dualopend already does).  And move
the two feature args next to each other on the wire.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell fb4edc2938 Makefile: update bolt version to include option_anchors_zero_fee_htlc_tx.
This touches a lot of text, mainly to change "if `option_anchor_outputs`"
to "if `option_anchors`"

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-09 12:04:48 +09:30
Rusty Russell 88d55441c5 channeld: allow large HTLCs if peer offers option_support_large_channel
This check is going away anyway (only Electrum enforced it), but we
know that all wumbo peers expect large HTLCs to work today.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: Allow sending large HTLCs if peer offers option_support_large_channel (> 4294967295msat)
2021-09-09 12:04:48 +09:30
Rusty Russell a5fee67b91 common/memleak: take over dump_memleak(), allow print pointer.
This will let plugins use it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 19:11:47 +02:00
Rusty Russell 4ea0fa6457 dualopend: remove runtime memleak in favor of at-termination.
dualopend doesn't always listen to lightningd messages, so it would
sometimes hang at the end of tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-08-05 12:53:38 -05:00
Rusty Russell ceb40dea38 lightningd: don't turn zero-length tlv fields into NULL.
Fixes: #4667
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-21 13:27:27 -04:00
Rusty Russell d38cfcf33b lightningd: don't assume zero-length tlv fields will be NULL.
1. We assumed an empty upfront_shutdown_script TLV would become NULL:

	RPC call failed: method: fundchannel, payload: {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'amount': 1000000, 'announce': True}, error: {'code': -1, 'message': 'They sent error channel e7c2d5d14462fe269631418fbfc3db327843382e6a2a5a9c2991d2d6ba31d9f5: Unacceptable upfront_shutdown_script ', 'data': {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'method': 'fundchannel_start'}}"

2. We were assuming an empty enctlv would become NULL, too.

We should not have done this (there's a semantic difference between
"empty" and not-present for TLVs), so prepare for the change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-21 13:27:27 -04:00
niftynei dd00d4dcf8 reestablish_tlvs: don't lose them btw tmpctx cleanup 2021-07-20 13:28:38 -04:00
niftynei a8ee69cdc8 dualopend: hold onto open_tlv for longer than the tmpctx persists
with channel leases, we use the open_tlv data after a round of talking
to the peer (which clears out the tmpctx). It'll get cleaned up
when this peer opens/fails.
2021-07-20 13:28:38 -04:00
niftynei d4408a9ae0 channel-leases: add lease fee to accepter's funding earlier up
We need the 'actual' accepter's funding for the reserve calculations,
which includes the lease fee that the opener is paying them, so we
calculate it before doing all that jazz.

However, we MUST send the actual "on paper" (e.g. without lease fee)
amount to the peer in accept_channel2, so we stash the original amount
and send it.
2021-07-20 13:28:38 -04:00
niftynei 68e5c8ca93 nit: better error messages on dualopend's check_balances failures
Make it easier to figure out what the inputs were to check_balances
on two failure cases
2021-07-20 13:28:38 -04:00
niftynei 70bf57d54b channel-lease: reject if we're not currently advertising liquidity
If there's no plugin currently in place, we simply won't return any
funding at all, in which case we'd expect them to handle however
they want. (our implementation would fail the open, as we only accept
opens that have at least as much as we've requested provided)
2021-07-20 13:28:38 -04:00
niftynei f24bbac8d9 channel leases: pass expected lease rates around in compat form
We need to know what the lease we're expecting is. To do this
we pass around the hex encoded portion of the wire format.

We can use this passed in expected lease rates to confirm that the peer
is, in fact, using the same rates as what we have currently.

Changelog-Added: JSON-RPC: fundchannel, multifundchannel, and openchannel_init now accept a 'compact_lease' for any requested funds
2021-07-20 13:28:38 -04:00
niftynei 265f960cfe liquidity-ads: persist channel blockheight states to disk
Adds new tables to database, backfills, basically copies the fee_rates
state machine for channeld.
2021-07-20 13:28:38 -04:00
niftynei a396c341cf lease_rates: persist channel's lease info 2021-07-20 13:28:38 -04:00
niftynei 5989433810 lease_rates: pass in 'lease_expiry' and 'csv' to commitments/channel 2021-07-20 13:28:38 -04:00
niftynei 7a6f84ae63 lease-rates: add to accepter's side on accepter pathway 2021-07-20 13:28:38 -04:00
niftynei 63e2ce01e7 lease-rates: calculate the fee owed to peer for the funds lease 2021-07-20 13:28:38 -04:00
niftynei 9dd0a2c2e5 channel-lease: validate accepter's sig on lease terms 2021-07-20 13:28:38 -04:00
niftynei 89f210fcd6 rpc: add queryrates
Undocumented RPC call for asking a peer what their rates are
2021-07-20 13:28:38 -04:00
niftynei 334ec0084b liquidity-ad: fill in acceptance response
Asks HSMD for signed lease termsheet, fills in the details to the
accept_channel2 TLV
2021-07-20 13:28:38 -04:00
niftynei e41d2dc0e6 liquidity-ad: request amount, pass through to dualopend
Changelog-Experimental: EXPERIMENTAL-DUAL-FUND: JSON-RPC: openchannel_init now takes a `requested_amt`, which is an amount to request from peer
2021-07-20 13:28:38 -04:00
niftynei 5b3c02f401 liquidity-ads: import from spec
Import the wires from spec. Here we go!
2021-07-20 13:28:38 -04:00
niftynei 376e6f8bd1 dual-funding: update fee_step to be a feerate
Using a 'feestep' is more restrictive than you'd want, instead we
enforce that the next feerate must be at least 1/64th more than the
last, but put no upper limit on it

Includes update to lnprototest changes

Contributed-By: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Changelog-EXPERIMENTAL: Protocol: Replaces init_rbf's `fee_step` for RBF of v2 opens with `funding_feerate_perkw`, breaking change
2021-07-19 16:13:24 -04:00
niftynei 8654c817da sendcustommsg: promote to non-dev
Enable non-dev builds to send custom messages.

Preserves 'dev-' for compat-enabled builds.

Changelog-Changed: JSON-RPC: moved dev-sendcustommsg to sendcustommsg
2021-07-14 14:39:44 -05:00
Christian Decker b4ead97517 tlv: Allow passing some extra types to accept when parsing the stream 2021-06-26 10:55:13 +09:30
Rusty Russell 44829d1361 openingd: tell lightningd if we get a reestablish.
It simply uses connectd to send an error if it doesn't know anything
about the channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-25 13:23:28 +09:30
Rusty Russell b223a6acbb common/read_peer_msg: don't try to handle reestablish/reopen.
Let the callers do that (only channeld needs to do this).

We temporarily send an error on unknown reestablish in openingd, as
this mimic previous behavior and avoids breaking tests (it does leave
a BROKEN message in the logs though, so
test_funding_external_wallet_corners needs to ignore that for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-25 13:23:28 +09:30
Rusty Russell 45e6080764 channel: import upgrade spec.
See https://github.com/lightningnetwork/lightning-rfc/pull/868

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-04 16:13:08 +09:30
Rusty Russell 2fea448498 gen/impl_template: fix generation of singleton varsize elements.
And as Lisa requested, add testcases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-04 16:13:08 +09:30
Rusty Russell bf0320a53e openingd/dualopend: remove send_msg functionality.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-03 16:16:34 +09:30
Rusty Russell f7adbd5d58 EXPERIMENTAL: import spec for quiescence.
Imported from commit b96218b06b68cf349457b282f05d48ebd89c7273

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-01 12:08:51 -05:00
Rusty Russell 9dadcc858b common/gossip_store: avoid fd pass for new store, use end marker.
This is also simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-22 17:53:04 +09:30
niftynei c75ca8c112 df-bugs: if we've already got the funding_locked, dont renotify
Peer sends funding locked, we tell lightningd who saves it to disk.
Then we restart/reconnect and they retransmit funding_locked. We were
re-notifying lightningd about their lock-in, which was crashing/breaking
things. Instead, we ignore duplicate lock-in messages from the peer.

lightningd-1: 2021-05-11T18:00:12.844Z **BROKEN** 022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-chan#1: Internal error DUALOPEND_AWAITING_LOCKIN: channel_got_funding_locked twice
2021-05-12 11:25:41 +09:30
niftynei 56e8d75dbb dualfund: set the locktime for the user-provided PSBT
This is set by the peer and is non-negotiable. We're not even going to
check if you got it right. You were told about it via `openchannel2`.

It is what it is.
2021-05-03 11:06:10 +09:30
niftynei 382264e207 dualopend: don't use final channel_id for accepter_start2
The other side doesn't know it until *after* it parses this msg.  We
add a quick hack to still allow old nodes to work (for now!).

This also fixes a bug (spotted by @niftynei) where any errors we sent
before accepter_start2 would have the new (unknowable!) channel_id
rather than the temp one.

Authored-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-03 11:06:10 +09:30
niftynei b366453c6a dual-funding: rework how funding feerates are passed around
Cleans up some duplication/unnecessary re-assignment of the feerate.
Left over from when the feerates used to be min/max/best in
open_channel2.
2021-04-16 15:33:44 +09:30
niftynei d5bf6bb994 dual-fund: on witness failure, route through dualopend
We want to notify the peer that we've failed and why, as a courtesy.
2021-04-16 15:33:44 +09:30
Rusty Russell 9dbac21d3b doc: remove suffix for included-in-master BOLTs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-07 14:34:39 +09:30
niftynei 3e8f575f9e dual-funding: convert to runtime flag, --experimental-dual-fund
You can now activate dual-funded channels using the
`--experimental-dual-fund` flag

Changelog-Changed: Config: `--experimental-dual-fund` runtime flag will enable dual-funded protocol on this node
2021-03-25 20:05:11 +10:30
niftynei bc90c4f822 df: don't ignore their sigs, even if we've already seen them
In the case of failures/disconnects between dualopend receiving the sigs
and the main man disconnecting (as can happen using the testing
disconnects), failing to forward their sigs over to lightningd can
result in the channel never progressing from DUALOPEND_OPEN_INIT
to DUALOPEND_AWAITING_LOCKIN.

Always re-relay.
2021-03-17 10:25:18 +10:30
Rusty Russell 30145209a9 protocol: add TLV for shutdown message, use 100 as "wrong_funding" outpoint.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
niftynei bfa5db79b3 df-spec: limit allowable inputs/outputs to 252
The maximum inputs and outputs are capped at 252. This effectively fixes
the byte size of the input and output counts on the transaction to one (1).
2021-03-09 14:55:05 +10:30
niftynei a5fedc4e1f df-spec: use an empty bit-set as the basepoint for chan-id at start
> If the peer's revocation basepoint is unknown (e.g. `open_channel2`),
> a temporary `channel_id` should be found by using a zeroed out basepoint
> for the unknown peer.
2021-03-09 14:55:05 +10:30
niftynei 31e3bdb42d df-spec: consolidate dual-funding patches, update feerate protocol
We consolidate to the latest/singular RFC patch for dual-funding, so
there's just a single patchfile for the change. Plus we move back to the
opener setting the desired feerate, the accepter merely declines to
participate if they disagree with the set rate.
2021-03-09 14:55:05 +10:30
niftynei 71164799f9 dual-fund: remove all references to PODLEs
We're punting on PODLE's for v1 of dual-funded channels
2021-03-09 14:55:05 +10:30
Christian Decker 21355edc43 plugin: Do not send the internal framed message over the wire
Looks like #4394 treated a symptom but not the root cause. We were
actually sending the message framed with the WIRE_CUSTOMMSG_OUT and
the length prefix over the encrypted connection to the peer. It just
happened to be a valid custommsg...

This fixes the issue, and this time I made sure we actually send the
raw message over the wire. However for backward compatibility we
needed to imitate the faulty behavior which is 90% of this patch :-)

Changelog-Fixed: plugin: `dev-sendcustommsg` included the type and length prefix when sending a message.
2021-03-09 14:39:22 +10:30
niftynei e0a2d47903 df-rbf: reconnection tests (init_rbf + ack_rbf) 2021-03-06 15:03:56 +10:30
niftynei ad0f92aef1 df-rbf: update rejection criteria for tx_sigs
since we might be in the middle of an RBF, update our checks to be more
robust
2021-03-06 15:03:56 +10:30
niftynei c519c84ef8 df: handle funding_locked + tx_signatures messages out of order
If we're doing an RBF, it's possible that the peer will send us a
funding_locked, shutdown, or tx_signatures message. (We get tx_sigs out
of order on a reconnect)

This lets us gracefully handle a shutdown or funding_locked
sent at any time (after first funding tx) as well.
2021-03-06 15:03:56 +10:30
niftynei 6825a6715e df: move methods around so we can call them elsewhere
Will reuse these elsewhere soon
2021-03-06 15:03:56 +10:30
niftynei ff069ff924 rbf: consolidate failure paths, use "warnings"
We move over to the new "warning" paradigm, instead of using
an "rbf_fail" message.

Every failure is either a warning or an error; on warnings we
hang up and reconnect later, effectively resetting the state.
2021-03-06 15:03:56 +10:30
niftynei f22fed3fd5 df-rbf: only permit the channel initiator to init RBF
We're *mostly* set up for both sides doing RBF, except that it reverses
the callback flow (using the plugin vs RPC calls) and we're not
currently smart enough to flip between them gracefully
2021-03-06 15:03:56 +10:30
niftynei a0cb7bd9b4 df: update reserve calculation
We can use the funding amount to derive the reserve requirement.
2021-03-06 15:03:56 +10:30
niftynei d47358848f df-rbf: init an rbf for real, using openchannel_bumpfee
Reorg a bit of the RBF code so we use the same codepaths for we-init vs
they-init starts.
2021-03-06 15:03:56 +10:30
niftynei 063948d51a df-feerates: send back original + last known feerates
For calculating the next RBF attempt's feerate, we need some historical
information about the feerate used for this channel
2021-03-03 16:19:04 -06:00
niftynei fe688ab718 df: revert channel state in dualopend
Now that RBF's are possible, we revert the channel's state
after a failure to the previous channel info.
2021-03-03 16:19:04 -06:00
niftynei 628f9df320 df: consolidate callbacks for opener/accepter, move to open_attempt 2021-03-03 16:19:04 -06:00
niftynei 6474779e38 df-rbf: hook for rbf_init attempt, called "rbf_channel"
When we get an RBF request, we ask the/a plugin what they'd like to do
about it. This pipes the request through to the plugin
2021-03-03 16:19:04 -06:00
lisa neigut 0d8351155e df-rbf: validate that the candidate funding transaction is valid
We need to make sure that there's at least one input that's represented
in every single RBF-attempt for this channel, to prevent "parallel"
subsequent RBFs from succeeding/opening (the multi-channel backdoor?!)
2021-03-03 12:28:22 +10:30
niftynei b30489310b df-rbf: break out opener commitment codepath, use for rbf 2021-03-03 12:28:22 +10:30
niftynei 63b060066b df-rbf: opener setup for "interactive" protocol portion
If we're the opener, there's a bit of extra setup we need to do before
calling "run_tx_interactive", namely adding the funding_output to the
PSBT
2021-03-03 12:28:22 +10:30
niftynei e67d5d7559 df: move out logic for adding funding output to PSBT 2021-03-03 12:28:22 +10:30
niftynei 804b93c81f df-rbf: split out "commitment txs" portion of accepter
use it for received RBFs requests, when we're the "accepter"
2021-03-03 12:28:22 +10:30
niftynei 22078262f0 df-reinit: pass back channel_flags
We should also restore the channel_flags field on reinit; we use them if
we do an RBF after a reconnection
2021-03-03 12:28:22 +10:30
niftynei 940347b04e df: put channel_flags onto state
They need to exist through multiple open channel attempst (via RBF)
2021-03-03 12:28:22 +10:30
niftynei a489f92ee8 df-rbf: start of handling an incoming RBF attempt from peer
A peer init's an RBF, we start handling it
2021-03-03 12:28:22 +10:30
niftynei 067f1f2eb7 df-rbf: add method to fail an RBF
this is a bit different than straight up failing a channel. we want to
signal that the RBF attempt failed, only
2021-03-03 12:28:22 +10:30
niftynei 54d5cdb938 df-rbf: update wires with ack and fail rbf 2021-03-03 12:28:22 +10:30
niftynei cf2f0c32d1 df-rbf: refactor state for opening attempts
Since a channel can now have multiple successful funding transactions
constructed for it, we need space to express this in the states.
2021-03-03 12:28:22 +10:30
Rusty Russell d0946b75bc common: support opt_shutdown_anysegwit checks (EXPERIMENTAL_FEATURES).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-02 14:42:34 +10:30
Rusty Russell 26627bdf7d openingd: check upfront shutdown script.
The spec doesn't say to do this, but it makes sense, otherwise
they'll never be able to mutually close the channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-02 14:42:34 +10:30
Rusty Russell 93d3b0d126 doc: update BOLT quotes (to include LOW-S-standard rule).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-25 13:23:16 +10:30
niftynei fbaf8aa6d9 df: more descriptive error message 2021-02-24 10:06:42 -06:00
Rusty Russell 6b11cc8b8c common: disallow NULL channel_id to peer_failed_err.
No more sending "all-channel" errors; in particular, gossipd now only
sends warnings (which make us hang up), not errors, and peer_connected
rejections are warnings (and disconnect), not errors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Plugins: `peer_connected` rejections now send a warning, not an error, to the peer.
2021-02-04 12:02:52 +10:30
Rusty Russell f4ee41a989 common: remove peer_failed in favor of peer_failed_warn/peer_failed_err
And make all the callers choose which one.  In general, I prefer warn,
which lets them reconnect and try again, however some places are either
stated that they must be errors in the spec itself, or in openingd
where we abandon the channel when we close the connection anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: we now send warning messages and close the connection, except on unrecoverable errors.
2021-02-04 12:02:52 +10:30
Rusty Russell d14e273b04 common: treat all "all-channels" errors as if they were warnings.
This is in line with the warnings draft, where all-zeroes in a
channel_id is no longer special (i.e. it will be ignored).

But gossipd would send these if it got upset with us, so it's best
practice to ignore them for now anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: we treat error messages from peer which refer to "all channels" as warnings, not errors.
2021-02-04 12:02:52 +10:30
Rusty Russell a7c5a1f1d2 lightningd: implement receiving warnings.
This takes from the draft spec at https://github.com/lightningnetwork/lightning-rfc/pull/834

Note that if this draft does not get included, the peer will simply
ignore the warning message (we always close the connection afterwards
anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: we now report the new (draft) warning message.
2021-02-04 12:02:52 +10:30
Rusty Russell 6dab04ebd5 tools/generate-wire.py: include digits in #ifndef idempotent header.
Otherwise check complains that it's '#ifndef LIGHTNING_WIRE_BOLT_WIREGEN_H':

wire/bolt12_wiregen.h seems to be missing the expected include guard:
  #ifndef LIGHTNING_WIRE_BOLT12_WIREGEN_H
  #define LIGHTNING_WIRE_BOLT12_WIREGEN_H
  ...
  #endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */

make: *** [Makefile:458: check-includes] Error 1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-13 14:45:36 +01:00
niftynei 7e324177de df-tests: simultaneous openchannel_init (while in progress)
Reject a peer's request to open a channel while we're already in progress
2021-01-10 13:44:04 +01:00
niftynei 205a7057c9 df: use dev-env flagged upfront shutdown script
This lets the test_option_upfront_shutdown_script test pass
2021-01-10 13:44:04 +01:00
niftynei 5387f6736c df: free psbt on negotiation failed 2021-01-10 13:44:04 +01:00
niftynei 2cd95aa806 df: add a new 'channel_open_failed' notification
Let plugins know when a channel open has failed.

We need to notify accepters now too, so we remove the check on who's
funding the channel before sending the 'failed' message from
dualopend->master.
2021-01-10 13:44:04 +01:00
niftynei d4ec052668 df: include channel_id in openchannel2 hook
We already know what the channel id is, we should go ahead and pass it
on to any listening plugins -- this makes clean up easier/possible
if a open fails early on and we've got reserved utxos.
2021-01-10 13:44:04 +01:00
niftynei 99a621dd99 df-reconnects: allow tx-sigs in channeld iff we're reconnecting
There's a case where a dropped funding_locked will result in the peer
moving onto channeld, while we stay in dualopend. As we haven't
received their funding_locked, we retransmit tx_sigs, which channeld
will need to handle.

With the patch the peer drops it on the floor; the peer will resend
funding_locked on reconnect, which will correctly advance us to
channeld and CHANNELD_NORMAL
2021-01-10 13:44:04 +01:00
niftynei 0a9c562664 df: state, clean more things up 2021-01-10 13:44:04 +01:00
niftynei 2f3acb91fc df: actually send a temp-id to the peer in open_channel2 WIP
We actually need a channel_id in openchannel so we can properly
attribute any errors that we get back
2021-01-10 13:44:04 +01:00
niftynei f62f8b9c6b df: assume this is a 'negotiation failure'
The most likely reason this failed is that we didn't like parameters the
peer sent us.
2021-01-10 13:44:04 +01:00
niftynei 9cffa769b8 df: actually run 'reconnect' code 2021-01-10 13:44:04 +01:00
niftynei 9984c34f14 df: handle locked in etc in dualopend 2021-01-10 13:44:04 +01:00
niftynei 9fdf1ea32a df: reinitialize dual-funding
Prior to this, all reconnect logic lived in channeld. If you
disconnected before we finished building a funding transaction, that was
no big deal. Now, however, we're waiting for the funding to lock in in
dualopend, instead of handing straight to channeld to wait.

So we need a way to restart dualopend.
2021-01-10 13:44:04 +01:00
niftynei 1b6deaffc8 df: bunch of driveby formatting fixes 2021-01-10 13:44:04 +01:00
niftynei 924aaf180e temp_channel_id: move to common
We actually do need this for dualopend's, specifically for returning
errors to open_channel2
2021-01-10 13:44:04 +01:00
niftynei c3a387a6d8 dual-fund: use correct 'last_tx'
We were incorrectly saving the *remote's* commitment transaction as the
'last_tx' for a peer, not our own local one.

When we applied the 'remote_commit_sig' to it, it would fail since the
remote's signature doesn't validate for their commitment transaction.
2021-01-10 13:44:04 +01:00
niftynei 90d936bb60 df: handle shutdown (before lockedin) in dualopend
A channel can be closed before it locks in. This lets dualopend handle
shutdown messages from the peer before the channel is locked in.
2021-01-10 13:44:04 +01:00
niftynei ae532614a3 df: handle fails
We weren't handling failure messages, now we handle them.

Also, fail/kill dualopend if there's a failure.
2021-01-10 13:44:04 +01:00
niftynei d47992a46d billboard: add in billboard updates from dualopend
Uses shared messaging now!
2021-01-10 13:44:04 +01:00
niftynei 1ea4e63331 dual-open: handle sigs and channel lockin in dualopend, not channeld
This will make it possible to do RBF, since we can re-start the opening
process in dualopend while waiting for lock-in.

Note the new channel states are being used, DUALOPEND_INIT and
DUALOPEND_AWAITING_LOCKIN, to differentiate from openingd/channeld opens
2021-01-10 13:44:04 +01:00
niftynei e0a7907d79 dual-fund: don't kill dualopend after commitments exchanged
We're going to handle the funding tx sigs here, so we keep dualopend
open still, so we can get them in/out before moving on
2021-01-10 13:44:04 +01:00
niftynei 0bb483f9b1 whitespace changes, 80 chars etc 2021-01-10 13:44:04 +01:00