Commit Graph

3294 Commits

Author SHA1 Message Date
niftynei a396c341cf lease_rates: persist channel's lease info 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 d7f76a6e1f dualopend, openchannel_init: pull out feerate parsing logic
we'll use it again here shortly
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 f1b7e5fffe liquidity-ads: pipe through request to funder, update policy
When a request comes through, we forward it over to the funder who
uses the currently set policy to figure out how to handle it.

Includes small update to the policy engine which decides whether or not
to fund a request.

Changelog-Experimental: Plugins: `openchannel2` hook now includes optional fields for a channel lease request
2021-07-20 13:28:38 -04:00
niftynei b1982f04be amount: add 'is_zero' helper
convenience, mostly
2021-07-20 13:28:38 -04:00
niftynei 876ff6821e setleaserates: new RPC to pass in lease rates
Changelog-Experimental: JSON-RPC: new RPC `setleaserates`, for passing in the rates to advertise for a channel lease (option_will_fund)
2021-07-20 13:28:38 -04:00
niftynei 49bae2a873 lease_rates: parse them out of node_announcements
When we get a node announcement out, we can now pull out its offer
characteristic
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
Michael Schmoock ec9693863d plugin: rescan restarts plugin on update
This adds a `u32 checksum` field to the plugin struct that is used
to identify if a plugin is outdated and needs to be restarted on `rescan`.

Note: Only affects non-important plugins.

Changelog-Added: Plugin: Restart plugin on `rescan` when binary was changed.
2021-07-15 13:26:05 -04:00
Christian Decker ce66466cfb opts: Add option to register extra TLV types to accept
Incoming HTLCs are rejected by the HTLC logic if the payload contains
an even type that `lightningd` doesn't recognize. This is to prevent
us from accidentally accepting a payment that has extra semantics
attached (for example if we get a keysend payment and don't know what
to do with the TLV field containing the message we should reject it,
otherwise the overall semantics of the message delivery fail).
2021-07-15 12:13:06 -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
Rusty Russell e7716c86fb lightningd: insist on payment_secret if bit compulsory on invoices.
This grandfathers in old invoices for the moment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-14 14:38:00 -05:00
Rusty Russell 9eb531868f lightningd: make invoices insist on payment_secret.
In fact, we make it compulsory, which means if you don't understand it
you'll hang up on us!

Add some logging for that in future.

Changelog-Changed: Protocol: All new invoices require a payment_secret (i.e. modern TLV format onion)
Changelog-Changed: Protocol: We can no longer connect to peers which don't support `payment_secret`.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-14 14:38:00 -05:00
Rusty Russell 3f5d5a1de5 invoice: output payment_secret in JSON.
This makes it easier to access (rather than decoding bolt11).

Changelog-Added: JSON-RPC: `invoice` now outputs explicit `payment_secret` it its own field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-14 14:38:00 -05:00
Rusty Russell 2aa833d424 doc: fix up bolt12 quotes.
The one about size needs the offers PR rebased onto the latest
onion-message PR.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-14 14:33:18 -05:00
Rusty Russell 424ac84263 patch remove-payer-backcompat.patch 2021-07-14 14:33:18 -05:00
Rusty Russell 30faf96efb lightningd: don't complain about unable to estimate fees if not mainnet.
'force-feerates' already bypasses this logic, but we should still suppres

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-09 07:26:09 +09:30
Rusty Russell adab9eb301 lightningd: add force-feerates option.
Useful for regtest and testnet.  Sure, you shouldn't use this on mainnet,
but I haven't restricted it because our users are usually pretty clever.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #1806
Changelog-Added: config: `force_feerates` option to allow overriding feerate estimates (mainly for regtest).
2021-07-09 07:26:09 +09:30
Rusty Russell 063366ed7e listinvoices: support listing by local offer_id.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-03 12:13:45 +09:30
Rusty Russell 2cb16a65c4 invoices: display the payer note if it's for local offer, allow in fetchinvoice.
We don't do it for sendinvoice (yet?).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: `fetchinvoice` can take a payer note, and `listinvoice` will show the payer_notes received.
2021-07-03 12:13:45 +09:30
Rusty Russell 18b6aa5e66 BOLT 12: update to include replace_invoice options.
We don't support it (yet), but update the spec to include it.

We include the previous field (recurrence_signature) as a shim for the
moment, for compat with existing nodes.  It's ugly, but next release
we'll stop *sending* it, then finally we'll stop accepting it!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-03 12:13:45 +09:30
Rusty Russell f9fe814ea3 offers: signatures are now optional.
As per latest spec revision.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: BOLT12 offers can now be unsigned, for really short QR codes.
2021-07-03 12:13:45 +09:30
Rusty Russell 68962083e7 listinvoice: don't crash if listinvoice given a non-bolt11 string.
Discovered by the next test, oops.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSONRPC: `listinvoice` no longer crashes if given an invalid (or bolt12) `invstring` argument.
2021-07-03 12:13:45 +09:30
Rusty Russell 85562db432 lightningd: print out what errno we got if unexpected in sigchild.
Looking at #4575, I'm not sure what happened.  This prints it out, at least.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-30 14:12:49 +09:30
Rusty Russell 8f33f46960 closingd: use a more accurate fee for closing fee negotiation.
We were actually using the last commit tx's size, since we were
setting it in lightningd.  Instead, hand the min and desired feerates
to closingd, and (as it knows the weight of the closing tx), and have
it start negotiation from there.

This can be significantly less when anchor outputs are enabled: for
example in test_closing.py, the commit tx weight is 1124 Sipa, the
close is 672 Sipa!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: Use a more accurate fee for mutual close negotiation.
2021-06-30 14:12:24 +09:30
Rusty Russell e27eaa9343 lightningd: fix typo in debug statements.
Show amount they were trying to pay with, not invoice amount.
Also, show min fee in closing, not fee they offered.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-30 14:12:24 +09:30
Christian Decker 473be0f6e4 plugin: Add extra TLVs to the invoice_payment hook 2021-06-26 10:55:13 +09:30
Christian Decker 477f574569 htlc: Keep the parsed TLV payload around with the htlc_in
We want to show the fields in the invoice_payment hook.
2021-06-26 10:55:13 +09:30
Christian Decker edf4b416c2 htlc: Wire extra TLV types into the HTLC onion decoding 2021-06-26 10:55:13 +09:30
Christian Decker b68acb8cf0 opts: Add option to register extra TLV types to accept
Incoming HTLCs are rejected by the HTLC logic if the payload contains
an even type that `lightningd` doesn't recognize. This is to prevent
us from accidentally accepting a payment that has extra semantics
attached (for example if we get a keysend payment and don't know what
to do with the TLV field containing the message we should reject it,
otherwise the overall semantics of the message delivery fail).
2021-06-26 10:55:13 +09:30
Rusty Russell ca0358f978 channeld: send shutdown_complete even if reestablish_only.
This lets us transition (with a few supporting changes) to closingd,
which will happily let them mutual close with us.

We already handle the case where this mutual close is redundant (for
packet loss), so this is easy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: We will now reestablish and negotiate mutual close on channels we've already closed (great if peer has lost their database).
2021-06-25 13:23:28 +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 9929d6383a channeld: add a message to read if we only want to reestablish.
This supports reestablish on a closed channel: we tell channeld to
respond to the reestablish message appropriately, then close the
channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-25 13:23:28 +09:30
Rusty Russell 6afb9f8fe7 lightningd: add channel_closed helper, expose find_channel_by_id().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-25 13:23:28 +09:30
Rusty Russell 9f8a6e2314 lightningd: always pass closing connections through channeld.
It handles all the cases of retransmission, and in the normal case
retransmits shutdown and immediately returns for us to run closingd.

This is actually far simpler and reduces code duplication.

[ Includes fixup to stop warn_unused_result from Christian ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Protocol: We could get stuck on signature exchange if we needed to retransmit the final revoke_and_ack.
2021-06-25 13:23:28 +09:30
Rusty Russell d7e8e220e6 lightningd: clean up listconfigs output.
1. Hide the now-deprecated enable-autotor-v2-mode option.
2. Really don't print dev- options.
3. Don't print true and false as strings in some cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `listconfigs` would list some boolean options as strings `"true"` or `"false"` instead of using JSON booleans.
2021-06-25 09:49:33 +09:30
Rusty Russell bf74be3348 plugins: add `command` field to subcommand output.
Makes it possible to write a decent JSON schema, but means we need to carry
additional data, so we create a `struct plugin_command`.

We remove the unused struct dynamic_plugin, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-25 09:49:33 +09:30
Rusty Russell d8136d856b listpeers: clean up JSON output.
In general, it's better to omit a field than put in a 'null', and
putting variable-named fields in an object is also a bad idea.

This is reflected in how hard this is to express in JSON schema, too.

Others:
1. Remove the obsolete "funding": "LOCAL" from unopened channels, but add
   "opener": "local" as used in normal channels.
2. htlc cltv_expiry is a u16.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `listfunds` `channels` `funding_allocation_msat` and `funding_msat`: use `funding`.
Changelog-Deprecated: JSON-RPC: `listfunds` `channels` `last_tx_fee`: use `last_tx_fee_msat`.
Changelog-Deprecated: JSON-RPC: `listfunds` `channels` `closer` is now omitted if it does not apply, not JSON `null`.
2021-06-25 09:49:33 +09:30
Rusty Russell 50ebdfb5e8 invoice: allow creation of giant invoices.
https://github.com/lightningnetwork/lightning-rfc/pull/877 talks about
removing this restriction (only Electrum actually enforced it on
receive), so start by allowing creation of giant invoices, though
we mark them as requiring mpp.

Changelog-Changed: JSON-RPC: `invoice` now allows creation of giant invoices (>= 2^32 msat)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-20 14:25:40 +09:30
Rusty Russell 75720ad0e1 lightningd: wait for gossipd to finish initalizing before starting plugins.
This mainly helps our CI under valgrind, which starts a fresh instance
and immediately calls the invoice command.  This can cause the topology
plugin to try to access the gossmap file before it's created.

We can also move the gossmap reading in topology to init time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell 7e7ab4cb3b gossipd: remove routing, listchannels and listnodes infrastructure.
This involves removing some fields from the now-misnamed routing.h
datastructures, and various internal messages.

One non-obvious change is to our "keepalive" logic which refreshes
channels every 13 days: instead of using the 'enabled' flag on the
last channel broadcast to decide whether to refresh it, we use the
local connected status directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell b6aa9510a9 signmessage: use listnodes instead of gossipd_getnodes_request.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell cda8f8190b invoice: overhaul routehints to use topology.listincoming, cleanup.
This turned into a more extensive cleanup than intended.  The previous
warnings were overlapping and confusing, especially now MPP is the norm.

*warning_capacity* is now the "even under best circumstances, we don't
have enough incoming capacity", which is really what
warning_mpp_capacity was trying to say (no longer printed).

*warning_offline* and *warning_deadends* are only given if adding such
peers would have helped give capacity (i.e. not if *warning_capacity*
is set).  The new *warning_private_unused* tells you that we would
have sufficient capacity, but we refused to expose private channels.

The test cases have been enhanced to cover the new warnings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `invoice` now gives `warning_private_unused` if unused unannounced channels could have provided sufficient capacity.
Changelog-Changed: JSON-RPC: `invoice` warnings are now better defined, and `warning_mpp_capacity` is no longer included (since `warning_capacity` covers that).
2021-06-16 10:29:17 +09:30
Rusty Russell 280f5a71a8 plugins/topology: add listnodes command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell 63d97d2467 plugins/topology: listchannels command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell e81e640e76 topology: plugin to implement getroute command.
Temporarily rename old getroute to getrouteold (we will remove this).

Changelog-Changed: JSON-RPC: `getroute` is now implemented in a plugin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell 064ad486e3 close: check that destination is going to be accepted.
Prior to this, sending a v1 address (or, in fact, any random crap!)
would cause the unsupporting node to unilaterally close.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-11 13:54:20 +09:30
Rusty Russell a4df2c7697 lightning/pay: don't crash when trying to send payment down unconfirmed channel.
An "active" channel may still be CHANNELD_AWAITING_LOCKIN, so have ->scid NULL.

You can only trigger this by trying to sendpay to the node using a
manual route, since routing would never use such a channel.

```
lightningd: FATAL SIGNAL 11 (version v0.10.0-319-g81cbc20-modded)
0x55e79d194e17 send_backtrace
	common/daemon.c:39
0x55e79d194ec1 crashdump
	common/daemon.c:52
0x7fce2d79920f ???
	???:0
0x7fce2d8e16f7 ???
	???:0
0x55e79d2019eb tal_dup_
	ccan/ccan/tal/tal.c:801
0x55e79d14e1d9 immediate_routing_failure
	lightningd/pay.c:365
0x55e79d14fe91 send_payment_core
	lightningd/pay.c:1022
0x55e79d150995 send_payment
	lightningd/pay.c:1180
0x55e79d151975 json_sendpay
	lightningd/pay.c:1462
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-11 13:54:09 +09:30
Christian Decker 76b8eb3afd plugin: Add debug log entries when calling and returning from hooks 2021-06-05 17:47:32 +09:30
Christian Decker 610d8a0a74 plugin: Add a status field to htlcs in listpeers
Annotating the htlc in `listpeers` with their current status, and
which plugin is currently holding on to them with their
`htlc_accepted` hook can help us debug where plugins may go wrong.

Changelog-Added: jsonrpc: HTLCs in `listpeers` are now annotated with a status if they are waiting on an `htlc_accepted` hook of a plugin.
2021-06-05 17:47:32 +09:30
Christian Decker a503032bab lightning: Add status field to htlc_in 2021-06-05 17:47:32 +09:30
Christian Decker 6062b40a5d plugin: Add the plugin we're serializing for in the serializer
We will start annotating some of the in-memory objects with a message
indicating which plugin currently is processing the hook.
2021-06-05 17:47:32 +09:30
Rusty Russell 29f042daac channeld: handle upgrade match.
We don't actually set desired_type yet, but this handles it.

Changelog-EXPERIMENTAL: Protocol: we can now upgrade old channels to `option_static_remotekey` from 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 fa0cd3cc76 onchaind: handle static_remotekey thresholds.
No longer a global "on" or "off", it depends on the commitment number.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-04 16:13:08 +09:30
Rusty Russell 220b6129bf wallet: save thresholds for option_static_remotekey.
Since we will soon be able to activate it on existing channels,
we need to mark the threshold.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-04 16:13:08 +09:30
fiatjaf 28953256d0
stop requiring channel and direction on `sendonion` since they're not used.
Changelog-Changed: `sendonion` no longer requires the gratuitous `direction` and `channel` fields in the `firsthop` parameter.
2021-06-04 10:48:10 +09:30
openoms c2e22344f7 lightningd: remove duplicate temp term creation 2021-06-03 20:10:07 +02:00
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 e2f225e4cd lightningd: use connectd to send the final error message, not openingd/dualopend
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-03 16:16:34 +09:30
Rusty Russell 7cffea10ce connectd: new command to make us send message and close.
Currently we abuse openingd and dualopend to do this, but connectd already
has the ability to talk to peers, so it's more efficient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-03 16:16:34 +09:30
fiatjaf e424180058 remove checking for unused "direction" property in sendpay. 2021-06-03 13:25:59 +09:30
niftynei cead5e16c0 openingd: return more informative error message for v2 opens
Fixes #4562

Reported-By: William Casarin @jb55

New error message:

	zircon:lightning (nifty/fix-4562)$ l1-cli fundchannel_start 03fce775508719e4064b7f19d4e884ddaf51db23bbfc560286ce872f9ed106fee0 10000 253perkw
	{
	   "code": 312,
	   "message": "Peer negotiated `option_dual_fund`, must use `openchannel_init` not `fundchannel_start`."
	}
2021-06-03 11:30:16 +09:30
Rusty Russell 03cfe0b468 EXPERIMENTAL: dev-quiesce to initiate (and test) quiescence.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-01 12:08:51 -05:00
Nalin Bhardwaj 57935b20d6 lightningd: check closing tx signature
Changelog-None
2021-05-30 09:49:44 +09:30
Rusty Russell fc9b24a746 close: add "unopened" type if we simply discard channel.
Undocumented (caught by json schema!) if we discard channel because it
wasn't open yet, then close returned the empty object.  Make it return
a new type in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSONRPC: `close` returns `type` "unopened" if it simply discards channel instead of empty object.
2021-05-27 20:28:49 +09:30
Rusty Russell b6223eb117 lightningd: option_shutdown_anysegwit is no longer experimental.
https://github.com/lightningnetwork/lightning-rfc/pull/672 was merged.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `option_shutdown_anysegwit` allows future segwit versions on shutdown transactions.
2021-05-26 20:01:03 +09:30
Rusty Russell 6753b95470 lightningd: respect anysegwit on dual-funding opens too.
Instead of open-coding, use the helper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-26 20:01:03 +09:30
Antoine Poinsot fe8074c8c3 Refuse to parse v2 onion addresses without deprecated_apis
Tor v2 hidden services have been deprecated for a while:
https://blog.torproject.org/v2-deprecation-timeline .

This prevents user from being able to set them in the configuration
and to connect to them while still letting us be able to parse them
for gossip.

Changelog-Deprecated: lightningd: v2 Tor addresses.  Use v3.  See https://blog.torproject.org/v2-deprecation-timeline.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-05-24 20:22:45 +09:30
fiatjaf 64199d99fd "createonion" to accept an optional custom onion_size.
Changelog-Added: `createonion` RPC command now accepts an optional `onion_size`.
2021-05-24 12:52:19 +02:00
niftynei 8c949be207 dual-open: save our now updated info about broadcast state 2021-05-24 12:17:48 +09:30
niftynei b3565fe2ed nit: add another debug log
log when we're telling the peer our depth's been reached
2021-05-24 12:17:48 +09:30
niftynei 85ec604238 rbf: when a peer is activated, also keep track of all of its inflights
We weren't watching for all inflights after the node is restarted.
Yikes.
2021-05-24 12:17:48 +09:30
niftynei d04c373283 rbf: when a channel is open, remove all the inflights
The channel's open has been mined, we don't need to keep all of these around
now.
2021-05-24 12:17:48 +09:30
niftynei 062bc12813 rbf: update the channel's funding_txid to match what's mined
If the peer is offline when we see the funding txid, we don't actually
update the channel's info. Here, we move it up to where the scid is set,
so that we always update the channel's funding_txid to the correct
(mined) information.
2021-05-24 12:17:48 +09:30
niftynei e45b09358a inflights: relax assertion channel funding_txid is last inflight txid
This assertion is not valid if a non-last funding tx is mined
2021-05-24 12:17:48 +09:30
niftynei 1d922bff1c dev-sign-last-tx: include inflight signed txs
For convenience sake, include the inflight's signed txs as well
2021-05-24 12:17:48 +09:30
niftynei f468c204eb listpeers: always show all the inflights
If you close a channel, the state won't be DUALOPEND_AWAITING_LOCKIN
2021-05-24 12:17:48 +09:30
niftynei e6c7928e76 listpeers: show the inflight's 'commitment tx' txid
Changelog-Added: EXPERIMENTAL JSON-RPC: `listpeers` now includes the `scratch_txid` for every inflight (if is a dual-funded channel)
2021-05-24 12:17:48 +09:30
niftynei 5f1ba02ece rbf: on close, drop every inflight transaction's commitment
If it's a unilateral close, we need to drop all the inflights also,
as we don't know which of them ended up being mined.
2021-05-24 12:17:48 +09:30
niftynei 024bc83fca listpeers: add inflights info
Changelog-Added: for v2 channels, we now list the inflights information for a channel
2021-05-24 12:17:48 +09:30
niftynei 8925fc8b01 inflights: add checks that there's actually an inflight 2021-05-24 12:17:48 +09:30
niftynei 8908dd08ec df-bugs: only include the `funding` if we're the opener
`funding` field belongs to the INITIATOR!
2021-05-23 17:42:09 +09:30
niftynei 260adb824e df: differentiate error message between
There's a difference between "no channel" and "channel in progress
but no open available to cancel"
2021-05-23 17:42:09 +09:30
Rusty Russell e531a38963 gossipd / plugin: clean up names in struct route_hop.
We're going to unify them, but the names are not the normal ones.

Fix that first.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-22 17:53:04 +09:30
Rusty Russell cc198748d4 common/json_tok: hoist param_short_channel_id from inside lightningd/
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-22 17:53:04 +09:30
Rusty Russell 25b5e1e099 update-mocks: make sure we cover all test programs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-22 17:53:04 +09:30
Rusty Russell 33736b860a lightningd: attach HTLC timeout to htlc itself, fix gratuitous disconnect bug.
We set the timeout on first HTLC, but didn't clear it if that HTLC failed.

It's saner to have a per-HTLC timeout (since that's what it is!) and
also our timer infra is specially coded to scale approximately infinitely so
trying to optimize this is vastly premature.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Protocol: We would sometimes gratuitously disconnect 30 seconds after an HTLC failed.
2021-05-21 14:45:05 +09:30
Rusty Russell 214fdcc9d7 plugin notifications: minor cleanups.
1. We don't need to check for NULL before tal_count(NULL).
2. Use of json_for_each_arr iterator is probably better.
3. Weird indent fixed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-14 10:24:05 +09:30
niftynei 71a4a2e31c df: rework closing logic
Trying to put all the disconnect logic into the same path was a dumb
idea. If you asked to reconnect but passed in an 'unsaved' channel, we
would not call the 'reconnect' code.

Instead, we make a differentiation between "unsaved" channels
(ones that we haven't received commitment tx for) and handle the
disconnect for these separate from where we want to do a reconnect.
2021-05-12 11:25:41 +09:30
niftynei ef333d5cee df-callbacks: dont log as broken, just reconnect 2021-05-12 11:25:41 +09:30
niftynei 4432672300 df-bug: avoid referencing null channel->owner
If dualopend dies, we shouldn't reference it
2021-05-12 11:25:41 +09:30
niftynei 5ee4c9e46c df: patch for valgrind error
We were freeing the payload, which is then subsequently freed by the
plugin_hook caller. Whoops.

Now we pass through to the callback function and just clean up neatly.

------------------------------- Valgrind errors --------------------------------
Valgrind error file: valgrind-errors.406602
==406602== Invalid read of size 8
==406602==    at 0x12AC93: openchannel2_hook_cb (dual_open_control.c:669)
==406602==    by 0x12AF0A: openchannel2_hook_deserialize (dual_open_control.c:721)
==406602==    by 0x16EF0E: plugin_hook_callback (plugin_hook.c:186)
==406602==    by 0x169746: plugin_response_handle (plugin.c:514)
==406602==    by 0x169959: plugin_read_json_one (plugin.c:620)
==406602==    by 0x169B23: plugin_read_json (plugin.c:665)
==406602==    by 0x1F4076: next_plan (io.c:59)
==406602==    by 0x1F4C5B: do_plan (io.c:407)
==406602==    by 0x1F4C9D: io_ready (io.c:417)
==406602==    by 0x1F6F35: io_loop (poll.c:445)
==406602==    by 0x13D48D: io_loop_with_timers (io_loop_with_timers.c:24)
==406602==    by 0x143388: main (lightningd.c:1111)
==406602==  Address 0x75e7418 is 56 bytes inside a block of size 3,520 free'd
==406602==    at 0x483CA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==406602==    by 0x204FB0: del_tree (tal.c:421)
==406602==    by 0x20527E: tal_free (tal.c:486)
==406602==    by 0x122D68: delete_channel (channel.c:124)
==406602==    by 0x129291: channel_disconnect (dual_open_control.c:63)
==406602==    by 0x129364: channel_close_conn (dual_open_control.c:82)
==406602==    by 0x131CF6: peer_please_disconnect (connect_control.c:304)
==406602==    by 0x131DEB: connectd_msg (connect_control.c:326)
==406602==    by 0x172023: sd_msg_read (subd.c:509)
==406602==    by 0x1F4076: next_plan (io.c:59)
==406602==    by 0x1F4C5B: do_plan (io.c:407)
==406602==    by 0x1F4C9D: io_ready (io.c:417)
==406602==  Block was alloc'd at
==406602==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==406602==    by 0x204A39: allocate (tal.c:250)
==406602==    by 0x204FFA: tal_alloc_ (tal.c:428)
==406602==    by 0x123165: new_unsaved_channel (channel.c:209)
==406602==    by 0x130D34: peer_start_dualopend (dual_open_control.c:2985)
==406602==    by 0x15BD2A: peer_connected_hook_final (peer_control.c:1105)
==406602==    by 0x16F2E5: plugin_hook_call_ (plugin_hook.c:275)
==406602==    by 0x15BF5C: plugin_hook_call_peer_connected (peer_control.c:1155)
==406602==    by 0x15C16C: peer_connected (peer_control.c:1208)
==406602==    by 0x131E3B: connectd_msg (connect_control.c:332)
==406602==    by 0x172023: sd_msg_read (subd.c:509)
==406602==    by 0x171842: read_fds (subd.c:310)
2021-05-12 11:25:41 +09:30
niftynei 6d3fb11bc6 df-tests: patch for state == AWAITING_UNILATERAL problem
Found on CI where DEVELOPER=0 EXPERIMENTAL_DUAL_FUND=1,
as we turn off automatic reconnects when DEVELOPER=1

This test has been modified to make the error happen every time, and
then fixed.

lightningd-2: 2021-05-07T20:12:03.790Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#1: Peer has reconnected, state AWAITING_UNILATERAL
lightningd-2: 2021-05-07T20:12:03.812Z **BROKEN** lightningd: FATAL SIGNAL 6 (version e8b3f78)
lightningd-2: 2021-05-07T20:12:03.812Z **BROKEN** lightningd: backtrace: common/daemon.c:44 (send_backtrace) 0x56384ee072e9
lightningd-2: 2021-05-07T20:12:03.813Z **BROKEN** lightningd: backtrace: common/daemon.c:52 (crashdump) 0x56384ee0733b

----------------------------- Captured stderr call -----------------------------
lightningd: lightningd/peer_control.c:1100: peer_connected_hook_final: Assertion `channel->state == DUALOPEND_OPEN_INIT || channel->state == DUALOPEND_AWAITING_LOCKIN' failed.
lightningd: FATAL SIGNAL 6 (version e8b3f78)
0x56384ee072a1 send_backtrace
	common/daemon.c:39
0x56384ee0733b crashdump
	common/daemon.c:52
0x7f88486a020f ???
	???:0
0x7f88486a018b ???
	???:0
0x7f884867f858 ???
	???:0
0x7f884867f728 ???
	???:0
0x7f8848690f35 ???
	???:0
0x56384eddc94e peer_connected_hook_final
	lightningd/peer_control.c:1100
0x56384edea2ed plugin_hook_call_
	lightningd/plugin_hook.c:275
0x56384eddfeb8 plugin_hook_call_peer_connected
	lightningd/peer_control.c:1156
0x56384eddfeb8 peer_connected
	lightningd/peer_control.c:1209
0x56384edc30cd connectd_msg
	lightningd/connect_control.c:332
0x56384edebe6f sd_msg_read
	lightningd/subd.c:509
0x56384edebfb1 read_fds
	lightningd/subd.c:310
0x56384ee483b0 next_plan
	ccan/ccan/io/io.c:59
0x56384ee4885b do_plan
	ccan/ccan/io/io.c:407
0x56384ee488f8 io_ready
	ccan/ccan/io/io.c:417
0x56384ee4a23c io_loop
	ccan/ccan/io/poll.c:445
0x56384edcabda io_loop_with_timers
	lightningd/io_loop_with_timers.c:24
0x56384edce826 main
	lightningd/lightningd.c:1111
0x7f88486810b2 ???
	???:0
0x56384edb52ad ???
	???:0
0xffffffffffffffff ???
	???:0
2021-05-12 11:25:41 +09:30
niftynei ef9d8bcd5a dual-fund: reconnections were borked, this fixes them 2021-05-12 11:25:41 +09:30
niftynei 6dc954bb91 df-bugs: rm duplicate call to channeld
This gets called from channel_set_owner, which both `delete_channel` and
the `channel_fail_reconnect` pathways call.

Fixes crash
------------------------------------------------------ Captured stderr teardown -------------------------------------------------------
lightning_connectd: peer_disconnected unknown peer: 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518 (version v0.10.0-144-gfaf98c9)
0x560e90d59d08 send_backtrace
        common/daemon.c:39
0x560e90d648a5 status_failed
        common/status.c:214
0x560e90d50e8f peer_disconnected
        connectd/connectd.c:1606
0x560e90d510d5 recv_req
        connectd/connectd.c:1662
0x560e90d5a266 handle_read
        common/daemon_conn.c:31
0x560e90d98ccb next_plan
        ccan/ccan/io/io.c:59
0x560e90d998b0 do_plan
        ccan/ccan/io/io.c:407
0x560e90d998f2 io_ready
        ccan/ccan/io/io.c:417
0x560e90d9bb8a io_loop
        ccan/ccan/io/poll.c:445
0x560e90d512c8 main
        connectd/connectd.c:1735
0x7fbdb828b0b2 ???
        ???:0
0x560e90d4a6dd ???
        ???:0
0xffffffffffffffff ???
        ???:0
2021-05-11 15:37:24 +09:30
Rusty Russell 9825f32874 lightningd: implement --log-timestamps=false.
Fixes: #4494
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: config: New option `log-timestamps` allow disabling of timestamp prefix in logs.
2021-05-05 17:19:19 -05:00
Christian Decker 98aa3c3da7 plugin: Make unannounced notification topics no longer fatal
Since plugins will start sending them soon, and they are likely to get
it wrong sometimes, be a bit more lenient, warn them in the logs
instead and then make sure it doesn't accidentally work anyway.
2021-05-03 11:20:15 +09:30
Christian Decker f08ae49134 plugin: Restrict plugin notifications only to announced topics
We want to have well-behaved notifications that are clearly announced
during the initialization, kill plugins that don't behave.
2021-05-03 11:20:15 +09:30
Christian Decker 62e3358a5b plugin: Wrap custom notifications in a dict with additional origin
This should allow us to differentiate the origin of the notification,
and further prevent plugins from spoofing native notifications.
2021-05-03 11:20:15 +09:30
Christian Decker cfb1107244 plugin: Remember the shortname for a plugin
We use it in a couple of places, so let's remember it for easier
access.
2021-05-03 11:20:15 +09:30
Christian Decker 2e27e4e443 plugin: Move list of notification topics to each plugin
We want to ensure that plugins register their topics before sending
any notification, so we need to remember which plugin registered which
topics.
2021-05-03 11:20:15 +09:30
Christian Decker c8c2c33952 plugin: Prevent plugins from registering native notification topics
They may already have subscribers, and they may crash if presented
with a malformed notification.
2021-05-03 11:20:15 +09:30
Christian Decker f716c55983 plugin: Implement custom notification dispatch for plugins
Changelog-Added: plugin: Plugins may now send custom notifications that other plugins can subscribe to.
2021-05-03 11:20:15 +09:30
Christian Decker 9d310366af plugin: Store the notification topics announced by the plugins 2021-05-03 11:20:15 +09:30
Christian Decker f77a0bcd8f plugin: Move the notification subscription check into a second phase
A plugin might subscribe to a notification topic that is only
registered by another plugin later, so push the check to that
consistency check phase where we do hook ordering as well.
2021-05-03 11:20:15 +09:30
Christian Decker 083b41f090 plugin: Add a list of notification topics registered by plugin
We will eventually start emitting and dispatching custom notifications
from plugins just like we dispatch internal notifications. In order to
get reasonable error messages we need to make sure that the topics
plugins are asking for were correctly registered. When doing this we
don't really care about whether the plugin that registered the
notification is still alive or not (it might have died, but
subscribers should stay up and running), so we keep a list of all
topics attached to the `struct plugins` which gathers global plugin
information.
2021-05-03 11:20:15 +09:30
niftynei a293bf3269 rbf_channel hook: add channel_max_msat parameter
Changelog-Added: Plugins: `rbf_channel` hook has `channel_max_msat` parameter
2021-05-03 11:06:10 +09:30
niftynei 5a04dc185c openchannel2/rbf hooks: reject if response malformed
You gotta send over an amount if you send a psbt!
2021-05-03 11:06:10 +09:30
niftynei 7c76363e20 openchannel2: add channel_max_msat to openchannel2 hook payload
Changelog-Added: Plugins: add a `channel_max_msat` value to the `openchannel2` hook. Tells you the total max funding this channel is allowed to have.
2021-05-03 11:06:10 +09:30
Rusty Russell f97a51cc0f lightningd: don't send other messages until we've received version.
This avoids subdaemons complaining about malformed messages from us,
or doing the completely wrong thing, if they are really the wrong
version.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-24 13:56:58 +09:30
Rusty Russell 32d650f9df lightningd: don't abort on incorrect versions, but try to re-exec.
You still shouldn't do this (you could get some transient failures),
but at least you have a decent chance if you reinstall over a running
daemon, instead of getting confusing internal errors if message
formats have changed.

Changelog-Added: lightningd: we now try to restart if subdaemons are upgraded underneath us.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #4346
2021-04-24 13:56:58 +09:30
Rusty Russell b36e9fe473 status: new message for subdaemons to tell us their versions.
For this patch we simply abort if it's wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-24 13:56:58 +09:30
niftynei 0ae2b0c33d dual-funding: bugfix, swapped commitment/funding feerates
Found via a protocol test, huzzah. And also whoops.
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
niftynei a948cf5c10 closingd: handle custommessages
We fail on odd messages in otherwise.

--------------------------------------------------------- Captured stderr call ----------------------------------------------------------
lightning_closingd: common/read_peer_msg.c:170: handle_peer_gossip_or_error: Assertion `!is_unknown_msg_discardable(msg)' failed.
lightning_closingd: FATAL SIGNAL 6 (version v0.10.0-3-gd0c30a4)
0x563b8eabd9a2 send_backtrace
        common/daemon.c:39
0x563b8eabda4c crashdump
        common/daemon.c:52
0x7f496292020f ???
        ???:0
0x7f496292018b ???
        ???:0
0x7f49628ff858 ???
        ???:0
0x7f49628ff728 ???
        ???:0
0x7f4962910f35 ???
        ???:0
0x563b8eaca7e3 handle_peer_gossip_or_error
        common/read_peer_msg.c:170
0x563b8eab79f2 closing_read_peer_msg
        closingd/closingd.c:116
0x563b8eab838a receive_offer
        closingd/closingd.c:362
0x563b8eab9299 main
        closingd/closingd.c:752
0x7f49629010b2 ???
        ???:0
0x563b8eab75dd ???
        ???:0
0xffffffffffffffff ???
        ???:0
lightning_closingd: FATAL SIGNAL (version v0.10.0-3-gd0c30a4)
0x563b8eabd9a2 send_backtrace
        common/daemon.c:39
0x563b8eacb384 status_failed
        common/status.c:207
0x563b8eacb5f0 status_backtrace_exit
        common/subdaemon.c:25
0x563b8eabda55 crashdump
        common/daemon.c:55
0x7f496292020f ???
        ???:0
0x7f496292018b ???
        ???:0
0x7f49628ff858 ???
        ???:0
0x7f49628ff728 ???
        ???:0
0x7f4962910f35 ???
        ???:0
0x563b8eaca7e3 handle_peer_gossip_or_error
        common/read_peer_msg.c:170
0x563b8eab79f2 closing_read_peer_msg
        closingd/closingd.c:116
0x563b8eab838a receive_offer
        closingd/closingd.c:362
0x563b8eab9299 main
        closingd/closingd.c:752
0x7f49629010b2 ???
        ???:0
0x563b8eab75dd ???
        ???:0
0xffffffffffffffff ???
        ???:0
2021-04-16 15:33:44 +09:30
Rusty Russell ade10e7fc4 peer_control: fix leak false positive.
We generally hang things off our JSON response (this pattern predates
tmpctx!) but sometimes it gets reported as a memleak.  I'd prefer not
to mark JSON responses as "notleak", since they can be allocated for
a while), so use tmpctx here.

```
E           ValueError:
E           Node errors:
E           Global errors:
E            - Node /tmp/ltests-spnausnb/test_htlc_out_timeout_1/lightning-1/ has memory leaks: [
E               {
E                   "backtrace": [
E                       "ccan/ccan/tal/tal.c:442 (tal_alloc_)",
E                       "ccan/ccan/tal/tal.c:471 (tal_alloc_arr_)",
E                       "wallet/wallet.c:1775 (wallet_state_change_get)",
E                       "lightningd/peer_control.c:922 (json_add_channel)",
E                       "lightningd/peer_control.c:1424 (json_add_peer)",
E                       "lightningd/peer_control.c:1454 (json_listpeers)",
E                       "lightningd/jsonrpc.c:643 (command_exec)",
E                       "lightningd/jsonrpc.c:767 (rpc_command_hook_final)",
E                       "lightningd/plugin_hook.c:275 (plugin_hook_call_)",
E                       "lightningd/jsonrpc.c:855 (plugin_hook_call_rpc_command)",
E                       "lightningd/jsonrpc.c:942 (parse_request)",
E                       "lightningd/jsonrpc.c:1033 (read_json)",
E                       "ccan/ccan/io/io.c:59 (next_plan)",
E                       "ccan/ccan/io/io.c:435 (io_do_always)",
E                       "ccan/ccan/io/poll.c:300 (handle_always)",
E                       "ccan/ccan/io/poll.c:377 (io_loop)",
E                       "lightningd/io_loop_with_timers.c:24 (io_loop_with_timers)",
E                       "lightningd/lightningd.c:1097 (main)"
E                   ],
E                   "label": "wallet/wallet.c:1775:struct state_change_entry[]",
E                   "parents": [
E                       "common/json_stream.c:29:struct json_stream",
E                       "ccan/ccan/io/io.c:91:struct io_conn",
E                       "lightningd/lightningd.c:116:struct lightningd"
E                   ],
E                   "value": "0x55c6b02150b8"
E               }
E           ]
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-12 23:03:47 +02:00
Rusty Russell c4dfac5c4b plugins: remove now-unused single-hook infrastructure.
Should have really let @mschmook do this, as he did all the work to
make it possible!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-07 14:34:39 +09:30
Rusty Russell da4c2cab62 plugin: always send allow-deprecated-apis in getmanifest.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: plugins: we now always send `allow-deprecated-apis` in getmanifest.
2021-04-07 14:34:39 +09:30
Rusty Russell 107c7ec0e3 lightningd: remove unused `original_directory` field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-07 14:34:39 +09:30
Rusty Russell 3d1c376f1d chaintopology: remove deprecated urgent/normal/slow feerate display.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-07 14:34:39 +09:30
Rusty Russell 162ba9d162 close: activate notifications even with deprecated-apis.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `close` now always returns notifications on delays.
2021-04-07 14:34:39 +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
Rusty Russell 3ccb6d6e7a Makefile: update to latest BOLT versions.
The main change which affects us is that 2016 blocks to forget a channel
is a fixed number in the spec; we make this clear by renaming the
(developer-only) max_funding_unconfirmed to dev_max_funding_unconfirmed
and making it compile DEVELOPER only.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-07 14:34:39 +09:30
Rusty Russell 006300ab96 lightningd: set "direction" correctly for connect which is already connected.
This means remembering the connection direction.  We also use the address to try
to reconnect, which we shouldn't bother with if they connect to us.

For peers from the database, we currently always save the addr: we shouldn't really
do this if they connected to us, since it's not useful for reconnecting (we don't
show the addr in JSON reply to listpeers unless we're connected, so it's only an
internal issue).  This is left for future work.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-26 13:22:33 +10:30
Rusty Russell b0d6996ed6 lightningd: get connection direction from connectd.
This matters: if we connected, the address is probably usable for future connections.
But if they connected, the port is probably not (but the IP address may be).

Changelog-Added: JSON-RPC: `connect` returns "direction" ("in": they iniatated, or "out": we initiated)
Changelog-Added: plugins: `peer_connected` hook and `connect` notifications have "direction" field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-26 13:22:33 +10: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 2baa24801e dual-funding: implies anchor outputs.
| 28/29 | `option_dual_fund`             | Use v2 of channel open, enables dual funding              | IN9      | `option_anchor_outputs`, `option_static_remotekey`   | [BOLT #2](02-peer-protocol.md)        |
2021-03-25 20:05:11 +10:30
Christian Decker 71c45dc55c plugin: Call invoice_payment hook before the matching notification
As @fiatjaf points out we were notifying before we were actually set
on accepting, since the hook could also still reject. Switched them
around does and calling the notification only once it's been decided
is the correct thing to do.

Changelog-Fixed: plugin: The `invoice_payment` notification was being sent before the hook was called, which could still abort it.
Suggested-by: Fiatjaf <@fiatjaf>
Signed-off-by: Christian Decker <@cdecker>
2021-03-19 10:18:42 +10:30
Rusty Russell 286c526a81 channel: initialize inflight->tx_broadcast (EXPERIMENTAL_FEATURES)
valgrind rightfully complains:

```
Valgrind error file: valgrind-errors.182892
==182892== Conditional jump or move depends on uninitialised value(s)
==182892==    at 0x16B381: handle_peer_tx_sigs_sent (dual_open_control.c:1415)
==182892==    by 0x16E9F4: dual_opend_msg (dual_open_control.c:2681)
==182892==    by 0x165759: sd_msg_read (subd.c:480)
==182892==    by 0x1EECCB: next_plan (io.c:59)
==182892==    by 0x1EF8B0: do_plan (io.c:407)
==182892==    by 0x1EF8F2: io_ready (io.c:417)
==182892==    by 0x1F1B8A: io_loop (poll.c:445)
==182892==    by 0x131332: io_loop_with_timers (io_loop_with_timers.c:24)
==182892==    by 0x13711B: main (lightningd.c:1102)
==182892==
--------------------------------------------------------------------------------
------------------------------- Valgrind errors --------------------------------
Valgrind error file: valgrind-errors.182899
==182899== Conditional jump or move depends on uninitialised value(s)
==182899==    at 0x16C0EE: handle_peer_tx_sigs_msg (dual_open_control.c:1737)
==182899==    by 0x16E9D3: dual_opend_msg (dual_open_control.c:2678)
==182899==    by 0x165759: sd_msg_read (subd.c:480)
==182899==    by 0x1EECCB: next_plan (io.c:59)
==182899==    by 0x1EF8B0: do_plan (io.c:407)
==182899==    by 0x1EF8F2: io_ready (io.c:417)
==182899==    by 0x1F1B8A: io_loop (poll.c:445)
==182899==    by 0x131332: io_loop_with_timers (io_loop_with_timers.c:24)
==182899==    by 0x13711B: main (lightningd.c:1102)
==182899==
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-18 13:25:52 +10:30
niftynei fc64ebdb53 dual-funding: don't not update the state! log the issue and move on with
with your life
2021-03-17 10:25:18 +10:30
niftynei dd696a7c05 df: move from warning to unusual
There are perfectly valid reasons for us to not have a command on return
(something went boom while sending them our sigs and we've now gotten
their sigs during a reconnect and subsequently broadcast the tx)
2021-03-17 10:25:18 +10:30
niftynei 61df08c50d df-broadcasts: use an impermanent marker to make sure we've sent things
This can result in us logging a warning if we've 1) dropped their sigs
response, 2) only us (the opener) added inputs, 3) and we broadcast on
their reconnect (when they retransmit their sigs)
2021-03-17 10:25:18 +10:30
niftynei c317b642c3 channel: why were these commas in the first place
How did this ever work?
2021-03-17 10:25:18 +10:30
Rusty Russell 6c9d9ee9a2 connect: return address we actually connected to.
Otherwise, we might find an address other than the one given and
the user might think that address worked.

Fixes: #4185
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `connect` returns `address` it actually connected to
2021-03-17 08:38:08 +10:30
Rusty Russell b563cafd83 lightningd: don't complain about bad funding PSBT for elements.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:10:07 +10:30
Rusty Russell 22e1107581 lightningd/opening_control: deprecate old fundchannel_complete args.
And update all the in-tree callers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `fundchannel_complete` `txid` and `txout` parameters (use `psbt`)
2021-03-16 13:10:07 +10:30
Rusty Russell da7ba6c146 lightningd/opening_control: allow single-arg fundchannel_complete with PSBT
Requiring the user to calculate the txid of the PSBT is a horrible, bad,
no-good idea.

Doesn't deprecate yet, so I can test that this path works while
multifundchannel still uses it.

Fixes: #4416 (at least for future users!)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `fundchannel_complete` takes a psbt parameter.
2021-03-16 13:10:07 +10:30
Rusty Russell bf928ef47a lightningd/opening_control: store funding scriptpubkey.
We'll need it in next patch to identify the funding output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:10:07 +10:30
Rusty Russell 58ee8d427a lightningd/opening_control: d_o_n_t a_d_d e_x_t_r_a u_n_d_e_r_s_c_o_r_e_s
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:10:07 +10:30
Rusty Russell a1b43a3653 onchaind: see closes when wrong_funding shutdowns are used.
Fairly easy to do, though we also have to add the watch when we load
from the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Rusty Russell b62706aa01 close: accept wrong_funding outpoint arg if we negotiated the feature.
Changelog-Added: lightningd: experimental-shutdown-wrong-funding to allow remote nodes to close incorrectly opened channels.
Changelog-Added: JSON-RPC: close has a new `wrong_funding` option to try to close out unused channels where we messed up the funding tx.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Rusty Russell 1cfb7b84d0 closingd: add support for handling wrong_funding.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Rusty Russell 820fbcd65a channeld: code to send wrong_funding if lightningd says to.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Rusty Russell 80c2f28373 channeld: accept the 'wrong_funding' shutdown TLV.
If it passes checks, lightningd puts it in the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Rusty Russell cc6d2afe21 Experimental option option_shutdown_wrong_funding: help me, I screwed up!
It's not unheard of for people to give the wrong funding tx to us,
getting their funds stuck.  Interestingly, we can allow mutual close
using a different txid and output number as long as they (solely)
funded the channel, and the channel hasn't been used.

This defines a "play area" feature to do just that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Jan Sarenik 1b02d15695 typo: information is an uncountable mass noun
See https://en.wikipedia.org/wiki/Information

In libplugin.c also the word "details" was added (without removing
the 'information').

Changelog-None
2021-03-16 10:45:40 +10:30
niftynei bec96a6c5b df: add openchannel_abort command
Allows us to clean up an in-progress open that we won't be completing

Changelog-Added: EXPERIMENTAL JSON-RPC: Permit user-initiated aborting of in-progress opens. Only valid for not-yet-committed opens and RBF-attempts
2021-03-15 14:08:44 +10:30