Commit Graph

13452 Commits

Author SHA1 Message Date
Rusty Russell e39fe41ff0 pytest: fix flake in penalty tests
Make sure we've completely processed htlc, so we will definitely consider it an old spend.  If we're too fast, l2 might consider it a legitimate unilateral close:

```
        # Make sure both sides got revoke_and_ack for final.
        l1.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
        l2.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
    
        # Now we really mess things up!
        bitcoind.rpc.sendrawtransaction(tx)
        bitcoind.generate_block(1)
    
        l2.daemon.wait_for_log(' to ONCHAIN')
        # FIXME: l1 should try to stumble along!
    
        # l2 should spend all of the outputs (except to-us).
        # Could happen in any order, depending on commitment tx.
        needle = l2.daemon.logsearch_start
        ((_, txid1, blocks1), (_, txid2, blocks2)) = \
>           l2.wait_for_onchaind_txs(('OUR_PENALTY_TX',
                                      'THEIR_REVOKED_UNILATERAL/DELAYED_CHEAT_OUTPUT_TO_THEM'),
                                     ('OUR_PENALTY_TX',
                                      'THEIR_REVOKED_UNILATERAL/OUR_HTLC'))

tests/test_closing.py:687: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
contrib/pyln-testing/pyln/testing/utils.py:1264: in wait_for_onchaind_txs
    r = self.daemon.wait_for_log('Telling lightningd about {} to resolve {}'
contrib/pyln-testing/pyln/testing/utils.py:346: in wait_for_log
    return self.wait_for_logs([regex], timeout)
```

You can see l2 here:

```
lightningd-2 2023-07-27T03:34:24.533Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-onchaind-chan#1: Their unilateral tx, old commit point
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-28 09:44:58 +09:30
Rusty Russell b2c1ef73cb build: avoid printing PLUGIN_BASES on every build.
Debugging left over in 94205c094f.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-28 09:44:58 +09:30
Rusty Russell f15e2506ca pytest: fix flake in test_gossip_store_compact_on_load.
We can have almost arbitrary re-transmissions of private updates, looking at the decode: in this case, instead of the expected:

```
  DELETED: private channel_announcement (scid23)
  DELETED: private channel_update (scid23/0)
  DELETED: private channel_update (scid23/1)
delete channel (scid23)
channel_announcement (scid23)
channel_amount
  DELETED: channel_update (scid23/0)
  DELETED: channel_update (scid23/1)
node_announcement
node_announcement
channel_update (scid23)
private channel_announcement (scid12)
  DELETED: private channel_update (scid12/0)
  DELETED: private channel_update (scid12/1)
channel_update (scid23)
private_channel_update (scid12)
private_channel_update (scid12)
```

We had:

```
  DELETED: private channel_announcement
  DELETED: private channel_update
  DELETED: private channel_update
  DELETED: private channel_update
  DELETED: private channel_update
channel_announcement
channel_amount
  DELETED: channel_update
  DELETED: channel_update
node_announcement
node_announcement
channel_update
private channel_announcement
  DELETED: private channel_update
  DELETED: private channel_update
channel_update
private channel_update
private channel_update
```

Which means we deleted 9, and hence failed:

```
    @pytest.mark.developer("gossip without DEVELOPER=1 is slow")
    def test_gossip_store_compact_on_load(node_factory, bitcoind):
        l2 = setup_gossip_store_test(node_factory, bitcoind)
    
        gs_path = os.path.join(l2.daemon.lightning_dir, TEST_NETWORK, 'gossip_store')
        gs = subprocess.run(['devtools/dump-gossipstore', '--print-deleted', gs_path],
                            check=True, timeout=TIMEOUT, stdout=subprocess.PIPE)
        print(gs.stdout.decode())
    
        l2.restart()
    
>       wait_for(lambda: l2.daemon.is_in_log(r'gossip_store_compact_offline: [5-8] deleted, 9 copied'))

tests/test_gossip.py:1776: 
```
2023-07-28 09:44:58 +09:30
Adi Shankara 7281c448ab update dead links 2023-07-28 09:24:21 +09:30
Christian Decker 6ee98ae74c doc: Add documentation for the tracing subsystem
Changelog-Added: ops: A new tracing system with minimal performance impact was added allowing performance tracing in productive systems
2023-07-28 09:21:42 +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 039aaaf777 trace: Instrument topology functions 2023-07-28 09:21:42 +09:30
Christian Decker 3da974ca19 trace: Instrument the wallet startup functions 2023-07-28 09:21:42 +09:30
Christian Decker 7743062928 trace: Instrument lightningd startup sequence
Should tell us where we're spending time.
2023-07-28 09:21:42 +09:30
Christian Decker ed8d3336c9 trace: First draft of API 2023-07-28 09:21:42 +09:30
Christian Decker df10a7ec9b config: Detect presence of USDT header in configure 2023-07-28 09:21:42 +09:30
Matt Morehouse 693d510992 SECURITY.md: fix email address 2023-07-28 09:20:22 +09:30
Rusty Russell 435a4623ad wallet: fix migration of existing invoices's id variable.
Rusty can't type.  Rusty can't test.  Bad Rusty.  Bad.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-27 15:54:08 +09:30
Rusty Russell 909bed6a30 pytest: add test for db crash on conflicting invoice.id
```
2023-07-26T14:26:37.504Z BROKEN lightningd: Error executing statement: wallet/invoices.c:282: INSERT INTO invoices ( id, payment_hash, payment_key, state , msatoshi, label, expiry_time , pay_index, msatoshi_received , paid_timestamp, bolt11, description, features, local_offer_id) VALUES ( ?, ?, ?, ? , ?, ?, ? , NULL, NULL , NULL, ?, ?, ?, ?);: UNIQUE constraint failed: invoices.id
```

Reported-by: https://github.com/hMsats
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-27 15:54:08 +09:30
Christian Decker 7b8ea7f60a msggen: Add two missing fields to the `listpays` schema
The fields were missing because they weren't annotated with a type and
a description. Adding those fixes them.

Changelog-Fixed: msggen: `listpays` now includes the missing `amount_msat` and `amount_sent_msat` fields
No-schema-diff-check: fields were always there, just undocumented!
2023-07-27 12:40:28 +09:30
Alex Myers 7915a9d678 pytest: add reckless local install test 2023-07-27 06:53:49 +09:30
Alex Myers 8704a4b499 reckless: add installation capability for additional sources
Abstracts search and directory traversal. Adds support for installing
from a local git repository, a local directory, or a web hosted git repo
without relying on an api.

Changelog-Changed: Reckless can now install directly from local sources.
2023-07-27 06:53:49 +09:30
Alex Myers 30b873de31 reckless: style cleanups, type hints, simplify create_dir 2023-07-27 06:53:49 +09:30
Alex Myers 4a4da00d28 gossipd: handle upgrade from version 11 gossip_store 2023-07-27 06:41:44 +09:30
Christian Decker bc59bb71fa pay: Fix a non-rebased PR merge error
Looks like there was a PR that was merged without being rebased on top of
master first. Don't to that!

Changelog-None
2023-07-26 13:50:03 +02:00
Rusty Russell 978c1699ea lightningd: fail incoming HTLCs if peer would close channel.
This cause of cascading failure was pointed out by @t-bast: if fees spike and
you don't timeout an outgoing onchain HTLC, you should nonetheless fail the incoming htlc
because otherwise the incoming peer will close on you.

Of course, there's a risk of losing funds, but this only happens if you weren't going to get the HTLC spend in time anyway.  And it would also catch any other reason that the downstream onchain goes wrong, containing the damage.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reported-by: @t-bast
Changelog-Fixed: Protocol: We will close incoming HTLCs early if the outgoing HTLC is stuck onchain long enough, to avoid cascating failure.
2023-07-26 06:58:38 +09:30
Rusty Russell af71fd689a onchaind: keep trying to collect HTLC even if we're past timeout.
The test actually triggers this:
1. We don't get our commitment tx mined at all (we block it).
2. By the time the peer does, the HTLC is expired.
3. We have the preimage but we don't even try, since it's expired.

We should at least *try* to collect the HTLC in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:58:38 +09:30
Rusty Russell fd445aa467 pytest: test that we proactively close incoming HTLCs to avoid them closing on us.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:58:38 +09:30
Rusty Russell 0a727ae6c5 plugins/bcli: plug temporary leak on retry.
Caught by leak detection, we just re-assigned this when we retried: sure,
it's temporary, but it's technically a leak.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:58:38 +09:30
Rusty Russell 7ddebada90 plugins/bcli: fix leak report when bitcoind goes away.
I shut down bitcoind during a test, and bcli leak reports flooded in.
They're all temporary, but this fixes them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:58:38 +09:30
Vincenzo Palazzo 5190a21d3d ci: Update lnprototest
This update incorporates the proposed version of lnprototest from
the patch [1], which includes the following fixes:

- Corrects the `ExpectError` event and updates BOLT 7 to expect a
warning instead of an error.
- Implements a new test for when the runner sends a bad signature
within the announcement_signatures message.

[1] https://github.com/rustyrussell/lnprototest/pull/100

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-07-26 06:57:15 +09:30
Vincenzo Palazzo f4fd12cc15 channeld: Verify the signature sent by the counterparty
This commit addresses an issue to enhance the resilience of core
lightning when receiving node announcements.

According to BOLT 7 (The announcement_signatures Message),
if the node_signature OR the bitcoin_signature is NOT correct,
it is recommended to either send a warning and close the connection or send an error and fail the channel.

In this commit, we take a strict approach. If any error is detected, we
send an error and fail the open channel operation.
This is because the announcement_signatures operation is optional,
and we assume that it must be correct.

lnprototest at commit dea47c29b5541dbfe7fe53cc2598330e897fa4f4 report
the following error now.

```
2023-07-06T21:03:20.930Z DEBUG   hsmd: Shutting down

ERROR    root:helpers.py:170 Traceback (most recent call last):
  File "/home/vincent/Github/lightning/external/lnprototest/tests/helpers.py", line 167, in run_runner
    runner.run(test)
  File "/home/vincent/Github/lightning/external/lnprototest/lnprototest/runner.py", line 99, in run
    all_done = sequence.action(self)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/vincent/Github/lightning/external/lnprototest/lnprototest/structure.py", line 55, in action
    all_done &= e.action(runner)
                ^^^^^^^^^^^^^^^^
  File "/home/vincent/Github/lightning/external/lnprototest/lnprototest/event.py", line 365, in action
    raise EventError(self, "{}: message was {}".format(err, msg.to_str()))
lnprototest.errors.EventError: `Expected msgtype-warning, got msgtype-error: message was error channel_id=a37362839b13f61cfe82d35bd397b1264c389b245847cfb6111b38892546dc77 data=4661696c656420746f20766572696679206e6f64655f7369676e61747572652e` on event [{"event": "ExpectMsg", "file": "test_bolt2-01-close_channel.py", "pos": "157"},]
============================================================================================================================================================== short test summary info ===============================================================================================================================================================
FAILED tests/test_bolt2-01-close_channel.py::test_close_channel_shutdown_msg_normal_case_receiver_side - AssertionError: `Expected msgtype-shutdown, got msgtype-error: message was error channel_id=a37362839b13f61cfe82d35bd397b1264c389b245847cfb6111b38892546dc77 data=4661696c656420746f20766572696679206e6f64655f7369676e61747572652e` on event [{"event": "ExpectMsg", "file": "test_bolt2-01-close_channel.py", "pos": "75"},]
FAILED tests/test_bolt2-01-close_channel.py::test_close_channel_shutdown_msg_wrong_script_pubkey_receiver_side - AssertionError: `Expected msgtype-warning, got msgtype-error: message was error channel_id=a37362839b13f61cfe82d35bd397b1264c389b245847cfb6111b38892546dc77 data=4661696c656420746f20766572696679206e6f64655f7369676e61747572652e` on event [{"event": "ExpectMsg", "file": "test_bolt2-01-close_channel.py", "pos": "157"},]

```

Changelog-Fixes: channeld: Verify the signature sent in announcement_signatures by the counterparty
Reported-by: lnprototest
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-07-26 06:57:15 +09:30
Rusty Russell 620135335d libplugin/pay: allow shortcut for self-pay.
This is the simplest solution, not the best, but there's significant risk in try to remove the "we have a path" assumption in the code pay code.

Includes removing a `tal_steal` which was incorrect: the buffer has the same lifetime as the plugin, so if we steal it then things get messy when we free the  struct payment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: `pay` will now pay your own invoices if you try.
2023-07-26 06:55:48 +09:30
Rusty Russell 18760db66d lightningd: sendpay implement zero-length path == self-pay.
Previously, the "payment" and "invoice" paths were completely separate, but this now calls both.  It bypasses htlc_sets (and thus, cannot do MPP), and bypasses the hook too: the former is tied closely to HTLCs, and the hook is also very htlc-centric.

Includes finishing unfinished sentence in sendpay man page, as a bonus.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: `sendpay` now allows self-payment of invoices, by specifying an empty route.
2023-07-26 06:55:48 +09:30
Rusty Russell c377edfbd1 pay: generalize payment_succeeded().
We'll want this without an htlc_out, for self-pay.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +09:30
Rusty Russell 07e00d50c6 invoice: return error string from invoice_check_payment.
Clean these up: they were debug logs, but we want to pass this information
back for self-payments.

Also fixes "Attept" typo which altered tests!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +09:30
Rusty Russell 23fafe98e3 wallet: implement and use wallet_payment_new.
We open-coded initialization in two places, now we will want a third,
it's time to clean up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +09:30
Rusty Russell 8c64f2311e lightningd: extract check_progress() from send_payment_core().
We'll need to do this for self-pay as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +09:30
Rusty Russell b4f0929280 db/bindings: allow db_col_short_channel_id_arr and db_col_node_id_arr on null columns
The other _arr helpers allow this, and we want it for the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +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
Rusty Russell b6d347a6d3 db: add optional column string helper, and make db_col amounts return sat/msat.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-26 06:55:48 +09:30
Rusty Russell adee07125a pytest: test self-payments using sendpay.
We want to allow this, so write a test.

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
Shahana Farooqui 911d2c117e plugins/clnrest: Websocket Server
- Added Dependencies
- Updated WS client instructions
- WS Server
2023-07-25 19:20:16 +09:30
Shahana Farooqui 94205c094f plugins/clnrest: Update clnrest dependencies in scripts and Dockerfiles
Adding python3-json5 python3-flask python3-gunicorn flask_restx pyln-client
Also run `pip3 install -r plugins/clnrest/requirements.txt`
2023-07-25 19:20:16 +09:30
Shahana Farooqui 5e3ffc468b plugins/clnrest: removing notifications queue in favor of websocket server 2023-07-25 19:20:16 +09:30
Rusty Russell 2ab0b4af3e plugins/clnrest: disable ourselves unless rest-port is set.
This mirrors grpc's behavior, and avoids listening on ports without
explicit user permission.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 19:20:16 +09:30
Shahana Farooqui abcfda133f plugin: On-boarding default python plugins
plugin: On-boarding default python plugins
2023-07-25 19:20:16 +09:30
Rusty Russell 8f2c9ce0ed lightningd: if a plugin disables at getmanfest time, use INFO log level.
This gets printed by default, so it's not lost!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 19:20:16 +09:30
Rusty Russell a6701bf180 plugins/clnrest: fail gracefully if dependencies not installed.
json and sys are Python built-in packages, so we can do this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 19:20:16 +09:30
Rusty Russell 6d63199d6e doc: update installation to not refer to PPA, and indicate how to get clnrest support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 19:20:16 +09:30
Shahana Farooqui 21160aa6a7 plugin: clnrest
plugin: clnrest
2023-07-25 19:20:16 +09:30
Shahana Farooqui f5f496d698 docs: Incorrect params sequence for checkrune command
It accepts rune first and nodeid second but the documentation showed
incorrect sequence.

No-schema-diff-check
2023-07-25 17:41:34 +09:30
Rusty Russell 11b5f31034 lightningd: clean up commando rune_counter from datastore on migration.
Pointed out by @ShahanaFarooqui, we leave a single unused entry in the datastore,
so we should clean that up too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30
Rusty Russell 925f9fcce5 lightningd: migrate (and delete) old commando blacklists.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-07-25 14:47:12 +09:30