Commit Graph

2770 Commits

Author SHA1 Message Date
Matt Morehouse
41a2901ad4 fuzz: target for update_fee
Fuzz the decoding and encoding of update_fee.
2023-09-18 13:58:45 +09:30
Matt Morehouse
08898333a4 fuzz: target for update_fail_malformed_htlc
Fuzz the decoding and encoding of update_fail_malformed_htlc.
2023-09-18 13:58:45 +09:30
Matt Morehouse
298fe06c20 fuzz: target for update_fail_htlc
Fuzz the decoding and encoding of update_fail_htlc.
2023-09-18 13:58:45 +09:30
Matt Morehouse
fb6d5cf587 fuzz: target for update_add_htlc
Fuzz the decoding and encoding of update_add_htlc.
2023-09-18 13:58:45 +09:30
Matt Morehouse
1fff136d66 fuzz: target for shutdown
Fuzz the decoding and encoding of shutdown.
2023-09-18 13:58:45 +09:30
Matt Morehouse
4aa165e7a2 fuzz: target for revoke_and_ack
Fuzz the decoding and encoding of revoke_and_ack.
2023-09-18 13:58:45 +09:30
Matt Morehouse
1520fac809 fuzz: target for reply_short_channel_ids_end
Fuzz the decoding and encoding of reply_short_channel_ids_end.
2023-09-18 13:58:45 +09:30
Matt Morehouse
4997d0df5b fuzz: target for reply_channel_range
Fuzz the decoding and encoding of reply_channel_range.
2023-09-18 13:58:45 +09:30
Matt Morehouse
389ab0e46f fuzz: target for query_short_channel_ids
Fuzz the decoding and encoding of query_short_channel_ids.
2023-09-18 13:58:45 +09:30
Matt Morehouse
10757bc49c fuzz: target for query_channel_range
Fuzz the decoding and encoding of query_channel_range.
2023-09-18 13:58:45 +09:30
Matt Morehouse
c987b0e43c fuzz: target for pong
Fuzz the decoding and encoding of pong.
2023-09-18 13:58:45 +09:30
Matt Morehouse
06f37a3c86 fuzz: target for ping
Fuzz the decoding and encoding of ping.
2023-09-18 13:58:45 +09:30
Matt Morehouse
62ffb42908 fuzz: target for open_channel
Fuzz the decoding and encoding of open_channel.
2023-09-18 13:58:45 +09:30
Matt Morehouse
07d593a24e fuzz: target for node_announcement
Fuzz the decoding and encoding of node_announcement.
2023-09-18 13:58:45 +09:30
Matt Morehouse
b437835241 fuzz: target for init
Fuzz the decoding and encoding of init.
2023-09-18 13:58:45 +09:30
Matt Morehouse
e41f263b72 fuzz: target for gossip_timestamp_filter
Fuzz the decoding and encoding of gossip_timestamp_filter.
2023-09-18 13:58:45 +09:30
Matt Morehouse
9fababd668 fuzz: target for funding_signed
Fuzz the decoding and encoding of funding_signed.
2023-09-18 13:58:45 +09:30
Matt Morehouse
247457f1f8 fuzz: target for funding_created
Fuzz the decoding and encoding of funding_created.
2023-09-18 13:58:45 +09:30
Matt Morehouse
b1064e0309 fuzz: target for error
Fuzz the decoding and encoding of error.
2023-09-18 13:58:45 +09:30
Matt Morehouse
1f974b8349 fuzz: target for commitment_signed
Fuzz the decoding and encoding of commitment_signed.
2023-09-18 13:58:45 +09:30
Matt Morehouse
38a329f9e6 fuzz: target for closing_signed
Fuzz the decoding and encoding of closing_signed.
2023-09-18 13:58:45 +09:30
Matt Morehouse
f409f3374c fuzz: target for channel_update
Fuzz the decoding and encoding of channel_update.
2023-09-18 13:58:45 +09:30
Matt Morehouse
b7b046ce83 fuzz: target for channel_reestablish
Fuzz the decoding and encoding of channel_reestablish.
2023-09-18 13:58:45 +09:30
Matt Morehouse
7686909c65 fuzz: target for channel_ready
Fuzz the decoding and encoding of channel_ready.
2023-09-18 13:58:45 +09:30
Matt Morehouse
b56177c625 fuzz: target for channel_announcement
Fuzz the decoding and encoding of channel_announcement.
2023-09-18 13:58:45 +09:30
Matt Morehouse
1b8137649a fuzz: target for announcement_signatures
Fuzz the decoding and encoding of announcement_signatures.
2023-09-18 13:58:45 +09:30
Matt Morehouse
ef28e54d65 fuzz: target for accept_channel
Fuzz the decoding and encoding of accept_channel.

We create a wire.h header to share code with future targets.
2023-09-18 13:58:45 +09:30
Tony Giorgio
a5367773d5 wallet: Exclude uneconomical UTXOs from fundchannel
If a node has an onchain balance with at least one uneconomical UTXO, the fundchannel RPC call will lock up the node and will eventually crash it with OOM issues if the economical UTXO(s) do not add up to the fundchannel amount. This is because the while loop never exits because it keeps pulling in the same uneconomical UTXOs forever.

Changelog-Fixed: wallet: fundchannel no longer loops forever if the wallet contains insufficient funds, but an uneconomical UTXO.
2023-09-13 14:34:59 +09:30
Rusty Russell
47f4e11c87 tests: test for fundchannel fail with tiny utxo
Tony Giorgio <tonygiorgio@protonmail.com> says:

Reproduce:

1.  Add 1 600 sat UTXO to a fresh node

2.  Verify the fundchannel command fails with a low fee rate:

```
./lightning-cli fundchannel 0366abc8eb4da61e31a8d2c4520d31cabdf58cc5250f855657397f3dd62493938a 100000 1000
{
   "code": 301,
   "message": "Could not afford 100000sat using all 1 available UTXOs: 99522sat short"
}
```

3.  Now do the command again, but with a higher fee rate, making the 600 sat UTXO uneconomical:

```
./lightning-cli fundchannel 0366abc8eb4da61e31a8d2c4520d31cabdf58cc5250f855657397f3dd62493938a 100000 10000
```

4. Observe the RPC call and the logs. The RPC call will never return, and the logs will stop after this:

```
2023-04-16T10:58:45.839Z DEBUG   plugin-spenderp: mfc 34: multiconnect done.
2023-04-16T10:58:45.839Z DEBUG   plugin-spenderp: mfc 34: 'parsefeerate' done
2023-04-16T10:58:45.839Z DEBUG   plugin-spenderp: mfc 34: fundpsbt.
```

5. Keep CLN running long enough and you'll eventually run OOM.
2023-09-13 14:34:59 +09:30
Rusty Russell
785fe973a6 runes: ensure that uniqueid is a valid number.
It always is for runes we create, but in theory you can take our secret key
and make our own runes with your own tools.

(We correctly refuse runes without uniqueids if they're *not* ours
anyway: uniqueid is only used for our own runes).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell
ecb09778db lightningd: refuse to create rune with empty fields.
These look like uniqueids, and so can confuse us (I discovered this by
making a typo in a test!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
Rusty Russell
bb38f83b88 checkrune: make nodeid and method optional.
nodeid is only useful when we know the peer we're talking to (e.g. commando).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
No-schema-diff-check: We're simply making optional, not deprecating!
2023-09-12 15:19:02 +09:30
Rusty Russell
f4f4ab34f3 renepay: fix case where shadow increases amount past payment amount.
Without this, sendpay will refuse to pay.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 16:13:21 +09:30
Rusty Russell
a234888209 pytest: test for shadow route additions.
This fails currently, so next commits fix it up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 16:13:21 +09:30
Rusty Russell
7a92eb2d89 renepay: calculate fee and delay accumulation correctly.
1. When we add a shadow amount, we were using the wrong channel for
   the fee calculation.
2. Similarly, when calculating the delay amount.

The result is that we can get WIRE_INCORRECT_CLTV_EXPIRY repeatedly
from nodes.

Reported-by: https://github.com/Sjors
Fixes: #6620
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changlog-Experimental: Fixed: `renepay` handles ctlv correctly when it varies along a path.
2023-08-31 16:13:21 +09:30
Rusty Russell
0135d563a0 pytest: write test to ensure renepay the correct channel's fee/cltv info.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 16:13:21 +09:30
Rusty Russell
b88583e346 db: migrate old runes table to fix up id fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 05:33:15 +09:30
Rusty Russell
2de304314a runes: insert rune with correct id field.
"id" is a magic name, so it was being populated by sqlite3
automatically, starting at 0.  Fortunately, we only fetched by id in
one place: to indicate the `stored` flag when asked about an explicit
rune in `showrunes`.

Reported-by: @ShahanaFarooqui
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `showrunes` on a specific rune would always say `stored`: false.
2023-08-31 05:33:15 +09:30
Rusty Russell
7429b1e7e1 pytest: test to show that we got db ids incorrect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 05:33:15 +09:30
Rusty Russell
138d178dff pytest: fix plugin_connected_hook_chaining flake.
The code to workaround the intermittant error didn't work,
and we finally hit it again:

```
        # If reject happens fast enough, connect fails with "disconnected
        # during connection"
        try:
            l3.connect(l1)
        except RpcError as err:
>           assert "disconnected during connection" in err.error
E           assert 'disconnected during connection' in {'code': 402, 'message': 'disconnected during connection'}
E            +  where {'code': 402, 'message': 'disconnected during connection'} = RpcError("RPC call failed: method: connect, payload: {'id': '0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518', 'host': '127.0.0.1', 'port': 41865}, error: {'code': 402, 'message': 'disconnected during connection'}").error
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-21 21:14:01 +09:30
Rusty Russell
dec8ad3b8d pytest: fix autoclean test flake
```
        l3.rpc.setconfig('autoclean-cycle', 10)
    
        # First it expires.
>       wait_for(lambda: only_one(l3.rpc.listinvoices('inv1')['invoices'])['status'] == 'expired')

```

If we're slow enough, the invoice is cleaned before we see it expire!
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-21 21:14:01 +09:30
Rusty Russell
b5d1708900 plugins/sql: make testing-only sqlfilename option dev-sqlfilename.
dev options don't need to be documented, and this is only for debugging
the plugin itself.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 20:29:34 +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
Rusty Russell
2c3f8b8a04 pytest: test that we can pay via routehints even if a 1000-min-htlc channel is in path.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 14:55:32 +09:30
Rusty Russell
f4e2d9a0ae lightningd: clean up properly if we fail to exec plugin.
Reported-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: we clean up properly if a plugin fails to start, and we don't kill all processes if it's from `plugin startdir`.
2023-08-18 13:18:49 +09:30
Rusty Russell
04ddb4af8d pytest: test that failing to start a plugin due to failure to exec does not put it in plugins list.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 13:18:49 +09:30
Rusty Russell
bc36a4580c pytest: test (failing) for not crashing if plugin fails to exec via plugin startdir
It hits the new assert(): before that (tested!) it actually kills everything and logs you out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 13:18:49 +09:30
Dusty Daemon
c67f1f92a8
splice: prevent splice going to onchaind & race prevention
Don’t send the funding spend to onchaind if we detect it in inflights (aka. a splice). While we already prevented onchaind_funding_spent from being called directly, the call to wallet_channeltxs_add meant onchaind_funding_spent would be called *anyway* on restart. This is now fixed.

Additionally there was a potential for a race problem depending on the firing order of the channel depth and and funding spent events.

Instead of requiring these events fire in a specific order, we make a special “memory only” inflight object to prevent the race regardless of firing order.

Changelog-Fixed: Splice: bugfix for restart related race condition interacting with adversarial close detection.
2023-08-16 12:28:53 +09:30
Alex Myers
553369896b pytest: add no argument cli test 2023-08-16 12:25:25 +09:30
Rusty Russell
6a16a6fe25 closingd: fix case where we we can pass under min-relay-fee for mutual close.
In spec commit 498f104fd399488c77f449d05cb21c0b604636a2 (August 2021),
Bastien Teinturier removed the requirement that the mutual close fee be
less than or equal the final commitment tx.

We adopted that change in v0.10.2, but we made sure to never offer a fee
under the final commitment tx's fee, so we didn't break older nodes.

However, the closing tx can actually be larger than the final commitment tx!
The final commit tx has a 22-byte P2WKH output and a 34-byte P2WSH output;
the closing can have two 34-byte outputs, making it 4*8 = 32 Sipa heavier.
Previously this would only happen if both sides asked for P2WSH outputs,
but now it happens with P2TR, which we now do.

The result is that we create a tx which is below the finally commitment
tx fee, and may be below minrelayfee (as it was in regtest).

So it's time to remove that backwards-compatibility hack.

Changelog-Fixed: Protocol: We may propose mutual close transaction which has a slightly higher fee than the final commitment tx (depending on the outputs, e.g. two taproot outputs).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #6545
2023-08-12 13:17:46 +09:30