Commit Graph

8211 Commits

Author SHA1 Message Date
Christian Decker f557955515 paymod: Consolidate parsing RPC results in libplugin
We handle these in a number of different ways, and regularly get the parsing
and logic for optional fields wrong, so let's consolidate them here.
2020-07-07 23:25:45 +02:00
Christian Decker 4b3e849ce9 paymod: Add function to set the current step
This is necessary otherwise we would not be calling modifiers for the newly
set state which can lead to unexpected results.
2020-07-07 23:25:45 +02:00
Christian Decker 4aed45e98d paymod: Add attempts array to `pay` return value 2020-07-07 23:25:45 +02:00
Christian Decker 030633bb28 paymod: Add a human readable failreason to payments
This makes it easier to stash a human readable failure message in an attempt.
2020-07-07 23:25:45 +02:00
Christian Decker 2ef130e427 paymod: Apply and unapply routes to the channel hints
Add/remove the HTLC amount from the channel hints so concurrent getroute calls
have the correct exclusions. This can sometimes underflow, if we're unlucky
and call getroute too closely, but that's not a big issue, it can only result
in a failed MPP attempt too many, nothing fatal, and it'll get corrected based
on the result returned by the failing node.
2020-07-07 23:25:45 +02:00
Christian Decker 6a75497eb2 pytest: Add a `compat()` fixture allowing checks for specific flags
Since we change the interface for `pay` and `paystatus` we need a way to
determine which one to expect. This just parses the COMPAT_Vxyz flags and
allows us to check if, based on the configuration, we are in compat mode for
that set of changes or not.
2020-07-07 23:25:45 +02:00
Christian Decker cb00cbac7c paymod: Add support for the msatoshi override argument 2020-07-07 23:25:45 +02:00
Christian Decker 2331cd62e1 paymod: Add user-provided label back into the paystatus result 2020-07-07 23:25:45 +02:00
Christian Decker 215a0ada8b paymod: Update the route constraints as we apply routes and mods
These are primarily the fee and cltv constraints that we need to keep up to
date in order to give modifiers a correct view of what is and what isn't
allowed.
2020-07-07 23:25:45 +02:00
Christian Decker 935578e567 paymod: Exclude most expensive/slowest chan if limits are exceeded 2020-07-07 23:25:45 +02:00
Christian Decker 4648d2867f paymod: Compute fee and CLTV delta limits for a payment
So far we got away with not caring about these but since we're implementing
modifiers that impact these limits, we better keep track of them.
2020-07-07 23:25:45 +02:00
Christian Decker e71bdf9ed8 paymod: Wrap the getroute request in a struct
Keeping the arguments in their non-serialized form allows us to amend them as
we apply modifiers and learn new information.
2020-07-07 23:25:45 +02:00
Christian Decker 1b057f025c paymod: Let the payment know the local ID
This is necessary for the routehint modifier.
2020-07-07 23:25:45 +02:00
Christian Decker 097cb8d3a0 paymod: Exclude nodes that we found to be faulty 2020-07-07 23:25:45 +02:00
Christian Decker 2f0e535b81 paymod: Add reason why a payment was attempted
This is a slight change in interface in that the string no longer spells out
that a specific node was excluded.
2020-07-07 23:25:45 +02:00
Christian Decker 3a35dd34ac paymod: Add the contents of paystatus
This proved to be rather difficult given the tight coupling of the old structs
and the output of the command.
2020-07-07 23:25:45 +02:00
Christian Decker 2e88249a7b paymod: Make the transition to FAILED a function call
We need to set some variables as well, and the transition to FAILED is a bit
special in that quite some modifiers will skip into FAILED.
2020-07-07 23:25:45 +02:00
ZmnSCPxj jxPCSnmZ 4a89819cdd plugins/Makefile: Change plugins build procedure.
Changelog-None
2020-07-07 21:32:31 +02:00
ZmnSCPxj jxPCSnmZ 7f24646139 tools/hsmtool.c: Make password optional for `guesstoremote` and `dumpcommitments` commands.
Changelog-Fixed: Actually make the password argument optional for `guesstoremote` and `dumpcommitments` sub-commands, as shown in our documentation and help text.

Reported by `Barno` on #c-lightning IRC.
2020-07-07 13:34:11 +00:00
joe.miyamoto 0b1f8fdbf0 Take LIGHTNINGD_NETWORK env variable in Dockerfile.
Before this, docker image will never detects that
`lightning-rpc` was created if it is running in regtest
or testnet, because the file will be created under
subfolder for each network name, and entrypoint does not
check "lightning-rpc" file in those folders.
By specifying `LIGHTNINGD_NETWORK` environment var
in dockerfile, we can now check correct path.

Changelog-Added: Docker build now includes `LIGHTNINGD_NETWORK` ENV variable which defaults to "bitcoin". An user can override this (e.g. by `-e` option in `docker run`) to run docker container in regtest or testnet or any valid argument to `--network`.
2020-07-07 12:14:42 +02:00
Rusty Russell 3fec96a7b1 tests: fix flake in test_partial_payment_htlc_loss
Make sure we've actually confirmed the HTLC; if it's not confirmed yet
then we won't fast-fail it, and we'll timeout instead:

```
>           l1.rpc.waitsendpay(payment_hash=inv['payment_hash'], timeout=TIMEOUT, partid=1)
E           AssertionError: Pattern 'WIRE_PERMANENT_CHANNEL_FAILURE \\(reply from remote\\)' not found in "RPC call failed: method: waitsendpay, payload: {'payment_hash': 'c186643391469aa8190415496c85b1eb789cb2b756a76d4c9ce21dd34c698d92', 'timeout': 30, 'partid': 1}, error: {'code': 200, 'message': 'Timed out while waiting'}"
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-07 17:02:21 +09:30
Rusty Russell e12defa7fb wallet: no longer expose wallet_add_utxo function.
All users are now internal.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-06 19:25:05 +02:00
Rusty Russell 4271fc8652 wallet: add explicit API for onchaind to register UTXOs.
This is the only place outside the wallet code where we create
a 'struct utxo', so it makes sense for us to move that logic inside
the wallet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-06 19:25:05 +02:00
Rusty Russell 1708fb91e5 wallet: clean up json output creation, part 2.
It looked like we weren't printing the address on closing outputs.

But we are, because the 'scriptPubkey' field is in the 'outputs' db
table since 0.7.3 (66a47d2761).

So make the logic clearer, and remove a completely bogus comment (UTXOs
with closing_info are definitely spendable!).

We export the json_add_utxos() for future use, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-06 19:25:05 +02:00
Rusty Russell 5b82271187 wallet: clean up json output creation, part 1.
We're not allowed to command_fail() once we've started json_success.

That's OK, because encoding a known output can only fail if something is
badly, badly wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-06 19:25:05 +02:00
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 1ef0ca51b0 ci: Add pytest-sentry so we have a place to collect failing tests 2020-07-06 17:08:45 +02:00
Christian Decker 324d39bb6b docker: Add python3 to the docker image
Most user-contributed plugins are written in python, and not having it
available in the docker image is rather annoying to work around. So we just
add that tiny dependency to the image.

Fixes #3765
2020-07-06 17:08:45 +02:00
ZmnSCPxj jxPCSnmZ a6374ad431 openingd/openingd.c: Fix a mild deviation from BOLT#2.
Fixes: #3815

Changelog-Fixed: Fixed a deviation from BOLT#2: if both nodes advertised `option_upfront_shutdown_script` feature: MUST include ... a zero-length `shutdown_scriptpubkey`.
2020-07-06 14:53:49 +00:00
Rusty Russell fc2561fd9e pytest: fix test breakage added by d0c85033d2
By setting nLocktime to the current block, the reorg test
"test_funding_reorg_remote_lags" actually drops the funding transaction
entirely when a reorg happens.

Except the 1 in 10 cases where nLocktime is randomly set to 1-10
blocks earlier.

This implies, strongly, that we hit "restart" too often on Travis.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-06 14:55:14 +09:30
Christian Decker 7981f4c4d9 paymod: Extract the channel hints update into its own function
We could end up with multiple channel hints, which is a bit wasteful. We now
look for existing ones before adding a new one, and if one exists we use the
more restrictive parameters.

Suggested-by: Lisa Neigut <@niftynei>
2020-07-02 11:54:12 +02:00
Christian Decker ddb0424a4d paymod: Remove the dummy payment modifier
It was there only for demonstration purposes, and is no longer useful.
2020-07-02 11:54:12 +02:00
Christian Decker fc714bf2df paymod: Fill in the `pay` return value 2020-07-02 11:54:12 +02:00
Christian Decker 9aff885828 paymod Collect the final failure when aggregating the tree results
We're lucky that we can distinguish the severity of the failure based on the
failcode, so we bubble up the one with the maximum failcode, and let callers
inspect details if they need more information.
2020-07-02 11:54:12 +02:00
Christian Decker 2acb86bfe3 paymod: Consider new payments when checking if an attempt is ongoing
Without this the flapping behavior tested in `test_pay_retry` would reappear.
2020-07-02 11:54:12 +02:00
Christian Decker 7a266b8239 paymod: Make payment_tree_result public to users can query state 2020-07-02 11:54:12 +02:00
Christian Decker fbd8cf1495 paymod: Keep a copy of the serialized bolt11 in the root payment
We frequently query by the bolt11 string, so keeping it around saves us from
having to parse the query or serialize the parsed one.
2020-07-02 11:54:12 +02:00
Christian Decker 895542c6f1 paymod: Simplify retry mod logic and add abort logic 2020-07-02 11:54:12 +02:00
Christian Decker 73fc10e25f paymod: Parse error from waitsendpay and exclude failed chans 2020-07-02 11:54:12 +02:00
Christian Decker 81dce4096e pytest: Fix up test_pay_no_secret to wait for node_announcements
This was racy since we didn't know whether the peer supports TLV payloads yet
so we defaulted to legacy, which doesn't support secrets.
2020-07-02 11:54:12 +02:00
Christian Decker 9d7a48d0f4 pay: Key the MPP payments based on the payment_hash not the bolt11
This allows us to drive the payment from outside, and still get the
aggregation that we want.
2020-07-02 11:54:12 +02:00
Christian Decker be9b55fcb5 pyln: Add a traceback if a hook or rpc method fails 2020-07-02 11:54:12 +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
Christian Decker 957a3a01b9 json: Add helper to decode sha256 hashes 2020-07-02 11:54:12 +02:00
Christian Decker 0b85b983ac paymod: Teach the retry_mod not to insist when it's futile
An important life lesson: if there is no path to happiness, then trying harder
will still not get you there.
2020-07-02 11:54:12 +02:00
Christian Decker 10f231bcb5 paymod: Include excludes resulting from channel_hints for getrotue 2020-07-02 11:54:12 +02:00
Christian Decker c2538392e9 json: Add helper to serialize short_channel_id_dir
We'll need it in the next commit to exclude channels and their directions.
2020-07-02 11:54:12 +02:00
Christian Decker 5e3134083e paymod: Add a local_channel_hints modifier to collect local channels
We can have quite detailed information about our local channels, so call
`listpeers` before the `getroute` call on the root payment, to seed that
information in the channel_hints.
2020-07-02 11:54:12 +02:00
Christian Decker b1e9f4923b paymod: Add the final cltv delta to the getroute call 2020-07-02 11:54:12 +02:00
Christian Decker 6fbfe24e3e paymod: Add a COMPAT_090 flag
Since we end up consolidating some of the return values for `pay` and
`paystatus` and change the public interface we need to add the compatibility
flag and guard the switchover behind it.
2020-07-02 11:54:12 +02:00