Commit Graph

2539 Commits

Author SHA1 Message Date
Rusty Russell 0a9a87ec10 pytest: fix test_commando_stress
On fast machines, we don't get failures sometimes on commando commands.

(*But* we still got "New cmd replacing old" messages, which is how I
realized we weren't freeing them promptly, hence the previous fix).

```
        # Should have exactly one discard msg from each discard
>       nodes[0].daemon.wait_for_logs([r"New cmd from .*, replacing old"] * discards)

tests/test_plugin.py:2839: 
...
>                   raise TimeoutError('Unable to find "{}" in logs.'.format(exs))
E                   TimeoutError: Unable to find "[]" in logs.

```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-26 09:33:40 -07:00
Rusty Russell 8da361b49b pytest: fix flake in test_channel_persistence w/ TEST_CHECK_DBSTMTS
This was weird.  Here is the message (with \n turned into real new lines):

```
2022-07-24T07:20:08.9144998Z Plugin '/home/runner/work/lightning/lightning/tests/plugins/dblog.py' returned an invalid response to the db_write hook: {"jsonrpc": "2.0", "id": 40, "error": {"code": -32600, "message": "Error while processing db_write: UNIQUE constraint failed: shachain_known.shachain_id, shachain_known.pos", "traceback": "Traceback (most recent call last):
  File \"/home/runner/work/lightning/lightning/contrib/pyln-client/pyln/client/plugin.py\", line 631, in _dispatch_request
    result = self._exec_func(method.func, request)
  File \"/home/runner/work/lightning/lightning/contrib/pyln-client/pyln/client/plugin.py\", line 616, in _exec_func
    return func(*ba.args, **ba.kwargs)
  File \"/home/runner/work/lightning/lightning/tests/plugins/dblog.py\", line 45, in db_write
    plugin.conn.execute(c)
sqlite3.IntegrityError: UNIQUE constraint failed: shachain_known.shachain_id, shachain_known.pos
"}}
```

Finally, I realized that we *kill* l2: this means it has updated the
plugin db but not the real db.  This is expected: a real backup plugin
would handle this case.

Simply disable the test for this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-26 09:33:40 -07:00
Rusty Russell 1480257644 pytest: set dblog-file when adding the dblog plugin (TEST_CHECK_DBSTMTS=1)
As we'll see in the next patch, this wasn't *supposed* to work wihtout dblog-file,
but it did, creating a dblog called "null".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-26 09:33:40 -07:00
Rusty Russell da4e33cd0d decode: fix crash when decoding invalid rune.
If rune contains invalid UTF-8, offers (which implements decode) would
produce JSON with invalid UTF-8, which causes lightningd to complain
and kill it, and then die because it's an important plugin.

So don't decode invalid UTF-8!

Reported-by: @jb55
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-25 15:14:01 -07:00
Rusty Russell 8f6afedafe fuzz: fix fuzzing compilation.
It had bitrotted.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-25 08:08:32 -07:00
niftynei 7bbfef5054 tests: flake fix; l1 was waiting too long to reconnect
We were waiting too long for the reconnect to happen (60s default),
which caused this test to timeout.

When testing, let's speed up the reconnect.

L2 tried to reconnect but didn't have connection information in its
gossip -- is there a way to ask/save connection data from a node you're
making a channel with that doesn't rely on their node_announcement?
2022-07-25 16:28:09 +09:30
niftynei 4cc0da7432 nit: speedup retry timeout test 2022-07-25 16:28:09 +09:30
niftynei 9adf5f17de tests:redirect output, so test log passes 2022-07-25 16:28:09 +09:30
niftynei bed00754ad test-flake: dont let `l1` send their unilateral tx
`l1` got their tx in before `l2`, but we're waiting for `l2`'s
commitment tx. (l2 sends an error message to l1 when we call dev-fail,
l1 broadcasts their commitment tx when they get the error)

Instead, we let l1 send their commitment tx, except we blackhole it.

```
        l2.rpc.dev_fail(l1.info['id'])
        l2.daemon.wait_for_log('Failing due to dev-fail command')
>       l2.wait_for_channel_onchain(l1.info['id'])
tests/test_connection.py:2275:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
contrib/pyln-testing/pyln/testing/utils.py:1043: in wait_for_channel_onchain
    wait_for(lambda: txid inself.bitcoin.rpc.getrawmempool())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
success = <function LightningNode.wait_for_channel_onchain.<locals>.<lambda> at 0x7f0f5f7577a0>
timeout = 900
defwait_for(success, timeout=TIMEOUT):
        start_time = time.time()
        interval = 0.25
whilenot success():
            time_left = start_time + timeout - time.time()
if time_left <= 0:
>               raiseValueError("Timeout while waiting for {}", success)
E               ValueError: ('Timeout while waiting for {}', <function LightningNode.wait_for_channel_onchain.<locals>.<lambda> at 0x7f0f5f7577a0>)
contrib/pyln-testing/pyln/testing/utils.py:93: ValueError
```
2022-07-23 11:37:35 -05:00
Rusty Russell 53c333a01b pytest: fix flake in test_zeroconf_forward
pay failed (non-DEVELOPER) because one node didn't see blocks in time:

```
        inv = l3.rpc.invoice(42 * 10**6, 'inv1', 'desc')['bolt11']
>       l1.rpc.pay(inv)
tests/test_opening.py:1394:
...
>           raise RpcError(method, payload, resp['error'])
E           pyln.client.lightning.RpcError: RPC call failed: method: pay, payload: {'bolt11': 'lnbcrt420u1p3dnwv7sp5qnquuwndgz35ywfg3p3dtu07ywmju78r8s0379eaxjxkv5d8jueqpp5kmaxgsye02dzmdlkqkedqvrh2evdl45sz7njrm5dff42dvp4v5qsdq8v3jhxccxqyjw5qcqp9rzjqgkjyd3q5dv6gllh77kygly9c3kfy0d9xwyjyxsq2nq3c83u5vw4n0wkf0y9gwfwhgqqqqqpqqqqqzsqqc9qyysgqad2x2zv0axa3hrfz7nurw4plvspvxlld9wtcg3xxjyxqlzm773a4fkyl09gs8uskj4m7len8r4pf4rh7v9snh3grrpawhk9qsd7vwmcqa9rgxg'}, error: {'code': 210, 'message': 'Ran out of routes to try after 176 attempts: see `paystatus`', 'attempts': [{'status': 'pending', 'partid': 1, 'amount_msat': 42000000msat}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 2, 'amount_msat': 9278783msat, 'parent_partid': 1}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 10, 'amount_msat': 9278783msat, 'parent_partid': 2}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 15, 'amount_msat': 9278783msat, 'parent_partid': 10}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 18, 'amount_msat': 9278783msat, 'parent_partid': 15}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 23, 'amount_msat': 9278783msat, 'parent_partid': 18}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 29, 'amount_msat': 9278783msat, 'parent_partid': 23}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 33, 'amount_msat': 9278783msat, 'parent_partid': 29}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 39, 'amount_msat': 9278783msat, 'parent_partid': 33}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 43, 'amount_msat': 9278783msat, 'parent_partid': 39}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 48, 'amount_msat': 9278783msat, 'parent_partid': 43}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 54, 'amount_msat': 9278783msat, 'parent_partid': 48}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 59, 'amount_msat': 4659837msat, 'parent_partid': 54}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 69, 'amount_msat': 4659837msat, 'parent_partid': 59}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 82, 'amount_msat': 4659837msat, 'parent_partid': 69}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 92, 'amount_msat': 4659837msat, 'parent_partid': 82}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 102, 'amount_msat': 4659837msat, 'parent_partid': 92}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 112, 'amount_msat': 4659837msat, 'parent_partid': 102}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 122, 'amount_msat': 4659837msat, 'parent_partid': 112}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 131, 'amount_msat': 4659837msat, 'parent_partid': 122}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 141, 'amount_msat': 4659837msat, 'parent_partid': 131}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 147, 'amount_msat': 4659837msat, 'parent_partid': 141}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 158, 'amount_msat': 4659837msat, 'parent_partid': 147}, {'status': 'pending', 'partid': 175, 'amount_msat': 2250620msat, 'parent_partid': 158}, {'status': 'pending', 'partid': 176, 'amount_msat': 2409217msat, 'parent_partid': 158}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 60, 'amount_msat': 4618946msat, 'parent_partid': 54}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 70, 'amount_msat': 4618946msat, 'parent_partid': 60}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 81, 'amount_msat': 4618946msat, 'parent_partid': 70}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 91, 'amount_msat': 4618946msat, 'parent_partid': 81}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 101, 'amount_msat': 4618946msat, 'parent_partid': 91}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 111, 'amount_msat': 4618946msat, 'parent_partid': 101}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 121, 'amount_msat': 4618946msat, 'parent_partid': 111}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 132, 'amount_msat': 4618946msat, 'parent_partid': 121}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 142, 'amount_msat': 4618946msat, 'parent_partid': 132}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 148, 'amount_msat': 4618946msat, 'parent_partid': 142}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 157, 'amount_msat': 4618946msat, 'parent_partid': 148}, {'status': 'pending', 'partid': 168, 'amount_msat': 2320055msat, 'parent_partid': 157}, {'status': 'pending', 'partid': 169, 'amount_msat': 2298891msat, 'parent_partid': 157}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 3, 'amount_msat': 9016551msat, 'parent_partid': 1}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 7, 'amount_msat': 9016551msat, 'parent_partid': 3}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 12, 'amount_msat': 9016551msat, 'parent_partid': 7}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 17, 'amount_msat': 9016551msat, 'parent_partid': 12}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 21, 'amount_msat': 9016551msat, 'parent_partid': 17}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 25, 'amount_msat': 9016551msat, 'parent_partid': 21}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 30, 'amount_msat': 9016551msat, 'parent_partid': 25}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 36, 'amount_msat': 9016551msat, 'parent_partid': 30}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 40, 'amount_msat': 9016551msat, 'parent_partid': 36}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 47, 'amount_msat': 9016551msat, 'parent_partid': 40}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 51, 'amount_msat': 9016551msat, 'parent_partid': 47}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 56, 'amount_msat': 4458645msat, 'parent_partid': 51}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 63, 'amount_msat': 4458645msat, 'parent_partid': 56}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 77, 'amount_msat': 4458645msat, 'parent_partid': 63}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 87, 'amount_msat': 4458645msat, 'parent_partid': 77}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 94, 'amount_msat': 4458645msat, 'parent_partid': 87}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 105, 'amount_msat': 4458645msat, 'parent_partid': 94}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 120, 'amount_msat': 4458645msat, 'parent_partid': 105}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 124, 'amount_msat': 4458645msat, 'parent_partid': 120}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 134, 'amount_msat': 4458645msat, 'parent_partid': 124}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 143, 'amount_msat': 4458645msat, 'parent_partid': 134}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 154, 'amount_msat': 4458645msat, 'parent_partid': 143}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 164, 'amount_msat': 2306527msat, 'parent_partid': 154}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 165, 'amount_msat': 2152118msat, 'parent_partid': 154}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 57, 'amount_msat': 4557906msat, 'parent_partid': 51}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 68, 'amount_msat': 4557906msat, 'parent_partid': 57}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 76, 'amount_msat': 4557906msat, 'parent_partid': 68}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 86, 'amount_msat': 4557906msat, 'parent_partid': 76}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 96, 'amount_msat': 4557906msat, 'parent_partid': 86}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 103, 'amount_msat': 4557906msat, 'parent_partid': 96}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 115, 'amount_msat': 4557906msat, 'parent_partid': 103}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 125, 'amount_msat': 4557906msat, 'parent_partid': 115}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 136, 'amount_msat': 4557906msat, 'parent_partid': 125}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 146, 'amount_msat': 4557906msat, 'parent_partid': 136}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 161, 'amount_msat': 4557906msat, 'parent_partid': 146}, {'status': 'pending', 'partid': 173, 'amount_msat': 2208152msat, 'parent_partid': 161}, {'status': 'pending', 'partid': 174, 'amount_msat': 2349754msat, 'parent_partid': 161}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 4, 'amount_msat': 10655305msat, 'parent_partid': 1}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 9, 'amount_msat': 10655305msat, 'parent_partid': 4}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 13, 'amount_msat': 10655305msat, 'parent_partid': 9}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 19, 'amount_msat': 10655305msat, 'parent_partid': 13}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 24, 'amount_msat': 10655305msat, 'parent_partid': 19}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 28, 'amount_msat': 10655305msat, 'parent_partid': 24}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 34, 'amount_msat': 10655305msat, 'parent_partid': 28}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 38, 'amount_msat': 10655305msat, 'parent_partid': 34}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 44, 'amount_msat': 10655305msat, 'parent_partid': 38}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 49, 'amount_msat': 10655305msat, 'parent_partid': 44}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 53, 'amount_msat': 10655305msat, 'parent_partid': 49}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 61, 'amount_msat': 4872267msat, 'parent_partid': 53}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 71, 'amount_msat': 4872267msat, 'parent_partid': 61}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 79, 'amount_msat': 4872267msat, 'parent_partid': 71}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 89, 'amount_msat': 4872267msat, 'parent_partid': 79}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 100, 'amount_msat': 4872267msat, 'parent_partid': 89}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 109, 'amount_msat': 4872267msat, 'parent_partid': 100}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 114, 'amount_msat': 4872267msat, 'parent_partid': 109}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 126, 'amount_msat': 4872267msat, 'parent_partid': 114}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 139, 'amount_msat': 4872267msat, 'parent_partid': 126}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 149, 'amount_msat': 4872267msat, 'parent_partid': 139}, {'status': 'failed', 'failreason': 'Cannot split payment any further without exceeding the maximum number of HTLCs allowed by our channels', 'partid': 162, 'amount_msat': 4872267msat, 'parent_partid': 149}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 62, 'amount_msat': 5783038msat, 'parent_partid': 53}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 72, 'amount_msat': 5783038msat, 'parent_partid': 62}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 80, 'amount_msat': 5783038msat, 'parent_partid': 72}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 90, 'amount_msat': 5783038msat, 'parent_partid': 80}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 99, 'amount_msat': 5783038msat, 'parent_partid': 90}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 110, 'amount_msat': 5783038msat, 'parent_partid': 99}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 117, 'amount_msat': 5783038msat, 'parent_partid': 110}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 128, 'amount_msat': 5783038msat, 'parent_partid': 117}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 138, 'amount_msat': 5783038msat, 'parent_partid': 128}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 150, 'amount_msat': 5783038msat, 'parent_partid': 138}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 156, 'amount_msat': 5783038msat, 'parent_partid': 150}, {'status': 'pending', 'partid': 170, 'amount_msat': 2902801msat, 'parent_partid': 156}, {'status': 'pending', 'partid': 171, 'amount_msat': 2880237msat, 'parent_partid': 156}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 5, 'amount_msat': 8942693msat, 'parent_partid': 1}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 8, 'amount_msat': 8942693msat, 'parent_partid': 5}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 16, 'amount_msat': 8942693msat, 'parent_partid': 8}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 20, 'amount_msat': 8942693msat, 'parent_partid': 16}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 27, 'amount_msat': 8942693msat, 'parent_partid': 20}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 32, 'amount_msat': 8942693msat, 'parent_partid': 27}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 35, 'amount_msat': 8942693msat, 'parent_partid': 32}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 42, 'amount_msat': 8942693msat, 'parent_partid': 35}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 45, 'amount_msat': 8942693msat, 'parent_partid': 42}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 50, 'amount_msat': 8942693msat, 'parent_partid': 45}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 58, 'amount_msat': 8942693msat, 'parent_partid': 50}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 64, 'amount_msat': 4159394msat, 'parent_partid': 58}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 78, 'amount_msat': 4159394msat, 'parent_partid': 64}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 84, 'amount_msat': 4159394msat, 'parent_partid': 78}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 98, 'amount_msat': 4159394msat, 'parent_partid': 84}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 108, 'amount_msat': 4159394msat, 'parent_partid': 98}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 116, 'amount_msat': 4159394msat, 'parent_partid': 108}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 123, 'amount_msat': 4159394msat, 'parent_partid': 116}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 135, 'amount_msat': 4159394msat, 'parent_partid': 123}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 144, 'amount_msat': 4159394msat, 'parent_partid': 135}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 155, 'amount_msat': 4159394msat, 'parent_partid': 144}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 163, 'amount_msat': 4159394msat, 'parent_partid': 155}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 65, 'amount_msat': 4783299msat, 'parent_partid': 58}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 73, 'amount_msat': 4783299msat, 'parent_partid': 65}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 83, 'amount_msat': 4783299msat, 'parent_partid': 73}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 93, 'amount_msat': 4783299msat, 'parent_partid': 83}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 104, 'amount_msat': 4783299msat, 'parent_partid': 93}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 119, 'amount_msat': 4783299msat, 'parent_partid': 104}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 127, 'amount_msat': 4783299msat, 'parent_partid': 119}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 140, 'amount_msat': 4783299msat, 'parent_partid': 127}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 151, 'amount_msat': 4783299msat, 'parent_partid': 140}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 160, 'amount_msat': 4783299msat, 'parent_partid': 151}, {'status': 'pending', 'partid': 172, 'amount_msat': 4783299msat, 'parent_partid': 160}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 6, 'amount_msat': 4106668msat, 'parent_partid': 1}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 11, 'amount_msat': 4106668msat, 'parent_partid': 6}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 14, 'amount_msat': 4106668msat, 'parent_partid': 11}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 22, 'amount_msat': 4106668msat, 'parent_partid': 14}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 26, 'amount_msat': 4106668msat, 'parent_partid': 22}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 31, 'amount_msat': 4106668msat, 'parent_partid': 26}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 37, 'amount_msat': 4106668msat, 'parent_partid': 31}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 41, 'amount_msat': 4106668msat, 'parent_partid': 37}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 46, 'amount_msat': 4106668msat, 'parent_partid': 41}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 52, 'amount_msat': 4106668msat, 'parent_partid': 46}, {'status': 'pending', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 55, 'amount_msat': 4106668msat, 'parent_partid': 52}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 66, 'amount_msat': 2165538msat, 'parent_partid': 55}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 75, 'amount_msat': 2165538msat, 'parent_partid': 66}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 85, 'amount_msat': 2165538msat, 'parent_partid': 75}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 95, 'amount_msat': 2165538msat, 'parent_partid': 85}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 107, 'amount_msat': 2165538msat, 'parent_partid': 95}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 113, 'amount_msat': 2165538msat, 'parent_partid': 107}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 130, 'amount_msat': 2165538msat, 'parent_partid': 113}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 137, 'amount_msat': 2165538msat, 'parent_partid': 130}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 152, 'amount_msat': 2165538msat, 'parent_partid': 137}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 159, 'amount_msat': 2165538msat, 'parent_partid': 152}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 167, 'amount_msat': 2165538msat, 'parent_partid': 159}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 67, 'amount_msat': 1941130msat, 'parent_partid': 55}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 74, 'amount_msat': 1941130msat, 'parent_partid': 67}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 88, 'amount_msat': 1941130msat, 'parent_partid': 74}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 97, 'amount_msat': 1941130msat, 'parent_partid': 88}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 106, 'amount_msat': 1941130msat, 'parent_partid': 97}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 118, 'amount_msat': 1941130msat, 'parent_partid': 106}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 129, 'amount_msat': 1941130msat, 'parent_partid': 118}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 133, 'amount_msat': 1941130msat, 'parent_partid': 129}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 145, 'amount_msat': 1941130msat, 'parent_partid': 133}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 153, 'amount_msat': 1941130msat, 'parent_partid': 145}, {'status': 'failed', 'failreason': 'failed: WIRE_EXPIRY_TOO_SOON (reply from remote)', 'partid': 166, 'amount_msat': 1941130msat, 'parent_partid': 153}]}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-22 17:57:28 +02:00
Rusty Russell 8c38302ab8 hsmtool: implement checkhsm.
This gives a nice way to ensure your secret is the correct one.

Also, we don't need to suppress VALGRIND for this test, now the output
races are fixed.

Changelog-Added: `hsmtool`: new command `checkhsm` to check BIP39 passphrase against hsm_secret.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-22 16:57:27 +02:00
Rusty Russell c10e385612 commando: add stress test, fix memleak report.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-21 15:37:05 -05:00
Rusty Russell 4cada557ba pytest: don't redirect stderr by default.
Some tests need to inspect it, but most don't, and I suspect I'm missing some
error messages due to this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-21 15:37:05 -05:00
Rusty Russell aaf743e438 commando: fix crash when rune is completely bogus.
The error routine returns a string literal in this case, which we can't take().

Reported-by: @jb55
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-21 15:37:05 -05:00
Rusty Russell 08bef48d5c pytest: disable autoreconnect in test_rbf_reconnect_tx_construct
It reconnects itself, so we don't see the ['connected'] is False.

```
2022-07-20T20:37:06.3808161Z     @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
2022-07-20T20:37:06.3809031Z     @pytest.mark.developer("uses dev-disconnect")
2022-07-20T20:37:06.3809547Z     @pytest.mark.openchannel('v2')
2022-07-20T20:37:06.3810058Z     def test_rbf_reconnect_tx_construct(node_factory, bitcoind, chainparams):
...
2022-07-20T20:37:06.3864163Z         # Now we finish off the completes failure check
2022-07-20T20:37:06.3864604Z         for d in disconnects[-2:]:
2022-07-20T20:37:06.3865162Z             l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
2022-07-20T20:37:06.3865711Z             bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
2022-07-20T20:37:06.3866169Z             with pytest.raises(RpcError):
2022-07-20T20:37:06.3866674Z                 update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
2022-07-20T20:37:06.3867367Z >           wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'] is False)
...
2022-07-20T20:37:06.5215961Z lightningd-1 2022-07-20T20:21:49.691Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-connectd: dev_disconnect: -WIRE_TX_COMPLETE (WIRE_TX_COMPLETE)
2022-07-20T20:37:06.5216482Z lightningd-1 2022-07-20T20:21:49.691Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-dualopend-chan#1: peer_out WIRE_TX_COMPLETE
2022-07-20T20:37:06.5216756Z lightningd-1 2022-07-20T20:21:49.691Z DEBUG   connectd: drain_peer
2022-07-20T20:37:06.5217064Z lightningd-1 2022-07-20T20:21:49.692Z DEBUG   connectd: drain_peer draining subd!
2022-07-20T20:37:06.5217549Z lightningd-1 2022-07-20T20:21:49.692Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-lightningd: peer_disconnect_done
2022-07-20T20:37:06.5218482Z lightningd-1 2022-07-20T20:21:49.692Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-lightningd: Reconnecting in 1 seconds
2022-07-20T20:37:06.5219110Z lightningd-1 2022-07-20T20:21:49.692Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-lightningd: Will try reconnect in 1 seconds
2022-07-20T20:37:06.5219427Z lightningd-1 2022-07-20T20:21:49.692Z DEBUG   gossipd: REPLY WIRE_GOSSIPD_GET_ADDRS_REPLY with 0 fds
2022-07-20T20:37:06.5219994Z lightningd-1 2022-07-20T20:21:49.696Z DEBUG   plugin-funder: Cleaning up inflights for peer id 022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59
2022-07-20T20:37:06.5220305Z lightningd-1 2022-07-20T20:21:49.696Z DEBUG   connectd: maybe_free_peer freeing peer!
2022-07-20T20:37:06.5220743Z lightningd-2 2022-07-20T20:21:49.699Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-gossipd: seeker: chosen as startup peer
2022-07-20T20:37:06.5221136Z lightningd-2 2022-07-20T20:21:49.699Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-hsmd: Got WIRE_HSMD_ECDH_REQ
2022-07-20T20:37:06.5221380Z lightningd-2 2022-07-20T20:21:49.699Z DEBUG   connectd: drain_peer
2022-07-20T20:37:06.5221805Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-hsmd: Got WIRE_HSMD_READY_CHANNEL
2022-07-20T20:37:06.5223761Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-dualopend-chan#1: signature 30440220338460c0e75c08c21f4f4f96806d81426aee48e06ccc54e87892b332f55fe49e0220527573286f801a0d23317978a9aabbbbcb95c2ceb614596c0ab50bb72b96158b01 on tx 020000000105f2aa5f346f46007b9f8b128e8c6e4d40d0477aefd81250ba99adc9349aabe300000000009db0e280024a01000000000000220020be7935a77ca9ab70a4b8b1906825637767fed3c00824aa90c988983587d684881e6301000000000022002047021684129f8aa1c0b5b97dc99607f5f0850b548813a5da346fda22511284759a3ed620 using key 02324266de8403b3ab157a09f1f784d587af61831c998c151bcc21bb74c2b2314b
2022-07-20T20:37:06.5224194Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-connectd: Connected out, starting crypto
2022-07-20T20:37:06.5224723Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-gossipd: seeker: chosen as startup peer
2022-07-20T20:37:06.5225006Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   hsmd: Client: Received message 31 from client
2022-07-20T20:37:06.5225461Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-dualopend-chan#1: peer_out WIRE_COMMITMENT_SIGNED
2022-07-20T20:37:06.5225852Z lightningd-1 2022-07-20T20:21:49.700Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-connectd: Connect OUT
```
2022-07-21 14:25:25 -05:00
Christian Decker bac322ccdb pytest: Move generated grpc bindings to pyln-testing
These may eventually end up in pyln-client, as they allow talking to
the GRPC interface exposed by cln-grpc, however for now they are used
for testing only. Once we have sufficient API and test coverage we can
move them and leave imports in their place.
2022-07-21 14:19:06 +09:30
Rusty Russell e96eb07ef4 lightningd: test that hsm_secret is as expected, at startup.
If you get the wrong hsm_secret, your node_id will change, and
peers won't know who you are, bitcoind will reject your transaction
signatures, and other madness.

Catch this as soon as it happens, by storing our node_id in the db.

Suggested-by: @cdecker, @fiatjaf
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Config: `lightningd` will refuse to start with the wrong node_id (i.e. hsm_secret changes).
2022-07-20 19:28:33 +09:30
Vincenzo Palazzo ba4e870a1c test: disable schema check of `checkmessage` with deprecated API
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-07-19 17:55:31 +02:00
Vincenzo Palazzo 7ae616ef60 rpc: improve error format
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-07-19 17:55:31 +02:00
Vincenzo Palazzo 1d671a2380 rpc: checkmessage return an error if pubkey is not found
Returning an warning message when the pub key is not specified and there is no node in the graph.

We try to help people that use core lightning as a signer and nothings else.

Changelog-Deprecated: rpc: checkmessage return an error when the pubkey is not specified and it is unknown in the network graph.
2022-07-19 17:55:31 +02:00
Rusty Russell acc9dc4852 pytest: fix flake in test_channel_lease_post_expiry
We close the channel because the payment fulfilment is not totally done, and
we generate 6 blocks, causing it to hit CLTV deadline.

```
        # send some payments, mine a block or two
        inv = l2.rpc.invoice(10**4, '1', 'no_1')
        l1.rpc.pay(inv['bolt11'])
    
        # l2 attempts to close a channel that it leased, should fail
        with pytest.raises(RpcError, match=r'Peer leased this channel from us'):
            l2.rpc.close(l1.get_channel_scid(l2))
    
        bitcoind.generate_block(6)
        sync_blockheight(bitcoind, [l1, l2])
        # make sure we're at the right place for the csv lock
>       l2.daemon.wait_for_log('Blockheight: SENT_ADD_ACK_COMMIT->RCVD_ADD_ACK_REVOCATION LOCAL now 115')

tests/test_closing.py:823: 
...
lightningd-2 2022-07-17T13:15:34.242Z DEBUG   lightningd: Adding block 115: 39d95061935e9fc42b04c86ae60d0cf157765aff4c040f3a8d0b7888db19e015
lightningd-2 2022-07-17T13:15:34.244Z UNUSUAL 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#2: Peer permanent failure in CHANNELD_NORMAL: Fulfilled HTLC 0 SENT_REMOVE_COMMIT cltv 115 hit deadline
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 099d149104 pytest: work around dualopend issue.
Dualopend is not listening to the peer fd when it hangs up, so doesn't
notice it's gone.  We don't clean up the channel until it's done (usually
a good thing: it could be about to lock it in), but this harms us
here.

Fix the test failure and make a comment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 02e169fd27 lightningd: drive all reconnections out of disconnections.
The only places which should call try_reconnect now are the "connect"
command, and the disconnect path when it decides there's still an
active channel.

This introduces one subtlety: if we disconnect when there's no active
channel, but then the subd makes one, we have to catch that case!

This temporarily reverts "slow" reconnections to fast ones: see next
patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell a3c4908f4a lightningd: don't explicitly tell connectd to disconnect, have it do it on sending error/warning.
Connectd already does this when we *receive* an error or warning, but
now do it on send.  This causes some slight behavior change: we don't
disconnect when we close a channel, for example (our behaviour here
has been inconsistent across versions, depending on the code).

When connectd is told to disconnect, it now does so immediately, and
doesn't wait for subds to drain etc.  That simplifies the manual
disconnect case, which now cleans up as it would from any other
disconnection when connectd says it's disconnected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 2962b93199 pytest: don't assume disconnect finished atomically, and suppress interfering redirects.
In various places, we assumed that when `connected` is false,
everything is finished.  This is not true: we should wait for the
state we expect.

In addition, various places allows reconnections, which interfered
with the logic; suppress them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 719d1384d1 connectd: give connections a chance to drain when lightningd says to disconnect, or peer disconnects.
We want to avoid lost messages in the common cases.

This generalizes our drain code, by giving the subds each 5 seconds to
close themselves, but continue to allow them to send us traffic (if
peer is still connected) and continue to send them traffic.

We continue to send traffic *out* to the peer (if it's still
connected), until all subds are gone.  We still have a 5 second timer
to close the connection to peer.

On reconnects, we don't do this "drain period" on reconnects: we kill
immediately.

We fix up one test which was looking for the "disconnect" message
explicitly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 2daf461762 pytest: enable race test.
Now this passes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 6a9a091234 pytest: add another connection stress test, using multiple channels (bug #5254)
This one actually triggers an assert() on my machine, so though it
wasn't what I was looking for, let's include it:

```
lightning_connectd: connectd/connectd.c:1905: peer_conn_closed: Assertion `tal_count(peer->subds) == 0' failed.
lightning_connectd: FATAL SIGNAL 6 (version v0.11.0.1-15-gc812595)
0x55b3e1e21302 send_backtrace
	common/daemon.c:33
0x55b3e1e213ac crashdump
	common/daemon.c:46
0x7f44292ff08f ???
	/build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x7f44292ff00b __GI_raise
	../sysdeps/unix/sysv/linux/raise.c:51
0x7f44292de858 __GI_abort
	/build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:79
0x7f44292de728 __assert_fail_base
	/build/glibc-SzIz7B/glibc-2.31/assert/assert.c:92
0x7f44292effd5 __GI___assert_fail
	/build/glibc-SzIz7B/glibc-2.31/assert/assert.c:101
0x55b3e1e125db peer_conn_closed
	connectd/connectd.c:1905
0x55b3e1e17b4f destroy_subd
	connectd/multiplex.c:1112
0x55b3e1e7fdf4 notify
	ccan/ccan/tal/tal.c:240
0x55b3e1e8030b del_tree
	ccan/ccan/tal/tal.c:402
0x55b3e1e8035d del_tree
	ccan/ccan/tal/tal.c:412
0x55b3e1e806a7 tal_free
	ccan/ccan/tal/tal.c:486
0x55b3e1e6ef59 io_close
	ccan/ccan/io/io.c:450
0x55b3e1e17429 write_to_subd
	connectd/multiplex.c:957
0x55b3e1e6e1a3 next_plan
	ccan/ccan/io/io.c:59
0x55b3e1e6eebc io_do_always
	ccan/ccan/io/io.c:435
0x55b3e1e70baa handle_always
	ccan/ccan/io/poll.c:304
0x55b3e1e70ea1 io_loop
	ccan/ccan/io/poll.c:385
0x55b3e1e12dd5 main
	connectd/connectd.c:2159
0x7f44292e0082 __libc_start_main
	../csu/libc-start.c:308
0x55b3e1e0885d ???
	???:0
0xffffffffffffffff ???
	???:0
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Rusty Russell 8e1d5c19d6 pytest: test to reproduce "channeld: sent ERROR bad reestablish revocation_number: 0 vs 3"
It's caused by a reconnection race: we hold the new incoming connection while we
ask lightningd to kill the old connection.  But under some circumstances we leave
the new incoming hanging (with, in this case, old reestablish messages unread!)
and another connection comes in.

Then, later we service the long-gone "incoming" connection, channeld
reads the ancient reestablish message and gets upset.

This test used to hang, but now we've fixed reconnection races it is fine.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-18 20:50:04 -05:00
Michael Schmoock 65433de05f options: set DNS port to network default if not specified
- set port for a DNS announcement without port to network default
- remove x-fail

Changelog-Fixed: Port of a DNS announcement can be 0 if unspecified
2022-07-17 23:26:07 +02:00
Michael Schmoock 6d4285d7c4 pytest: add xfail test to show DNS w/o port issue
This adds an X-Fail testcase that demonstrates that currently
the port of a DNS announcement is not set to the corresponding
network port (in this case regtest), but it will be set to 0.

Changelog-None
2022-07-17 23:26:07 +02:00
Rusty Russell 8c48eda8c7 decode: support decoding runes.
This is a bit weird since it lives in the offers plugin, but it works
well.  This should make runes much more approachable for people!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell 468dff1723 commando: add rate for maximum successful rune use per minute.
I'm assuming that nobody wants a rate slower than 1 per minute; we can
introduce 'drate' if we want a per-day kind of limit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell 4ab09f7cfb commando: add support for parameters by array, parameter count.
Awkward to filter, but they're really practical for many commands.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell 8688daf937 commando: require runes for operation.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell ae4856df70 commando: don't look at messages *at all* unless they've created a rune.
This means we can leave commando on by default, without an explicit config flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell 419cb60b1b commando: add commando-rune command.
Can both mint new runes, and add one or more restrictions to existing ones.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell b49703e279 commando: correctly reflect error data field.
Some JSON error include "data", and we should reflect that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell 49df89556b commando: support commands larger than 64k.
This is needed for invoice, which can be asked to commit to giant descriptions
(though that's antisocial!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Rusty Russell 3fe246c2e7 plugins/commando: basic commando plugin (no runes yet).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au
Changelog-Added: Plugins: `commando` a new builtin plugin to send/recv peer commands over the lightning network, using runes.
2022-07-17 08:51:02 +09:30
Rusty Russell 3e672b784d Makefile: use a library archive for CCAN
The linker discards whole files in an archive if it doesn't need them,
so saves a bit of space (and time).  Also allows us to add more niche
things to CCAN (e.g. runes support!) without bloating all the binaries.

We also had many places which depended on $(CCAN_FILES), but that was
already a dependent of $(ALL_PROGRAMS) and $(ALL_TEST_PROGRAMS).

Before:

```
$ size lightningd/lightning*d
   text	   data	    bss	    dec	    hex	filename
2247683	   8696	  39008	2295387	 23065b	lightningd/lightning_channeld
2086607	   7432	  38880	2132919	 208bb7	lightningd/lightning_closingd
2227916	   8056	  39200	2275172	 22b764	lightningd/lightning_connectd
3369236	 119288	  39240	3527764	 35d454	lightningd/lightningd
2183551	   8352	  38880	2230783	 2209ff	lightningd/lightning_dualopend
2196389	   8024	  39136	2243549	 223bdd	lightningd/lightning_gossipd
2086216	   7488	  39264	2132968	 208be8	lightningd/lightning_hsmd
2134396	   8136	  39424	2181956	 214b44	lightningd/lightning_onchaind
2133391	   8352	  38880	2180623	 21460f	lightningd/lightning_openingd
1512168	   2136	  34384	1548688	 17a190	lightningd/lightning_websocketd
```

After:
```
text	   data	    bss	    dec	    hex	filename
2192065	   8488	  38912	2239465	 222be9	lightningd/lightning_channeld
2030957	   7224	  38816	2076997	 1fb145	lightningd/lightning_closingd
2179571	   7968	  39104	2226643	 21f9d3	lightningd/lightning_connectd
3354296	 119288	  39208	3512792	 3599d8	lightningd/lightningd
2127933	   8144	  38816	2174893	 212fad	lightningd/lightning_dualopend
2141699	   7856	  39072	2188627	 216553	lightningd/lightning_gossipd
2024482	   7288	   5240	2037010	 1f1512	lightningd/lightning_hsmd
2072074	   7920	   5400	2085394	 1fd212	lightningd/lightning_onchaind
2077773	   8144	  38816	2124733	 206bbd	lightningd/lightning_openingd
1408958	   1752	    344	1411054	 1587ee	lightningd/lightning_websocketd
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-17 08:51:02 +09:30
Simon Vrouwe ad3cbed7c2 plugin: autoclean fix double free when re-enable, remove xfail mark from test_
Fixes a crash when enabling after a disable with cycle_seconds=0.
2022-07-16 14:19:05 +09:30
Simon Vrouwe 94f16f14b7 test: test_invoices add a stress test 2022-07-16 14:19:05 +09:30
Rusty Russell 401f1debc5 common: clean up json routine locations.
We have them split over common/param.c, common/json.c,
common/json_helpers.c, common/json_tok.c and common/json_stream.c.

Change that to:
* common/json_parse (all the json_to_xxx routines)
* common/json_parse_simple (simplest the json parsing routines, for cli too)
* common/json_stream (all the json_add_xxx routines)
* common/json_param (all the param and param_xxx routines)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 12:24:00 -05:00
Rusty Russell ec76ba3895 lightningd/connect_control: remove param_tok from connect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 12:24:00 -05:00
Rusty Russell 9685c1adaf lightningd: remove getsharedsecret.
This was introduced to allow creating a shared secret, but it's better to use
makesecret which creates unique secrets.  getsharedsecret being a generic ECDH
function allows the caller to initiate conversations as if it was us; this
is generally OK, since we don't allow untrusted API access, but the commando
plugin had to blacklist this for read-only runes explicitly.

Since @ZmnSCPxj never ended up using this after introducing it, simply
remove it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: JSONRPC: `getsharedsecret` API: use `makesecret`
2022-07-15 22:17:58 +09:30
Rusty Russell c34a0a22ad makesecret: change info_hex arg to simply "hex" to match datastore command.
And fix schema: it wasn't tested as there was no test-by-parameter-name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-15 22:17:58 +09:30
niftynei 769efe8d54 tests: massively speed up our wait for enormous feerates
We do smoothing, waiting for this to hit the target (50k+) was taking
longer than my TIMEOUT=15; here we increase the speed at which it hits
exit velocity, so to speak.
2022-07-15 22:16:27 +09:30
niftynei f2e7e9d919 coin-moves: only log htlc_timeout pair for penalty txs
We cleanup our output tracking for timeout txs when the peer's
htlc_timeout self-expiry is hit; we'd also log its spend if happen to
see it get spent.

This is a bit of a race as they can't spend it until the locktime is
available. Hence the flakiness in tests that expected the `htlc_timeout`
to *not* be spent.

Instead, we only log an external's `htlc_timeout` spend in the case
where we also immediately register another output to track for it (only
happens when said htlc is stealable)

Fixes #5405
In-Collab-With: @ddustin
2022-07-15 22:16:27 +09:30
niftynei d284b98911 notify: `channel_state_changed` now receives notice when channel opens
Previously we wouldn't notify when a channel moves into state
"CHANNELD_AWAITING_LOCKIN", as this is the original state (so there's
no movement btw states). This meant that it's impossible to track when a
channel's commitment txs have been exchanged and we're waiting for
onchain confirmation.

It's useful to have notice of this initialization though, all in one
place so that the `channel_state_changed` notification can successfully
track the entire lifecycle of a channel, from inception to close.

Note that for v2 "dual-funded" channels, we already notify at the same place, at
"DUALOPEND_AWAITING_LOCKIN" (the initial state for a dualopend channel
is "DUALOPEND_OPEN_INIT" -- this is the only state we don't get notified
at now...)

Changelog-Added: Plugins: `channel_state_changed` now triggers for a v1 channel's initial "CHANNELD_AWAITING_LOCKIN" state transition (from prior state "unknown")
2022-07-14 12:42:48 -05:00
Rusty Russell bdefbabbef lightningd: re-transmit all closing transactions on startup.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-14 12:40:57 -05:00
Rusty Russell d544ae075b pytest: test (failing) that we rexmit closing transactions on startup.
Usually bitcoind will have them, but it's best to re-xmit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-14 12:40:57 -05:00
adi2011 7b160b203a tests: Add tests for the RPCs
Changelog-Added: Static channel backup, to enable smooth fund recovery in case of complete data loss
2022-07-14 12:24:48 -05:00
niftynei 95ec897ac0 dual-fund: Fail if you try to buy a liquidity ad w/o dualfunding on
Fixes #5271

In-Collaboration-With: Base58 'n Coding Seminar Participants

Changelog-Changed: `fundchannel` now errors if you try to buy a liquidity ad but dont' have `experimental-dual-fund` enabled
2022-07-13 12:29:50 -05:00
Rusty Russell 1217f479df sendpay: allow route to contain both amount_msat and (deprecated) msatoshi.
Since it's a deprecation, we simply ignore one, rather than properly
checking they match etc.

Fixes: #5386
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-12 12:42:05 -05:00
Rusty Russell 1d78911b29 pytest: test that we allow both msatoshi and amount_msat is route for sendpay.
We deprecated msatoshi, but getroute() still returns both (unless
--allow-deprecated-apis=False), so we need to accept both.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-12 12:42:05 -05:00
Rusty Russell f98df63b75 Revert "pytest: fix test_gossip_no_backtalk flake."
This reverts commit 6cc4858847.

No longer needed now we don't flush gossip rcvd_filter as aggressively.
2022-07-12 21:41:19 +09:30
Rusty Russell 06e1e119aa pytest: fix test_gossip_no_empty_announcements flake.
This is a side-effect of fixing aging: sometimes, we age our
rcvd_filter cache too fast, and thus re-xmit.  This breaks
our test, since it used dev-disconnect on the channel_announce,
but that closes to l3, not l1!

```
>       assert l1.rpc.listchannels()['channels'] == []
E       AssertionError: assert [{'active': T...ags': 1, ...}] == []
E         Left contains 2 more items, first extra item: {'active': True, 'amount_msat': 100000000msat, 'base_fee_millisatoshi': 1, 'channel_flags': 0, ...}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #5403
2022-07-12 21:41:19 +09:30
Rusty Russell 312751075c lightningd: save outgoing information for more forwards.
There's one case where we can present more infomation, so do that, and
fix documentation.

Changelog-Added: JSON-RPC: `listforwards` now shows `out_channel` in more cases: even if it couldn't actually send to it.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #5329
2022-07-12 06:38:11 +09:30
Rusty Russell 980f3bda1f pytest: test that listforwards gives as much outgoing information as possible.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-12 06:38:11 +09:30
Simon Vrouwe 7115611249 pytest: test plugin does not register same option "name" 2022-07-10 21:09:41 -05:00
Simon Vrouwe 981fd2326a lightningd: convert plugin->cmd to absolute path, fail plugin early when non-existent
Otherwise different relative paths (e.g. /dir/plugin and /dir/../dir/plugin) to same plugin
executable would not be recognized as the same plugin
2022-07-10 21:09:41 -05:00
Rusty Russell 9d1b5a654e pytest: fix flake in test_node_reannounce
Fixes 25699994e5 (pytest: fix flake in test_node_reannounce).

Converting ->set->list does not give deterministic order, so we can
end up with the two lists differing due to order:

```
 May send its own announcement *twice*, since it always spams us.
        msgs2 = list(set(msgs2))
>       assert msgs == msgs2
E       AssertionError: assert ['01012ff5580...000000000000'] == ['01014973d81...000000000000']
E         At index 0 diff: '01012ff55800f5b9492021372d74df4d6547bb0d32aec8d4c932a8c3b044e4bd983c429154e73091b0a2aff1cf9bbf16b37e6e9dd10ce4c2d949217366472acd341b0007800000080269a262bbd1750266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c035180266e453454e494f524245414d000000000000000000000000000000000000000000000000' != '01014973d8160dd8fc28e8fb25c40b9d5c68aed8dfb36af9fc13e4d2040fb3718553051a188ce98239c0bed138e1f8713a64acc7de98c183c9597fa58bf37f0b89bb0007800000080269a262bbd16c022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59022d2253494c454e544152544953542d336333626132392d6d6f6464656400000000000000'
E         Full diff:
E           [
E         +  '01012ff55800f5b9492021372d74df4d6547bb0d32aec8d4c932a8c3b044e4bd983c429154e73091b0a2aff1cf9bbf16b37e6e9dd10ce4c2d949217366472acd341b0007800000080269a262bbd1750266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c035180266e453454e494f524245414d000000000000000000000000000000000000000000000000',
E            '01014973d8160dd8fc28e8fb25c40b9d5c68aed8dfb36af9fc13e4d2040fb3718553051a188ce98239c0bed138e1f8713a64acc7de98c183c9597fa58bf37f0b89bb0007800000080269a262bbd16c022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59022d2253494c454e544152544953542d336333626132392d6d6f6464656400000000000000',
E         -  '01012ff55800f5b9492021372d74df4d6547bb0d32aec8d4c932a8c3b044e4bd983c429154e73091b0a2aff1cf9bbf16b37e6e9dd10ce4c2d949217366472acd341b0007800000080269a262bbd1750266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c035180266e453454e494f524245414d000000000000000000000000000000000000000000000000',
E           ]
``

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-09 12:27:05 +09:30
Rusty Russell 7dd8e27862 connectd: don't insist on ping replies when other traffic is flowing.
Got complaints about us hanging up on some nodes because they don't respond
to pings in a timely manner (e.g. ACINQ?), but that turned out to be something
else.

Nonetheless, we've had reports in the past of LND badly prioritizing gossip
traffic, and thus important messages can get queued behind gossip dumps!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: connectd: give busy peers more time to respond to pings.
2022-07-09 12:27:05 +09:30
Rusty Russell 6cc4858847 pytest: fix test_gossip_no_backtalk flake.
Because we expire cache every flush, in DEVELOPER mode that can happen in
just over a second.  If gossipd takes a while to process the gossip,
this can mean we actually forget we received it from the peer.

Easiest fix is to run this test in non-DEVELOPER mode.

```       # With DEVELOPER, this is long enough for gossip flush.
        time.sleep(2)
>       assert not l3.daemon.is_in_log(r'\[OUT\] 0100')
E       AssertionError: assert not '2022-06-30T06:00:31.031Z 022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-connectd: [OUT] 0100294834e94aa2407ace65373c84c2a8056d67a6778c22bd43f03a9000d8a01f075c3996ab6c88951bd9805adbfde78292022d7514ffcec37d5e466ef5ebd235c87ffa8a8567904502cd65ae913dbb8014509f442a6e37b00fd59fa3a06811a4965f45df1612d3a32b2566001430cfec4346cc021bd0a1bf6a87417dbc29e0715f16c4f9dc5a01bff07368ba8f54cf9813c3fc8f9f8b8c8005da2a18021f322a9a168af8f82d9deba49ced51bb26a9abc001bbad314a15baccc87c685e9302533c2e86a7b9dfe90bd4cb6be5c2da375be8c4a535a63cacff0544957a34ca865fdb61f9198d19dfd990a0fcbf8de39fa2c0fc54435c16e74df2b49fe3b6e905d599000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0000670000010001022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d590266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c0351802e3bd38009866c9da8ec4aa99cc4ea9c6c0dd46df15c61ef0ce1f271291714e5702324266de8403b3ab157a09f1f784d587af61831c998c151bcc21bb74c2b2314b'
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-09 09:59:52 +09:30
Rusty Russell 6aec374674 lightningd: make log-prefix actually prepend all log messages as expected.
It actually only sets the prefix for the lightningd core log messages;
the other logs have their own prefix.

Make it a real, process-wide prefix which actually goes in front of the timestamp.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: options: `log-prefix` now correctly prefixes *all* log messages.
2022-07-09 09:59:52 +09:30
Rusty Russell ae49545875 pytest: fix flake in test_option_upfront_shutdown_script
Looking at the CI logs, it seems like it took over 5 seconds, so
the unilateral close occurred instead of the expected rejection
of the WIRE_SHUTDOWN reply.  Make it bulletproof.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-07-09 09:59:52 +09:30
Rusty Russell f6f1844e15 options: let log-level subsystem filter also cover nodeid.
That's useful for "tell me everything about this node" debugging.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #5348
Changelog-Added: lightningd: `log-level=debug:<partial-nodeid>` supported to get debug-level logs for everything about a peer.
2022-07-09 09:59:52 +09:30
niftynei 0374fc16ac df tests: node still correctly picks up new tx if broadcast fails
Now that we're more broadcast failure aware, let's check that on
actual broadcast failure we still update UTXO set properly and the
channel opens.
2022-07-08 19:21:11 +09:30
niftynei d0937a2e97 df: check mempool/block for funding output on broadcast fail
If we can't broadcast the tx, confirm that it didn't end up in the
mempool or the utxo set before throwing an error.

Note that this doesn't protect us in the case where the funding
output has already been *spent*... but that's extremely rare, right?

Fixes #5296

Reported-By: @rustyrussell
Collab-With: @vincenzopalazzo
2022-07-08 19:21:11 +09:30
Alex Myers 87a66c1802 gossipd: store and index most recent and last non-rate-limited gossip
This grows the routing state in order to index both okay-to-broadcast
and rate-limited gossip. The gossip_store also logs the rate-limited
gossip if useful. This allows the broadcast of the last non-rate-limited
gossip.
2022-07-06 14:31:19 +09:30
Alex Myers 08a2b3b86c pytest: test_gossip_ratelimit checks routing graph and squelch 2022-07-06 14:31:19 +09:30
Alex Myers cbafc0fa33 gossip_store: add flag for spam gossip, update to v10
This will be used to decouple internal use of gossip from what is
passed to gossip peers. Updates GOSSIP_STORE_VERION to 10.

Changelog-Changed: gossip_store updated to version 10.
2022-07-06 14:31:19 +09:30
Christian Decker db61b048a9 zeroconf: Announce the channel with the real scid as well as aliases
With zeroconf we have to duplicate the `local_channel_announcement`
since we locally announce the aliased version, and then on the first
confirmation we also add the funding scid version.
2022-07-04 22:14:06 +02:00
Christian Decker b195e6d9d4 pytest: Add test for zeroconf channels transitioning to be public
We need to switch to the real short_channel_id at 6 confirmations, and
gossip messages should reflect that in order to be valid to others.
2022-07-04 22:14:06 +02:00
Christian Decker 306d26357e pytest: Add test for forwarding over zeroconf channels 2022-07-04 22:14:06 +02:00
Christian Decker df739956ab pytest: Add a test for direct payment over zeroconf channels 2022-07-04 22:14:06 +02:00
Christian Decker 8609f9e00d pytest: Test the `mindepth` customizations of `fundchannel` and hook
Just test that we can customize, and we'll add mindepth=0 support in
the next couple of commits.
2022-07-04 22:14:06 +02:00
Christian Decker e4511452ac bolt: Reflect the zeroconf featurebits in code 2022-07-04 22:14:06 +02:00
Vincenzo Palazzo 2754e30269 devtools: revert changes and make sure chainparams always set.
[Also fixes crash with -h, since chainparams was not set! --RR]
2022-06-28 06:09:01 +09:30
Vincenzo Palazzo 2c9d7484a2 test: introduce the default port function and remove hard coded port 2022-06-28 06:09:01 +09:30
Vincenzo Palazzo 7ff62b4a00 lightnind: remove`DEFAULT_PORT` global definition
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-06-28 06:09:01 +09:30
Rusty Russell 9152b8c424 pytest: fix test_multifunding_feerates
There's a 1 in 256 chance that our signature on the transaction is 70,
not 71 bytes long.  This changes the freerate.  So fix up the weight in
this case, to be the expected weight.

```
@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', "Fees on elements are different")
@pytest.mark.developer("uses dev-fail")
@pytest.mark.openchannel('v1')  # v2 the weight calculation is off by 3
deftest_multifunding_feerates(node_factory, bitcoind):
'''
    Test feerate parameters for multifundchannel
    '''
        funding_tx_feerate = '10000perkw'
        commitment_tx_feerate_int = 2000
        commitment_tx_feerate = str(commitment_tx_feerate_int) + 'perkw'
        l1, l2, l3 = node_factory.get_nodes(3, opts={'log-level': 'debug'})
        l1.fundwallet(1 << 26)
def_connect_str(node):
return'{}@localhost:{}'.format(node.info['id'], node.port)
        destinations = [{"id": _connect_str(l2), 'amount': 50000}]
        res = l1.rpc.multifundchannel(destinations, feerate=funding_tx_feerate,
                                      commitment_feerate=commitment_tx_feerate)
        entry = bitcoind.rpc.getmempoolentry(res['txid'])
        weight = entry['weight']
        expected_fee = int(funding_tx_feerate[:-5]) * weight // 1000
>       assert expected_fee == entry['fees']['base'] * 10 ** 8
E       AssertionError: assert 7000 == (Decimal('0.00007010') * (10 ** 8))
tests/test_connection.py:1982: AssertionError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 25699994e5 pytest: fix flake in test_node_reannounce
Again, our new behaviour of sending our own gossip even before
they ask can confuse our gossip query tests.

In this case, simply eliminate duplicates.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell a677ea404b pytest: fix flake in test_query_short_channel_id
Again, our new behaviour of sending our own gossip even before
they ask can confuse our gossip query tests.

Create a new node, attach it, and perform queries on it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 4970704d24 pytest: fix gossipwith flake harder.
Even though we generally wait until a node has seen the gossip,
that doesn't mean that connectd has processed it!  This means when
we connect it may still send us "old" gossip.

So we set the OPT_GOSSIP_QUERIES bit, which means don't send until we
ask.  But now it sends us WIRE_QUERY_CHANNEL_RANGE, so everyone needs
to filter that out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 3958d59e39 pytest: fix test_channel_lease_post_expiry flake.
Make sure bitcoind gets tx before mining blocks!

```
# l1<->l2 mutual close should work
        chan = l1.get_channel_scid(l2)
        l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
        l1.rpc.close(chan)
        l2.daemon.wait_for_log('State changed from CLOSINGD_SIGEXCHANGE to CLOSINGD_COMPLETE')
        bitcoind.generate_block(2)
        sync_blockheight(bitcoind, [l1, l2])
>       l1.daemon.wait_for_log('Resolved FUNDING_TRANSACTION/FUNDING_OUTPUT by MUTUAL_CLOSE')
tests/test_closing.py:851:
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell fcff21fae5 pytest: allow more time for test_waitblockheight !DEVELOPER.
It actually timed out with the default 60 seconds, just before it
saw the block:

```
2022-06-07T02:16:05.2557049Z         bitcoind.generate_block(1)
2022-06-07T02:16:05.2557300Z         sync_blockheight(bitcoind, [node])
2022-06-07T02:16:05.2557594Z         fut1.result(5)
2022-06-07T02:16:05.2557912Z         assert not fut2.done()
2022-06-07T02:16:05.2558121Z     
2022-06-07T02:16:05.2558370Z         # Trigger two blocks.
2022-06-07T02:16:05.2558689Z         bitcoind.generate_block(1)
2022-06-07T02:16:05.2558941Z         sync_blockheight(bitcoind, [node])
2022-06-07T02:16:05.2559219Z >       fut2.result(5)
2022-06-07T02:16:05.2559350Z 
2022-06-07T02:16:05.2559508Z tests/test_misc.py:2138: 
...
2022-06-07T02:16:05.2586947Z         elif "error" in resp:
2022-06-07T02:16:05.2587398Z >           raise RpcError(method, payload, resp['error'])
2022-06-07T02:16:05.2588026Z E           pyln.client.lightning.RpcError: RPC call failed: method: waitblockheight, payload: {'blockheight': 103}, error: {'code': 2000, 'message': 'Timed out.'}
2022-06-07T02:16:05.2588325Z 
2022-06-07T02:16:05.2588563Z contrib/pyln-client/pyln/client/lightning.py:387: RpcError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 6221ac621d pytest: fix timeout in test_option_types
We were waiting for the start to timeout waiting for the "public key"
message.  Instead, start manually.

Before, this took (with TIMEOUT=30) 97 seconds, after 8 seconds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell d2952576cd pyln-testing: restore proper streaming behaviour for lightningd.
Get it to log direct to stdout, so we see what's happening *as it
happens* rather than as we read it.  We could restore the thread we
were using before, but that added more problems than it solved.

This means that we need the hsm password prompts in the log though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell a0e0dbf229 pyln-testing: use files for stdout and stderr, not threads.
Some flakes are caused by weird races in this code.  Plus, if we
get things to write straight to files, we might see things in
there on post-mortem which happen after the python runner exits.

It's a bit less efficient, but much simpler.  Let's see if it helps!

Some tests need a rework now, since we don't get a failure (except
eventual timeout), but they're simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell bcd050a610 pytest: fix test_ping_timeout flake.
We can hang up due to ping while waiting for channel to become active.
But we don't even need an active channel for this test, so simplify.

```
______________________________ test_ping_timeout _______________________________
[gw1] linux -- Python 3.7.13 /opt/hostedtoolcache/Python/3.7.13/x64/bin/python3

node_factory = <pyln.testing.utils.NodeFactory object at 0x7f132cca8a90>

    @pytest.mark.developer("dev-disconnect required")
    def test_ping_timeout(node_factory):
        # Disconnects after this, but doesn't know it.
        l1_disconnects = ['xWIRE_PING']
    
        l1, l2 = node_factory.line_graph(2, opts=[{'dev-no-reconnect': None,
                                                   'disconnect': l1_disconnects},
>                                                 {}])

tests/test_connection.py:3826: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
contrib/pyln-testing/pyln/testing/utils.py:1493: in line_graph
    self.join_nodes(nodes, fundchannel, fundamount, wait_for_announce, announce_channels)
contrib/pyln-testing/pyln/testing/utils.py:1470: in join_nodes
    nodes[i].wait_channel_active(scids[i])
contrib/pyln-testing/pyln/testing/utils.py:1003: in wait_channel_active
    wait_for(lambda: self.is_channel_active(chanid))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

success = <function LightningNode.wait_channel_active.<locals>.<lambda> at 0x7f132c3ef830>
timeout = 900

    def wait_for(success, timeout=TIMEOUT):
        start_time = time.time()
        interval = 0.25
        while not success():
            time_left = start_time + timeout - time.time()
            if time_left <= 0:
>               raise ValueError("Timeout while waiting for {}", success)
E               ValueError: ('Timeout while waiting for {}', <function LightningNode.wait_channel_active.<locals>.<lambda> at 0x7f132c3ef830>)
```
2022-06-27 17:21:35 +09:30
Rusty Russell 517828adb2 lightningd: don't print nasty message when onchaind fails partially-failed HTLC
1. We set an outgoing htlc's `failonion` when we get a commitment_signed.
2. We don't transfer it to the corresponding incoming HTLC until we send
   commitment_signed and receive revoke_and_ack (meaning, outgoing htlc is
   completely dead).
3. If between these steps we go onchain, onchaind (after 3 blocks) tells us
   to fail the HTLC.
4. hout->failonion is set, but hout->hin has not been failed yet.  We
   do a sanity check and print a nasty message, and fail it with
   WIRE_PERMANENT_CHANNEL_FAILURE instead of relaying the error.

So handle this case explicitly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 353361a05c pytest: test to demonstrate BROKEN message on onchaind htlc close.
We assumed that if the outgoing htlc has failed, we should have always
failed the incoming one.  This is not true, as this testcase demonstrates:

```
lightningd-2: 2022-05-25T04:38:31.449Z DEBUG   035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d-onchaind-chan#2: Sending 1 missing htlc messages
lightningd-2: 2022-05-25T04:38:31.449Z DEBUG   035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d-chan#2: onchain_failed_our_htlc
lightningd-2: 2022-05-25T04:38:31.449Z DEBUG   035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d-chan#2: HTLC id 0 failonion = 0x55cb8bc045d8, failmsg = (nil), preimage = (nil)
lightningd-2: 2022-05-25T04:38:31.449Z **BROKEN** 035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d-chan#2: HTLC id 0 already complete, but ->in not resolved! failonion = 206816a391d3a7666ddd5213914cbb68f5da1fc4a0937e729de5a1990c94d26312caa5f2778e8da0c6bdefc68dd1a3bc28b5b5650fc0bdb3c2247ecca94ed0bbb224c8448c2c71eb1656a8740cadb301bd1ee1c1e774a8fef817352f502e4217b11e93aa6877b88b37afab0e4d4e49ed0385be9ab9a1ab1ac0e3460e41cfafb30ed896cea96e346041919a6c524ce56c3e5f27c7cd78a36b6df221e90a1c6e048c72b4146a5a51885fb70649037fe7ace77a016ae3ec8aee97960d0e5f0582713f671df79d8dee11b82708b6d882ee5adbb328db1938e824110f57ead1b27410bc6f775c7bb4ae40c1768d77a166c9bfda8f634ba0ac4f8a9fe199894dd3754c5ce41c9694544c805ffc177517661f11221dd8dffac60ce1c8c5bf54cda8e5ea44d8ec6b, failmsg = (null), preimage = (null)
lightningd-2: 2022-05-25T04:38:31.449Z **BROKEN** 035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d-chan#2: MISSING incoming fail for 0: failing incoming now
lightningd-2: 2022-05-25T04:38:31.449Z **BROKEN** 0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#1: MISSED incoming fail for 0: failing now
lightningd-2: 2022-05-25T04:38:31.449Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#1: HTLC in 0 RCVD_ADD_ACK_REVOCATION->SENT_REMOVE_HTLC
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell c1a111b68c pytest: wait for stderr, rather than asserting.
Two almost identical assertion fails under CI.  Try waiting.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 2f27aad8d0 pytest: fix flake in test_wallet.py::test_hsm_secret_encryption
Under valgrind, at least, this test fails regularly, and this sleep
fixes it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell b1f393f355 pytest: fix race in test_multichan
We can fail to use larger channel if it's not ready yet:

```
2022-05-23T01:20:05.5325600Z         # Check it used the larger channel!
2022-05-23T01:20:05.5326376Z >       assert before[chan23a_idx]['to_us_msat'] == after[chan23a_idx]['to_us_msat']
2022-05-23T01:20:05.5326961Z E       assert 1000000000msat == 900000000msat
2022-05-23T01:20:05.5327240Z 
2022-05-23T01:20:05.5327621Z tests/test_connection.py:3896: AssertionError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 6247bee11e pytest: try to fix bitcoind socket timeout in test_channel_lease_unilat_closes
Split harder!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

```
 # This can timeout, so do it in four easy stages.
        for i in range(4):
>           bitcoind.generate_block(4032 // 4)

tests/test_closing.py:971: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
contrib/pyln-testing/pyln/testing/utils.py:475: in generate_block
    return self.rpc.generatetoaddress(numblocks, to_addr)
contrib/pyln-testing/pyln/testing/utils.py:372: in f
    res = proxy._call(name, *args)
/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/bitcoin/rpc.py:233: in _call
    response = self._get_response()
/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/bitcoin/rpc.py:263: in _get_response
    http_response = self.__conn.getresponse()
/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/http/client.py:1373: in getresponse
    response.begin()
/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/http/client.py:319: in begin
    version, status, reason = self._read_status()
/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/http/client.py:280: in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <socket.SocketIO object at 0x7f1a4b3702d0>
b = <memory at 0x7f1a4ac51600>

    def readinto(self, b):
        """Read up to len(b) bytes into the writable buffer *b* and return
        the number of bytes read.  If the socket is non-blocking and no bytes
        are available, None is returned.
    
        If *b* is non-empty, a 0 return value indicates that the connection
        was shutdown at the other end.
        """
        self._checkClosed()
        self._checkReadable()
        if self._timeout_occurred:
            raise OSError("cannot read from timed out object")
        while True:
            try:
>               return self._sock.recv_into(b)
E               socket.timeout: timed out
```
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell eb25e08039 pytest: fix port allocation race when nodes restart.
We use ephemeral_port_reserve to grab ports, but this can fail when we
restart a node, since the port can be reallocated at that point.

Attempt to overcome this using a global reserved list (is there a
neater way?).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell d274de2bf4 pytest: fix flake in test_htlc_too_dusty_outgoing
We can sneak the HTLC add in before we do the update_fee which fails:

```
        # the channel should start warning -- too much dust
        inv = l2.rpc.invoice(htlc_val_msat, str(num_dusty_htlcs + 1), str(num_dusty_htlcs + 1))
        with pytest.raises(RpcError, match=r'WIRE_TEMPORARY_CHANNEL_FAILURE'):
>           l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
E           Failed: DID NOT RAISE <class 'pyln.client.lightning.RpcError'>

tests/test_pay.py:2654: Failed
```

From the logs:

```
lightningd-1: 2022-05-20T02:16:40.008Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: NEW:: HTLC LOCAL 14 = SENT_ADD_HTLC/RCVD_ADD_HTLC
lightningd-1: 2022-05-20T02:16:40.010Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: Adding HTLC 14 amount=10000000msat cltv=113 gave CHANNEL_ERR_ADD_OK
lightningd-1: 2022-05-20T02:16:40.012Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: peer_out WIRE_UPDATE_ADD_HTLC
lightningd-1: 2022-05-20T02:16:40.015Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: REPLY WIRE_CHANNELD_OFFER_HTLC_REPLY with 0 fds
lightningd-1: 2022-05-20T02:16:40.026Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: peer_out WIRE_WARNING
lightningd-1: 2022-05-20T02:16:40.029Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-channeld-chan#1: billboard perm: Too much dust to update fee (Desired feerate update 20000)
lightningd-1: 2022-05-20T02:16:40.035Z INFO    022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-chan#1: Peer transient failure in CHANNELD_NORMAL: channeld WARNING: Too much dust to update fee (Desired feerate update 20000)
lightningd-1: 2022-05-20T02:16:40.039Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-lightningd: Will try reconnect in 60 seconds
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 930860c781 pytest: fix flakes in test_gossip_query_channel_range
Nodes now spray their own gossip at the start; this can race with
our query, and they can give us gossip we didn't ask for.

The fix is to always query an uninvolved node: in this case, we
only connected l3 and l4 to test zlib, which is gone, so now we can
remove that and simply always query l4.

```
2022-05-23T01:32:53.4695809Z         # reply_channel_range == 264
2022-05-23T01:32:53.4696416Z >       assert msgs == ['0108'
2022-05-23T01:32:53.4696835Z                         # blockhash
2022-05-23T01:32:53.4697328Z                         + genesis_blockhash
2022-05-23T01:32:53.4697841Z                         # first_blocknum, number_of_blocks, complete
2022-05-23T01:32:53.4698685Z                         + format(0, '08x') + format(65535, '08x') + '01'
2022-05-23T01:32:53.4699245Z                         # encoded_short_ids
2022-05-23T01:32:53.4699859Z                         + format(len(encoded) // 2, '04x')
2022-05-23T01:32:53.4700255Z                         + encoded]
2022-05-23T01:32:53.4700799Z E       AssertionError: assert ['0100194b419...700000010000'] == ['010806226e4...700000010000']
2022-05-23T01:32:53.4710678Z E         At index 0 diff: '0100194b4190af98beedf231901aeda2dcee0e757dd5327219aa007ea6027e769c98665f49e0f99e03b91e80896ed01cd9c4b157c77e908852097d2ba753c6ca01ae41a90a81c9f492c770d9dd35010c702c7c564045cf85a4bf6efaf25cceb9b81b56d1526429d3c60bf1c7ed6a835720730fd7ad1851a937d18aecf8bc3400dd4e0a30d5c4d65999ac39ae6eb3b98d27e3157973598256d2dd4718cd39010a3612580e7f3bba9eda0fb595976f955e345b6affa62fd556f7257a30d54dd87743dc38585e7c31e1ca80b42cf803bd4c1aaa3127351c95de8a4198c46eb0bd7b4ce175a4b51fcaf9676b01806d237758494fcf3d1558279060a0c3b84806a3330c41000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0000700000010000035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d0382ce59ebf18be7d84677c2e35f23294b9992ceca95491fcf8a56c6cb2d9de19903c47b1b2afcfd68c7b86c0976adb9a4f0835bc78242fced745d78433497a867d6021c29746e4136ddff456483df3980c2d0d5f31c93ef5ded564f7294a10d7414aa' != '010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000000000000ffff01001900000068000001000100006900000100000000700000010000'
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell aefcea44a3 pytest: fix flake in test_gossip_timestamp_filter
We didn't get the second channel_announcement in the filter:
```
        # Now choose range which will only give second update.
        msgs = l4.query_gossip('gossip_timestamp_filter',
                               genesis_blockhash,
                               after_12 - backdate,
                               after_23 - after_12 + 1,
                               filters=['0109', '0012'])
    
        # 0x0100 = channel_announcement
        # 0x0102 = channel_update
        # (Node announcement may have any timestamp)
        types = Counter([m[0:4] for m in msgs])
>       assert types['0100'] == 1
E       assert 0 == 1
```

Looking at the gossip store:

```
1089: t=1653008725 channel_announcement: 0100420c13f233d9b461b035257b77704e0003a0280efdbb8f8964bf4c5bd22b8f8b2e205a3c57d7d5f4dcd812cd41be3d8f84c60046c1fd31abefd0985c2263f8f5074bb7dff548ac106dc10ef4485f5921d9b252d094f9518b44a842c1a2c7f98759fa2f8803febeb59e50b65a8f258877e18f6224262e218de38f21438b2112ef0425d64174092bcd8d757f18982c3fb83c8ae2fb5ee88363248e51bdea247cef055a01a17580b60735b82b88fea87dccb724a743beaf4bf3cf578b0da445afcc786fe3b061429f3288e6970819236e97134898ce900b7b61159148d6785e26932e21f1c337cb6f86a16e967e27396b168a19b0d1478c4be2579a9b96aa0125aa000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00006e0000010000022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d02d595ae92b3544c3250fb772f214ad8d4c51425033740a5bcc357190add6d7e7a02d6063d022691b2490ab454dee73a57c6ff5d308352b461ece69f3c284f2c2412
1533: channel_amount: 100000sat
1555: t=1653008725 channel_update: 01022b98e7d680ffa8096d0a2bda62c0b8b3fc975a5f91c0cff0a42a76b37285276c0156581f85c0be2ee0ed7e7003cb67f5d476a7e3714960836b882bb3ad78097406226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00006e00000100006286e955010000060000000000000000000000010000000a0000000005e69ec0
1705: t=1653008729 node_announcement: 010175f8ed9f48db511d43f1da96aa307ccc53a521dcc2f8fb732c6938650e6cc00f672e772134a29e16b723a1e9cf626cf942323bd3fa294befd25430a9395c1fa40007800000080269a26286e959035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d035d2b484f5050494e47464952452d34646636366661000000000000000000000000000000
1866: t=1653008720 channel_update: 010266385083f1d6e554e1701f2456c24212c5aa937f7b090d32d243678b2fe78f7f52ed3626d6cdd52703bf78013bb9d1a621ae5b7d68fc965d29bb94574e340b5606226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00006e00000100006286e950010100060000000000000000000000010000000a00000
```

It's not clear what we times we were querying, but let's make it
clearer by putting a full 10 seconds between them, and making our
queries more exact.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 575b94c1ef pytest: Remove all trace of python's "flaky" module.
Over time, it has cost us more developer cycles than it has gained.
It has hidden intermittant bugs, and allowed cruft to accumulate:
when we eventually tried to figure out what was going wrong, the
actual change which caused it was now stale and forgotten.

This was a particular bane during the connectd rewrite, and I
worked through some issues which had occurred before, but were not
more likely.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-27 17:21:35 +09:30
Rusty Russell 56dde2cb77 lightningd: multiple log-file options allow more than one log output.
I've wanted this for a while: the ability to log to multiple places
at once.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: lightningd: `log-file` option specified multiple times opens multiple log files.
2022-06-27 17:21:35 +09:30
Vincenzo Palazzo d4bc4f6460 signmessage: improve the UX of the rpc command when zbase is not a valid one
Changelog-Fixed: signmessage: improve the UX of the rpc command when zbase is not a valid one

Stacktrace generated with a bad `zbase`

```
lightningd: lightningd/signmessage.c:59: from_zbase32: Assertion `len == tal_bytelen(u8arr)' failed
lightningd: FATAL SIGNAL 6 (version v0.11.1)
0x55b9b1b4e617 send_backtrace
[...]
```

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-06-24 14:02:04 +09:30
Rusty Russell 37403e471c pytest: add (failing) test for db with old Tor v2 address.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-24 10:24:39 +09:30
Rusty Russell 60bd70be85 JSON: deprecate printing msat fields as strings.
This changes many fields: in non-deprecated mode, they're now raw integers.
This was always the intention, but the transition was never completed.

Suggested-By: @ShahanaFarooqui
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: "_msat" fields can be raw numbers, not "123msat" strings (please handle both!)
Changelog-Deprecated: JSON-RPC: "_msat" fields as "123msat" strings (will be only numbers)
2022-06-21 06:52:35 +09:30
Rusty Russell 08d5776ebc lightningd: deprecate `msatoshi` in `sendpay` `route`.
We should be using amount_msat always.  Many tests were not.  Plus,
deprecating it simplifies the code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSONRPC: `sendpay` `route` elements `msatoshi` (use `amount_msat`)
2022-06-21 06:52:35 +09:30
Rusty Russell c3efba16ff JSON: don't print deprecated amount fields any more
A small change in one routine creates a lot of changes!  We actually
recommended moving away from these in v0.7.0 (2019-02-28), but never
deprecated them formally.

Changelog-Deprecated: JSON-RPC: `pay`, `decode`, `decodepay`, `getroute`, `listinvoices`, `listpays` and `listsendpays` `msatoshi` fields (use `amount_msat`).
Changelog-Deprecated: JSON-RPC: `getinfo` `msatoshi_fees_collected` field (use `fees_collected_msat`).
Changelog-Deprecated: JSON-RPC: `listpeers` `channels`: `msatoshi_to_us`, `msatoshi_to_us_min`, `msatoshi_to_us_max`, `msatoshi_total`, `dust_limit_satoshis`, `our_channel_reserve_satoshis`, `their_channel_reserve_satoshis`, `spendable_msatoshi`, `receivable_msatoshi`, `in_msatoshi_offered`, `in_msatoshi_fulfilled`, `out_msatoshi_offered`, `out_msatoshi_fulfilled`, `max_htlc_value_in_flight_msat` and `htlc_minimum_msat` (use `to_us_msat`, `min_to_us_msat`, `max_to_us_msat`, `total_msat`, `dust_limit_msat`, `our_reserve_msat`, `their_reserve_msat`, `spendable_msat`, `receivable_msat`, `in_offered_msat`, `in_fulfilled_msat`, `out_offered_msat`, `out_fulfilled_msat`, `max_total_htlc_in_msat` and `minimum_htlc_in_msat`).
Changelog-Deprecated: JSON-RPC: `listinvoices` and `pay` `msatoshi_received` and `msatoshi_sent` (use `amount_received_msat`, `amount_sent_msat`)
Changelog-Deprecated: JSON-RPC: `listpays` and `listsendpays` `msatoshi_sent` (use `amount_sent_msat`)
Changelog-Deprecated: JSON-RPC: `listforwards` `in_msatoshi`, `out_msatoshi` and `fee` (use `in_msat`, `out_msat` and `fee_msat`)
Changelog-Deprecated: JSON-RPC: `listfunds` `outputs` `value` (use `amount_msat`)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-21 06:52:35 +09:30
Rusty Russell 6afc0affef pytest: don't use deprecated amount fields
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-06-21 06:52:35 +09:30
Rusty Russell fccb11a641 fetchinvoice: amount_msat not msat.
The name in the spec is `msat`, but I don't want to make an API exception.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `fetchinvoice` `changes` `amount_msat`
Changelog-Deprecated: JSON-RPC: `fetchinvoice` `changes` `msat` (use `amount_msat`)
2022-06-21 06:52:35 +09:30
Rusty Russell cd7e784d6f lightningd: change `msatoshi` args to `amount_msat`.
This is consistent with our output changes, and increases consistency.
It also keeps future sanity checks happy, that we only use JSON msat
helpers with '_msat' fields.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `invoice`, `sendonion`, `sendpay`, `pay`, `keysend`, `fetchinvoice`, `sendinvoice`: `msatoshi` argument is now called `amount_msat` to match other fields.
Changelog-Deprecated: JSON-RPC: `invoice`, `sendonion`, `sendpay`, `pay`, `keysend`, `fetchinvoice`, `sendinvoice` `msatoshi` (use `amount_msat`)
2022-06-21 06:52:35 +09:30
Rusty Russell ca69e293d1 coinmvt: don't use msats in fields not called "_msat".
The new msat fields are turned into Millisatoshi, so handle that correctly
too in tests too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: Plugins: `coin_movement` notification: `balance`, `credit`, `debit` and `fees` (use `balance_msat`, `credit_msat`, `debit_msat` and `fees_msat`)
2022-06-21 06:52:35 +09:30
Rusty Russell 36a2491a89 json: fix up msat amounts in non-_msat fields.
We had json_add_amount_msat_only(), which was designed to be used to
print out msat fields, if we had sats.

However, we misused it, so split it into the three different cases:
1. json_add_amount_sat_msat: We are using it correctly, with a field called
   xxx_msat.
2. json_add_amount_sats_deprecated: We were using it wrong, so deprecate
   the old field and create a new one which does end in _msat.
3. json_add_sats: we were using it to hand sats as a JSON parameter to an
   interface, where "XXXsat".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: Plugins: `rbf_channel` and `openchannel2` hooks `their_funding` (use `their_funding_msat`)
Changelog-Deprecated: Plugins: `openchannel2` hook `dust_limit_satoshis` (use `dust_limit_msat`)
Changelog-Deprecated: Plugins: `openchannel` hook `funding_satoshis` (use `funding_msat`)
Changelog-Deprecated: Plugins: `openchannel` hook `dust_limit_satoshis` (use `dust_limit_msat`)
Changelog-Deprecated: Plugins: `openchannel` hook `channel_reserve_satoshis` (use `channel_reserve_msat`)
Changelog-Deprecated: Plugins: `channel_opened` notification `amount` (use `funding_msat`)
Changelog-Deprecated: JSON-RPC: `listtransactions` `msat` (use `amount_msat`)
Changelog-Deprecated: Plugins: `htlc_accepted` `forward_amount` (use `forward_msat`)
2022-06-21 06:52:35 +09:30
pn cff859331d tests: Update expected log prefix length to match truncated log 2022-06-19 16:42:11 +09:30
Michael Schmoock 475e4c9bd9 jsonrpc: adds optional `remote_addr` to listpeers
Changelog-Added: jsonrpc: adds optional `remote_addr` to listpeers
2022-06-17 20:30:16 +09:30
Michael Schmoock a2b75b66ba connectd: use dev_allow_localhost for remote_addr testing
Before this fix, there was the situation where a DEVELOPER=1 node would
announce non-public addresses on mainnet if detected. Since there
are some nodes on the internet that falsely report local addresses
we move this 'testing feature' to 'dev-allow-locahost' nodes.

Changelog-None
2022-06-17 20:30:16 +09:30
Rusty Russell 5735f71e3c gossipd: don't ever use zlib compression on gossip.
This was eliminated this morning in the latest spec.  We still accept them,
we just don't produce them any more.

Changelog-Removed: Protocol: We no longer create gossip messages which use zlib encoding (we still understand them, for now!)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-05-19 09:47:32 +09:30
Alex Myers 80db867a30 pytest: websocket test can tolerate ipv6 address
test_connection.py::test_websocket no longer fails on presence of ipv6
address.
2022-05-04 15:51:17 +02:00
Rusty Russell 98f64fb623 lightningd: don't crash listpeers if we're opening DF channel.
We call out to connectd to activate the peer, and while we do that,
channel->owner is NULL.  A better pattern would be to set up the unsaved
channel once connectd has given us the peer, but this works for now.

Fixes: #5204
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-21 20:45:32 +09:30
Rusty Russell f6e7d0c5dc pytest: add test for crashing listpeers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-21 20:45:32 +09:30
Rusty Russell c110d0b068 pytest: test that node_announcement regeneration works as expected.
We shorten 24 hours to 24 seconds using --dev--fast-gossip-prune.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-21 06:13:55 +09:30
Rusty Russell 3f94b74e07 pytest: don't add extra cln-grpc instance now plugin is builtin
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-13 05:25:00 +09:30
Christian Decker 8717c4e5a2 cln-grpc: Add midstate between configuration and replying to init
This is a bit special, in that it allows us to configure the plugin,
but then still abort startup by sending `init` with the `disable` flag
set.
2022-04-10 14:16:35 +09:30
Christian Decker 9826402c99 cln-grpc: Do not exit if grpc-port is not set
Exiting doesn't mesh well with builtin plugins, so just sit there and
do nothing

Changelog-None
2022-04-10 14:16:35 +09:30
Michael Schmoock 0799328775 pytest: test custom config options for fees and htlc limits 2022-04-05 05:45:04 +09:30
Michael Schmoock 62df569d49 pytest: option disable-ip-discovery 2022-04-05 05:45:04 +09:30
Rusty Russell c1e7c14c46 pytest: test that deduplication for `bolt11` works as expected.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-04 20:26:04 +09:30
Rusty Russell f51a3d8ef7 plugins/pay: always include `bolt11` (and `description`) in listpays.
We were setting it on the root, but that doesn't get handed to
sendpay.  Our schema doesn't *require* bolt11, either, so this was
missed (there could be a *bolt12* instead).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `listpays` always includes `bolt11` or `bolt12` field.
2022-04-04 20:26:04 +09:30
Rusty Russell e47786da04 pay/sendpay: also store description in case bolt11 uses description_hash.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-04 20:26:04 +09:30
Rusty Russell d5c736fe86 pay: require description if bolt11 only has hash.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `pay` has `description` parameter, will be required if bolt11 only has a hash.
Changelog-Deprecated: JSON-RPC: `pay` for a bolt11 which uses a `description_hash`, without setting `description`.
2022-04-04 20:26:04 +09:30
Rusty Russell 6c54e0e7e7 pay: add absolute "maxfee" parameter.
This is what LND does, and it's better for upper layers than trying to
twist our maxfeepercent / exemptfee heuristics to suit.

(I don't remember who complained about this, sorry!)

I'm doing this now because I want to add YA parameter next!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `pay` has new parameter `maxfee` for setting absolute fee (instead of using `maxfeepercent` and/or `exemptfee`)
2022-04-04 20:26:04 +09:30
Rusty Russell 92028ebaee plugins/pay: remove legacypay.
I think the new pay command has proven itself in the last 18 months!

Also various pay tests took "compat" then didn't use it, so clean them
up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: JSON-RPC: `legacypay` (`pay` replaced it in 0.9.0).
2022-04-04 20:26:04 +09:30
Rusty Russell 591a51ca6a pytest: fix invalid invoice() call.
Trips on our RPC checking introduced at the same time: msat should be
an integer or an "xxxmsat"/sat/btc string.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-04 20:26:04 +09:30
Rusty Russell 5a1e58f0dc pytest: fix RUST=0 pytest.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Christian Decker 241a891190 cln-rpc: Yet more RPC methods being mapped
- disconnect
 - feerates
 - getroute
 - listforwards
 - listpays
 - ping
 - signmessage
2022-04-02 09:46:01 +10:30
Christian Decker 33960be040 cln-rpc: Test that we forward errors correctly
So far we were papering over the actual error with a generic string
that isn't very useful. Now we decode the error and forward it through
the grpc layer as well (though still as a string).
2022-04-02 09:46:01 +10:30
Rusty Russell c1ee32027d pyln-testing: check the request schemas.
This means suppressing schemas in some places too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Rusty Russell 1b6f4e7026 pytest: don't hand a string for an integer value.
lightningd is happy, but our schema won't be.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Rusty Russell 5d8fc84675 pyln-testing: add dev-invoice.
This will override the schema later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Rusty Russell 26bee7a2ab pyln-testing: add dev-pay.
This will override the schema later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Rusty Russell 9784fa816f lightningd: deprecate invoice expiry suffixes.
Makes types harder, and I've never personally used them.

Changelog-Deprecated: JSON-RPC: `invoice` `expiry` no longer allowed to be a string with suffix, use an integer number of seconds.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Rusty Russell bf4d9e30d2 fundpsbt: deprecate reserve=true/false usage.
Make it always a number; this makes the JSON request specification
simpler.  We allowed a number since v0.10.1.

(reserve=True is the default anyway, so usually it can be omitted:
reserve=False becomes reserve=0).

Changelog-Deprecated: JSON-RPC: `fundpsbt`/`utxopsbt` `reserve` must be a number, not bool (for `true` use 72/don't specify, for `false` use 0).  Numbers have been allowed since v0.10.1.
2022-04-02 09:46:01 +10:30
Rusty Russell 3feb634d31 pytest: fix if no rust installed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:46:01 +10:30
Christian Decker bba68e2136 cln-grpc: Map AmountOrAll and AmountOrAny 2022-04-02 09:46:01 +10:30
Rusty Russell 01e5f1886e pytest: fix flake in test_multichan.
I have a separate branch which fixes this race properly, but it's not anything
to do with this PR.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:40:18 +10:30
Rusty Russell 1c685ce3e8 plugins/pay: send payment_metadata if provided in invoice.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: `pay` (and decode, etc) supports bolt11 payment_metadata a-la https://github.com/lightning/bolts/pull/912
2022-04-02 09:40:18 +10:30
Rusty Russell e01abf0b34 bolt11: support payment_metadata.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:40:18 +10:30
Rusty Russell 2526e804f7 doc: big BOLT update to incorporate warnings language.
We do this (send warnings) in almost all cases anyway, so mainly this
is a textual update, but there are some changes:

1. Send ERROR not WARNING if they send a malformed commitment secret.
2. Send WARNING not ERROR if they get the shutdown_scriptpubkey wrong (vs upfront)
3. Send WARNING not ERROR if they send a bad shutdown_scriptpubkey (e.g. p2pkh in future)
4. Rename some vars 'err' to 'warn' to make it clear we send a warning.

This means test_option_upfront_shutdown_script can be made reliable, too,
and it now warns and doesn't automatically close channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-04-02 09:40:18 +10:30
Rusty Russell 9f06a59e3c shutdown: don't allow shutdown to p2pkh or p2sh addresses for anchor outputs.
This doesn't have an effect now (except in experimental mode), but it
will when we support anchors.  So we deprecate the use of those in the
close command too.

For experimental mode we have to avoid using p2pkh; adapt that test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `shutdown` no longer allows p2pkh or p2sh addresses.
2022-04-02 09:40:18 +10:30
Rusty Russell 2f7f7ec255 lightningd: add "style" to listforwards.
Suggested-by: @t-bast
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `listforwards` has new entry `style`, currently "legacy" or "tlv".
2022-03-31 19:38:05 +10:30
Rusty Russell 116a77f1be lightningd: Restore forwarding of legacy onions.
Partial revert of 43a833e405
"lightningd: remove support for legacy onion format."; we restore the
ability to decode legacy onions for forwarding, but not to generate them.
(We don't accept them properly since making payment_secret compulsory
anyway, so no real change there!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: Protocol: ... but we still forward legacy HTLC onions for now.
2022-03-31 19:38:05 +10:30
Rusty Russell 141d4ef675 pytest: test legacy onion acceptance.
Using a canned sendonion call from an old version (v0.10.2), where I
forced it to use legacy onion for l2.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-31 19:38:05 +10:30
Rusty Russell 5033e22835 pytest: make test_onchain_close_upstream more accurately reflect report.
1. Don't use dust HTLCs.
2. Make l3 unresponsive, like report.
3. Make l2-l3 fail because we time out on successive HTLC.

We use sendpay rather than pay, because pay can do multiple attempts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-31 13:40:27 +10:30
Rusty Russell 1e08c3b882 pytest: simple "does onchaind on missing HTLC cause upstream failure" test.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-31 13:40:27 +10:30
Rusty Russell 0c3aa355db tests: add test that pay gets update correct.
This is the part which works: we have another old PR (or simply
uncomment the FIXME section) for the routehint case.

Closes: #4781
See-also: #4808
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-30 14:18:39 +10:30
Rusty Russell ae5b98a727 pytest: fix flake due to cln-grpc starting before "public key" message.
e.g.
```
lightningd-1: 2022-03-28T11:02:12.476Z DEBUG   plugin-cln-grpc: add_pem_file processed 1 valid and 0 invalid certs
lightningd-1: 2022-03-28T11:02:12.478Z DEBUG   plugin-cln-grpc: Connecting to \"lightning-rpc\" and serving grpc on 0.0.0.0:36331
lightningd-1: 2022-03-28T11:02:12.478Z DEBUG   connectd: REPLY WIRE_CONNECTD_ACTIVATE_REPLY with 0 fds
lightningd-1: 2022-03-28T11:02:12.478Z INFO    lightningd: --------------------------------------------------
lightningd-1: 2022-03-28T11:02:12.478Z INFO    lightningd: Server started with public key
```

Which means we don't see it, since start() swallows it:

```
>               raise TimeoutError('Unable to find "{}" in logs.'.format(exs))
E               TimeoutError: Unable to find "[re.compile('serving grpc on 0.0.0.0:')]" in logs.
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-30 12:15:55 +10:30
Christian Decker 09ee28cb51 cln-grpc: Do not start unless a `grpc-port` is specified
For now we don't want to autostart.

Suggested-by: Rusty Russell <@rustyrussell>
2022-03-30 12:15:55 +10:30
Christian Decker dd66c85fcb grpc-plugin: Make the grpc port to listen on configurable
Changelog-Added: cln-grpc-plugin: The plugin can be configured to listen on a specific port using the `grpc-port` option
2022-03-30 12:15:55 +10:30
Christian Decker f5147bbf1e pytest: Add a test for incorrect credentials
If we aren't using the correct certificates we should reject the
connections during the mTLS connection setup. This test tries to
connect with the wrong client cert to the node, and the server will
reject it.
2022-03-30 12:15:55 +10:30
Christian Decker 27e468d2ae grpc-plugin: Generate mTLS certificates and use them in grpc 2022-03-30 12:15:55 +10:30
Christian Decker d221c9b491 pytest: Add a test for the grpc plugin
Currently still unencrypted, but will get its mTLS authentication in
the next commits.
2022-03-30 12:15:55 +10:30
Rusty Russell 20392ae526 connectd: restore obs2 onion support.
I removed these prematurely: we *haven't* had a release since
introducing them!

This consists of reverting d15d629b8b
"plugins/fetchinvoice: remove obsolete string-based API." and
plugins/fetchinvoice: remove obsolete string-based
API. "onion_messages: remove obs2 support."

Some minor changes due to updated fromwire_tlv API since they
were removed, but not much.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: REVERT: Removed backwards compat with onion messages from v0.10.1.
2022-03-29 10:55:12 +10:30
Rusty Russell aad4495f56 delinvoice: allow desconly arg to only remove the description.
Means that field is now optional in JSON output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `delinvoice` has a new parameter `desconly` to remove description.
2022-03-29 10:04:16 +10:30
Rusty Russell ccaf04d268 invoice: add deschashonly parameter.
LNURL wants this so they can include images etc in descriptions.

Replaces: #4892
Changelog-Added: JSON-RPC: `invoice` has a new parameter `deschashonly` to put hash of description in bolt11.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-29 10:04:16 +10:30
Rusty Russell 7829f2eb06 onion_messages: remove obs2 support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: Removed backwards compat with onion messages from v0.10.1.
2022-03-25 13:55:44 +10:30
Rusty Russell 65f5bb2638 pytest: test for compat code.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-25 13:55:44 +10:30
Rusty Russell 5aa108f176 pytest: fix flake in test_pay.py::test_setchannel_state
The second disconnect could fail, if slow enough:

```
>       l1.rpc.disconnect(l2.info['id'], force=True)

tests/test_pay.py:2067:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
contrib/pyln-client/pyln/client/lightning.py:690: in disconnect
    return self.call("disconnect", payload)
contrib/pyln-testing/pyln/testing/utils.py:639: in call
    res = LightningRpc.call(self, method, payload)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pyln.testing.utils.PrettyPrintingLightningRpc object at 0x7fb139ce87d0>
method = 'disconnect'
payload = {'force': True, 'id': '035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d'}

...
>           raise RpcError(method, payload, resp['error'])
E           pyln.client.lightning.RpcError: RPC call failed: method: disconnect, payload: {'id': '035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d', 'force': True}, error: {'code': -1, 'message': 'Peer not connected'}
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-24 09:53:38 +10:30
Vincenzo Palazzo 53806d1abd cli: make the command line more user friendly.
Also has to fix up tests.

Changelog-Fixed: cli doesn't required anymore to confirm the password if the `hsm_secret` is already encrypted.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-03-24 09:53:38 +10:30
Rusty Russell be75518559 pytest: fix bad gossip flake in test_multifunding_v1_v2_mixed
This was missed in e8d2176e6b.

```
>           raise ValueError(str(errors))
E           ValueError: 
E           Node errors:
E            - lightningd-2: had bad gossip messages
E            - lightningd-3: had bad gossip messages
E           Global errors:

contrib/pyln-testing/pyln/testing/fixtures.py:201: ValueError

...

0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-gossipd: Ignoring future channel_announcment for 105x1x2 (current block 104)
0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-gossipd: Bad gossip order: WIRE_CHANNEL_UPDATE before announcement 105x1x2/0
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell bcf3cef96c pytest: fix flake in test_connection.py::test_opener_feerate_reconnect
Make sure it sees disconnect before reconnect, otherwise the next command
fails since we're now disconnected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 2a80400a0f pytest: fix test_connection.py::test_funding_close_upfront fake
Breaks when there are no peers:

```
>       _fundchannel(l1, l2, amt_normal, None)

tests/test_connection.py:1564: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_connection.py:1535: in _fundchannel
    wait_for(lambda: not has_normal_channels(l2, l1))
contrib/pyln-testing/pyln/testing/utils.py:88: in wait_for
    while not success():
tests/test_connection.py:1535: in <lambda>
    wait_for(lambda: not has_normal_channels(l2, l1))
tests/test_connection.py:1527: in has_normal_channels
    for c in only_one(l1.rpc.listpeers(l2.info['id'])['peers'])['channels']])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

arr = []

    def only_one(arr):
        """Many JSON RPC calls return an array; often we only expect a single entry
        """
>       assert len(arr) == 1
E       AssertionError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 486b1b2481 pytest: fix flake in test_funding_fail
We may not see a disconnect instantly:

```
>       assert len(l2.rpc.listpeers()['peers']) == 0
E       assert 1 == 0
E         +1
E         -0
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell aeeaa14430 pytest: add reconnect and restart to test_multichan.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 8458994a7f pytest: test closing one multichannel works as expected.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 75596b3e0f lightningd: use a better channel if available to next hop.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell debc1b90d3 lightningd: remove checks which prevent us from opening multiple channels.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: we now support opening multiple channels with the same peer.
2022-03-23 13:20:12 +10:30
Rusty Russell 21e1d68e3b lightningd: remove (most) functions to search channels by status.
This is generally verboten now, since there can be multiple.  There are a
few exceptions:

1. We sometimes want to know if there are *any* active channels.
2. Some dev commands still take peer id when they mean channel_id.
3. We still allow peer id when it's fully determined.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `close` by peer id will fail if there is more than one live channel (use `channel_id` or `short_channel_id` as id arg).
2022-03-23 13:20:12 +10:30
Rusty Russell cb5dc48cab lightningd: make setchannelfee handle multiple channels per peer.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 90be2cc104 lightningd: remove some "single active channel" assumptions.
Generally this means converting a lazy "peer_active_channel(peer)" call
into an explicit iteration.

1. notify_feerate_change: call all channels (ignores non-active ones anyway).
2. peer_get_owning_subd remove unused function.
3. peer_connected hook: don't save channel, do lookup and iterate channels.
4. In json_setchannelfee "all" remove useless call to peer_active_channel
   since we check state anyway, and iterate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 7de7b7be61 lightningd: use channel_id when a peer is activated.
Rather than intuiting whether this is a new channel / active channel,
use the channel_id.  This simplifies things and makes them explicit,
and prepares for multiple live channels per peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 2424b7dea8 connectd: hold peer until we're interested.
Either because lightningd tells us it wants to talk, or because the peer
says something about a channel.

We also introduce a behavior change: we disconnect after a failed open.
We might want to modify this later, but we it's a side-effect of openingd
not holding onto idle connections.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell deecedb033 connectd: tell lightningd when disconnect is complete.
This avoids races in our tests where we assume it's sync (and is kind
of nicer).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 10e36e073c openingd: disconnect from peer when an error occurs.
openingd currently holds the connection to idle peers, but we're about
to change that: it will only look after peers which are actively
opening a connection.  We can start this process by disconnecting
whenever we have a negotiation failure.

We could stay connected if we wanted to, but that would be up to
connectd to decide.  Right now it's easier if we disconnect from any
idle peer once it's been active.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 0cba062318 pytest: add test to check we notice remote disconnects.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell fcd0b2eb42 connectd: prepare for multiple subd connections.
We still always have 1, but the infrastructure is now in place.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-23 13:20:12 +10:30
Rusty Russell 5704653d4c setchannel: don't let them advertize htlc_maximum_msat larger than capacity.
And check for the obvious setting min > max.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-22 18:45:41 +10:30
Rusty Russell 999c734bb5 setchannel: add minhtlc
Suggested by @m-schmook, I realized that if we append it later I'll
never get it right: I expect parameters min and max, not max and min!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: you can now alter the `htlc_minimum_msat` and `htlc_maximum_msat` your node advertizes.
2022-03-22 18:45:41 +10:30
Rusty Russell f29890ed66 lightningd: check htlc_maximum_msat of channels for routehints.
We still use the channel hint here (as it's the only option), we just
warn about lack of capacity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-22 18:45:41 +10:30
Rusty Russell 1751b1becc pytest: add checks that pay and getroute respect htlc_maximum_msat.
We need to add some, since our internal representations of
htlc_maximum_msat round up, and we need to disable mpp which succeeds
in getting a payment through by splitting.

We also allow dev_routes to suppress invoice routehints altogether.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-22 18:45:41 +10:30
Rusty Russell 42f91ff2fa lightningd: deprecate setchannelfee, use setchannel in tests.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `setchannelfee` (use `setchannel`).
2022-03-22 18:45:41 +10:30
Rusty Russell 43a833e405 lightningd: remove support for legacy onion format.
As per proposal in https://github.com/lightning/bolts/pull/962

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: protocol: support for legacy onion format removed, since everyone supports the new one.
2022-03-18 09:20:11 +10:30
Rusty Russell 072c4711ec pytest: convert test_sendonion_rpc to modern TLV onion.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-18 09:20:11 +10:30
Rusty Russell 45143cc731 pytest: Remove onion test vectors containing legacy onions.
I thought about fixing them up, but really these should be in
lnprototest anyway.  Turns out they're from the spec, so we should
actually fix them up there.

I moved the vector files into contrib/pyln-proto, since that still
needs them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-18 09:20:11 +10:30
Rusty Russell 0db05f6e9c lightningd: opt_var_onion is now a compulsory feature.
We're about to drop support for legacy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-18 09:20:11 +10:30
Michael Schmoock ef84d6eec5 chore: remove EXPERIMENTAL for rfc #917 remote_addr 2022-03-11 16:42:45 +10:30
Michael Schmoock 07fbc7ef13 pytest: IP address discovery updates node_announcement 2022-03-11 16:42:45 +10:30
Michael Schmoock f1981461ef connectd: ignore private remote_addr on non-DEVELOPER builds
When compiled without DEVELOPER this will now filter out `remote_addr` that
come from localhost. The testcase checks for DEVELOPER to test for correct
function of `remote_addr`.

Also, I renamed "test_connect" to "test_connect_basic" so it can be started
without all the other tests in that file that start with "test_connect..."
2022-03-11 16:42:45 +10:30
Michael Schmoock e92176248e chore: fix typo announcable -> announceable
"announcable" is a common misspelling of "announceable", see:

https://en.wiktionary.org/wiki/announcable
2022-03-11 16:42:45 +10:30
Christian Decker af4eed3787 cln-plugin: Make hooks asynchronous 2022-03-10 10:21:41 +10:30
Christian Decker a7ef38732f cln-plugin: Make rpcmethod handlers async 2022-03-10 10:21:41 +10:30
Christian Decker 60e773239c cln-plugin: Add notification subscriptions and hooks to the plugins
For now hooks are treated identically to rpcmethods, with the
exception of not being returned in the `getmanifest` call. Later on we
can add typed handlers as well.
2022-03-10 10:21:41 +10:30
Christian Decker 8c6af21169 cln-plugin: Add support for synchronous RPC methods
Changelog-Experimental: cln-plugin: Added support for non-async RPC method passthrough (async support coming soon)
2022-03-10 10:21:41 +10:30
Christian Decker 4aba119733 pytest: Use valgrind target suppressions instead of skipping tests
Having a list of very targeted suppressions allows us to still run the
majority of tests with valgrind checking, and not fail when Rust does
some trickery. This is for example the case with `std::sync::Once`
which uses `num_procs` calling out to the cgroups subsystem, sometimes
with a null path.

Suggested-by: Rusty Russell <@rustyrussell>
2022-03-10 10:21:41 +10:30
Christian Decker a1555623bc pytest: Mark Rust-dependent tests as skipped with VALGRIND
`valgrind` reports seems to flag some memory accesses that are ok in
the Rust standard library, which we can consider false positives for
our purposes:

```Valgrind error file: valgrind-errors.69147
==69147== Syscall param statx(file_name) points to unaddressable byte(s)
==69147==    at 0x4B049FE: statx (statx.c:29)
==69147==    by 0x2E2DA0: std::sys::unix::fs::try_statx (weak.rs:139)
==69147==    by 0x2D7BD5: <std::fs::File as std::io::Read>::read_to_string (fs.rs:784)
==69147==    by 0x2632CE: num_cpus::linux::Cgroup::param (linux.rs:214)
==69147==    by 0x263179: num_cpus::linux::Cgroup::quota_us (linux.rs:203)
==69147==    by 0x263002: num_cpus::linux::Cgroup::cpu_quota (linux.rs:188)
==69147==    by 0x262C01: num_cpus::linux::load_cgroups (linux.rs:149)
==69147==    by 0x26289D: num_cpus::linux::init_cgroups (linux.rs:129)
==69147==    by 0x26BD88: core::ops::function::FnOnce::call_once (function.rs:227)
==69147==    by 0x26B749: std::sync::once::Once::call_once::{{closure}} (once.rs:262)
==69147==    by 0x139717: std::sync::once::Once::call_inner (once.rs:419)
==69147==    by 0x26B6D5: std::sync::once::Once::call_once (once.rs:262)
==69147==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==69147==
==69147== Syscall param statx(buf) points to unaddressable byte(s)
==69147==    at 0x4B049FE: statx (statx.c:29)
==69147==    by 0x2E2DA0: std::sys::unix::fs::try_statx (weak.rs:139)
==69147==    by 0x2D7BD5: <std::fs::File as std::io::Read>::read_to_string (fs.rs:784)
==69147==    by 0x2632CE: num_cpus::linux::Cgroup::param (linux.rs:214)
==69147==    by 0x263179: num_cpus::linux::Cgroup::quota_us (linux.rs:203)
==69147==    by 0x263002: num_cpus::linux::Cgroup::cpu_quota (linux.rs:188)
==69147==    by 0x262C01: num_cpus::linux::load_cgroups (linux.rs:149)
==69147==    by 0x26289D: num_cpus::linux::init_cgroups (linux.rs:129)
==69147==    by 0x26BD88: core::ops::function::FnOnce::call_once (function.rs:227)
==69147==    by 0x26B749: std::sync::once::Once::call_once::{{closure}} (once.rs:262)
==69147==    by 0x139717: std::sync::once::Once::call_inner (once.rs:419)
==69147==    by 0x26B6D5: std::sync::once::Once::call_once (once.rs:262)
==69147==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==69147==

```
2022-03-10 10:21:41 +10:30
Christian Decker fbcb4c33ad cln-plugin: Populate the options when we get an `init` call 2022-03-10 10:21:41 +10:30
Christian Decker 249fa8675a cln-plugin: Add options to the `getmanifest` call 2022-03-10 10:21:41 +10:30
Christian Decker fe21b89b56 pytest: Add a test for the cln-plugin logging integration 2022-03-10 10:21:41 +10:30
niftynei ecb19ba6f2 coin_mvt: report mutual close outputs also
It's better to report every single utxo on close so we know when
to mark a channel account as definitively closed.
2022-03-05 15:12:12 +10:30
niftynei 7a00277b43 coin_mvt: mark coins destined for wallet w/ originating acct
Only shows up on delayed to us outputs, but nice to have anyway.

It's missing for channel index destined deposits, maybe nice to add at
some point in the future; right now you can figure out which close a
wallet deposit comes from via the channel close txid
2022-03-05 15:12:12 +10:30
niftynei 7bfbe1492a test_close: sync l1 to the blockchain, so that the events are there
Flake on CI coming from `penalty_in/outhtlc` due to the fact that all
the events haven't arrived for the check.

If we wait to sync `l1` as well as `l2`, this should resolve the flake.

        # We use a subset of tags in expected_2 that are used in expected_1
>       tags = check_utxos_channel(l1, [channel_id], expected_1)

tests/test_closing.py:726:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/utils.py:321: in check_utxos_channel
    txid = matchup_events(u_set, evs, chans, tag_list)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

u_set = [[{'account_id': 'external', 'blockheight': 104, 'coin_type': 'bcrt', 'credit': '100000000msat', ...}, None]]
evs = [('external', ['penalty'], None, None), ('external', ['penalty'], None, None), ('external', ['penalty'], None, None)]
chans = ['2722a5fe49a8b5fa4004c19828f3e903632ac02712c6fe78ebea418daad2691f']
tag_list = {'0': '892c64c7d8c8f15d7bdcdcde34b615817d273d2e33d9d775cc9ff38e8e3deeb2', 'A': '1e69d2aa8d41eaeb78fec61227c02a6303e9f32898c10440fab5a849fea52227', 'B': '0e11e2ca01bf5f30b4c54522af172af055dcff8e3810f80a5069a2394cad74b5'}

    def matchup_events(u_set, evs, chans, tag_list):
>       assert len(u_set) == len(evs) and len(u_set) > 0
E       AssertionError
2022-03-01 16:19:34 -06:00
Simon Vrouwe 175e0b54b3 testing: fix flake in test_ping_timeout
[ Folded 2 fixups --RR ]
2022-03-01 09:38:40 +10:30
Simon Vrouwe 84bead9396 pyln-testing: in LightningNode.openchannel, make wait_for_announce more reliable
it now waits for 'alias' in node_announcement, not just block confirms.
more cleanup
2022-03-01 09:38:40 +10:30
Simon Vrouwe 2d06c38997 plugin-funder: fix typos in option lease-fee-base-msat and funder-fuzz-percent
Changelog-Experimental: option `--lease-fee-base-msat` renamed to `--lease-fee-base-sat`

Changelog-Experimental: option `--lease-fee-base-msat` deprecated and will be removed next release
2022-03-01 09:38:40 +10:30
Simon Vrouwe 9bbb52097e lightningd: fix parsing of option dev-force-features
It did not pick-up the last (bolt11) bits set.
2022-03-01 09:38:40 +10:30
Simon Vrouwe 32fb8a42fd testing: cleanup in test_plugin_shutdown 2022-03-01 09:38:40 +10:30
Christian Decker 86b83e473b pytest: Remove 3 stress-tests
These tests have proven to be:

 a) very expensive, as they spin up many nodes, and perform long setup
 b) are not testing anything specific, they just fuzz functionality
    that is already tested otherwise
 c) have not helped pinpoint any issues in living memory
 d) are very flaky, making for really bad signal-to-noise, so much
    that devs usually just restart without even looking at the logs
 e) even if we were to look at the logs, we'd be unable to reproduce
    due to the inherent randomness involved in these tests
 f) are really noisy neighbors, causing other tests to flake as well,
    further muddying the water

All in all, these tests are a waste of time, and source of
frustration.

[ Cleaned up python unused imports --RR ]
Changelog-None
2022-02-26 14:36:50 +10:30
Rusty Russell 1da9b30b9a gossipd: don't send updates in error messages for unannounced channels.
This restores the behaviour prior to `lightningd: use our cached
channel_update for errors instead of asking gossipd.`, where gossipd
would refuse to give us channel_updates for unannounced channels.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-23 14:47:39 +10:30
Rusty Russell 01f2ca4fe7 pytest: remove test_htlc_rexmit_while_closing as too flaky.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-23 14:46:10 +10:30
Michael Schmoock 6db97b4235 pytest: check for remote_addr 2022-02-22 05:45:47 +10:30
Rusty Russell d0c7e18995 bitcoind: importmulti fails (bitcoin master), use importdescriptors
But this requires a watch-only wallet, and python-bitcoinlib doesn't support
multiple wallets, so we need to unload the original one, but then we need
to generate a block, so that can't generate a new address, so we need
an address arg to generate_block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-20 19:29:44 +10:30
Rusty Russell c4ec1d576e pytest: fix test_statictor_onions
It wasn't binding to .onion:<l2.port>, but .onion:9735.  Test both cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-20 19:29:44 +10:30
Rusty Russell 00cbe6959b pytest: YA bitcoind API break.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-20 19:29:44 +10:30
Christian Decker 787350eaa9 pytest: Test the rust bindings from cln-rpc 2022-02-11 16:02:25 +01:00
Rusty Russell bba9525cc3 pytest: note unfixable test_htlc_rexmit_while_closing test.
We really need our own lnprototest tests for packet-based stuff;
these message-based tests are inherently delicate and awkward.

In particular, connectd now does dev-disconnect, so the socket is not
immediately closed after a dev-disconnect command.  In this case, the
WIRE_SHUTDOWN has often already been written from connectd to channeld.

But it sometimes works, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell fc2401c1ac pytest: make test_mpp_adaptive more reliable
If the HTLCs are completely negotiated, we can get a channel break when
we mine a pile of blocks.  This is mainly seen with Postgres, due to the db
speed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell d9b1e69243 dual_funding: don't steal inflight field in update_channel_from_inflight.
If we call update_channel_from_inflight *twice* with the same inflight, we
will get bad results.  Using tal_steal() here was a premature optimization:

```
Valgrind error file: valgrind-errors.496395
==496395== Invalid read of size 8
==496395==    at 0x22A9D3: to_tal_hdr (tal.c:174)
==496395==    by 0x22B4B5: tal_steal_ (tal.c:498)
==496395==    by 0x16A13D: update_channel_from_inflight (peer_control.c:1225)
==496395==    by 0x16A4C7: funding_depth_cb (peer_control.c:1299)
==496395==    by 0x182807: txw_fire (watch.c:232)
==496395==    by 0x182AA9: watch_topology_changed (watch.c:300)
==496395==    by 0x1290ED: updates_complete (chaintopology.c:624)
==496395==    by 0x129BF4: get_new_block (chaintopology.c:835)
==496395==    by 0x125EEF: getrawblockbyheight_callback (bitcoind.c:362)
==496395==    by 0x176ECC: plugin_response_handle (plugin.c:584)
==496395==    by 0x1770F5: plugin_read_json_one (plugin.c:690)
==496395==    by 0x1772D9: plugin_read_json (plugin.c:735)
==496395==  Address 0x89fbb08 is 24 bytes inside a block of size 104 free'd
==496395==    at 0x483CA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==496395==    by 0x22B193: del_tree (tal.c:421)
==496395==    by 0x22B461: tal_free (tal.c:486)
==496395==    by 0x16A123: update_channel_from_inflight (peer_control.c:1223)
==496395==    by 0x16A4C7: funding_depth_cb (peer_control.c:1299)
==496395==    by 0x182807: txw_fire (watch.c:232)
==496395==    by 0x182AA9: watch_topology_changed (watch.c:300)
==496395==    by 0x1290ED: updates_complete (chaintopology.c:624)
==496395==    by 0x129BF4: get_new_block (chaintopology.c:835)
==496395==    by 0x125EEF: getrawblockbyheight_callback (bitcoind.c:362)
==496395==    by 0x176ECC: plugin_response_handle (plugin.c:584)
==496395==    by 0x1770F5: plugin_read_json_one (plugin.c:690)
==496395==  Block was alloc'd at
==496395==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==496395==    by 0x22AC1C: allocate (tal.c:250)
==496395==    by 0x22B1DD: tal_alloc_ (tal.c:428)
==496395==    by 0x22B3A6: tal_alloc_arr_ (tal.c:471)
==496395==    by 0x22C094: tal_dup_ (tal.c:805)
==496395==    by 0x12B274: new_inflight (channel.c:187)
==496395==    by 0x136D4C: wallet_commit_channel (dual_open_control.c:1260)
==496395==    by 0x13B084: handle_commit_received (dual_open_control.c:2839)
==496395==    by 0x13B6AF: dual_opend_msg (dual_open_control.c:2976)
==496395==    by 0x1809FF: sd_msg_read (subd.c:553)
==496395==    by 0x218F5D: next_plan (io.c:59)
==496395==    by 0x219B65: do_plan (io.c:407)
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell e8d2176e6b pytest: protect against bad gossip messages from mining confirms too fast.
If we fund a channel between two nodes, then mine all the blocks to
announce it, any other nodes may see the announcement before the
blocks, causing CI to complain about "bad gossip":

```
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Ignoring future channel_announcment for 113x1x1 (current block 112)
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Bad gossip order: WIRE_CHANNEL_UPDATE before announcement 113x1x1/0
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Bad gossip order: WIRE_CHANNEL_UPDATE before announcement 113x1x1/1
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Bad gossip order: WIRE_NODE_ANNOUNCEMENT before announcement 032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e
```

Add a new helper for this case, and use it where there are more than 2 nodes.

Cleans up test_routing_gossip and a few other places which did this manually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell 6d9f6ffd67 pytest: make test_gossip_no_empty_announcements more robust.
Don't assume gossip send order: explicitly disconnect and reconnect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell f7f9f35f2a pytest: remove flake in test_upgrade_statickey_onchaind
We were relying on the fee update to create an additional tx.  That's
ugly; do an actual payment and make sure we definitely complete a new
tx by waiting for that *then* both revoke_and_ack.

(Without this, we could get a unilateral close instead of a penalty).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell 1c71c9849b connectd: handle custom messages.
This is neater than what we had before, and slightly more general.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON_RPC: `sendcustommsg` now works with any connected peer, even when shutting down a channel.
2022-02-08 11:15:52 +10:30
Rusty Russell 0ac5c4f8df pytest: ignore pings when doing query_gossip.
Next patch starts a timeout ping, which can interfere with results.

In theory, we should reply, but in practice (so far!) we seem to get enough
time that it doesn't hang up on us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell 5065bd6fc2 lightningd: use our cached channel_update for errors instead of asking gossipd.
We also no longer strip the type off: everyone handles both forms, and
Eclair doesn't strip (and it's easier!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell 430a380e35 gossipd: feed lightningd the channel_updates as soon as we make them.
Even if we're deferring putting them in the store and broadcasting them,
we tell lightningd so it will use it in any error messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-08 11:15:52 +10:30
Rusty Russell c0e3155bb6 pytest: update elements for new, more accurate feerate calc.
And skip some tests: I'd simply be pasting in the results, which is
not very useful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-27 12:22:36 +01:00
Rusty Russell de28bbd792 closingd, lightningd: use bitcoin_tx_2of2_input_witness_weight
This fixes lightningd's chronic weight underestimate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: closingd: more accurate weight estimation helps mutual closing near min/max feerates.
2022-01-27 12:22:36 +01:00
Rusty Russell 169c113d15 pytest: test that our closingd tx weight estimate is correct.
Compare against lightningd's, and the actual tx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-27 12:22:36 +01:00
niftynei 4dafeede5c coin moves: notify when we make deposits to external accounts
The blockheight is zero though, since these aren't included in a block
yet.

We also don't issue an 'external' deposit event if we can tell that the
address you're sending to actually belongs to our wallet (we'll issue a
deposit event when it gets included in a block)
2022-01-26 13:34:45 +10:30
Rusty Russell 16dd091d8b pytest: fix flake in test_upgrade_statickey_fail
```
        l1.rpc.disconnect(l2.info['id'], force=True)
        l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
    
>       l1.daemon.wait_for_log('option_static_remotekey enabled at 2/2')

tests/test_connection.py:3653: 
```

If l2's channeld gets killed (due to reconnect) before it tells
lightningd it got the revoke_and_ack it will need a retransmission
*again*.

This makes the test more robust, and does more checks too. 

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-25 06:26:52 +10:30
Rusty Russell 3281d72169 pytest: clean up test_channel_state_changed_unilateral
OK, now this test makes more sense!  Now we don't ignore errors, we
*will* drop to chain if we reconnect after one side has dropped to
chain.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-25 06:26:52 +10:30
Rusty Russell fc44846e10 pytest: disable test_closing_different_fees for elements temporarily.
There's actually a bug in our closing tx size estimation; I'll do
a separate patch for this, though.

Seems this used to be flaky, now we always flush queues, so it's
more reliably caught.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 3ccb3da2c5 pytest: disable automatic reconnection.
We seem to hit a race between manual reconnect (with address hint) and an automatic
reconnection attempt which fails:

```
 >       l4.rpc.connect(l3.info['id'], 'localhost', l3.port)
...
 E           pyln.client.lightning.RpcError: RPC call failed: method: connect, payload: {'id': '035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d', 'host': 'localhost', 'port': 41285}, error: {'code': 401, 'message': 'All addresses failed: 127.0.0.1:36678: Connection establishment: Connection refused. '}
```

See how it didn't even try the given address?

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 109b3e62e9 pytest: disable tests/test_closing.py::test_onchain_all_dust
Here's the "Normal Tet Config clang-fuzzing" setup where it fails:

```
CC=clang
CONFIGURATOR_CC=clang
CWARNFLAGS=-Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror
CDEBUGFLAGS=-std=gnu11 -g -fstack-protector-strong
COPTFLAGS=
SQLITE3_CFLAGS=
SQLITE3_LDLIBS=-lsqlite3
POSTGRES_INCLUDE=-I/usr/include/postgresql
POSTGRES_LDLIBS=-L/usr/lib/x86_64-linux-gnu -lpq
VALGRIND=0
DEVELOPER=1
EXPERIMENTAL_FEATURES=0
COMPAT=1
```

Here's the truncated test output:

```
        if anchor_expected():
            expected_1['B'].append(('external', ['anchor'], None, None))
            expected_2['B'].append(('external', ['anchor'], None, None))
            expected_1['B'].append(('wallet', ['anchor'], None, None))
            expected_2['B'].append(('wallet', ['anchor'], None, None))
    
        tags = check_utxos_channel(l1, [channel_id], expected_1)
>       check_utxos_channel(l2, [channel_id], expected_2, tags)

tests/test_closing.py:2662: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/utils.py:321: in check_utxos_channel
    txid = matchup_events(u_set, evs, chans, tag_list)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

u_set = [[{'account_id': 'external', 'blockheight': 104, 'coin_type': 'bcrt', 'credit': '0msat', ...}, {'account_id': 'external', 'blockheight': 110, 'coin_type': 'bcrt', 'credit': '0msat', ...}]]
evs = [('external', ['to_them'], None, None), ('external', ['htlc_timeout'], None, None)]
chans = ['8ede62cea34c5196467c68175f70b8915f0edda421c5087a99584d4197cfb6c4']
tag_list = {'A': 'c5b6cf97414d58997a08c521a4dd0e5f91b8705f17687c4696514ca3ce62de8e', 'B': 'bb09b25d6653aeeec188961347ff80e90dca6f4a29cc017856f6585adb8cb468'}

    def matchup_events(u_set, evs, chans, tag_list):
        assert len(u_set) == len(evs) and len(u_set) > 0
    
        txid = u_set[0][0]['utxo_txid']
        for ev in evs:
            found = False
            for u in u_set:
                # We use 'cid' as a placeholder for the channel id, since it's
                # dyanmic, but we need to sub it in. 'chans' is a list of cids,
                # which are mapped to `cid` tags' suffixes. eg. 'cid1' is the
                # first cid in the chans list
                if ev[0][:3] == 'cid':
                    idx = int(ev[0][3:])
                    acct = chans[idx - 1]
                else:
                    acct = ev[0]
    
                if u[0]['account_id'] != acct or u[0]['tags'] != ev[1]:
                    continue
    
                if ev[2] is None:
>                   assert u[1] is None
E                   AssertionError
```
2022-01-20 15:24:06 +10:30
Rusty Russell e366cb17f6 pytest: fix flake in test_reconnect_sender_add1
l1 might split in a commitment_signed before it notices the disconnect, and this test fails:

```
        for i in range(0, len(disconnects)):
            with pytest.raises(RpcError):
                l1.rpc.sendpay(route, rhash, payment_secret=inv['payment_secret'])
>               l1.rpc.waitsendpay(rhash)
E               Failed: DID NOT RAISE <class 'pyln.client.lightning.RpcError'>
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 6115ed02e8 subdaemons: don't stream gossip_store at all.
We now let gossipd do it.

This also means there's nothing left in 'struct per_peer_state' to
send across the wire (the fds are sent separately), so that gets
removed from wire messages too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 029d65cf2e connectd: serve gossip_store file for the peer.
We actually intercept the gossip_timestamp_filter, so the gossip_store
mechanism inside the per-peer daemon never kicks off for normal connections.

The gossipwith tool doesn't set OPT_GOSSIP_QUERIES, so it gets both, but
that only effects one place.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell e37a638c0c connectd: do nagle by packet type.
channeld can't do it any more: it's using local sockets.  Connectd
can do it, and simply does it by type.

Amazingly, on my machine the timing change *always* caused
test_channel_receivable() to fail, due to a latent race.

Includes feedback from @cdecker.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 7a514112ec connectd: do dev_disconnect logic.
As connectd handles more packets itself, or diverts them to/from gossipd,
it's the only place we can implement the dev_disconnect logic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Rusty Russell 8f3b390356 pytest: make test_channel_state_changed_unilateral more robust.
This test started mostly failing (in non-DEVELOPER mode) after the
next patch, due to timing issues.

Handle both cases for now, and we'll add more enhancements later to
things we should be handling more consistently.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-20 15:24:06 +10:30
Michael Schmoock 019b31c522 options: only allow one DNS announcement 2022-01-02 16:01:38 +01:00
Rusty Russell b659fbbdf7 pytest: further deflake test_funding_push.
I also got an error under CI; it seems the sleep() was insufficient.
So try adding a sleep inside the check_coin_moves, which should cover
everyone.

```
                acct_moves = acct_moves[number_moves:]
            else:
>               if not move_matches(m, acct_moves[0]):
E               IndexError: list index out of range
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-30 14:36:55 +10:30
Rusty Russell 70ed47d77a channeld: add dev-disable-commit-after instead of dev-disconnect -nocommit
It was always a hack, but an impossible one once connectd will be
interpreting dev-disconnect!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-30 09:50:40 +10:30
Rusty Russell 888745be16 dev_disconnect: remove @ marker.
Once connectd is doing this, we can't close as soon as we send,
and in fact we can't do 'fail write' either.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-30 09:50:40 +10:30
Rusty Russell 560fa06f42 pytest: disable dev-disconnect blackhole tests.
These would have to be done by connectd, not the local daemon, once it's
intermediating.  Otherwise the remote peer won't see any change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-30 09:50:40 +10:30
niftynei 70a73928cb balance-snaps: add a `balance_snapshot` event; fires after first catchup
Fire off a snapshot of current account balances (node wallet + every
'active' channel) after we've caught up to the chain tip for the *first*
time (in other words, on start).
2021-12-28 04:42:42 +10:30
niftynei f169597a02 test plugins/coin_moves: clean up/tidy coin moves plugin logic
removes unused in-memory stash of coin-moves; don't write the entire set
of coinmoves out on every update.
2021-12-28 04:42:42 +10:30
niftynei 8225a9decf coin_mvt: log events for pushes/lease_fees for leased channels
We need to stash/save the amount of the lease fees on a leased channel,
we do this by re-using the 'push' amount field on channel (which is
technically correct, since we're essentially pushing the fee amount to
the peer).

Also updates a bit of how the pushes are accounted for (pushed to now
has an event; their channel will open at zero but then they'll
immediately register a push event).

Leases fees are treated exactly the same as pushes, except labeled
differently.

Required adding a 'lease_fee' field to the inflights so we keep track of
the fee for the lease until the open happens.
2021-12-28 04:42:42 +10:30
niftynei bddd3694fa coin_mvt: record fees for an outbound htlc
If we initialized the payment, the fees are the entire fee-chain
(final hop amount - starting hop amount)

If it's a payment we routed, the fees are the diff between the
inbound htlc and the outbound (net gain by this routing)

Added to database so data persists nicely.
2021-12-28 04:42:42 +10:30
niftynei 29c6718297 coin_mvt: record new 'fees' field on htlc channel moves
We record the amount of fees collected for a routed payment. For
simplicity's sake on the data agg side, we record the fee payment on
*BOTH* the incoming htlc and the outgoing htlc. Note that this results
in double counting if you add up the fees from both an in-routed and
out-routed payment.
2021-12-28 04:42:42 +10:30
niftynei b6463174d6 coin moves: turn 'tag' into 'tags' array, add OPENER tag
Channels that the node has hopened will now be tagged with 'opener' in a
list of tags.
2021-12-28 04:42:42 +10:30
niftynei 4506f639fa coin_moves: remove 'index' for moves; bump version
Get rid of the 'movement_idx', since we replay events now.

Since we're removing a field from the 'coin_movement' event emission, we
bump the version type.

Changelog-Updated: `coin_movements` events have been revamped and are now on version 2.
2021-12-28 04:42:42 +10:30
niftynei 27ff87c045 coin_moves: de-dupe moves as they come in
test_onchain_dust_out restarts a node, which produces duplicate events.
this is expected, but we need to de-duplicate the events stream to get
accurate results
2021-12-28 04:42:42 +10:30
niftynei d2c4d4aec2 coin_mvts: rewrite how onchain events are recorded, update tests
The old model of coin movements attempted to compute fees etc and log
amounts, not utxos. This is not as robust, as multi-party opens and dual
funded channels make it hard to account for fees etc correctly.

Instead, we move towards a 'utxo' view of the onchain events. Every
event is either the creation or 'destruction' of a utxo. For cases where
the value of the utxo is not (fully) debited/credited to our account, we
also record the output_value. E.g. channel closings spend a utxo who's
entire value we may not own.

Since we're now tracking UTXOs onchain, we can now do more complex
assertions about the onchain footprint of them. The integration tests
have been updated to now use more 'chain aware' assertions about the
ending state.
2021-12-28 04:42:42 +10:30
Vincenzo Palazzo 43ff949ea7 lightningd: support hsm error code
Suggested-by: Rusty Russell
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Changelog-Changed: Support hsm specific error error code in lightning-cli
2021-12-15 12:24:54 +10:30
Rusty Russell 1ac5a1b7e2 pytest: restore gossip advertizement tests for default port.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-14 13:41:31 +10:30
Simon Vrouwe 28816c387c testing: remove test_htlc_accepted_hook_shutdown, move relevant parts
into test_plugin_shutdown

The fact that plugins are kept alive untill the very end also ensures
their hooks are not silently unregistered.
2021-12-14 09:33:10 +10:30
Simon Vrouwe 9b70c9d63b testing: fix flake in test_fetchinvoice_3hop 2021-12-14 09:33:10 +10:30
Michael Schmoock c2d2cc1274 connectd: fix empty error message
1. Adds the missing DNS error massages so they can be handled by
   connect_control.
2. Prepends a 'All addresses failed' to code 401 message, so we
   always have at least some error message to the user.

Changelog-None
2021-12-08 13:52:24 +01:00
Michael Schmoock bad09887e0 pytest: fix test_pluginconnected_hook_chaining
The last line of the testcase was checking on the wrong node l3
instead of l1. l3 didn't had the plugins configured that would
produce the log entry we were looking for not to be present.

Changelog-None
2021-12-06 14:53:37 +01:00
Jan Sarenik 96f28323bd Set default port according to network
The idea is to have different default ports for different networks.

Current default port is `9735` for everything. Let's use it for
the mainnet and reuse the difference added to the default port
from `rpc_port` values in `bitcoin/chainstate.c`.

Testnet would be `19735` (adding rpc_port - 8332 = `10000`).

Signet would be `39735` (adding rpc_port - 8332 = `30000`).

Regtest would be `19846` (adding rpc_port - 8332 = `10111`).

With Vincenzo's kind pair-programming help over tmate.

Two other commits were squashed into this one so that bisecting
never ends up in half-baked state:

1. chainparams: Fix regtest default rpc_port

   bitcoind -help says this:

    -rpcport=<port>
         Listen for JSON-RPC connections on <port> (default: 8332, testnet:
         18332, signet: 38332, regtest: 18443)

2. test_gossip: Default port for regtest

   hex: 2607 is now .... (could be 4d86 but Elements uses another port)
   dec: 9735 is now any port (could be 19846 ^^ but now is for any port)

   The lines which were binding to default port were removed as the
   default port is different on each network.

NOTE: Remember not to modify gossip_store tests which loads everything raw
      including the checksums.

Changelog-Changed: If the port is unspecified, the default port is chosen according to used network similarly to Bitcoin Core.
2021-12-06 17:10:08 +10:30
Rusty Russell 4ffda340d3 check: make sure all files outside contrib/ include "config.h" first.
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30
Rusty Russell bdabef9a9b pytest: fix occasional flake in test_announce_address
We make sure the gossip msg was sent, but the other node might not
have digested it yet:

```
        # Check other node can parse these
>       addresses = l2.rpc.listnodes(l1.info['id'])['nodes'][0]['addresses']
E       KeyError: 'addresses'
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:18 +10:30
Rusty Russell b45544c659 options: fix handling of wildcard (allproto) address.
We treated ':' as an empty DNS name in EXPERIMENTAL, which is wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-05 16:43:09 +01:00
Rusty Russell cf40e585c3 pytest: test to show conflict between websocket and wildcard addresses.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-05 16:43:09 +01:00
Andrew Toth 69bc1191cb tests: add pay test for exclude arg 2021-12-04 21:37:42 +10:30
Rusty Russell 5a5cf8c696 pytest: fix flake in testing.
As noted in 0a406230d0 (diff-5871d4c569454db5e625383975462132da0bd03d32df145d8d72d8fafd86d952R3544-R3546)

Turns out we sometimes hang up before l2 sees the previous tx revoked,
so we get a normal unilateral close, not a cheat.

Reported-by: Simon Vrouwe
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-01 09:48:00 +10:30
Rusty Russell 605b3bf985 pytest: re-enable modern/obsolete fetchonion tests.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-01 05:44:28 +10:30
Rusty Russell b74848f6f6 common: remove support for pre v0.10.2 onionmessages.
Temporarily disable sendpay_blinding test which uses obsolete onionmsg;
there's still some debate on the PR about how blinded HTLCs will work.

Changelog-EXPERIMENTAL: onionmessage: removed support for v0.10.1 onion messages.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-01 05:44:28 +10:30
Simon Vrouwe aae5e7822f testing: fix test_upgrade_statickey_onchaind
Seems a timing issue that should be figured out, his makes the test pass.
2021-11-30 13:34:44 +10:30
Simon Vrouwe 2240f09f8b testing: fix test_closing_higherfee
shutdown_subdaemons frees the channel and calls destroy_close_command_on_channel_destroy, see gdb:

    0  destroy_close_command_on_channel_destroy (_=0x55db6ca38e18, cc=0x55db6ca43338) at lightningd/closing_control.c:94
    1  0x000055db6a8181b5 in notify (ctx=0x55db6ca38df0, type=TAL_NOTIFY_FREE, info=0x55db6ca38e18, saved_errno=0) at ccan/ccan/tal/tal.c:237
    2  0x000055db6a8186bb in del_tree (t=0x55db6ca38df0, orig=0x55db6ca38e18, saved_errno=0) at ccan/ccan/tal/tal.c:402
    3  0x000055db6a818a47 in tal_free (ctx=0x55db6ca38e18) at ccan/ccan/tal/tal.c:486
    4  0x000055db6a73fffa in shutdown_subdaemons (ld=0x55db6c8b4ca8) at lightningd/lightningd.c:543
    5  0x000055db6a741098 in main (argc=21, argv=0x7ffffa3e8048) at lightningd/lightningd.c:1192

Before this PR, there was no io_loop after shutdown_subdaemons and client side raised a
general `Connection to RPC server lost.`
Now we test the more specific `Channel forgotten before proper close.`, which is good!

BTW, this test was added recently in PR #4599.
2021-11-30 13:34:44 +10:30
Simon Vrouwe 89cbdf4dce testing: test that RPC calls made in shutdown fail and receive error code -5
and the two conditions in which plugins can receive shutdown notification
2021-11-30 13:34:44 +10:30
Simon Vrouwe ef503f2fea testing: remove test_stop_pending_fundchannel
Not needed anymore, see previous commit
2021-11-30 13:34:44 +10:30
Simon Vrouwe 5fb3674233 testing: test hook semantics is preserved in shutdown
plugins expect their hooks to work also in shutdown, see issue #4883
2021-11-30 13:34:44 +10:30
Michael Schmoock a3ea9fdc87 chore: use EXPERIMENTAL for BOLT7 DNS #911
Changelog-EXPERIMENTAL: Ability to announce DNS addresses
2021-11-30 09:38:17 +10:30
Michael Schmoock 2b8896a0b5 pytest: test connecting to a DNS only announced node 2021-11-30 09:38:17 +10:30
Michael Schmoock 01e8a523e9 bolt7: allow announcement of ADDR_TYPE_DNS 2021-11-30 09:38:17 +10:30
Rusty Russell 7a6fd70078 pytest: Reduce memory consumption by test_plugin_disable
It runs 6 nodes: under valgrind this ends up consuming 5.3 GB RSS.  By
stopping nodes between, we peak about 1G RSS.

Measured using:
	(while true; do echo $(for i in 4 5 6; do ps uh | tr -s ' ' | cut -d\  -f$i | tally; done); sleep 5; done)&

(Which measures my other processes as well, but that's only about 100M).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-27 12:41:37 +00:00
ZmnSCPxj jxPCSnmZ a294683675 wallet/db_sqlite3.c: Support direct replication of SQLITE3 backends.
ChangeLog-Added: With the `sqlite3://` scheme for `--wallet` option, you can now specify a second file path for real-time database backup by separating it from the main file path with a `:` character.
2021-11-17 12:10:07 +10:30
Rusty Russell 68043c2e8c common: clean up autodata in common_shutdown().
valgrind locally complains about the allocations in autodata leaking:

```
==138200== 16 bytes in 1 blocks are still reachable in loss record 1 of 2
==138200==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==138200==    by 0x10D41A: autodata_register_ (autodata.c:20)
==138200==    by 0x10E7B8: register_autotype_type_to_string (type_to_string.h:79)
==138200==    by 0x10F5CA: register_one_type_to_string0 (block.c:259)
==138200==    by 0x19734C: __libc_csu_init (in /home/rusty/devel/cvs/lightning/common/test/run-route-specific)
==138200==    by 0x4A3D03F: (below main) (libc-start.c:264)
==138200== 
==138200== 176 bytes in 1 blocks are still reachable in loss record 2 of 2
==138200==    at 0x483DFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==138200==    by 0x10D472: autodata_register_ (autodata.c:26)
==138200==    by 0x122D37: register_autotype_type_to_string (type_to_string.h:79)
==138200==    by 0x122F1F: register_one_type_to_string0 (node_id.c:50)
==138200==    by 0x19734C: __libc_csu_init (in /home/rusty/devel/cvs/lightning/common/test/run-route-specific)
==138200==    by 0x4A3D03F: (below main) (libc-start.c:264)
==138200== 
make: *** [Makefile:638: unittest/common/test/run-route-specific] Error 7
```
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-17 10:51:48 +10:30
Rusty Russell 82c66b10df pytest: allow bad gossip in pruning test.
If we forget a channel, we can get upset when we get an update about it:

```
2021-11-04T00:35:43.8242370Z lightningd-3: 2021-11-04T00:29:22.073Z DEBUG   gossipd: Pruning channel 103x1x1 from network view (ages 61 and 22s)
...
2021-11-04T00:35:43.8263502Z lightningd-3: 2021-11-04T00:29:22.509Z DEBUG   022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59-gossipd: Bad gossip order: WIRE_CHANNEL_UPDATE before announcement 103x1x1/0
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-17 10:51:48 +10:30
Rusty Russell 65bb989cf1 pytest: don't checksum plugins on startup in VALGRIND developer mode.
This loads up 20MB of plugins temporarily; we seem to be getting OOM
killed under CI and I wonder if this is contributing.

Doesn't significantly reduce runtime here, but I have lots of memory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-14 18:49:46 +01:00
Rusty Russell 09bbda4bca pytest: don't create 5 nodes in test_fetchinvoice.
CI seems to be OOM killing us; 5 may be too many under valgrind.

VALGRIND=1 pytest tests/test_pay.py::test_fetchinvoice 
Before:
	1 passed in 199.33s (0:03:19)

After:
	1 passed in 177.91s (0:02:57)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-14 18:49:46 +01:00
Rusty Russell 9d18180172 lightningd: really do allow two Torv3 addresses.
This surprised me, since the CHANGELOG for [0.8.2] said:

	We now announce multiple addresses of the same type, if given. ([3609](https://github.com/ElementsProject/lightning/pull/3609))

But it lied!

Changelog-Fixed: We really do allow providing multiple addresses of the same type.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-14 18:49:46 +01:00
Rusty Russell 2f247c7bfb torv2: remove support for advertizing and connecting.
October was the date Torv2 is no longer supported by the Tor Project;
it will probably not work at all by next release, so we should remove
it now even though it's not quite the 6 months we prefer for
deprecation cycles.

I still see 110 nodes advertizing Torv2 (vs 10,292 Torv3); we still
parse and display it, we just don't advertize or connect to it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-14 18:49:46 +01:00
Rusty Russell c00202a0da pytest: remove test_shutdown_alternate_txid.
We're about to require that fundchannel_complete() take a PSBT, where it
does sanity checks to avoid this error, making this a difficult mistake
to make.

Is it time to remove this functionality anyway?  @cdecker?

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-11-14 18:49:46 +01:00
Christian Decker 012c2ecf17 pytest: Create less dust in `test_delpay_payment_split`
We were triggering the dust panic.
2021-10-23 12:59:13 +02:00
niftynei 303fbce479 tests: raise dust limit on mpp test
Fails liquid-regtest otherwise; liquid tends to hit the dust limit
earlier than non-liquid tx, and MPP exacerbates this by divvying up
payments into dusty bits then attempting to shove them through the same
channel, hitting the dust max. The MPP then fails as not all the parts
were able to arrive at their destination.
2021-10-23 12:59:13 +02:00
niftynei b57fed047a dusty htlcs: don't fail the channel, make it error a whole bunch
Let's make this a softer launch by just warning on the channel til the
feerates go back down.

You can also 'fix' this by upping your dust limit with
the `max-dust-htlc-exposure-msat` config.
2021-10-23 12:59:13 +02:00
niftynei 150d065088 tests: check for incoming + outgoing dust limits 2021-10-23 12:59:13 +02:00
niftynei 208b161226 tests: bump the ceiling for dust, fixes failures for liquid
Liquid's threshold for dust is a bit higher, so we bump up the max limit
here so we can actually get the whole MPP'd payment sent over the wire
2021-10-23 12:59:13 +02:00
Rusty Russell ed6eaf9171 experimental-websocket-port: option to create a WebSocket port.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-22 11:56:30 +02:00
Rusty Russell c503232cde common: use bitcoin_outpoint.
I started pulling this thread, and the entire codebase got unravelled.

Oh well, it's done now!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-15 12:09:36 +02:00
Rusty Russell 012dedc3d8 fuzz: make it build again.
How did this pass CI?  I saw this break in my PR, but it's (long)
broken in master.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-15 12:09:36 +02:00
Vincenzo Palazzo 67b790e3dc tests: Change currency from `msat` to `sat` in the regex string
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-10-14 10:09:20 +10:30
Christian Decker cd7d87f98e pay: listpays groups by payment_hash and groupid
Fixes #4482
Fixes #4481

Changelog-Added: pay: Payment attempts are now grouped by the pay command that initiated them
Changelog-Fixed: pay: `listpays` returns payments orderd by their creation date
Changelog-Fixed: pay: `listpays` no longer groups attempts from multiple attempts to pay an invoice
2021-10-13 13:41:18 +10:30
Christian Decker 98f74762a5 pytest: Adjust `test_sendpay` to the new semantics 2021-10-13 13:41:18 +10:30
Christian Decker ce3d3d8e54 pytest: Fix `test_onchain_timeout` to use `groupid` 2021-10-13 13:41:18 +10:30
Christian Decker 428982a9e7 pytest: Add `groupid` to `test_partial_payment_{timeout,restart}` 2021-10-13 13:41:18 +10:30
Christian Decker bc089d3350 pytest: Fix up `test_partial_payment` to use a single `groupid` 2021-10-13 13:41:18 +10:30
Christian Decker 324257b2bf pytest: Reproduce #4482 2021-10-13 13:41:18 +10:30
Rusty Russell c936540e0b pytest: fix flake in test_upgrade_statickey_onchaind
Reconnect manually, don't wait for automatic reconnect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-10 15:32:57 +02:00
Rusty Russell b2206744c0 pytest: fix flake when test reconnects by itself.
If it reconnects by itself, it will get a warning message:

```
lightningd-2: 2021-10-08T01:40:42.446Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-channeld-chan#3: billboard: Sent reestablish, waiting for theirs
lightningd-2: 2021-10-08T01:40:42.446Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-channeld-chan#3: peer_in WIRE_ERROR
lightningd-2: 2021-10-08T01:40:42.447Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-channeld-chan#3: billboard perm: Received error channel 0a6220a3e904d17e72b5c3499928dc8a65720063c6395c999a129a0ff0b06afb: Forcibly closed by `close` command timeout
lightningd-2: 2021-10-08T01:40:42.448Z INFO    0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#3: Peer transient failure in CHANNELD_NORMAL: channeld WARNING: error channel 0a6220a3e904d17e72b5c3499928dc8a65720063c6395c999a129a0ff0b06afb: Forcibly closed by `close` command timeout
```

And this will make CI complain.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-10 15:32:57 +02:00
Rusty Russell c9b82bf1d2 channeld: restore ping command, but only for channeld.
It's probably not worth fixing for the other daemons.

Changelog-Changed: JSON-RPC: `ping` now only works if we have a channel with the peer.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-10 15:32:57 +02:00
Rusty Russell be2622a4ff channeld: perform regular keepalive pings.
Send a ping every 15-45 seconds.  If we try to send another one and we
haven't got a reply, hang up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: Send regular pings to detect dead connections (particularly for Tor).
2021-10-10 15:32:57 +02:00
Rusty Russell 9138ebf807 channeld: remove liveness logic pre-commitment.
We're going to continuously ping, so this is redundant.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-10 15:32:57 +02:00
Rusty Russell 1c85b27b4c gossipd: remove ping/pong handling
To minimize the diffs, we #if 0 the code.  We'll reenable it once
channeld is ready.

We also temporarily disable the ping tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-10 15:32:57 +02:00
Dustin Dettmer 3aa31d7cfd On Mac OS X a different error is raised on failed connection
[ Typo fixed --RR ]
2021-10-10 13:22:29 +02:00
Rusty Russell 7157a92ea6 channeld: import updated channel_upgrade spec.
It now uses raw bitfields instead of a subtype, and only allows a single
option for any upgrade.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-08 16:07:21 +02:00
Rusty Russell 55dbe82162 features: EXPERIMENTAL_FEATURES: advertize option_quiesce
The latest draft has a feature bit here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-08 16:07:21 +02:00
Rusty Russell 45bf7a3974 bolt12: update to latest spec.
Main changes are:
1. Uses point32 instead of pubkey32.
2. Uses issuer instead of vendor.
3. Uses byte instead of u8.
4. blinded_path num_hops is now a byte, not u16 (we don't use that yet!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: bolt12: `vendor` is deprecated: the field is now called `issuer`.
2021-10-08 13:47:30 +02:00
ZmnSCPxj jxPCSnmZ d4690358d9 plugins/libplugin.c: Allow freeing notification `struct command *`.
We always allocate a new `struct command` when we get a full JSON
object from stdin:

b2df01dc73/plugins/libplugin.c (L1229-L1233)

If it happens to be a notification, we pass the `struct command` to
the handler, and not free it ourselves:

b2df01dc73/plugins/libplugin.c (L1270-L1275)

There are only nine points in `plugins/libplugin.c` where we `tal_free`
anything, and only one of them frees a `struct command`:

b2df01dc73/plugins/libplugin.c (L224-L234)

The above function `command_complete` is not appropriate for
notification handlers; the above function sends out a response
to our stdout, which a notification handler should not do.

However, as-is, it does mean that notification handling leaks
`struct command` objects, which can be problematic if we ever
have future built-in plugins which are significantly more
dependent on notifications.

This commit changes notification handlers to return
`struct command_result *`, because possibly in the future
notification handlers may want to perform `send_outreq`, so we
might as well use our standard convention for callbacks, and
to encourage future developers to check how to properly
terminate notification handlers (and free up the
`struct command`).

We also now provide a `notification_handled` function which a
notification handler must eventually call, as well as a
`notification_handler_pending` which is just a snowclone of
`command_still_pending`.
2021-10-08 14:40:04 +10:30
Rusty Russell 09c2fef4a4 onion_message: dev options to ignore obsolete/modern onions.
This lets us test that both work, as expected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-04 11:58:31 +02:00
Christian Decker accaa07dde pytest: Stabilize `test_addgossip`
It was incredibly flaky due to the potential for l2 announcing the
channel before l1 could get to it, thus suppressing the outgoing
announcement which we were looking for. This now checks either
direction.

Before this fix the failure rate was 24% (out of 100 runs), afterwards
it's 0%.

Changelog-None
2021-09-27 17:54:50 +02:00
Rusty Russell 33168fc733 lightningd: provide 10 minutes for channel fee increases to propagate.
This was measured as a 95th percentile in our rough testing, thanks to
all the volunteers who monitored my channels.

Fixes: #4761
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `setchannelfee` gives a grace period (`enforcedelay`) before rejecting old-fee payments: default 10 minutes.
2021-09-23 15:05:09 +02:00
Rusty Russell be8e45b16d pytest: fix flake in test_gossip.py::test_addgossip
We can miss it in both logs, so wait for it instead:

```
2021-09-22T07:25:59.1582950Z >       l3.rpc.addgossip(ann.split()[3])
2021-09-22T07:25:59.1583911Z E       AttributeError: 'NoneType' object has no attribute 'split'
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-23 12:57:07 +02:00
Vincenzo Palazzo 62ef403d20 doc: Update doc with the new parameter supported
Changelog-Added: Support to listpays the status parameter to filter the payments by status.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-22 16:23:24 +09:30
Vincenzo Palazzo fd33aed4b5 rpc: Integrate the status flow in the listsendpays command
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-22 16:23:24 +09:30
Rusty Russell 37ddf2e829 lightningd: rename sendonionmessage to sendobsonionmessage.
sendonionmessage is going to be the new one, and do much *less*.

As this is an internal experimental-only API, no deprecation cycle
required.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-22 06:44:26 +09:30
Rusty Russell 8b694907e6 gossipd: fix blinded onion forwarding.
We never tested that we can correctly unwrap on the next step after
unblinding: it failed because we mangled the onion in place!  Fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-22 06:44:26 +09:30
Rusty Russell 5b644a2319 pytest: ensure hsmtool tests do complete writes.
This may be causing the test flakiness we sometimes see in CI.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-21 20:19:03 +09:30
Rusty Russell 7401b26824 cleanup: remove unneeded includes in C files.
Before:
 Ten builds, laptop -j5, no ccache:

```
real	0m36.686000-38.956000(38.608+/-0.65)s
user	2m32.864000-42.253000(40.7545+/-2.7)s
sys	0m16.618000-18.316000(17.8531+/-0.48)s
```

 Ten builds, laptop -j5, ccache (warm):

```
real	0m8.212000-8.577000(8.39989+/-0.13)s
user	0m12.731000-13.212000(12.9751+/-0.17)s
sys	0m3.697000-3.902000(3.83722+/-0.064)s
```

After:
 Ten builds, laptop -j5, no ccache: 8% faster

```
real	0m33.802000-35.773000(35.468+/-0.54)s
user	2m19.073000-27.754000(26.2542+/-2.3)s
sys	0m15.784000-17.173000(16.7165+/-0.37)s
```

 Ten builds, laptop -j5, ccache (warm): 1% faster

```
real	0m8.200000-8.485000(8.30138+/-0.097)s
user	0m12.485000-13.100000(12.7344+/-0.19)s
sys	0m3.702000-3.889000(3.78787+/-0.056)s
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Rusty Russell ea30c34d82 cleanup: remove unneeded includes in header files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Rusty Russell d970cc070e closingd: add notifications for feerate ranges.
This allows cmdline users to have more idea what's going on.

Inspired-by: https://github.com/ElementsProject/lightning/issues/4777
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: `close` now notifies about the feeranges each side uses.
2021-09-15 18:23:30 +02:00
Rusty Russell f6a7a3f8a8 tests: test that successive closes do update parameters (particularly feerate!).
Noted by @t-bast, this is how it should work, and this tests that it does.

See also: #4777
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-15 18:23:30 +02:00
Rusty Russell 83e581b12a lightningd: print out support for channel_types in --list-features.
It's not a separate option, but lnprototest needs it to know to expect
the tlvs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell cb22015b2a common/channel_type: wrapper for generated 'struct channel_type'.
We make it a first-class citizen internally, even though we won't use
it over the wire (at least, non-experimental builds).  This scheme
follows the latest draft, in which features are flagged compulsory.

We also add several helper functions.

Since uses the *even* bits (as per latest spec), not the *odd* bits,
we have some other fixups.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-13 15:53:23 +02:00
Rusty Russell 84957be410 close: spec is final, it's not experimental.
That was quick!

We remove the 50% test, since the default is now to use quickclose.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Protocol: We now perform quick-close if the peer supports it.
2021-09-09 12:04:48 +09:30
Rusty Russell 6ee8c40b29 closing: add option to set closing range.
This affects the range we offer even without quick-close, but it's
more critical for quick-close.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSONRPC: `close` now takes a `feerange` parameter to set min/max fee rates for mutual close.
2021-09-09 12:04:48 +09:30
Rusty Russell e12f9f0872 pytest: add test for closing feerate greater than final commit tx.
This is now allowed for anchors (as per https://github.com/lightningnetwork/lightning-rfc/pull/847).

We need to play with feerates, since we don't put a discount on anchor
commitments yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-09 12:04:48 +09:30
Rusty Russell 79d7e83f51 --experimental-quick-close to enable quick-close negotiation
Based on a commit by @niftynei, but:
- Separated quickclose logic from main loop.
- I made it indep of anchor_outputs, use and option instead.
- Disable if they've specified how to negotiate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-09 12:04:48 +09:30
Rusty Russell 1b2c6964fd Makefile: update spec version
This includes the new bolt11 test vectors, and also removes the
requirement that HTLCs be less than 2^32 msat.  We keep that for now
because Electrum enforced it on receive: in two releases we will stop
that too.

So no longer warn about needing mpp in that case either.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: Protocol: No longer restrict HTLCs to
2021-09-09 12:04:48 +09:30
Rusty Russell 127539a993 plugins/topology: use memleak annotation instead of global_gossmap hammer.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 19:11:47 +02:00
Rusty Russell a0d531d515 pytest: annotate name_option against leak detection in test_libplugin
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 19:11:47 +02:00
Rusty Russell 516c38a750 lightningd: call shutdown plugin when we dynamic shutdown a single one.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-05 15:16:56 +02:00
Rusty Russell 2063049559 libplugin: plugin_exit helper which flushes stdout.
We weren't actually getting the last log out; this does that.

We have to fix test_bitcoin_failure which now notices the BROKEN
log message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: libplugin: Fatal error messages from plugin_exit() now logged in lightningd.
2021-09-05 15:16:56 +02:00
Michael Schmoock f6709a7a90 pytest: test new commitment_revocation hook values 2021-09-04 11:54:33 +09:30
Vincenzo Palazzo 218875a38d adding check for the deprecated api.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-02 14:19:42 +09:30
Vincenzo Palazzo 3b65a4caca Fixed order parameter in the listforwards command
Changelog-Changed: Change order parameters in the listforwards command

Changelog-Deprecated: Change order of the status parameter in the listforwards rpc command.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-02 14:19:42 +09:30
Rusty Russell 8f782b06f7 pytest: don't copy db to query it.
Should be safe to do in-place.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-08-26 12:44:02 +09:30
Rusty Russell fe86c117d9 datastore: turn keys into arrays
After some discussion with @shesek, and my own usage, we agreed that
a more comprehensive interface, which explicitly supports grouping,
is desirable.

Thus keys are now arrays, with the semantic that a key is either a
parent or has a value, never both.

For convenience in the JSON schema, we always return them as arrays,
though we accept simple strings as arguments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-08-25 10:06:31 +02:00