Commit Graph

1912 Commits

Author SHA1 Message Date
Rusty Russell
841a8bd03a lightningd: extract core of coin_movement notification, for use in list functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `coin_movement` notification `utxo_txid`, `vout` and `txid` fields (use `utxo` and `spending_txid`).
Changelog-Added: JSON-RPC: `coin_movement` notification `utxo` field.
Changelog-Added: JSON-RPC: `coin_movement` notification `spending_txid` field.
2025-08-14 19:49:09 +09:30
Rusty Russell
d066a5f301 common: make chain_coin_mvt's outpoint member a non-pointer.
It's always set, and in fact we assume it is (journal entries are not
internal to lightningd, so we won't see them in
lightningd/notification.c: that comment is misleading).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
c0221b1b74 coin_mvt: put timestamp into the struct.
This is not particularly relevant now (it's always the current time) but will be
useful when we implement the list commands.

Note that timestamp is set to be "u32" in various schemas.  This will
only become a problem on Sun 07 Feb 2106 06:28:15 UTC.  I apologize to
my grandchildren in advance.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
9b2c87f052 common: implement primary_mvt_tag() to extract primary tag.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
8c315c15b6 coin_mvt: use bitmap instead of tal_arr for tags.
We're going to store them in the db this way, so I thought I'd see what it looks like if
we lift that interface all the way through.

We use a struct, so that types are checked strictly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
bafda5ce02 common: mvt_tag parsing routine.
Rather than open-coding in json_parse.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
1833cc2d28 common: mvt_tag_strs() function to turn tags array into strings.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
0d40d43c01 common: enforce the use of a "primary" tag in coin_mvt tags.
Undocumented, but the first tag in the coin_movement notification is
considered the primary tag, and the others are optional.  The
bookkeeper plugin relies on this!

Enforce that this is true, and in the process document in the code which
is the primary tag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
5756b54f38 common: rename enum mvt_tag values.
Prefix MVT_ to them, for clarity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
1d3237f801 common/coin_mvt: make more fields const, reorder fields.
Make the common fields the first ones, and make part_and_group and
payment_hash const pointers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
6fc0b1f3d1 common/coin_mvt: add struct mvt_account_id to separate channels from others.
This means we can keep a pointer to the channel directly, *or* a string.
This avoids gratuitous formatting (on creation) and lookups (later).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
e372c2ec0b common/coin_mvt: use enum rather than true/false for credit/debit.
More readable for me.  Also, change order so we definitely break
compilation on all callers (putting enum before amount).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
bc5e54d153 common: coin movements for payments need group id as well as part id.
The part id is *only* unique within a group.  The payment_hash / partid / groupid tuple is unique.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: `coin_movement` notification with `part_id` field now always has `group_id` field.
2025-08-14 19:49:09 +09:30
Rusty Russell
f4ac8fccb6 common/coin_mvt: make more parameters const.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
e32b5141ef common: remove struct coin_mvt altogether.
Now we only ever use `struct chain_coin_mvt` or `struct channel_coin_mvt`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
0534c524b5 common: remove "ignored" tag.
We don't actually set it any more.  The bookkeeper db does a migration
for old anchors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 19:49:09 +09:30
Rusty Russell
6fbc5d02ca common/htlc_wire: add towire/fromwire helpers for wrapped tlv streams.
And make sure we check the length properly in fromwire!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 18:57:05 +09:30
Rusty Russell
63065aa99c common: handle taken() extra_tlvs in new_existing_htlc properly.
Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 18:57:05 +09:30
Peter Neuroth
631a1d950f channeld: Add extra_tlvs to wire htlcs
This appends the extra_tlvs to the internal wire htlcs "added" and
"existing" for the extra tlvs to be handed to lightningd.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2025-08-14 18:57:05 +09:30
Matt Whitlock
9112c1d518 common/json_parse_simple: make convenience functions inline
json_tok_streq(…) and json_get_member(…) are convenience wrappers for
json_tok_strneq(…) and json_get_membern(…) respectively. Unfortunately, using
them incurs a performance penalty in the common case where they are called with
a string literal argument because the compiler is unable to substitute a
compile-time constant in place of the buried call to strlen(…).

For example,

	json_get_member(buf, tok, "example");

…will have worse performance than…

	json_get_membern(buf, tok, "example", strlen("example"));

…because the former is forced to scan over "example" at run-time to count its
length whereas the latter is able to elide the strlen(…) call at compile time.

Hoist these convenience functions up into common/json_parse_simple.h and mark
them as inline so that the compiler can elide the strlen(…) call in the common
case of calling these functions with a string literal argument.

Changelog-None
2025-08-14 17:53:39 +09:30
Rusty Russell
80309dfbe6 common: add json_add_timerel helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-14 16:52:44 +09:30
Dusty Daemon
07f4bc39b1 splice: Add start_batch and an internal wire type
We add `start_batch` to match t-bast’s splicing spec and we add a new internal wire type `WIRE_PROTOCOL_BATCH_ELEMENT` using the type number 0

Changelog-Added: support for `start_batch`
2025-08-14 16:40:04 +09:30
Dusty Daemon
a5a71f3b22 psbt: don’t accumlate 0 lenth widtness data 2025-08-14 04:12:17 +09:30
Dusty Daemon
2e660d9f06 splice: Fix cross-channel splices
When doing a cross channel splice, inputs move from having no SIGHASH to having SIGHASH_ALL assigned.

This causes psbt_get_changeset to flag the input as having changed, as the sighash value is compared.

This causes the second channel splice to `tx_remove_input` the input as it doesn’t match anymore, breaking the splice.

We fix this by removing the sighash value from input comparisions.
2025-08-14 04:12:17 +09:30
Dusty Daemon
286124e3d9 interactive_tx: Add verbose logging
Adding verbose logging option to introspect into what interactive tx is doing with inputs.
2025-08-14 04:12:17 +09:30
Rusty Russell
506fa914e0 lightningd: always tell openingd/dualopend what channel type we want.
Prior to it being compulsory, these daemons would need a default value.  Now it's
always required, it's clearer if it's always told.

There's no "default_channel_type" now everyone has to specify channel_type either,
so rename it to "desired_channel_type" and put it in lightningd specifically.

Note that the channel_type can have options added: either option_scid_alias or option_zeroconf.

This results in a slight behavior change: we will get type zeroconf even if we didn't ask for it, if they gave it to us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: fundchannel / fundchannel_start returned `channel_type` will include option_zeroconf if it was implied by a 0 minimum_depth, even if we didn't explicitly ask for a zero conf channel.
2025-08-13 14:20:28 +09:30
Dusty Daemon
9215653c30 channel: Add test for channel state max
Adds a test so CI will fail if CHANNEL_STATE_MAX isn’t updated when new channel states are added.

Changelog-None
2025-08-07 16:13:20 +09:30
Lagrang3
fae176f4cc common/amount: add ceil division operation on msat
Changelog-None

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2025-07-19 10:09:17 +09:30
Chandra Pratap
e721b0a89a fuzz-tests: Enhance b64_encode() validation with roundtrip decoding
Changelog-None: Currently, fuzz testing for b64_encode() merely
encodes input and frees the result, providing no real verification
of its behavior.

Introduce a new b64_decode() function (modeled after b32_decode())
and update the fuzz test to perform a roundtrip—encoding followed
by decoding—to ensure that b64_encode() correctly preserves the
original data.
2025-07-08 12:54:56 +09:30
Erick Cestari
6724db65de BOLT11: Make payment secret field ('s') mandatory
Make the payment secret field ('s') mandatory for BOLT11 payment requests,
implementing the requirement specified in BOLT11 spec PR #1242
(https://github.com/lightning/bolts/pull/1242).

This security enhancement prevents payment probing attacks by requiring
all invoices to include payment secrets. Changes include:

1. Adding validation in bolt11_decode_nosig() to reject invoices without
   the 's' field
2. Adding payment secrets to all test vectors
3. Updating expected encoded values in test cases to include payment secrets
4. Adding a specific test case that verifies proper rejection of invoices
   missing the payment secret field

Changelog-Changed: Made payment secret ('s' field) mandatory in BOLT11 payment requests for improved security.
2025-07-07 11:18:37 +09:30
Rusty Russell
2b023be022 bolt11: don't accept wrong-length p, h, s or n fields.
Spec got stricter.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-07-07 11:18:37 +09:30
Rusty Russell
17b3fb5196 common/bolt11: meet the new tighter parsing requirements.
These checks are a SHOULD, but implementing them helps avoid anyone
making such weird things in future.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-07-07 11:18:37 +09:30
Erick Cestari
9b662a83e7 common/bolt11: validate public keys in routing hints
Changelog-Fixed: Validated public keys in BOLT11 routing hints to
prevent processing of malformed public keys.
2025-05-16 14:37:52 +09:30
Lagrang3
a899dea3e1 use amount_msat_mul_div operation to compute fees
Changelog-None

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2025-05-13 19:16:51 +09:30
Lagrang3
b379500d21 askrene: fixed routing in high capacity channels
We may introduce high capacity channels in askrene to represent problems
with multiple destinations (eg. multiple blinded paths) or to solve
self-payments. The integer computation of the deliverable amount through
these channels (I tested this with a channel with 21M bitcoin) would
fail due to an integer overflow in the function `amount_msat_sub_fee`,
21M BTC = 21 x 10^17 msat, which overflows u64 integers when multiplied
by 10^6. We have fixed `amount_msat_sub_fee` operations, so that it
doesn't overflow.

Changelog-Fixed: askrene: fixed routing in high capacity channels.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2025-05-13 19:16:51 +09:30
Dusty Daemon
c9c56e340d PSBT: Clean up PSBT chunk allocations
Cleaning up the memory hierarchy of PSBT usage in splicing and `psbt_finalize_input`
2025-05-13 14:52:15 +09:30
Dusty Daemon
10616b0694 PSBT: tal_wally updates and docs
Default wally_tal_ctx to NULL, add extra asserts and tal_checks, and documentation explaning the usage of tal_wally_start/end.

Changelog-None
2025-05-13 14:52:15 +09:30
Dusty Daemon
5e5ed774fc PSBT: Add audi_psbt routine
A routine that audit’s and asserts PSBT memory to confirm it has a sane memory allocation hierarchy.

Changelog-None
2025-05-13 14:52:15 +09:30
Dusty Daemon
e8e30a420c PSBT: Fix compare to not mutate memory
PSBT changeset routines were using linearize_output which mutated the memory of the objects it was comparing.

This commit fixes that and also cleans up the memory usage to be more clear and more guarentee there is no memory corruption.

Changelog-None
2025-05-13 14:52:15 +09:30
Richard Myers
168c3b0d55 Add debug outputs and fix prevtx issue 2025-05-13 14:52:15 +09:30
Lagrang3
b6388c710f HSMD: add new wire BIP137 sign message API
Changelog-Added: HSMD: add new wire API to sign messages with bitcoin wallet keys according to BIP137.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2025-05-13 13:19:03 +09:30
Rusty Russell
b387b26cb3 common: don't enable steal loop checking unless we're doing memleak checking.
Before:
92.26076173782349
91.9576666355133
90.92732524871826

After:
90.5989830493927
88.10309219360352
90.07689118385315
2025-05-08 14:01:38 +09:30
Rusty Russell
74e7264d54 bitcoin: make input witness weight calculation explicit.
This is inspired by a patch from @whitslack, which overlapped with this series.
Most importantly, there was only one call to bitcoin_tx_simple_input_weight(),
and it is better to be explicit with that one.

This also changes our funder calculation to assume our own input is taproot,
which it is likely to be given we've defaulted to taproot for outputs for
change addresses since 23.08.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-06 12:27:53 +09:30
Rusty Russell
c0d68c5c2c pytest: create warning if we grind signature shorter than 71 bytes, don't fail.
One in 256 times, we will grind a signature to 70 bytes (or shorter).  This breaks
our feerate tests.  Unfortunately the grinding is deterministic, so there doesn't
seem to be a way to avoid it.  So we add a log message, and then we skip the
feerate test if it happens.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-06 12:27:53 +09:30
Rusty Russell
a8f75cca28 common: fix utxo_spend_weight to understand how cheap P2TR is.
We previously treated it as a P2WPKH, which is wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: wallet: fees are much closer to target feerate when doing txprepare/fundchannel.
2025-05-06 12:27:53 +09:30
Rusty Russell
7a276bbe09 common/utxo: use a real type for the UTXO, not a boolean is_p2sh.
To actually evaluate spend cost, we need to know whether it's taproot or not.
Using an enum (rather than making callers examine the script) means we can
ensure all cases are handled.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-06 12:27:53 +09:30
Rusty Russell
2154289911 hsmd: rename simple_htlc to hsm_htlc, don't gratuitously dynamically allocate.
The renaming makes it clear that it's HSM specific.

And it has no pointers, so we can have an array instead of an array of pointers.

I tested this hadn't accidentally changed the wire format by disabling
version checks and using an old hsmd with the altered daemons and
running the test suite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-06 12:27:53 +09:30
Rusty Russell
29c8693b26 hsmd: roll the definition of simple_htlc into the csv.
This is such a simple struct that we can actually define it in csv.
This prevents us from accidentally breaking the ABI in future.

I tested this hadn't accidentally changed the wire format by disabling
version checks and using an old hsmd with the altered daemons and
running the test suite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-06 12:27:53 +09:30
Rusty Russell
daf1560eb4 hsmd: make our private utxo type, to ensure binary compatibility.
I'm about to update our utxo type, but Christian spotted that this is
part of the ABI for the hsm.  So make that a private "hsm_utxo" type,
to insulate it from changes.

In particular, the HSM versions only contain the fields that the
hsm cares about, and the wire format is consistent (even though that
*did* include some of those fields, they are now dummies).

In the long term, this should be removed from the ABI: once we
no longer have "close_info" utxos, this information should already be
in the PSBT.

I tested this hadn't accidentally changed the wire format by disabling
version checks and using an old hsmd with the altered daemons and
running the test suite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-05-06 12:27:53 +09:30
Se7enZ
284e38e692 doc: minor typos and standarizations to inline documentaion.
Fixed typos and standardized English spelling of "neighbor" to match
the variable names.

Changelog-None
2025-04-29 09:40:15 -07:00