Commit Graph

1577 Commits

Author SHA1 Message Date
Matt Morehouse
15c8ca9284 common: disable node ID check when fuzzing 2023-09-18 13:58:45 +09:30
Christian Decker
fe6707f952 openingd: Clean up channel_type_accept
The `accept_zeroconf` parameter is pointless, since it's too early to
check that anyway. Keeping it in there would suggest otherwise, so
remove it.
2023-08-18 20:30:03 +09:30
Rusty Russell
be3a59c7c3 gossmap: fix false valgrind uninitialized error on arm64, ppc.
Doesn't happen on x86, but struct gossmap_chan defines:

```
	u32 private: 1;
	u32 plus_scid_off: 31;
```

And complains when we initialize plus_scid_off and access it later:

```
VALGRIND=1 valgrind -q --error-exitcode=7 --track-origins=yes --leak-check=full --show-reachable=yes --errors-for-leak-kinds=all plugins/renepay/test/run-mcf > /dev/null
==186886== Conditional jump or move depends on uninitialised value(s)
==186886==    at 0x10076388: chan_iter (gossmap.c:1098)
==186886==    by 0x100797F3: gossmap_next_chan (gossmap.c:1112)
==186886==    by 0x1008C5AF: main (run-mcf.c:309)
==186886==  Uninitialised value was created by a heap allocation
==186886==    at 0x40F0A44: malloc (vg_replace_malloc.c:431)
==186886==    by 0x10072BAF: allocate (tal.c:256)
==186886==    by 0x100737A7: tal_alloc_ (tal.c:463)
==186886==    by 0x100738DF: tal_alloc_arr_ (tal.c:506)
==186886==    by 0x10079507: load_gossip_store (gossmap.c:690)
==186886==    by 0x10079667: gossmap_load (gossmap.c:978)
==186886==    by 0x1008C4AF: main (run-mcf.c:295)
```

Reported-by: @grubles
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #6557
2023-08-18 16:21:57 +09:30
Rusty Russell
d3c7d48acb pay: don't discard high-htlc_min channels when searching for routehint starts.
As side-effect, getroute(0) is special too.

Reported-by: MiddleW4y in Discord
Fixes: #6577
Changelog-Fixed: `pay` will still use an invoice routehint if path to it doesn't take 1-msat payments.
2023-08-18 14:55:32 +09:30
Alex Myers
bd4a001279 cli: don't crash when there's no argument
This should provide the default help message and exit, but was
resulting in a segmentation fault from freeing pointers passed to
the default config.

Changelog-Fixed: lightning-cli properly returns help without argument
2023-08-16 12:25:25 +09:30
Rusty Russell
be082cdff4 common/test: fix gcc-12.3.0 -O3 warning.
```
common/test/run-bolt12_decode.c:206:17: error: ‘valid’ may be used uninitialized [-Werror=maybe-uninitialized]
  206 |                 printf("%s %s\n", str, valid ? "OK": "INVALID");
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
common/test/run-bolt12_decode.c:191:22: note: ‘valid’ was declared here
  191 |                 bool valid, actual;
      |                      ^~~~~
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 06:21:23 +09:30
Rusty Russell
c889976d03 common: fix gcc-12.3.0 -O3 warning.
This is actually a valid complaint (though this is a sanity check for
things we make ourselves, still!).

```
In file included from common/test/run-blindedpath_onion.c:9:
common/test/../sphinx.c: In function ‘sphinx_add_hop_has_length’:
common/test/../sphinx.c:117:12: error: ‘prepended_len’ may be used uninitialized [-Werror=maybe-uninitialized]
  117 |         if (lenlen + prepended_len != tal_bytelen(payload))
      |            ^
common/test/../sphinx.c:109:27: note: ‘prepended_len’ was declared here
  109 |         bigsize_t lenlen, prepended_len;
      |                           ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 06:21:23 +09:30
Rusty Russell
15c30f4018 renepay: make pay_plugin a tal object.
Avoids a gratuitous "ctx" field, and the simplified declaration
is now understood by `make update-mocks`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-12 09:41:24 +09:30
Rusty Russell
66a5765725 common: add tal_arr_randomize() to shuffle an array.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-12 09:24:06 +09:30
Rusty Russell
0281111ca1 common: restore OPT_SPLICE definition for the day it's ratified.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-10 15:52:53 +09:30
Dusty Daemon
c50e93d9fb splice: Move splice to experimental feature bit
This was recommended by @t-bast: if the final spec commits to something
compatible, we can simply advertize and accept both features, but if it
does change in incompatible ways we won't cause problems for nodes
who implement the official spec.

(I split this, so first, we remove the OPT_SPLICE entirely, to make
sure we caught them all. --RR)

Suggested-by: @t-bast
Changelog-None
2023-08-10 15:52:53 +09:30
Rusty Russell
d95cfc0b64 hsmd: rename "capabilities" flags for hsm fds to "permissions"
I obviously like the word "capabilities" since I reused it to refer
to the HSM's overall features :(

Suggested-by: @ksedgwic
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-08 14:31:47 +09:30
Rusty Russell
84fe3dc940 build: more 32-bit printf fixes.
Reported-by: Shahana
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-07 11:52:40 +09:30
Rusty Russell
0f6687ec7b codex32: use "cl" instead of "ms" as our HRP.
This was strongly recommended by Russell O'Connor: the "ms" implies that
it's a BIP-32 master secret, and this is CLN specific.

If we changed the hrp to "cln" it would be better, but apparently that
means we no longer fit in a "standard billfold metal wallet" (and
our code assumes a 2-byte prefix anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-02 16:12:32 +09:30
Rusty Russell
4dcd712d6e hsmtool: tighten checks for validity on getcodexsecret
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-02 08:42:50 +09:30
Dusty Daemon
4628e3ace8 channeld: Code to implement splicing
Update the lightningd <-> channeld interface with lots of new commands to needed to facilitate spicing.

Implement the channeld splicing protocol leveraging the interactivetx protocol.

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

Changelog-Added: Added the features to enable splicing & resizing of active channels.
2023-07-31 21:00:22 +09:30
Dusty Daemon
ebd0a3fd69 interactive-tx: Renaming for clarity and cleaning up
New daemon process means we don’t have to deal with gossip, so that gets removed along with error cleanup and a refactoring of how we calculating PDBT diffs.
2023-07-31 21:00:22 +09:30
Dustin Dettmer
81a738c7cc psbt: Fix psbt linseraize_input bug
Some fields weren’t intitialized causing complex crashes elsewhere.

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

Small updates to psbt interface

Changelog-None
2023-07-31 21:00:22 +09:30
Dustin Dettmer
108658a539 psbt: routine for lining up sigantures in a witness stack
Changelog-None
2023-07-31 21:00:22 +09:30
Dusty Daemon
eda570c095 hsmd: Add sign splice command
Changelog-None
2023-07-31 21:00:22 +09:30
Dusty Daemon
e626f91267 Mac: Change format type to use PRIu64 instead of %ld
Changelog-None
2023-07-31 21:00:22 +09:30
adi2011
d00efbccde common/codex32: Add codex32_secret_encode to encode seeds in bip93 format. 2023-07-31 20:57:40 +09:30
Rusty Russell
58327a594f codex32: rework.
Firstly, I wanted the results easier to use:
1. Make them always lower case, even if the string was UPPER.
2. Decode the payload for them.
3. Don't give the user any fields they don't need, and make
   the field sizes explicit.

Secondly, I wanted to avoid the pattern of "check in one place, assume
in another", in favour of "check on use".

So, I changed the code to lower the string if it needs to at the start,
and then changed the pull functions so we always use them to get data:
this way we should fail clearly and gracefully if we don't have enough data.

I made all the checks explicit, where we assign the fields.

I also addressed the FIXME: I think the array is *often* one shorter,
but not always, so I trim the last byte at the end if needed.

[ Aditya modified the tests to work ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-31 11:29:59 +09:30
Rusty Russell
bf2d9b19c6 codex32: document the complete representations from BIP, adjust numbers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-31 11:29:59 +09:30
Rusty Russell
9721ddd2ab codex32: minor cleanups.
Nothing major here:
1. size_t for lengths.
2. pass engine to checksum_verify, as caller wants ->len (avoid repeating 13/15 magic numbers).
3. Use x.member instesad of (&x)->member.
4. Return memcmp result directly instead of if.
5. Spacing removal, `;;` removal.
6. codexl is a bool `true`/`false` not 0/1 (it's the same, but clearer)
7. Make sanity_check assign *fail directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-31 11:29:59 +09:30
adi2011
3b848d84d1 common/test: Added run-codex32 to test codex32.c decoding function. 2023-07-31 11:29:59 +09:30
adi2011
135a739023 common/codex32: Added checksum verification for codex32 encoding. 2023-07-31 11:29:59 +09:30
adi2011
efc783422f common/codex32: Added codex32_decode() without checksum verification. 2023-07-31 11:29:59 +09:30
niftynei
9b8909e507 dual-fund: keep track of aborted requests, seamlessly restart daemon
Clean restart of daemon after a tx-abort is a nice way to work around
the 'persistent' disconnect that we t-bast noticed.

Changelog-Fixed: `dualopend`: Fix behavior for tx-aborts. No longer hangs, appropriately continues re-init of RBF requests without reconnction msg exchange.
2023-07-30 15:20:04 +09:30
Christian Decker
ca808b8476 trace: Use User Statically-Defined Tracepoints to emit tracing spans 2023-07-28 09:21:42 +09:30
Christian Decker
ed8d3336c9 trace: First draft of API 2023-07-28 09:21:42 +09:30
Rusty Russell
981d82c406 common/utils: add tal_strdup_or_null helper.
It's not that uncommon to want to pass NULL through, for optional strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +09:30
niftynei
bcdfac7d1a bolt11: Don't push the size of the witness program for v1+ scripts
For non-v0 witness programs we weren't stripping the data push byte
before writing into the fallback address.

According to BIP14, all witness scripts will be data pushes (up to 40-bytes)
so trimming the datapush byte should be kosher.

From BIP141:

	A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that
	consists of a 1-byte push opcode (for 0 to 16) followed by a
	data push between 2 and 40 bytes gets a new special meaning.
	The value of the first push is called the "version byte". The
	following byte vector pushed is called the "witness program".

Changelog-Fixed: Adding a >0 version witness program to a fallback address now is *just* the witness program, as per bolt11 spec
2023-07-26 05:26:21 +09:30
Rusty Russell
e28469783e common: fix wrong comment on json_scan() return.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Rusty Russell
4037594c81 common/json_param: use assert() for param correctness checks.
And do them on the first run (where we check parameters), instead
of every time.  Might as well do them in non-developer mode too,
since they're simply programmer correctness.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Rusty Russell
5774737a5c lightningd: implement checkrune command.
This extracts the core checking functionality for a rune, so they can
easily be used more widely than just commando.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-21 16:44:22 +09:30
Rusty Russell
8178b7389f gossip_store: add "dying" flag to indicate not to gossip dying channels.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-20 11:47:32 +09:30
Rusty Russell
c074fe050f lightningd/log: clean up nomenclature.
`struct log` becomes `struct logger`, and the member which points to the
`struct log_book` becomes `->log_book` not `->lr`.

Also, we don't need to keep the log_book in struct plugin, since it has
access to ld's log_book.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-19 19:13:57 +09:30
Vincenzo Palazzo
5f6642a6ff fix(jsonrpc): trim the lightning: prefix from invoice
Previously, our code checked for the presence of the `lightning:`
prefix while decoding a bolt11 string. Although this prefix is valid
and accepted by the core lightning pay command, it was causing issues
with how we managed invoices. Specifically, we were skipping the prefix
when creating a copy of the invoice string and storing the raw invoice
(including the prefix) in the database, which caused inconsistencies
in the user experience.

To address this issue, we need to strip the `lightning:` prefix before
calling each core lightning command. In addition, we should
modify the invstring inside the db with the canonical one.

This commit fixes the issue by stripping the `lightning:` prefix
from the `listsendpays` function, which will improve the
user experience and ensure consistency in our invoice management (see
next commit).

Reported-by: @johngribbin
Link: ElementsProject#6207
Fixes: debbdc0
Changelog-Fixes: trim the `lightning:` prefix from invoice everywhere.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-07-14 15:04:26 +09:30
niftynei
0cd7fe5089 spec: update to latest dual-funding wire changes
the witnesses are maddeningly weird now (you concat everything together)

we also changed some things to be s64's (it's a teeny tiny change)
2023-07-13 19:34:47 +09:30
Dustin Dettmer
aba4d18ed1 signed types: add handlers for signed types
We're adding signed types to the spec! This adds the support mechanisms
for them.
2023-07-13 19:34:47 +09:30
Greg Sanders
4b70736d13 Support p2tr deposit addresses
Changelog-Added: JSON-RPC: newaddr: p2tr option to create taproot addresses.
Changelog-Changed: Wallet: we now use taproot change addresses.
2023-07-11 11:41:15 +09:30
Greg Sanders
55cad79d82 cleanup comments, variables with respect to bech32(m) 2023-07-11 11:41:15 +09:30
Greg Sanders
fdbb31e4d0 is_segwit_output: properly detect all known segwit script types 2023-07-11 11:41:15 +09:30
Greg Sanders
fa046ab80f encode_scriptpubkey_to_addr: support p2tr 2023-07-11 11:41:15 +09:30
Rusty Russell
0c4426a349 lightningd: remove deprecated_apis global, put into lightningd.
We usually have access to `ld`, so avoid the global.

The only place generic code needs it is for the json command struct,
and that already has accessors: add one for libplugin and lightningd
to tell it if deprecated apis are OK.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-09 16:49:48 +09:30
Rusty Russell
db7c608e2d common/utils: remove now-unused softref facility.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-09 16:49:48 +09:30
Rusty Russell
391da2f440 lightningd: don't let them fundpsbt below emergency reserve.
This is the simple version which always tries to keep some sats if we
have an anchor channel.  Turns out that we need something more
sophisticated for multifundchannel, so that's next.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `withdraw` will refuse to spend funds below `min-emergency-msat` if we have any anchor channels (and `all` will be reduced appropriately).
Changelog-Changed: JSON-RPC: `fundpsbt` and `utxopsbt` will refuse to spend funds below `min-emergency-msat` if we have any anchor channels.
2023-06-29 11:28:47 -04:00
Rusty Russell
af6d7c0779 global: thread zero fee option everywhere.
In most cases, it's the same as option_anchor_outputs, but for
fees it's different.  This transformation is the simplest:
pass it as a pair, and test it explicitly.

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

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-29 11:28:47 -04:00