Commit Graph

289 Commits

Author SHA1 Message Date
Rusty Russell 8cf2fff91b pytest: generalize tests.
Anchor outputs break many assumptions in our tests:

1. Remove some hardcoded numbers in favor of a fee calc, so we only have to
   change in one place.
   FIXME: This should also be done for elements!
2. Do binary search to get feerate for a given closing fee.
3. Don't assume output #0: anchor outputs perturb them.
4. Don't assume we can make 1ksat channels (anchors cost 660 sats!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-14 11:51:14 +09:30
Rusty Russell 6b39731c6a fundchannel: provide outnum
It's currently always 0, but it won't be once we replace txprepare.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `fundchannel` has new `outnum` field indicating which output of the transaction funds the channel.
2020-08-13 12:37:02 -05:00
Rusty Russell 2f4c16c388 pytest: fix race in test_bcli.
On my test machine, we queried bitcoind before the close tx was sent:

```
        # When output is spent, it should give us null !
        txo = l1.rpc.call("getutxout", {"txid": txid, "vout": 0})
>       assert txo["amount"] is txo["script"] is None
E       AssertionError: assert '20000000msat' is '00205b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd'

tests/test_plugin.py:1221: AssertionError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-13 12:49:49 +02:00
Rusty Russell fc097b8b48 libplugin: allow commands and options to mark themselves deprecated.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-11 08:43:18 +09:30
Rusty Russell fde353ab00 pytest: use get_nodes more widely.
I started replacing all get_node() calls, but got bored, so then just did the
tests which call get_node() 3 times or more.

Ends up not making a measurable speed difference, but it does make some
things neater and more standard.

Times with SLOW_MACHINE=1 (given that's how Travis tests):

Time before (non-valgrind):
	393 sec (had 3 failures?)
Time after (non-valgrind):
	410 sec

Time before (valgrind):
	890 seconds (had 2 failures)
Time after (valgrind):
	892 sec

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 7bb461acd8 pytest: fix flake in test_channel_opened_notification
We can have the message before the node ready message which line_graph
waits for.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
ZmnSCPxj jxPCSnmZ 1ded3fc52f lightningd/plugin.c: Add a `--dev-builtin-plugins-unimportant` for developers who want to mess around with the builtin plugins. 2020-08-04 13:27:51 -05:00
ZmnSCPxj jxPCSnmZ 1aa076845a tests/test_plugin.py: Test builtin plugins are important. 2020-08-04 13:27:51 -05:00
ZmnSCPxj jxPCSnmZ 48f36904c8 tests/test_plugin.py: Add test for --important-plugin. 2020-08-04 13:27:51 -05:00
Christian Decker 2146a548bd plugin: Do not return multiple times from `pay`
While we were unsetting the `payment->cmd` in case of a success to signal that
we should not return to the JSON-RPC command twice, we were not doing that in
the case of failures. This was causing multiple responses to a single incoming
command, and `lightningd` was correctly killing the plugin. This issue was
introduced through early returns (anything setting `payment->abort=true`) and
was caused in Rusty's case through an MPP timeout.

Fixes #3847
Reported-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <@cdecker>
2020-07-18 11:40:02 +02:00
Christian Decker 734f292695 pytest: Reproduce issue #3847
Reported-by: Rusty Russell <@rustyrussell>
2020-07-18 11:40:02 +02:00
Christian Decker 5bef4fc196 mpp: Lower amounts below the presplit amount
Some tests were failing because they were running into the presplit modifier
and then surprised that the payment got split.
2020-07-15 11:32:58 +02:00
niftynei ccb78712cf elements,tests: fixup output amounts for elements
no idea why the fees are different here now post pset, but lo and behold
they are...
2020-07-13 11:37:24 +09:30
Rusty Russell 7aa8ffa2a0 bitcoin: add weight calculation helpers.
These are pulled from wallet/wallet.c, with the fix now that we grind sigs.

This reduces the fees we pay slightly, as you can see in the coinmoves changes.

I now print out all the coin moves in suitable format before we match:
you only see this if the test fails, but it's really helpful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-06 19:25:05 +02:00
Christian Decker b5c9dcab5a pytest: Fix up the payload replacement test
There is a race between `getroute` learning that our peer accepts TLVs and us
initiating the payment. Waiting for announcements ensures we always use TLVs,
matching our expectation in the test / plugin.
2020-07-02 11:54:12 +02:00
niftynei 8185474bfb liquid-compat: update coinmove check to be liquid compatible
🎉 :waterfall:
2020-07-01 19:50:02 -05:00
Rusty Russell f4f8a363dd pytest: fix feature mask for EXPERIMENTAL_FEATURES, add wumbo support.
There are various places where our tests failed with
--enable-expimental-features.  And our plugin test overlapped an
existing feature.

We make our expected_feature functions more generic, and use them
everywhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-26 19:57:29 -05:00
lisa neigut d35149e5ca try to fix travis test flakes 2020-05-12 15:46:58 +09:30
lisa neigut ffd9467f14 coin moves: persist the coin movement index counter to disk
Should make it easier to track when coin moves in the plugin are
disjoint from what c-lightning says it's broadcast already.
2020-05-12 15:46:58 +09:30
lisa neigut de86e29e16 coin moves: log all withdrawals when confirmed in a block
This moves the notification for our coin spends from when it's
successfully submited to the mempool to when they're confirmed in a
block.

We also add an 'informational' notice tagged as `spend_track` which
can be used to track which transaction a wallet output was spent in.
2020-05-12 15:46:58 +09:30
lisa neigut 9c4c0f10fb coin_mvt: add integration tests for in-channel htlc movements 2020-05-12 15:46:58 +09:30
Christian Decker 8f2ce1e638 pytest: Add a test for the commitment_revocation hook 2020-05-07 15:05:39 +09:30
Rusty Russell fe365f930f lightningd: list disabled plugins in listconfig.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 24063ca972 lightningd: have plugin-disable be more persistent.
The previous implementation was a bit lazy: in particular, since we didn't
remember the disabled plugins, we would load them on rescan.

Changelog-Changed: config: the `plugin-disable` option works even if specified before the plugin is found.
2020-05-05 13:45:17 +09:30
Rusty Russell 8c59de5ee5 lightningd: make plugin_kill take a simple string.
That's more convenient for most callers, which don't need a fmt.

Fixed-by: Darosior <darosior@protonmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 051cbf7cc4 lightningd: make plugin_kill() free the plugin.
This is what I expected from plugin_kill, and now all the callers do the
equivalent anywat, it's easy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 4de11950ec lightningd: unify dynamic and static plugin initialization.
This means we now clean up options in startup plugins (that was only
done by dynamic code!), and now they both share the 60 second timeout
instead of 20 seconds for dynamic.

For the dynamic case though, it's 60 seconds to both complete
getmanifest and init, which seems fair.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 006ab1e367 pytest: test loading all plugins at once, including failing ones.
We modify the slow_init() so it doesn't go too slowly for this test.

This demonstrates a crash, where we currently try to fail a command
multiple times.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 6441233d2b pytest: add test for a plugin which falls over outside a command.
This actually passes fine, but it's an interesting case to test.

Fixed-by: Darosior <darosior@protonmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
rbndg 241fa00e97 plugin:added invoice creation event
New invoice_creation event triggered when an new invoice is created

Changelog-Added: plugin: New invoice_creation plugin event
2020-05-04 19:18:05 +02:00
lisa neigut d6d26dd056 features: split expected feature bits into node/peer sets
The new `keysend` plugin modifies the node features that we send to
peers. This commit breaks out the 'expected_features' we use for tests
to encompass this differentiation.
2020-04-28 10:39:07 -05:00
Rusty Russell 63441075b5 lightningd: allow htlc_accepted hook to replace onion payload.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-added: `htlc_accepted` hook can now offer a replacement onion `payload`.
2020-04-16 18:03:35 +09:30
Christian Decker 197a144505 plugin: Ensure RPC passthrough calls are terminated when plugin dies
We now track all pending RPC passthrough calls, and terminate them with an
error if the plugin dies.

Changelog-Fixed: JSON-RPC: Pending RPC method calls are now terminated if the handling plugin exits prematurely.
2020-04-14 11:07:55 +09:30
darosior af76bce0fa pyln-client: send proper JSONRPC2 errors on failed call
Changelog-Added: pyln now sends proper error on bad calls to plugin methods

Co-Authored-By: Sergi Delgado Segura <sergi.delgado.s@gmail.com>
2020-04-11 12:17:51 +09:30
darosior 5aafef1484 pytest: skip some test when DEPRECATED_APIS is enabled. 2020-04-05 11:06:27 +09:30
Rusty Russell 7a95e90ee4 plugins: add `feature_set` to init object.
Shows what features we use in various contexts, including those added
by plugins in getmanifest.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugin: `feature_set` object added to `init`
2020-04-03 13:13:21 +10:30
darosior 5e72b22e80 bcli: adapt interface to the new fees estimation interface
We keep the same behaviour as lightningd before.
2020-03-30 20:17:18 +10:30
lisa neigut 563b46814b plugins: remove 'blank' option parsing for bool
bools must be set!
2020-03-21 16:29:52 +10:30
lisa neigut 42cce55b45 plugins: add 'flag' type for plugin options
Updates the plugin docs to include more detailed info about how options
work.

Changelog-Added: Plugins: 'flag'-type option now available.
2020-03-21 16:29:52 +10:30
lisa neigut a08905c344 plugin tests: actually check log result + move over to '' -> true
a few things. one is that `is_in_log` returns a result rather than
enforcing a condition. so these lines all need asserts

two is that with the 'allow_deprecated_apis' option on, the python json
parser overwrites the now typed input with the later-added string
version, so the only option value present in the option key-value set is
the last, string one. the check for this has been updated to only verify
that the string version is included (i manually verified that both are
printed to the JSON message)
2020-03-21 16:29:52 +10:30
lisa neigut 41b18050a0 plugin: add in deprecated_api behavior and test
we also check that the node isn't running now, for extra pedancity
2020-03-10 13:25:36 +10:30
lisa neigut b25a8ba29d plugins: test for option value checking and parsing 2020-03-10 13:25:36 +10:30
Rusty Russell 3572d598bf tests: fix flake in libplugin test.
My test machine is fast enough that we might not have seen the plugin
msg yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-04 16:42:34 +01:00
Christian Decker 23149c3daa plugin: Actually wait the 20 seconds promised in the docs
We promised we'd be waiting up to 20 seconds, but were only waiting for
10. Fix that by bumping to the documented 20.
2020-02-27 09:21:44 +10:30
Christian Decker 4a21883553 plugin: Fix hanging hook calls if the plugin dies
Changelog-Fixed: plugin: A crashing plugin will no longer cause a hook call to be delayed indefinitely
2020-02-27 09:21:44 +10:30
Christian Decker 72757933f0 pytest: Test a plugin crash while handling a hook call 2020-02-27 09:21:44 +10:30
darosior a47fd8cf3e pytest: test Bitcoin plugin registration and the bcli plugin 2020-02-12 11:45:07 +10:30
darosior e6a6ef23fd pytest: make the libplugin test non flaky
Rusty fixed the underlying bug in 8b8e4bb5fd
2020-02-12 09:30:02 +10:30
Christian Decker 490550d508 plugin: Allow multiple plugins to register the `htlc_accepted` hook
Make the `htlc_accepted` hook the first chained hook in our repertoire. The
plugins are called one after the other in order until we have no more plugins
or the HTLC was handled by one of the plugins. If no plugins handles the HTLC
we continue to handle it internally like always.

Handling in this case means the plugin returns either `{"result": "resolve",
...}` or `{"result": "fail", ...}`.

Changelog-Changed: plugin: Multiple plugins can now register for the htlc_accepted hook.
2020-02-11 15:57:22 +10:30
Rusty Russell 30580731a6 Minor fixups on PR #3477
Feedback from @niftynei and me; nothing major, but avoids
another round-trip.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-11 13:53:31 +10:30
Christian Decker ebd3a8d7f2 plugin: Add featurebits registered by plugins to node_announcements
This is the last venue we need to add custom featurebits to, so we also unmark
the test as xfail.

Changelog-Added: plugin: Plugins can now signal support for experimental protocol extensions by registering featurebits for `node_announcement`s, the connection handshake, and for invoices. For now this is limited to non-dynamic plugins only
2020-02-11 13:53:31 +10:30
Christian Decker 966ac95098 pytest: Add a test for plugin featurebits 2020-02-11 13:53:31 +10:30
darosior 972b4def57 lightningd/plugin: unregister a plugin's options when stopping it
This also remove the now duplicate plugin_hook_unregister_all(), added
in the tal destructor of the struct plugin.
2020-02-10 09:49:15 +10:30
darosior 84e3fa39b3 pytest: test libplugin's send_outreq 2020-02-10 09:49:15 +10:30
darosior 75becf7227 pytest: test hooks and notifications with libplugin 2020-02-10 09:49:15 +10:30
darosior ceeb5503cc libplugin: fix 'dynamic' field in getmanifest
As a separated commit because it was pre-existent (changelog + xfail test).

This also fix a logical problem in lightningd/plugin_control: we were
assuming a plugin started with 'plugin start' but which did not comport
a 'dynamic' entry in its manifest to be dynamic, though it should have
been treated as static.

Changelog-fixed: plugins: Dynamic C plugins can now be managed when lightningd is up
2020-02-10 09:49:15 +10:30
darosior da476848d1 pytest: add a C testing plugin to test libplugin
We mark the test as xfail() as it exposes that libplugin's PLUGIN_RESTARTABLE
was not taken into account !
2020-02-10 09:49:15 +10:30
Rusty Russell 295ca2a436 lightningd: remove things we deprecated 6 months ago.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: Relative plugin paths are not relative to startup (deprecated v0.7.2.1)
Changelog-Removed: Dummy fields in listforwards (deprecated v0.7.2.1)
2020-01-31 03:48:01 +00:00
darosior dc3aa33927 pytest: use pyln.client for functional tests 2020-01-21 22:38:14 +01:00
Christian Decker b800904409 pay: Move notify_sendpay_* calls out of the waiter loop
Changelog-Changed: plugin: `notify_sendpay_success` and `notify_sendpay_failure` are now always called, even if there is no command waiting on the result.
2020-01-13 23:34:46 +01:00
Christian Decker cc37862273 pytest: Reproduce issue #3403, sendpay notifications with no waiter
We clone the test above, but this time we don't attach waiters (they'd be racy
anyway), and we wait for the notification to be called. This fails, but is
fixed in the next two commits.
2020-01-13 23:34:46 +01:00
darosior 1cfb8425f5 plugin_control: more descriptive key for 'plugin stop' result
Changelog-Changed: JSONRPC: 'plugin stop' result is now accessible using the 'result' key instead of the empty ('') key.
2019-12-29 06:44:22 +08:00
Rusty Russell 839909d2cf Protocol: make var_onion, payment_secret and basic_mpp non-EXPERIMENTAL.
Thanks to @t-bast, who made this possible by interop testing with Eclair!

Changelog-Added: Protocol: can now send and receive TLV-style onion messages.
Changelog-Added: Protocol: can now send and receive BOLT11 payment_secrets.
Changelog-Added: Protocol: can now receive basic multi-part payments.
Changelog-Added: RPC: low-level commands sendpay and waitsendpay can now be used to manually send multi-part payments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-12 22:16:03 +01:00
Rusty Russell 30c8db148d lightningd: make sure rpc_command replacement is well-formed.
In particular:
1. It must redirect to an existing command.
2. It must contain method, params and id.

And update the docs to show the id, which is vital.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-07 21:26:31 +01:00
Rusty Russell e572b487d3 pytest: demonstrate failing rpc_command hook rewrite to plugin.
lightningd: lightningd/plugin.c:648: plugin_rpcmethod_dispatch: Assertion `idtok != NULL' failed.
lightningd: FATAL SIGNAL 6 (version v0.7.3-234-gf3aeb51-modded)
0x557652363eb1 send_backtrace
	common/daemon.c:41
0x557652363f5b crashdump
	common/daemon.c:54
0x7f5b065a346f ???
	???:0
0x7f5b065a33eb ???
	???:0
0x7f5b06582898 ???
	???:0
0x7f5b06582768 ???
	???:0
0x7f5b06594005 ???
	???:0
0x557652355901 plugin_rpcmethod_dispatch
	lightningd/plugin.c:648
0x557652331836 command_exec
	lightningd/jsonrpc.c:588
0x557652331bad rpc_command_hook_callback
	lightningd/jsonrpc.c:655
0x557652358745 plugin_hook_callback
	lightningd/plugin_hook.c:90
0x55765235486a plugin_response_handle
	lightningd/plugin.c:258
0x557652354a16 plugin_read_json_one
	lightningd/plugin.c:356
0x557652354b6d plugin_read_json
	lightningd/plugin.c:388
0x5576523b5e6c next_plan
	ccan/ccan/io/io.c:59
0x5576523b6a51 do_plan
	ccan/ccan/io/io.c:407
0x5576523b6a93 io_ready
	ccan/ccan/io/io.c:417
0x5576523b8d2b io_loop
	ccan/ccan/io/poll.c:445
0x55765232dc6f io_loop_with_timers
	lightningd/io_loop_with_timers.c:24
0x557652334a6e main
	lightningd/lightningd.c:848
0x7f5b065841e2 ???
	???:0
0x5576523193ed ???
	???:0
0xffffffffffffffff ???
	???:0
Log dumped in crash.log.20191206093336

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-07 21:26:31 +01:00
Rusty Russell f6ed7f2e89 plugin: handle corner case where rpc_command is to stop the plugin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-06 16:52:16 +01:00
Rusty Russell d8fc5332c3 pytest: test rpc_command hook when it handles command to stop itself.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-06 16:52:16 +01:00
Rusty Russell aab83e729b lightningd: change config-dir from plugin / wallet / hsm POV into <network> subdir
Changelog-changed: .lightningd plugins and files moved into <network>/ subdir
Changelog-changed: WARNING: If you don't have a config file, you now may need to specify the network to lightning-cli
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Christian Decker 5a233a1b27 pytest: Fix TLV hook tests in experimental mode
I missed this test breaking with `EXPERIMENTAL_FEATURES` in #3261
2019-11-22 03:48:54 +00:00
Christian Decker dda792c766 plugin: Pass the full raw_payload including realm to htlc_accepted
So far we've only handled legacy payloads, which meant we could drop the realm
byte since it was always 0x00. Once we start handling TLV payloads the first
byte, i.e., the former realm byte, is important since it gives us the length
of the payload. This is a breaking change, however I don't think there's
anyone using the `raw_payload` as of yet.

Changelog-Changed: JSON-RPC: the `raw_payload` now includes the first byte, i.e., the realm byte, of the payload as well. This allows correct decoding of a TLV payload in the plugins.
2019-11-18 12:00:15 +01:00
Rusty Russell 709c98f539 logging: remove spaces from subsystem names.
Spaces just make life a little harder for everyone.

(Plus, fix documentation: it's 'jsonrpc' not 'json' subsystem).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-18 04:50:22 +00:00
Rusty Russell ef7a820ab1 log: make formatting more consistent.
1. Printed form is always "[<nodeid>-]<prefix>: <string>"
2. "jcon fd %i" becomes "jsonrpc #%i".
3. "jsonrpc" log is only used once, and is removed.
4. "database" log prefix is use for db accesses.
5. "lightningd(%i)" becomes simply "lightningd" without the pid.
6. The "lightningd_" prefix is stripped from subd log prefixes, and pid removed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-changed: Logging: formatting made uniform: [NODEID-]SUBSYSTEM: MESSAGE
Changelog-removed: `lightning_` prefixes removed from subdaemon names, including in listpeers `owner` field.
2019-11-18 04:50:22 +00:00
Rusty Russell e433d4ddc1 lightningd: have logging include an optional node_id for each entry.
A log can have a default node_id, which can be overridden on a per-entry
basis.  This changes the format of logging, so some tests need rework.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-18 04:50:22 +00:00
Rusty Russell bb06bec891 features: set OPT_VAR_ONION (bit 9) iff EXPERIMENTAL_FEATURES
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-14 10:15:33 +01:00
Rusty Russell 2a2259083a lightningd: handle tlv-style payloads.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-changed: JSON API: `htlc_accepted` hook has `type` (currently `legacy` or `tlv`) and other fields directly inside `onion`.
Changelog-deprecated: JSON API: `htlc_accepted` hook `per_hop_v0` object deprecated, as is `short_channel_id` for the final hop.
2019-11-14 10:15:33 +01:00
darosior 95c6513ff3 pytest: test the 'rpc_command' hook 2019-11-11 22:30:01 +01:00
darosior 7dac7a8c52 pytest: deactivate shadow routing for some tests that use 'pay'
So that we can assert payment values
2019-11-08 03:27:58 +00:00
darosior f3d304901b pay: add a dev-only parameter to deactivate shadow routing
Had to make a special pylightning function to avoid rewriting all calls
to 'pay()' with 'rpc.call()' in the next commit..
2019-11-08 03:27:58 +00:00
darosior c0ae3cb8c4 pytest: make test_plugin_slowinit a test again 2019-10-11 10:05:08 -05:00
darosior 32d98f0a87 plugins: refactor the tests for dynamic plugins
This adapts the test to the new 'plugin' command: no more sleeping,
since we are synchronous !

This tests the timeout by increasing the 'slowinit' plugin sleep
duration at init reception.

This adds a broken plugin to make sure we won't crash because of a
misbehaving plugin (unmet dependency is the most common case).
2019-09-30 00:20:16 +00:00
Christian Decker efc4aa94a3 pytest: Skip some tests that assume we have a sqlite3 db on postgres
These will not work since they touch the DB file itself.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-09-22 02:03:43 +00:00
trueptolemy a3a0f651e3 pytest: Let `fail_htlcs.py` plugin generates `TEMPORARY_NODE_FAILURE` error 2019-09-16 12:22:06 +08:00
trueptolemy 619362ae19 pytest: Add a test for 'sendpay_success' and 'sendpay_failure' 2019-09-11 00:57:39 +00:00
Christian Decker 492d77f213 db: Add setup and teardown function to DB
These are used to do one-time initializations and wait for pending statements
before closing.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-09-05 23:41:05 +00:00
Rusty Russell 049529542a lightningd: delay reprocessing of incoming htlcs at startup until plugins ready.
Fixes: #2923
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-01 16:55:32 +02:00
Rusty Russell f0ab4d72da pytest: add test that htlc_accepted hook only gets called after init.
We fail this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-01 16:55:32 +02:00
Rusty Russell 20a2bf9547 pytest: make test_forward_event_notification more explicit.
We seem to be getting intermittant failures, but it's hard
to disgnose.  Simplify it by moving all the test logic into
the test itself, and making the plugin dumber.  This means we'll
see exactly what the differences are if it fails again.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-28 04:04:28 +00:00
Simon Vrouwe 5b5d70d640 lightningd/plugin: extend plugins->startup window to include plugins_config
Fixes incorrect configuration[`startup`] in plugin `init`, modified tests
to test this.
2019-08-27 00:02:20 +00:00
Rusty Russell 63103db3f3 pytest: disable some v. slow tests when !DEVELOPER.
We've gone over 50 minutes with valgrind, and my measurements show
these are the slowest.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-14 05:53:36 +00:00
Rusty Russell 118150227e cli: restore 0.7.0-style whitespace printing.
@renepickhardt has a shell script we broke.  While we still produce
perfectly valid JSON, we should not gratuitously change tool output.

Plus, I prefer the missing space before the ':'.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-08 18:16:48 +08:00
Christian Decker e2f9a410f4 pytest: Run plugin --help tests in the test directory
This is a followup to #2892. Since we now attempt to lock the PID file before
starting plugins we need to make sure that we actually use a unique lightning
directory for anything that attempts to call `--help`. If not we may be
conflicting with a `lightningd` that is running against that directory.

Notice that this still means that we will be unable to call `--help` on
`lightningd` if we have a running instance, but isolation in this case is
good, otherwise we'd be reading the default config anyway.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-06 13:10:32 +08:00
Rusty Russell b460590278 plugins: detect and fixup old relative paths.
Note that we move adding the plugin to the plugins list to the end, otherwise
the hook from logging can examine the (uninitialized) plugin.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-03 09:10:11 +00:00
Rusty Russell 4fcd94a091 pytest: use absolute paths for plugin arguments.
We're going to change this in the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-03 09:10:11 +00:00
trueptolemy 5ac02907bb pytest: Add the test for 'forward_event' in test_plugin 2019-08-01 18:49:25 +08:00
Rusty Russell 79d32ec2f2 plugin: notice when plugin has *started* configuring.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-30 08:44:01 +08:00
Rusty Russell df8a6f615b pytest: test for crash when we do a plugin op and a plugin has not finished init
We try to start it twice, with predictable hilarious results:

   DEBUG plugin-manager started(20701) /home/rusty/devel/cvs/lightning/tests/plugins/slow_init.py
   DEBUG lightningd(20670): Adding block 101: 0f26301caaae390d1b956c3eb73827d1f87a2af306561348045bf1313b7551b0
   INFO plugin-slow_init.py slow_init.py initializing
   DEBUG plugin-manager started(20704) /home/rusty/devel/cvs/lightning/tests/plugins/slow_init.py
   **BROKEN** lightningd(20670): FATAL SIGNAL 6 (version v0.7.1-146-g7d3b352-modded)
   **BROKEN** lightningd(20670): backtrace: common/daemon.c:45 (send_backtrace) 0x55a29c3ec539
   **BROKEN** lightningd(20670): backtrace: common/daemon.c:53 (crashdump) 0x55a29c3ec589
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x7fa281ebcf5f
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x7fa281ebced7
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x7fa281e9e534
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x7fa281e9e40e
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x7fa281eae011
   **BROKEN** lightningd(20670): backtrace: lightningd/json_stream.c:225 (json_stream_output_) 0x55a29c3bff5f
   **BROKEN** lightningd(20670): backtrace: lightningd/plugin.c:383 (plugin_write_json) 0x55a29c3e103f
   **BROKEN** lightningd(20670): backtrace: ccan/ccan/io/io.c:59 (next_plan) 0x55a29c43316b
   **BROKEN** lightningd(20670): backtrace: ccan/ccan/io/io.c:435 (io_do_always) 0x55a29c433df1
   **BROKEN** lightningd(20670): backtrace: ccan/ccan/io/poll.c:300 (handle_always) 0x55a29c435865
   **BROKEN** lightningd(20670): backtrace: ccan/ccan/io/poll.c:377 (io_loop) 0x55a29c435b3d
   **BROKEN** lightningd(20670): backtrace: lightningd/io_loop_with_timers.c:24 (io_loop_with_timers) 0x55a29c3bdfcf
   **BROKEN** lightningd(20670): backtrace: lightningd/lightningd.c:830 (main) 0x55a29c3c44b6
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x7fa281e9fb6a
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0x55a29c3ac0f9
   **BROKEN** lightningd(20670): backtrace: (null):0 ((null)) 0xffffffffffffffff

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-30 08:44:01 +08:00
darosior 307fb0708e lightningd/plugin_control: don't control non-dynamic plugins 2019-07-28 07:24:04 +00:00
darosior 9ddc2e0334 Add the 'plugin' subcommands to pylightning and add a test for them 2019-07-28 07:24:04 +00:00
darosior 2683170da8 Test and document 'channel_opened' notification 2019-07-27 12:18:25 +02:00
darosior 34533ead68 Plugins: Add a test for the 'invoice_payment' notfication 2019-07-25 11:19:47 +08:00
Christian Decker 53488e5739 pytest: Strengthen the htlc_accepted tests
We were having a few issues with malformed data in the past, so this time we
really check that stuff.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-07-13 14:44:12 +02:00
Rusty Russell 54ce4ed1cf pytest: fail tests if we get any LOG_BROKEN level messages, unless flagged.
And clean up some dev ones which actually happen (mainly by calling
channel_fail_permanent which logs UNUSUAL, rather than
channel_internal_error which logs BROKEN).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-02 03:26:10 +00:00
Rusty Russell 5f02294b5b lightningd/log: prefix log messages with level.
In particular, this lets us spot UNUSUAL and BROKEN messages easily.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-02 03:26:10 +00:00
Rusty Russell 380c044668 tests: add plugin for simple invoice delay.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-06-11 23:19:11 +00:00
trueptolemy 4d08ed2fa6 pytest: Add a test for the 'warning' subscription and notification
1. Create a plugin: ./lightning/tests/plugins/pretend_badlog.py
This plugin subscribes 'warning' notification and log the payload of
'warning';
2. Add a new test: tests/test_plugin.py::test_warning_notification
This test runs the plugin-pretend_badlog.py and check if 'warning'
notification can be normal triggered and subscribed.
2019-06-07 01:23:51 +00:00
Michael Schmoock c40250ad0b test: adds wait mempool to flaky tests 2019-06-06 00:04:59 +00:00
Christian Decker dd26a01c54 pytest: Add a test for htlc_accepted hook replay on startup 2019-06-04 00:27:15 +00:00
Christian Decker 9fd8be6463 pytest: Add tests for htlc_accepted_hook
Two tests: one for failures and one for in-path resolution.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-06-04 00:27:15 +00:00
Christian Decker b54577041a pytest: Add a simple test for the hooks
This uses the `htlc_accepted` hook to delay payment acceptance.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-06-04 00:27:15 +00:00
Michael Schmoock 107381aca2 test: fix flakyness of funding_reorg_private openchannel_hook 2019-06-03 19:30:19 +02:00
Christian Decker ced2ff8aa7 pytest: Mark repeat offenders as flaky
It's always the same few tests that fail, so I'm marking them as flaky and
will do a cleanup round later to individually address them.

I've been tracking the failures on the master branch for a few months now and
these are the worst offenders:

|-----------------------------------------|--------|--------|-------|
| test_name                               | state  | branch | count |
|-----------------------------------------|--------|--------|-------|
| test_pay_direct                         | FAILED | master | 31    |
| test_reconnect_gossiping                | FAILED | master | 20    |
| test_htlc_send_timeout                  | FAILED | master | 15    |
| test_pay_limits                         | FAILED | master | 13    |
| test_permfail                           | FAILED | master | 13    |
| test_funding_reorg_private              | FAILED | master | 12    |
| test_invoice                            | FAILED | master | 12    |
| test_invoice_preimage                   | FAILED | master | 12    |
| test_shutdown                           | FAILED | master | 12    |
| test_withdraw                           | FAILED | master | 12    |
| test_gossip_store_load_v3               | FAILED | master | 11    |
| test_onchain_multihtlc_their_unilateral | FAILED | master | 10    |
| test_opening_tiny_channel               | FAILED | master | 10    |
| test_channel_reenable                   | FAILED | master | 9     |
| test_crashlog                           | FAILED | master | 9     |
| test_gossip_weirdalias                  | FAILED | master | 9     |
| test_invoice_expiry                     | FAILED | master | 9     |
| test_onchain_multihtlc_our_unilateral   | FAILED | master | 9     |
| test_peerinfo                           | FAILED | master | 9     |
| test_private_channel                    | FAILED | master | 9     |
| test_shutdown_reconnect                 | FAILED | master | 9     |
| test_closing                            | FAILED | master | 8     |
| test_closing_different_fees             | FAILED | master | 8     |
| test_closing_while_disconnected         | FAILED | master | 8     |
| test_gossip_timestamp_filter            | FAILED | master | 8     |
| test_gossipwith                         | FAILED | master | 8     |
| test_invoice_routeboost                 | FAILED | master | 8     |
| test_onchain_middleman                  | FAILED | master | 8     |
| test_plugin_notifications               | FAILED | master | 8     |
| test_reconnect_channel_peers            | FAILED | master | 8     |
| test_bad_onion                          | FAILED | master | 7     |
| test_closing_torture                    | FAILED | master | 7     |
| test_fulfill_incoming_first             | FAILED | master | 7     |
| test_funding_reorg_disagree_scid_route  | FAILED | master | 7     |
| test_pay_disconnect                     | FAILED | master | 7     |
| test_balance                            | FAILED | master | 6     |
| test_check_command                      | FAILED | master | 6     |
| test_closing_id                         | FAILED | master | 6     |
| test_gossip_addresses                   | FAILED | master | 6     |
| test_gossip_notices_close               | FAILED | master | 6     |
| test_setchannelfee_usage                | FAILED | master | 6     |
| test_announce_address                   | FAILED | master | 5     |
| test_connect_by_gossip                  | FAILED | master | 5     |
| test_gossip_badsig                      | FAILED | master | 5     |
| test_gossip_disable_channels            | FAILED | master | 5     |
| test_gossip_jsonrpc                     | FAILED | master | 5     |
| test_gossip_persistence                 | FAILED | master | 5     |
| test_gossip_pruning                     | FAILED | master | 5     |
| test_onchain_different_fees             | FAILED | master | 5     |
| test_onchain_dust_out                   | FAILED | master | 5     |
|-----------------------------------------|--------|--------|-------|
2019-05-26 16:19:10 +02:00
Rusty Russell e5b5f1d7e5 openingd: add openchannel hook.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-05-20 20:31:07 -04:00
Christian Decker c96cc8a444 pytest: Fix the flaky test_plugin_connected_hook test
It was a bit eager :-)

Signed-off-by: Christian Decker <@cdecker>
2019-04-30 17:56:09 -05:00
Rusty Russell 7f7ad4f89f connected_hook: allow hook to specify an error message.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-23 15:26:42 +02:00
Rusty Russell 9c373fecb6 pytest: test the invoice hook.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-12 03:32:48 +00:00
Rusty Russell 5009d628a3 lightning-cli: do pretty-printing.
Plugins don't do it right anyway, and we're about to remove it from
lightningd.  Produces same format as json_pp.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-09 12:37:16 -07:00
Rusty Russell 7ccf3af51d pytest: test the db hook plugin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-04-08 01:56:17 +00:00
Rusty Russell cc342fda83 pylightning: make sure UTF-8 gets passed intact.
1. We need to read in as a byte string, then decode into utf8 once we
   have a marker.  Otherwise we seem to mangle it horribly, and we
   might have a bad utf8 string anyway.

2. We need to suppress the JSON \u escapes on output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-03-05 11:43:22 +01:00
Rusty Russell 5f437de771 pytest: test passing utf8 into and out of plugin JSON.
We should be able to pass UTF-8 strings to and from plugins without
python turning them into JSON-\u escapes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-03-05 11:43:22 +01:00
Rusty Russell 6e63d79159 pylightning: translate msat input to class Millisatoshi
Rather than using LightningJSONDecoder's implicit "field name and
value ends in msat, try converting to Millisatoshi", we do it to
parameters using type annotations.

If you had a parameter which was an array or dict itself, we don't
delve into that, but that's probably OK.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-25 21:45:21 +00:00
Rusty Russell c7316d7ba2 pytest: test that we translate to and from Millisatoshi on plugin RPC.
We don't, but we should, like we do for normal RPC.  However, I chose
to use function annotations, rather than names-ending-in-'msat'
because it's more Pythony.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-25 21:45:21 +00:00
Rusty Russell 1ec959752b plugin/pay: rename 'description' to 'label', deprecate 'description'.
This is the same deprecation, but one level up.  For the moment, we
still support invoices with a `h` field (where description will be
necessary) but that will be removed once this option is removed.

Note that I just changed pylightning without backwards compatibility,
since the field was unlikely to be used, but we could do something
more complex here?

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-23 05:45:25 +00:00
Christian Decker 571fb44d20 pylightning: Add a small test for async rpcmethods
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-22 02:59:36 +00:00
Christian Decker 5d9d5ceed1 pytest: Test the new peer_connected hook with a reject plugin
This plugin just rejects `node_id`s it gets told about.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Rusty Russell 53c0a21d2c plugins: get usage from plugins (required unless deprecated_apis == True).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00
Rusty Russell ba8a9d1fde libplugin: quick fix for bad JSON produced by plugins on bad paramters.
Internally libplugin turns ' into ", which causes these messages to produce
bad JSON.

The real fix is to remove the '->" convenience substitution and port the
JSON creation APIs into common/ from lightningd/

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-21 11:20:11 +01:00
Rusty Russell 0a8b4f8935 pay: remove inbuilt command in favor of plugin.
This doesn't actually remove some of the now-unnecessary infrastructure
though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-17 13:02:24 +01:00
Rusty Russell ad1e1bd528 plugins: minimal 'pay' plugin.
I wrote this sync first, then rewrote async, then developed libplugin.
But committing all that just wastes reviewer time, so I present it as
if it was always asnc and using the library helper.

Currently the command it registers is 'pay2', but when it's complete
we'll remove the internal 'pay' and rename it. This does a single
'getroute/sendpay' call.  No retries, no options.

Shockingly, this by itself is almost sufficient to pass our current test
suite with `pay`->`pay2`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-17 13:02:24 +01:00
Rusty Russell 61420bf79b configure: (mostly) revert b7a56f0531
Plugins are a first-class citizen again.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-15 02:52:13 +00:00
Christian Decker b7a56f0531 plugin: Gate the plugin subsystem with the --enable-plugins configure flag
Since we are planning to release a bug fix release, and the plugin
subsystem is not yet complete, it is better to make plugin support
opt-in while we continue testing.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-01-10 17:15:10 -08:00
Christian Decker 25ca49c444 pytest: Add a test for the event subscription and notification
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-30 14:36:02 +01:00
Christian Decker 643480cfd8 pylightning: Migrate the test plugin to use the new wrapper
Should be a lot easier to see what happens :-)

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-15 15:04:32 +01:00
Christian Decker a304db9be2 plugin: Handle log notifications from plugins
Logs are parsed and injected into the main daemon's logs.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-13 02:36:43 +00:00
Christian Decker f5a3f1f0a2 plugin: Add a test for timeout and broken manifest
Both of these plugins will fail in interesting ways, and we should
still handle them correctly.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-05 23:15:59 +00:00
Rusty Russell eb03b33655 plugins: add and install built-in plugin dir, add clear and disable options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-05 01:22:55 +01:00
Rusty Russell a4287f99fd lightningd: add --plugin-dir option to load directory full of plugins.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-12-05 01:22:55 +01:00
Christian Decker 1d75a70995 pytest: Add a test for the JSON-RPC passthrough
Tests JSON-RPC registration, as well as success and failures.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-12-02 22:55:47 +00:00
Christian Decker 879f9b7986 plugin: Make a common directory of plugins in contrib
No need to create a directory each.

Signed-off-by: Christian Decker <@cdecker>
2018-11-26 22:53:37 +00:00
Christian Decker e27b2ea69b pytest: Add a test for the plugin option passthrough
Signed-off-by: Christian Decker <@cdecker>
2018-11-26 22:53:37 +00:00