Commit Graph

3218 Commits

Author SHA1 Message Date
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
niftynei 015a0555d0 df: nit, update to use proper helper json function for channel_id 2021-03-15 14:08:44 +10:30
niftynei 8182e9cea4 df: update the openchannel2 parameter 'accepter' -> 'our'
The `rbf_channel` hook uses `our_funding_msat`, which is a nicer
and more easily understood than the `openchannel2`
`accepter_funding_msat`.

This updates the `openchannel2` hook to use the same nomenclature as
`rbf_channel`.
2021-03-12 14:00:19 +10:30
niftynei a60d652517 df: add missing check for already set scriptpubkey
Noticed while adding the documentation for the hook.
2021-03-12 14:00:19 +10:30
niftynei 52b5dbb01d df: add doc for `channel_open_failed` notification
When a channel fails, send out a notification.

We were missing this notification in one case, which has been added.
2021-03-12 14:00:19 +10:30
niftynei fc9e72b62b df-doc: add docs for openchannel_bump, more checks for valid psbt
Add docs for openchannel_bump, plus some checks that were missed for
verifying the amount is valid.
2021-03-12 14:00:19 +10:30
niftynei a648ec827a df-doc: update error codes, make sure they're correct 2021-03-12 14:00:19 +10:30
Christian Decker 0bc8a47226 plugin: Add details about which plugin caused a clash in RPC methods 2021-03-10 12:03:10 -06:00
Christian Decker e59940eb61 plugin: Abort early if we have a misconfiguration in the plugins
We were reporting the failure immediately but still continuing with
the startup. This could happen if an important plugin ends up in a
race with another plugin (important or not) for a contended
resource (CLI option or RPC method name). We would eventually notice
that we were supposed to abort, but at that point we already processed
a couple of blocks, loaded the entire state, etc.

This just aborts early with a sane error message.

Changelog-Added: plugin: If there is a misconfiguration with important plugins we now abort early with a more descriptive error message.

Reported-by: PsySc0rpi0n
Reported-by: Ján Sáreník <@jsarenik>
2021-03-10 12:03:10 -06:00
niftynei 26e4bae9ce df: fail channel if peer sends witnesses that aren't paid for
The receiving node: ...
      - MUST fail the channel if:
        - the `witness_stack` weight lowers the effective `feerate`
          below the agreed upon transaction `feerate`
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 8cc2919884 connectd: clean up the channel stuffs when we get a reconnect
If they've disconnected/reconnected we need to terminate all the
inflight stuff, plus go ahead and call 'disconnect' plugin trigger etc.
2021-03-06 15:03:56 +10:30
niftynei 97e64915c5 df: add (over zealous?) note about the usage of `psbt_has_req_fields`
Requested-In-Part-By: Rusty Russell @rustyrussell
2021-03-06 15:03:56 +10:30
niftynei fc411a5925 df-memleak: expose memleak error and fix
We were getting a memleak error that the open_attempt isnt' being
cleaned up in test_rbf_reconnect_tx_construct. I had some trouble
reproducing it, so I removed the reliance on using `tmpctx` to clean it
up and was more surgical about cleaning it up inline.
2021-03-06 15:03:56 +10:30
niftynei e0a2d47903 df-rbf: reconnection tests (init_rbf + ack_rbf) 2021-03-06 15:03:56 +10:30
niftynei 07153bff6a df: cleanup error handling on lightningd side
Make existing methods understand how unsaved channels work, re-work
errors so that we handle everything appropriately
2021-03-06 15:03:56 +10:30
niftynei dfdf9259d7 listpeers: include feerate info for RBF-candidate channels
Changelog-Added: JSON-RPC: `listpeers` now includes 'last_feerate', 'next_feerate', 'initial_feerate' and 'next_fee_step' for channels in state DUALOPEND_AWAITING_LOCKIN

fixup! listpeers: include feerate info for RBF-candidate channels
2021-03-06 15:03:56 +10:30
niftynei 6c76dd338e channel: move inflight + feerate methods to channel.c
Need these more accessible for next patch, which moves the next_feerate
info into listpeers
2021-03-06 15:03:56 +10:30
niftynei a23277af57 listpeers: include info on channels that are in-process
Channels that we're in negotiation for, but don't have a commitment
transaction saved for yet.
2021-03-06 15:03:56 +10:30
niftynei 1acc1aa27e rbf: clean up channel on error
Make sure we clean up unsaved channels appropriately on failure.

We forget the peer/channel if it's unsaved!
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 4fb95a9350 df-rbf: separate first-time channel save from update (RBF)
We can't "first save" a channel twice; instead we split in two and just
update the underlying channel on subsequent passes (RBFs)
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 2719ff8c3b df-rbf: handle rbf failures in lightningd 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
Rusty Russell 4dcd4ca155 listpeers: add latest feerate and actual last fee amount.
Users have no idea what they would pay for unilateral closes.
At least this gives them a clue!

Reported-by: @az0re on IRC.

Changelog-Added: JSON-RPC: `listpeers` now shows latest feerate and unilaral close fee.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-05 13:12:41 +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 cf170c3909 df: allow for RBF_INIT in sigs states 2021-03-03 16:19:04 -06:00
niftynei 02d99acca1 dualopen: check that peer is connected for json calls
Before we start trying to talk to the peer, check that they're
connected.
2021-03-03 16:19:04 -06:00
niftynei d8221aae76 df: update channel_id when opening; closing; disconnecting
We were missing the channel_id for accepter opens; it's also a good idea
to reset it to 0xFF when we disconnect totally
2021-03-03 16:19:04 -06:00
niftynei 474233f1b7 memleak,df: patchup memleak code for v2 channels
Takes 'unsaved' channels into account for memleak cleanups, instead of
solely relying on `uncommitted_channels`
2021-03-03 16:19:04 -06:00
niftynei 6407ad334f df, channel: if a channel reconnects, but it's "unsaved" still
Go ahead and start dualopend, but as a fresh instance.
2021-03-03 16:19:04 -06:00
niftynei 779067d74c df: check inflights when deciding whether or not to allow command
We were missing the inflight state checks before allowing to proceed
with a command.
2021-03-03 16:19:04 -06:00
niftynei da81d4bced channel: skip unsaved channels
Now that "peer->channels" contains `unsaved` channels, skip overthem
where appropriate
2021-03-03 16:19:04 -06:00
niftynei b9f867b1dd connectd: check for re-connected unsaved channels 2021-03-03 16:19:04 -06:00
niftynei 4c9a4250bf subd: remove "swap" methods
only needed for moving the subd->channel from an uncommitted_channel to
a channel; we removed uncommitted_channel from dual_open so it's no
longer necessary
2021-03-03 16:19:04 -06:00
niftynei de3599e98a subd: remove ctype (channel_type)
We only needed the type check for dual_open, since it was the only
subdaemon path that used two 'types' in the subd->channel field.
2021-03-03 16:19:04 -06:00
niftynei 1e9a900918 df: start of RPC for bumping the fee!
Doesn't call into dualopend yet
2021-03-03 16:19:04 -06:00
niftynei d49db8ad41 df: do the right thing, now that we have a cancellation routine
removes a fixme
2021-03-03 16:19:04 -06:00
niftynei 3da2ae4d30 df: move to inflights for sigs/openchannel_signed parts of flow
We create an inflight once we get the commitment tx for a channel
instead of once we get the funding transaction signatures
2021-03-03 16:19:04 -06:00
niftynei 8b0e88dfb3 df: move initialization over to unsaved channel
uncommitted_channel -> channel (but unsaved)
2021-03-03 16:19:04 -06:00
niftynei 0951e2c941 df: get rid of unnecessary struct `commit_rcvd` 2021-03-03 16:19:04 -06:00
niftynei 95e81ce82c df: helper to find the last (most recent) inflight for a channel 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 bfb862564e df: method for disconnecting an *unsaved* channel
Since we're moving over to "unsaved channels" instead of
"uncommitted_channel" struct, we need a new utility to disconnect this
channe
2021-03-03 16:19:04 -06:00
niftynei 538fd670ce df: add helper for creating an "unsaved" channel
Channel that's not saved to database yet
2021-03-03 16:19:04 -06:00
niftynei 1786fcbbdc df: migrate from "uncommitted_channel" to "open_attempt"
We're going to move over to "unsaved channels" instead of using a
separate "uncommitted_channel" struct. This means a peer might have a
channel that's not saved to the database yet in its channel list
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
niftynei 50b8655cbe channel: remove 'uncommitted_channel' from channel lookup
We're going to be removing "uncommitted_channel" from v2 open stat
2021-03-03 12:28:22 +10:30
niftynei 4baa10ef68 channel: remove `psbt` and `remote_tx_sigs`
We just added this, but we've migrated them to the "inflight" struct
instead, as they actually pertain to an single inflight open attempt
2021-03-03 12:28:22 +10:30
niftynei e15de71375 channel: only delete saved channels from database
There will be 'unsaved' channels now, with a dbid of 0
2021-03-03 12:28:22 +10:30
niftynei 99123ddbe4 dual-funding, rbf: reject RBFs that will fail the total-fee rule
RBFs must have a total fee greater than the last successful RBF attempt
2021-03-03 12:28:22 +10:30
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 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 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 e18af6aaa3 rbf: check all inflights for matching transaction data
Even though, technically, we only need to check for v1 open data, go
ahead and extend this check to encompass the inflights
2021-03-03 12:28:22 +10:30
niftynei b8b910e4c4 df-rbf: update channel data on depth reached
When the funding tx reaches depth, update the channel's data to the
"correct" funding transaction info from inflights (if necessary).

This will be necessary if:
    - the transaction has been successfully RBF'd and
    - the lesser fee transaction is the one successfully mined, OR
    - the channel is in the process of being RBF'd
2021-03-03 12:28:22 +10:30
niftynei 36f3b13279 inflight: add a 'channel-inflight' concept, in-progress channel stuffs
"inflights" are all potential channel funding transactions that we
currently have commitment transactions for.
2021-03-03 12:28:22 +10:30
niftynei 1e4ff724a5 nit: make comments 80 chars 2021-03-03 12:28:22 +10:30
Karol Hosiawa 8a8f81175d Added in_channel,out_channel,state params to listforwards 2021-03-03 09:19:20 +10:30
Michael Schmoock afaaeb3c7d plugins: make rpc_command hook chainable
Changelog-Changed: The `rpc_command` hook is now chainable.
2021-03-03 09:18:53 +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 66dda32da2 common/shutdown_scriptpubkey: extract shutdown scriptpubkey test.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-02 14:42:34 +10:30
Christian Decker ebb1b19c65 plugin: Fix the custommsg hook not to include the internal prefix
We were always prefixing the `message` field with the internal type
prefix 0x0407, followed by the length prefix. Neither is needed since
the type being constant is of no interest to the plugin and the length
being implicit due to the JSON-encoding.

Reported-by: Ilya Evdokimov
Changelog-Fixed: plugin: The `custommsg` hook no longer includes the internal type prefix and length prefix in its `payload`
Changelog-Deprecated: plugin: The `message` field on the `custommsg` hook is deprecated in favor of the `payload` field, which skips the internal prefix.
2021-03-02 14:41:16 +10:30
Rusty Russell 959d1c9983 chaintopology: fix notification first time fee estimate works.
We probably want to notify everyone immediately, rather than
waiting for the first change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-02 13:34:55 +10:30
Rusty Russell 171af7742a plugin: log self-disable at debug level, other manifest fails at unusual.
This avoids spamming the logs.  We also remove the duplicate debug
logs on self-disable (plugin_kill logs it for us).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-01 12:16:42 +01:00
Rusty Russell a9aad0da98 plugin: add log-level to plugin_kill, make it take format string.
We currently log every kill at INFO level, even if it's during shutdown.
Change those to debug, but lift those where we got a malformed response.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-01 12:16:42 +01:00
Rusty Russell 7885d12eca lightningd: reap zombies (particularly plugins).
We use waitpid() manually for subdaemons, so we need to step
around that (otherwise we could simply ignore them).

We could destroy subdaemons only once they've exited, but
that works badly with the sd->conn, which will be freed
when error (i.e. close) is detected, so the current code
is probably the best compromise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-01 12:16:42 +01:00
Rusty Russell ee5da52677 lightningd: differentiate cases of plugin death correctly.
If a plugin died due to connection close, we'd always say
"Plugin exited before completing handshake.", which was often
wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-01 12:16:42 +01:00
Rusty Russell 874ca99c32 offers: make 'used' flag more useful.
We used to only set it for single-use offers (where it's required),
but it's still interesting for multi-use offers, so let's keep it
there.

We also put this field in the documentation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-25 14:44:03 +10:30
Rusty Russell 36bf037ca7 doc: update BOLT quotes (to include preimage leakage).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-25 13:23:16 +10:30
niftynei 84ed942dee df: patch hole where we wouldn't notify peer of failure 2021-02-24 10:06:42 -06:00
niftynei 367e377d5a df: use simplified version to print json 2021-02-24 10:06:42 -06:00
Rusty Russell f3159ec4ac pytest: detect warnings, too.
Since we turned many errors into warnings, we want our tests to fail
when they happen unexpectedly.  We make WARNING clear in the strings
we print, too, to help out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-04 12:02:52 +10:30
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 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 1a85edd207 lightningd: no longer forward failures to gossipd, let caller do it.
We fix up the test by using pay, instead of sendpay (and making pay log
the expected message).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: sendpay no longer extracts updates from errors, the caller should do it from the `raw_message`.
2021-02-02 13:44:01 +01:00
Rusty Russell 3c5502426b lightningd: addgossip API to inject gossip messages.
Importantly, this is synchronous, so pay will be able to use it
reliably.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-02 13:44:01 +01:00
Rusty Russell 0056dd7557 lightningd: disallow --daemon without --log-file.
From #clightning:

    (11:24:10) andytoshi: hiya, i'm trying to set up a new lightningd node, and when i run lightningd --network=bitcoin --log-level=debug --daemon
    (11:24:17) andytoshi: i get errors of the form fetchinvoice: Malformed JSON reply '2021-01-25T00:51:16.655Z DEBUG   plugin-offers: disabled itself at init: offers not enabled in config
    (11:24:43) andytoshi: there are a couple variants of this, but always some form of "something: failed to parse <a log line> as json"

Indeed, we close stdout, and it ends up being reused for some plugin.
But the real problem is that we log to stdout by default, which doesn't
make sense.  If they really want to discard logs, they can use
--log-file=/dev/null.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON failures when --daemon is used without --log-file.
2021-02-01 09:57:54 +10:30
Rusty Russell 5eb209f57a bitcoind: remove v0.9.0-compat for rejecting sendrawtransaction arg.
Changelog-Removed: `bcli` replacements must allow `allowhighfees` argument (deprecated 0.9.1).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-01 09:57:35 +10:30
Rusty Russell 406eb37717 listsendpays: remove deprecated "null" amount_msat.
Changelog-Removed: `listsendpays` will no longer add `amount_msat` `null` (deprecated 0.9.1).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-01 09:57:35 +10:30
Michael Schmoock 9eeb290637 chore: cleanup some nits
rearranges the`peer_connected_hook_payload` definition to the location
where this is used in the file.

Fixes certain blanklines and linebreaks to make the code look nicer.
2021-02-01 09:57:15 +10:30
Michael Schmoock 91bdb6d2d9 feat: make peer_connected hook chainable
Changelog-Changed: peer_connected hook is now chainable
2021-02-01 09:57:15 +10:30
Michael Schmoock bdf0d60fd6 chore: fix typo in openchannel hook log
Nit: The underscore in "openchannel_hook" is wrong, bcause the name of
the hook is just "openchannel". The "_hook" implied this to be part of
the name.

Changelog-None
2021-02-01 09:57:15 +10:30
Michael Schmoock 8e71c7a1f1 feat: make custommsg hook chainable
Changelog-Changed: custommsg hook is now chainable
2021-01-29 13:37:42 +10:30
niftynei d1a59b6f0d nit df: correct spelling mistake 2021-01-25 10:05:17 +10:30
Rusty Russell 79f32751d2 lightningd: don't expose (undocumented) experimental-dual-fund.
It doesn't make sense currently without EXPERIMENTAL_FEATURES, and
check-manpages complains about it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-14 13:56:13 +01:00
Rusty Russell 4d1214b432 lightningd: fix double-free when forking subdaemon fails.
payload is owned by the peer, which is freed in this case, then we
free payload (again).

==1404== Invalid read of size 8
==1404==    at 0x1F39E8: to_tal_hdr (tal.c:174)
==1404==    by 0x1F43A4: tal_free (tal.c:479)
==1404==    by 0x14B3D1: peer_connected_hook_cb (peer_control.c:1087)
==1404==    by 0x15D6E9: plugin_hook_call_ (plugin_hook.c:288)
==1404==    by 0x14B40E: plugin_hook_call_peer_connected (peer_control.c:1090)
==1404==    by 0x14B5B8: peer_connected (peer_control.c:1135)
==1404==    by 0x122FCF: connectd_msg (connect_control.c:310)
==1404==    by 0x160291: sd_msg_read (subd.c:480)
==1404==    by 0x15FBE7: read_fds (subd.c:308)
==1404==    by 0x1E37D1: next_plan (io.c:59)
==1404==    by 0x1E434E: do_plan (io.c:407)
==1404==    by 0x1E438C: io_ready (io.c:417)
==1404==  Address 0x2fcd2268 is 24 bytes inside a block of size 336 free'd
==1404==    at 0x4C32D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1404==    by 0x1F416E: del_tree (tal.c:421)
==1404==    by 0x1F40F2: del_tree (tal.c:412)
==1404==    by 0x1F442C: tal_free (tal.c:486)
==1404==    by 0x148816: delete_peer (peer_control.c:120)
==1404==    by 0x148899: maybe_delete_peer (peer_control.c:136)
==1404==    by 0x13A970: destroy_uncommitted_channel (opening_common.c:29)
==1404==    by 0x1F3BB1: notify (tal.c:240)
==1404==    by 0x1F40A0: del_tree (tal.c:402)
==1404==    by 0x1F442C: tal_free (tal.c:486)
==1404==    by 0x13D3E9: peer_start_openingd (opening_control.c:911)
==1404==    by 0x14B3C2: peer_connected_hook_cb (peer_control.c:1086)
==1404==  Block was alloc'd at
==1404==    at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1404==    by 0x1F3C1B: allocate (tal.c:250)
==1404==    by 0x1F41B4: tal_alloc_ (tal.c:428)
==1404==    by 0x14B454: peer_connected (peer_control.c:1105)
==1404==    by 0x122FCF: connectd_msg (connect_control.c:310)
==1404==    by 0x160291: sd_msg_read (subd.c:480)
==1404==    by 0x15FBE7: read_fds (subd.c:308)
==1404==    by 0x1E37D1: next_plan (io.c:59)
==1404==    by 0x1E434E: do_plan (io.c:407)
==1404==    by 0x1E438C: io_ready (io.c:417)
==1404==    by 0x1E6552: io_loop (poll.c:445)
==1404==    by 0x12E2AD: io_loop_with_timers (io_loop_with_timers.c:24)

Fixes: #4329
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-14 11:13:19 +01:00
Rusty Russell 001b5d6416 offers: make it a runtime option.
The fetchinvoice and offers plugins disable themselves if the option
isn't enabled (it's enabled by default on EXPERIMENTAL_FEATURES).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: `experimental-offers` enables fetch, payment and creation of (early draft) offers.
2021-01-13 14:45:36 +01:00
Rusty Russell 529ae0d766 plugins: allow plugins to disable themselves at startup.
By returning 'disable: <reason>' inside getmanifest or init result.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: plugins: plugins can now disable themselves by returning `disable`, even if marked important.
2021-01-13 14:45:36 +01:00
Rusty Russell fc3e679c97 lightningd: control onion messages by `experimental-onion-messages` option.
Note that this also changes so the feature is not represented in channels,
reflecting the recent drafts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: `experimental-onion-messages` enables send, receive and relay of onion messages.
2021-01-13 14:45:36 +01:00
niftynei 9906236769 autodata: requests new line number, please 2021-01-10 13:44:04 +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 fa539d3281 df-tests: make memleak happy by cleaning up `psbt`
We don't need it anymore. Normally it gets cleaned up by `cmd` but we're
done with it here.
2021-01-10 13:44:04 +01:00
niftynei ac88c72f1e df-tests: test_channel_state_changed_bilateral 2021-01-10 13:44:04 +01:00
niftynei ff0e2dbd28 df-tests: test_channel_opened_notification
We weren't sending a channel_open notification for dual-funded channels.

This is only sent for the 'accepter' side. We send it as soon as both
funding_tx sigs have been exchanged, even though it's possible the
funding transaction might be published without this having been the case.

Since we fail the channel if this happens, only notifying for good/valid
channels reaching the broadcast state is the right way to handle this.
2021-01-10 13:44:04 +01:00
niftynei 959ca793b0 df-tests: test_openchannel_hook_error_handling 2021-01-10 13:44:04 +01:00
niftynei 803d9701d3 df-tests: test_openchannel_hook_chaining 2021-01-10 13:44:04 +01:00
niftynei 327d9a3ff6 experimental-dual-fund: add config level option for enabling dual-fund
Allow a user to switch on dual-funding without needing to compile
as EXPERIMENTAL_FEATURES.

Doesn't work yet, since everything is still behind
'EXPERIMENTAL_FEATURES' compile time flags... but useful for testing
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 1393e187f9 df: don't update local shutdown scriptpubkey from dualopend
When we're the opener, we get the upfront shutdown scriptpubkey (if
there is one) from the `close_to` param of `openchannel_init`.

We were passing it through dualopend, but we need to break the update
chain so that our test_option_upfront_shutdown_script test works (same
as on the openingd flow.)
2021-01-10 13:44:04 +01:00
niftynei 52da9be598 df: if 'openchannel2' is "rejected" we should send that error
We weren't really handling 'rejected' channel open requests very
elegantly, now we do.
2021-01-10 13:44:04 +01:00
niftynei 857ff561bc df: move callback up
We're going to call it from the deserialization method here soon
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 85ecef2849 df-feerates: mimic old behavior if there's no plugin handling
We delegate the decision about what to do about 'out of bound' feerates
to the plugin (if one exists), however in the case that the plugin
doesnt exist or doesnt want to figure it out, we default to using the
'best' as their intended feerate, and rejecting if it's out of bounds.
2021-01-10 13:44:04 +01:00
niftynei 5d388b3128 df: there's only one state that we should be in for a `dualopend`
and that's DUALOPEND_AWAITING_LOCKIN; we'll have moved over to
subd type 'channeld' if we're in CHANNELD_NORMAL
2021-01-10 13:44:04 +01:00
niftynei 3e9f60011e channel: save the fact that funding_locked was rcvd to disk
I think this was an oversight?
2021-01-10 13:44:04 +01:00
niftynei 9cb2a15858 channel_fallen_behind: break out functionality into two methods
We'll need this for moving 'waiting for locked' into dualopend.
2021-01-10 13:44:04 +01:00
niftynei fd2e16f8bc db: add flag to database for recving remote's sigs
We need to know if they've sent us their sigs message yet. Ideally, we'd
be able to check the 'finalness' of the PSBT, however if the peer
doesn't have any inputs to the channel this doesn't work.
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 bf49bcfa90 subd: keep track of 'channel's type
Back in the days before dual-funding, the `channel` struct on subd was
only every one type per daemon (either struct channel or struct
uncommitted_channel)

The RBF requirement on dualopend means that dualopend's channel,
however, can now be two different things -- either channel or
uncommitted_channel.

To track the difference/disambiguate, we now track the channel type on a
flag on the subd. It gets updated when we swap out the channel.
2021-01-10 13:44:04 +01:00
niftynei 0c520850b0 setchannelfee: allow dualopend's "awaiting" state to be valid also 2021-01-10 13:44:04 +01:00
niftynei 79c01c1386 feerates: mimic behavior of original opening if feerates not specified
Setting to min is a premature optimization, at least until we're able to
intelligently use anchors to sink commitment txs
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 06b15f648f dual_open: move two functions
we'll call them from elsewhere later
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 57348e0470 channel_control: when we reach depth, for v2 channels, tell dualopend 2021-01-10 13:44:04 +01:00
niftynei 1c9a713dfa channel-state: add two new states, for dualopend
v2 channel opens are going to happen over in dualopend. In order
to make sure that these don't end up in the wrong place/to keep track of
the difference between "waiting for sigs" and "have merely initiatlized
a channel", we add two new states to the channel state machine.

A channel that 'originates' in dualopend will only ever arrive at
channeld in the state CHANNELD_NORMAL.
2021-01-10 13:44:04 +01:00
niftynei bdf7f250de channel_control: rename record_channel_open + expose 2021-01-10 13:44:04 +01:00
niftynei c5e28e4746 channel_control: break out function for on_funding_locked
We're about to move channel-locking over to dualopend, and will want to
reuse this.
2021-01-10 13:44:04 +01:00
niftynei b2bb80cb1b dual_open_control: correct name of hook
We're processing the PSBT for openchannel_changed, not
openchannel_signed
2021-01-10 13:44:04 +01:00
niftynei c6de4138e6 open_command: keep them local to channel
Since this all stays in dualopend/dual_open_control, we can hold
onto the openchannel_signed command to wait for a response here locally.
Previously we were splitting across the channeld/openingd boundary.
2021-01-10 13:44:04 +01:00
niftynei f37315c2f8 autodata: tweak where createinvoice is 2021-01-10 13:44:04 +01:00
niftynei e0e929ed14 peer_control: remove PSBT from peer_start_channeld
Since we're moving all of the PSBT signing to dualopend, we no longer
need a PSBT to be passed to channeld
2021-01-10 13:44:04 +01:00
niftynei 0bb483f9b1 whitespace changes, 80 chars etc 2021-01-10 13:44:04 +01:00
niftynei 01e37d61e8 channeld: remove peer->psbt
We used this for dual funded opens, to track the receipt of signatures.
We're moving all of this over to dualopend now, however, so we no longer
need the PSBT in channeld.
2021-01-10 13:44:04 +01:00
niftynei c8aa6d4a55 subd: swap out the channel + error callback
dual funding now swaps out the subdaemon's 'channel' struct in the
middle of daemon existence, so we update the channel and error callback
here.
2021-01-10 13:44:04 +01:00
niftynei 8ea1d5ec3b df: open_channel -> openchannel
Suggested-By: Christian Decker (@cdecker)
2021-01-10 13:44:04 +01:00
niftynei 80714de556 df: make sure to end wally alloc 2021-01-10 13:44:04 +01:00
niftynei 260bd04adb df: move tx_sigs from channeld to dualopend
Non-functional yet, but this gets all the pieces in the right places,
rips the signature signing functionality out of channeld.
2021-01-10 13:44:04 +01:00
Rusty Russell 23af9d4972 onion_message: support variable-length onion messages.
Updated to the BOLT, and a few tweaks, and we can send giant onion_messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 12:45:31 +01:00
Rusty Russell 8cf4bd902b lightningd: fix temporary onion_message leak:
This is fixed when payload is freed, but I noted a leak in the case of
an invalid payload:

```
E           ValueError: 
E           Node errors:
E           Global errors:
E            - Node /tmp/ltests-ipt6ab_y/test_sendinvoice_1/lightning-2/ 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                       "gossipd/gossipd_wiregen.c:925 (fromwire_gossipd_got_onionmsg_to_us)",
E                       "lightningd/onion_message.c:99 (handle_onionmsg_to_us)",
E                       "lightningd/gossip_control.c:166 (gossip_msg)",
E                       "lightningd/subd.c:480 (sd_msg_read)",
E                       "ccan/ccan/io/io.c:59 (next_plan)",
E                       "ccan/ccan/io/io.c:407 (do_plan)",
E                       "ccan/ccan/io/io.c:417 (io_ready)",
E                       "ccan/ccan/io/poll.c:445 (io_loop)",
E                       "lightningd/io_loop_with_timers.c:24 (io_loop_with_timers)",
E                       "lightningd/lightningd.c:1016 (main)"
E                   ],
E                   "label": "gossipd/gossipd_wiregen.c:925:u8[]",
E                   "parents": [
E                       "lightningd/onion_message.c:96:struct onion_message_hook_payload",
E                       "lightningd/plugin_hook.c:87:struct hook_instance *[]"
E                   ],
E                   "value": "0x560779438db8"
E               }
E           ]
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell 84dc943cf5 common/bolt11_json: extract bolt11->json code.
Our new "decode" command will also handle bolt11.  We make a few cleanups:

1. Avoid type_to_string() in JSON, instead use format functions directly.
2. Don't need to escape description now that JSON core does that for us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell 3514c8a034 lightning/onion_message: hack to allow x-only guesses for first hop.
I've proposed we use x-only pubkeys everywhere, but meanwhile we do
this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell 9d57612415 gossipd, channeld: handle onion messages in gossipd so we don't need a channel.
The previous onion_message code required a confirmed, not-shutting-down
channel, not just a connection.  That's overkill; plus before widespread
adoption we will want to connect directly as a last resort.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell bdfcec3eb6 fetchinvoice: check we're in the period before attempting to fetch.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell c1b38afcd3 lightningd: new api payersign to sign bolt12 message with a payer_key.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell a15878b3a4 sendonion: remove underscores from JSON arg name.
I fixed the "sendpay" one but not this one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell 1a8978100e invoice: add ctlv option.
This is required if we want to create a "bouncer" plugin (in my copious free time!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `invoice` now takes an optional `cltv` parameter.
2021-01-08 10:45:56 +01:00
Christian Decker 0d1b45dfcc json-rpc: Give `waitblockheight` an error code for timeouts
We need to differentiate timeouts from other results, so make it recognizable.
2021-01-08 09:19:24 +01:00
Rusty Russell 3b7d0e7a62 common/json: make json_scan return an error string.
This makes for more useful errors.  It prints where it was up to in
the guide, but doesn't print the entire JSON it's scanning.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-07 19:32:47 +01:00
Rusty Russell 53582a0f81 lightningd/bitcoind: use json_scan.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-07 19:32:47 +01:00
Rusty Russell 11a4d46c44 chaintopology: fix crash if bcli doesn't include errmsg.
Interestingly, we required that "sendrawtx" include "errmsg" field even
on success, otherwise we crashed in broadcast_remainder.

We only actually insist on an "errmsg" if success is false.  And this
logic here is weird (the !success) was added by darosior in
947f5ddde1, which makes the msg checks redundant.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-07 19:32:47 +01:00
Rusty Russell 2b6cdfeb5a json_to_psbt: fix API to match other allocating json_to functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-07 19:32:47 +01:00
Christian Decker 30abda2750 jsonrpc: Allow filtering via bolt11 or payment_hash in listinvoices
A user reported that it is sometimes cumbersome to search an invoice
based on the payment hash or the bolt11 string in the full list, which
may be required when we don't have the label available.

This adds support for querying / filtering based on the `payment_hash`
or `bolt11` string.

Changelog-Added: JSON-RPC: `listinvoices` can now query for an invoice matching a `payment_hash` or a `bolt11` string, in addition to `label`
2021-01-06 18:48:06 +01:00
Antoine Poinsot 45bb1bfa3c hsmd: cleanup encrypted hsm_secret detection
This makes use of the constant defined in the previous commits to more
accurately detect plaintext, encrypted, and invalid seeds. We now error
on invalid seeds.

Changelog-changed: hsmd: we now error at startup on invalid hsm_secret
Changelog-changed: hsmtool: all commands now error on invalid hsm_secret
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Antoine Poinsot a441485a35 lightningd: regroup hsm_secret password input logic
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Antoine Poinsot 917f78a4f8 lightningd: group hsm_secret encryption key derivation
This avoids duplication of both logic and error-prone values, such as
the salt. Grouping all hsm encryption logic into a public API will also
allow us to fuzz it.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Antoine Poinsot 56c223886c lightning: confirm password on hsm_secret encryption
Changelog-changed: lightningd: the `--encrypted-hsm` now asks you to confirm your password when first set
Changelog-changed: hsmtool: the `encrypt` now asks you to confirm your password
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
niftynei d98bd39d60 dual_open: neaten spacing for macro 2021-01-05 19:12:00 +01:00
fiatjaf 6af8adde26 fix memset for route_hop json parsing when no channel_id exists.
Changelog-None
2021-01-04 11:24:55 +01:00
Rusty Russell 19af1d10e6 invoice: hack in merkle of invoice as "payment_secret" (EXPERIMENTAL_FEATURES)
This lets actually pay the invoice that fetchinvoice returns.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-23 14:24:39 +01:00
Rusty Russell 43b71de897 lightningd: low-level createinvoicerequest API (EXPERIMENTAL_FEATURES)
This is similar to the createinvoice API, except we don't need to save
invoice requests in the database.  We may, however, have to look up
payment_key for recurring invoice requests, and sign the message with
the payment_key.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-23 14:24:39 +01:00
Rusty Russell 59efd160c1 hsmd: code to sign bolt12 messages with a tweaked key.
Invoices are signed with our own key, but we use a transient payer_key with a
tweak for invoice_requests (and refunds).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-23 14:24:39 +01:00
Rusty Russell eb4062bb14 setchannelfee: fix crash when channel is not in valid state.
You can't fail a cmd when you've already started streaming
a successful response:

lightningd: ccan/ccan/json_out/json_out.c:343: json_out_finished: Assertion `tal_count(jout->wrapping) == 0' failed.
lightningd: FATAL SIGNAL 6 (version v0.9.2-119-gf7cdf1d)
0x1847d1 send_backtrace
	common/daemon.c:38
0x184877 crashdump
	common/daemon.c:51
0x5bda03f ???
	???:0
0x5bd9fb7 ???
	???:0
0x5bdb920 ???
	???:0
0x5bcb489 ???
	???:0
0x5bcb501 ???
	???:0
0x1e07a8 json_out_finished
	ccan/ccan/json_out/json_out.c:343
0x18db0a json_stream_double_cr
	common/json_stream.c:95
0x18dbf3 json_stream_close
	common/json_stream.c:117
0x12fd98 command_raw_complete
	lightningd/jsonrpc.c:459
0x12fec9 command_failed
	lightningd/jsonrpc.c:488
0x12ffb9 command_fail
	lightningd/jsonrpc.c:503
0x14dc20 json_setchannelfee
	lightningd/peer_control.c:2052

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSONRPC: `setchannelfee` would fail an assertion if channel wasn't in normal state.
2020-12-21 17:10:28 -06:00
Rusty Russell 723c16072a cleanups: feedback from Christian Decker review.
1. Hoist 7200 constant into the bolt12 heade2.
2. Make preimage the last createinvoice arg, so we could make it optional.
3. Check the validity of the preimage in createinvoice.
4. Always output used flag in listoffers.
5. Rename wallet offer iterators to offer_id iterators.
6. Fix paramter typos.
7. Rename `local_offer_id` parameter to `localofferid`.
8. Add reference constraints on local_offer_id db fields.
9. Remove cut/paste comment.
10. Clarify source of fatal() messages in wallet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-15 12:05:02 +01:00
Rusty Russell a33e39b7e8 pay, wallet: rename internal `bolt11` vars to `invstring`.
And handle bolt12 strings if EXPERIMENTAL_FEATURES.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-15 12:05:02 +01:00
Rusty Russell 4c4288e3e5 invoice: handle bolt12 strings if EXPERIMENTAL_FEATURES.
The database still calls them `bolt11`, but we treat them depending on
prefix.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-15 12:05:02 +01:00
Rusty Russell fab0842d31 lightningd: createinvoice low-level invoice creation command.
This takes an unsigned bolt11 (or bolt12 if EXPERIMENTAL_FEATURES) string
and signs it and puts it in the database.

The invoice command could now be moved out to a plugin, in fact.

Changelog-Added: JSON-RPC: `createinvoice` new low-level invoice creation API.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-15 12:05:02 +01:00
Rusty Russell d66dbd473a lightningd: add low-level offer interfaces.
The real work is done in a plugin, but provide enough API that we can
manipulate the db.
2020-12-15 12:05:02 +01:00
Rusty Russell 3f4683e3f8 sendpay: optional argument to link local offer.
This is for offers which have `send_invoice`: we need to associate the
payment with the original offer, in (the usual) case where it is a single
use offer.  We mark it used when it's paid, to avoid a race.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-15 12:05:02 +01:00
Rusty Russell 963f6b5d67 invoice: add an optional local_offer_id.
This allows us to mark an offer used when an invoice derived from it
is paid, and importantly, avoid any other invoices for the offer being
paid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-15 12:05:02 +01:00
Rusty Russell d971e3de98 Plugin: support extra args to "start".
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: `start` command can now take plugin-specific parameters.
2020-12-15 09:28:56 +10:30
Rusty Russell 8a9976c4c1 plugins: support concatenation of multiple args.
"multi" means that specifying a parameter twice will append, not override.
Multi args are always given as a JSON array, even if only one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: new "multi" field allows an option to be specified multiple times.
2020-12-15 09:28:56 +10:30
Rusty Russell 646c564ec5 plugins: remove deprecated string plugin options.
This was fixed in 0.8.2.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: plugins: options to init are no longer given as strings if they are bool or int types (deprecated in 0.8.2).
2020-12-15 09:28:56 +10:30
Rusty Russell 32c7c133f4 common/sphinx: make onionpacket.routinginfo a dynamic member.
Still asserts that it's the standard size, but makes it a dynamic
member.  For simpliciy, changes the parse_onionpacket API (it must be
a tal object now, so we might as well allocate it here to catch all
the callers).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-11 15:51:24 +01:00
Rusty Russell 3776af4a35 common/sphinx: make TOTAL_PACKET_SIZE a macro.
This paves the way for using it on different-sized onions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-11 15:51:24 +01:00
Rusty Russell 28a903c917 channeld: hand up onionmessage fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-09 16:40:13 +10:30