Commit Graph

417 Commits

Author SHA1 Message Date
Christian Decker 041ee930a4 mpp: Consider an abort as the payment being finished
If one part sets the root to be aborted, there is little point in continuing
to wait for the remainder, return to the caller immediately.
2020-07-15 11:32:58 +02:00
Christian Decker 718b6e3398 mpp: Detect if destination supports MPP from invoice and abort early
We abort on the root since that is the coordination point for all parts of the payment.
2020-07-15 11:32:58 +02:00
Christian Decker de75d3ac0c mpp: Add CLI option to opt-out of multi-part payments
Several tests are not well-suited for mpp, so I added a CLI option to opt-out
of the MPP support at startup time.
2020-07-15 11:32:58 +02:00
Christian Decker a287bbe55d mpp: Enable adaptive splitter
Changelog-Added: The adaptive multi-part payment modifier will split payments that are failing due to their size into smaller parts, and re-attempted.
2020-07-15 11:32:58 +02:00
Christian Decker 535aaca109 paymod: Implement adaptive splitter
This modifier splits a payment that has been attempted a number of times (by a
modifier earlier in the mod chain) and has failed consistently. It splits the
amount roughly in half, with a but if random fuzz, and then starts a new round
of attempts for the two smaller amounts.
2020-07-15 11:32:58 +02:00
Christian Decker 443643e0b0 retrymod: Reset retry counter if parent is a split
If the parent is a split we have new payment parameters, and want to perform a
number of attempts with those.
2020-07-15 11:32:58 +02:00
Christian Decker d0eb3a79eb paymod: Not having a result doesn't mean we failed at getroute
Specifically if we split, there is no result, but we shouldn't add a failure
message.
2020-07-15 11:32:58 +02:00
Christian Decker b813974e13 mpp: Add the presplit MPP modifier
Changelog-Added: The MPP presplit modifier splits large payments into 10k satoshi parts to maximize chances of performing the payment and to obfuscate the overall amount being sent.
2020-07-15 11:32:58 +02:00
Christian Decker 3f399d15cb paymod: Don't assume that the first payment was executed at all
With the `presplit`-modifier we actually skip execution of the root altogether
which results in the root not having a result at all. Instead we should use
the result returned by `payment_collect_result`.
2020-07-15 11:32:58 +02:00
Christian Decker c97ff05ffb mpp: Add the presplit-modifier that splits a root payment first 2020-07-15 11:32:58 +02:00
Christian Decker 7f53ade64b paymod: Allow callers to opt out of shadow routing amount fuzzing
With MPP we require that the sum of parts is equal to the `total_msat` amount
declared in the onion. Since that can't be changed once the first part arrives
we need a way to disable amount fuzzing for MPP.
2020-07-15 11:32:58 +02:00
Rusty Russell 899ec2b3d4 JSON API: fix up two existing warnings to be conformant.
Technically an API break, but nobody relies on these I hope!

Note that the feerates warning was buried inside the style object:
it should be top-level.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-14 21:28:26 +02:00
Christian Decker 65963bc003 exemptfee: Only apply to the root payment and fix logs
We were applying the fee exemption to all payments individually, which is ok
until we switch to MPP, where amounts change. Also the log entry was referring
to the total amount, and not the fee of the payment.
2020-07-14 06:25:29 +09:30
Christian Decker 9be4d552fa paymod: Add a bit more information to the `pay` response
Amount, parent_part_id  and own partid can be helpful when debugging.
2020-07-14 06:25:29 +09:30
Christian Decker 6f40cb0202 paymod: Inherit exemptfee modifier data on retry 2020-07-14 06:25:29 +09:30
Christian Decker b88a55b2a4 paymod: Only wait on blockheight if we need to
We were wrongfully identifying all payment failures as blockheight mismatches.
2020-07-14 06:25:29 +09:30
Christian Decker f20091fc72 pay: Do not duplicate "message" field in response to `pay` 2020-07-14 06:25:29 +09:30
Christian Decker 411b760985 paymod: Reset the step if we're waiting for a block
This was causing the state flapping test to fail, since we were yielding
control of the io_loop, waiting for the blockheight to be reached, and not
setting the status beforehand. An interim `paystatus` call would then find a
failed leaf and deduce the entire payment failed. Setting it back to the
previous state keeps the overall payment pending while we wait.
2020-07-14 06:25:29 +09:30
Christian Decker 02e44e9903 paymod: Set the STOPPED_RETRYING status code if we stopped retrying 2020-07-14 06:25:29 +09:30
Christian Decker 5776a33116 paymod: Activate paymod and move legacy pay to `legacypay` command
As suggested during the paymod-03 review it is better to activate the new code
right away, and give users an escape hatch to use the legacy code instead. The
way I implemented it allows using either `legacypay` or `pay` and then set
`legacy` to switch to the other implementation.

Changelog-Added: JSON-RPC: The `pay` command now uses the new payment flow, the new `legacypay` command can be used to issue payment with the legacy code if required.

Suggested-by: Rusty Russell <@rustyrussell>
Suggested-by: ZmnSCPxj <@zmnscpxj>
2020-07-14 06:25:29 +09:30
Christian Decker 514c4044c8 tlv: Allow passing a raw pointer and a length to tlvstream_set_raw
Allows us to do fewer allocations, since the argument doesn't have to be tal
allocated itself.

Suggested-by: Rusty Russell <@rustyrussell>
2020-07-13 14:19:16 +02:00
Christian Decker 7978a13cae doc: Add a man-page for the new keysend command 2020-07-13 14:19:16 +02:00
Christian Decker 01a475161d paymod: Implement keysend sending support as a native RPC command
This makes use of the payment modifier structure to just add the preimage to
the TLV payload for the last hop.

Changelog-Added: JSON-RPC: The `keysend` command allows sending to a node without requiring an invoice first.
2020-07-13 14:19:16 +02:00
Rusty Russell a9427f1a8d bitcoin/feerate: new exposure for feerate parsing outside lightningd.
This exposes the numeric part of param_feerate() as param_feerate_val().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-08 21:07:20 +02:00
Christian Decker af4955c28e paymod: Fix waitsendpay error parsing for unknown failure codes
It turns out that the `failcodename` doesn't get populated if the `failcode`
isn't a known error from the enum (duh...) so don't fail parsing if it's
missing.
2020-07-07 23:25:45 +02:00
Christian Decker 5daa5bd61e paymod: Fix the onion payload construction
I wrongly used a pointer to the array that'd move on append, so an extra
dereference was required here.
2020-07-07 23:25:45 +02:00
Christian Decker 0aa5c197ec pytest: Fix tests broken by the pay and paystatus changes
This commit collects the changes required to the tests caused by the changes
to the `pay` and `paystatus` commands. They are also rather good hints as to
what these changes entail.
2020-07-07 23:25:45 +02:00
Christian Decker 2ac87c1490 paymod: Reorder paymod arguments to match pay
We've been adding modifiers and arguments out of order, and we need the
arguments order to match up if we want `paymod` to be a drop-in replacement.
2020-07-07 23:25:45 +02:00
Christian Decker da8eb6fb4c paymod: Expose riskfactor and wire through to getroute 2020-07-07 23:25:45 +02:00
Christian Decker d8b8a0b31e paymod: Add label to sendonion calls
These get reflected in the `listsendpays` command, and are quite useful.
2020-07-07 23:25:45 +02:00
Christian Decker 2649de54f2 paymod: Do not wait for a blockheight if we're already there
We want to differentiate a wrong block-height from other failure reasons, such
as an unknown `payment_hash`, so we skip the `waitblockheight` if we're
already at the correct height.
2020-07-07 23:25:45 +02:00
Christian Decker 5601a1ab21 paymod: Add a deadline to the pay command and retry modifier 2020-07-07 23:25:45 +02:00
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 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
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 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 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 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
niftynei 2ab41af8e2 rm pullpush: cleans up unused methods for push/pull
most likely unused since the switch to libwally for internal blockchain
things.

these method names were clashing with ones that are to be introduced
with some libwally cleanups, so getting rid of them pre-emptively keeps
us libwally compatible
2020-07-01 19:50:02 -05:00
Christian Decker 6af5ab9504 paymod: Move onion payload construction into its own function
Suggested-by: Rusty Russell <@rustyrussell>
2020-07-01 12:19:02 +02:00
Christian Decker b15876c112 paymod: Implement TLV onion payload generation 2020-07-01 12:19:02 +02:00
Christian Decker 958eb41cbb paymod: Do not pass cmd to sub-payments, plugin suffices
We were passing the `cmd` instance around where `plugin` suffices (used to
start RPC calls and logs).
2020-07-01 12:19:02 +02:00
Christian Decker df94ec35ba paymod: Do not reply to the same JSON-RPC command multiple times 2020-07-01 12:19:02 +02:00
Christian Decker c35df400b2 paymod: Maintain a list of current and past payments
We need to keep them around so we can inspect them later. We'll also need a
background cleanup every once in a while to free some memory. More on that in
a future commit.
2020-07-01 12:19:02 +02:00
Christian Decker 8207b4eac8 paymod: Use reasonable partids
We were just handwaving the partid generation, which broke some tests that
expected the first payment attempt to always have partid=0, so here we just
track the partids assigned in the payment tree, starting at 0.
2020-07-01 12:19:02 +02:00
Christian Decker 04c9c5e0d1 paymod: Collect and return results of a tree of partial payments
The status of what started as a simple JSON-RPC call is now spread across an
entire tree of partial payments and payment attempts. So we collect the status
in a single struct in order to report back success of failure.
2020-07-01 12:19:02 +02:00
Christian Decker 4fec969062 paymod: Parse and store the waitsendpay result
This is necessary so we can later aggregate across an entire tree of attempts
and report success or failure to the RPC caller.
2020-07-01 12:19:02 +02:00
Christian Decker 6fb81bf203 paymod: Call waitsendpay on the sendonion we just queued 2020-07-01 12:19:02 +02:00
Christian Decker d8ebe6fbcd paymod: Parse createonion result and call sendonion 2020-07-01 12:19:02 +02:00
Christian Decker d37b8548fb paymod: Call `createonion` to generate the onion and associated data
After we gave each modifier a chance to have its say, we can now proceed to
generate the onion that's going to be sent in the next step.
2020-07-01 12:19:02 +02:00
Christian Decker 5f32cfe9cd paymod: Implement legacy onion payload computation
This is just for testing for now, TLV payload computation will come next. We
stage all the payloads in deserialized form so modifiers can modify them more
easily and serialize them only before actually calling `createonion`.
2020-07-01 12:19:02 +02:00
Christian Decker 5ef7297e51 paymod: Add a `getinfo` call on payment_start to get the blockheight
This is necessary so we can build the absolute locktimes in the next step. For
now just fetch the blockheight on each (sub-)payment, later we can reuse the
root blockheight if it ends up using too much traffic.
2020-07-01 12:19:02 +02:00
Christian Decker 3c3e2c9c8f paymod: Implement getroute call 2020-07-01 12:19:02 +02:00
Christian Decker ce0025c95c paymod: Implement bubbling results up the hierarchy of payments
A payment is considered finished if it is in a final state (success or
failure) or all its sub-payments are finished. If that's the case we notify
`payment_finished` and bubble up through `payment_child_finished`, eventually
bubbling up to the root, which can then report success of failure back to the
RPC command that initiated the whole process.
2020-07-01 12:19:02 +02:00
Christian Decker 5c32e33aab paymod: Add a retry modifier that retries payments on failure
This is likely a bit of overkill for this type of functionality, but it is a
nice first use-case of how functionality can be compartmentalized into
modifiers. If makes swapping retry mechanisms in and out really simple.
2020-07-01 12:19:02 +02:00
Christian Decker aeb5cc0b7c paymod: Generate type-safe accessor functions for modifier data
This should make it easy for JSON-RPC functions and modifiers to get the
associated data for a given modifier name. Useful if a modifier needs to
access its parent's modifier data, or in other functions that need to access
modifier data, e.g., when passing destination pointers into the `param()`
call.
2020-07-01 12:19:02 +02:00
Christian Decker 23b4dca3c7 paymod: Add a simple test-command to test the paymod state-machine
This commit can be reverted/skipped once we have implemented all the logic and
have feature parity with the normal `pay`. It's main purpose is to expose the
unfinished functionality to test it, without completely breaking the existing
`pay` command.
2020-07-01 12:19:02 +02:00
Christian Decker 5d1725209d paymod: Implement base state-machine transitions
The actual steps are mocked out, but we can already run through the various
phases of a payment, and the modifiers should be called for each state.
2020-07-01 12:19:02 +02:00
Christian Decker e108ebe559 paymod: Add base state-machine for payment flow 2020-07-01 12:19:02 +02:00
Christian Decker 8138ef136f plugin: Add a data backend for the new payment state-machine 2020-07-01 12:19:02 +02:00
Vasil Dimov a3a37ea4ce build: fix compilation on i386
```
plugins/keysend.c:136:47: error: format specifies type 'unsigned long' but the argument has type 'time_t' (aka 'int') [-Werror,-Wformat]
        ki->label = tal_fmt(ki, "keysend-%lu.%09lu", now.ts.tv_sec, now.ts.tv_nsec);
                                         ~~~         ^~~~~~~~~~~~~
                                         %d
```

Changelog-None
2020-06-28 09:36:30 +00:00
Antoine Poinsot e0aef66ce2 plugins: make the autoclean plugin static
The autocleaning will only happen if the autocleaninvoice-cycle startup
option is passed, which cannot happen if the plugin is started
post-startup.
Thus, it's less misleading for users to restrict its usage to startup.

Changelog-Added: plugins: The `autoclean` plugin is now static (you cannot manage it with the `plugin` RPC command anymore).

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-06-24 15:29:39 +02:00
niftynei 2d5c61dfc1 psbt: methods to mutate psbt in place
add the missing psbt helpers for adding and removing an input and output
2020-05-21 18:45:07 +09:30
Antoine Poinsot d67743d511 bcli cleanups
Correct some comments wrt estimatefees, add a constructor for bitcoind

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-05-20 06:09:24 +09:30
Antoine Poinsot f598caa60d config: don't ignore the --commit-fee option.
We did not take the value of --commit-fee into account : this removes
the unused option from lightningd and instead registers it in bcli,
where we set the actual feerate of commitment transactions. This also
corrects the documentation.

Changelog-Fixed: config: we now take the --commit-fee parameter into account.
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-05-20 06:09:24 +09:30
niftynei fbe50e087a setup: create a common setup which will handle the wally-context
Since we now over-write the wally malloc/free functions, we need to do
so for tests as well. Here we pull up all of the common setup/teardown
logic into a separate place, and update the tests that use libwally to
use the new common_setup core

Changelog-None
2020-05-19 13:35:42 +09:30
Rusty Russell cfb320c972 wire: move remaining bitcoin functions out to bitcoin/ files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-18 14:51:12 +02:00
Antoine Poinsot 4bb7b4621f pay: respect maxfeepercent when choosing a shadow route
And the percentage of the initial amount, not the constently increasing
one !

Changelog-Fixed: pay: we now respect maxfeepercent, even for tiny amounts.
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-05-05 14:10:42 +09:30
lisa neigut 3cfafa81eb bcli-bugfix: pass along entire script
sizeof doesn't give the correct length, instead use tal_hex which will
measure the script length correctly

Changelog-None
2020-05-02 12:39:16 +02:00
Antoine Poinsot 3fc77730be bcli: don't log failed sendrawtransaction attempts twice
They are already logged both in bcli, and in lightningd.
This just adds a lot of noise to the logs. We keep successed attempts
though for the tests.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-04-30 19:27:54 -05:00
Christian Decker 9f298330b2 libplugin: It's featurebits, not features
The documentation was wrong, and I copied my mistake to `libplugin` where it
was then ignored instead of ORed into the node's featurebits. This fixes both.
2020-04-28 10:39:07 -05:00
Rusty Russell bf053dcf7c plugins: simplify htlc_accepted hook payload-setting API.
As discussed with Christian, prepending the length to the payload returned
is awkward, but it's the only way to set a legacy payload.  As this will
be soon deprecated, simplify the external API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-16 18:03:35 +09:30
Christian Decker de0fd1f274 keysend: Change the plugin to add an invoice and then continue
So far we were relying on `lightningd` to create an ad-hoc invoice when
telling it to `resolve` with a given preimage. We now switch to having the
plugin create the invoice, remove the mandatory `keysend_preimage`
field (which would upset `lightningd` otherwise), and then return the modified
payload with the instructions to `continue` instead of resolving.

This ties back in with the existing payment/invoice handling code. Invoices
are created only if we don't have a label clash (unlikely since we have the
nano-time in the label), or the `payment_hash` was already used for another
invoice (at which point `lightningd` will automatically reject the payment and
we're a bit poorer for it, but meh :-)
2020-04-16 18:03:35 +09:30
Christian Decker 97fb27650d keysend: Announce keysend featurebit in node_announcement
The featurebit isn't quite settled.
2020-04-16 18:03:35 +09:30
Christian Decker e03acd9663 libplugin: Add features to plugin_main and getmanifest 2020-04-16 18:03:35 +09:30
Christian Decker b5b11a3f67 keysend: Ignore keysends if the payload contains unknown even fields
We must really make sure that we understand the entire payload, not just the
fields we are interested in.
2020-04-16 18:03:35 +09:30
Christian Decker 1b32cc1c73 wire: Add a function to serialize a raw set of TLV fields
The generated wrappers will ignore the raw fields and will only consider the
shortcut fields. This function takes the raw fields and serializes them
instead.
2020-04-16 18:03:35 +09:30
Christian Decker ef0f28cd50 plugin: Implement the ability to receive keysend payments
This still uses the experimental TLV-type, but once the type is standardized
we can add detection for the new type quite easily.

Changelog-Added: pay: The `keysend` plugin implements the ability to receive spontaneous payments (keysend)
2020-04-16 18:03:35 +09:30
Christian Decker 5be59f4759 plugin: Add keysend skeleton 2020-04-16 18:03:35 +09:30
Christian Decker a696c8417e fundchannel: Remove the now disabled deprecated `satoshi` param
While we removed the `satoshi` param in #3603 it appears that the
`fundchannel` plugin was still passing it to the `fundchannel_start`
call. This fixes up the help text. Notice that technically the help text
changes the param name, but since it was internally always called `amount`
this change doesn't break the API, the help was just wrong.
2020-04-11 08:43:06 +09:30
ZmnSCPxj jxPCSnmZ 919d371fe8 common/json_stream.c: Implement a `json_add_jsonstr` to add already-JSON strings to `json_stream` objects.
Also incidentally fixes #3613

ChangeLog-none
2020-04-09 14:09:23 +09:30
lisa neigut b51772ff68 pay: fix #3613; string output must be quoted
`json_add_member` requires quotes for string types

Changelog-Fixed: `pay` would crash on expired waits with tried routes
2020-04-08 15:31:52 +02:00
lisa neigut 3124d43d9f pay: check for null route in maybe_exclude
Fixes (?) #3607

Changelog-Fixed: Fix crash in pay when attempting to find cheaper route with exemptfee
2020-04-08 15:31:52 +02:00
Rusty Russell 72327f5cc2 libplugin: fix compilation issue on recent gccs.
They now use -fno-common by default, so duplicated variables cause
a link error:

/usr/bin/ld: common/utils.o:(.bss+0x10): multiple definition of `chainparams'; plugins/libplugin.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:408: plugins/autoclean] Error 1

This was introduced in 9ebfdf0b8c.

Fixes: #3597
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Multiple definition of chainparams on Fedora (or other really recent gcc)
2020-04-07 20:49:58 -05:00
darosior b8262c3de2 fundechannel: don't pass deprecated 'satoshis' to fundchannel_start
Changelog-None
2020-04-06 11:54:37 +02:00
Christian Decker 891adfca1e pay: Speed up `pay` and fix the shadow route construction
The shadow route algorithm is extending the route randomly using channels
adjacent to the current destination, in the hope to create a plausible route
extension. However, instead of only retrieving the channels adjacent to the
destination it was retrieving all channels in the entire topology, and
selecting a random channel from there. This resulted in a very large request
for all channels being processed, and then mostly not being used, but also in
shadow extensions to the path which were not plausible (they didn't extend the
real path, just random edges). This is fixed by restricting the call to
`listchannels` to the channels with the current destination as source.

On my laptop retrieving all channels in the current mainnet takes
approximately 1.2 seconds, and given the geometric series expansion of the 50%
extension probability this indeed would result in an overhead of 1.2 seconds
to the `pay` command. In contrast specifying a source results in an overhead
of ~30ms.

So good news everyone, your pay commands just shaved 1.17 seconds off their
runtime.

Changelog-Changed: pay: Improved the performance of the `pay`-plugin by limiting the `listchannels` when computing the shadow route.
Changelog-Fixed: pay: The `pay`-plugin was generating non-contiguous shadow routes
2020-04-04 16:24:57 +10:30
Rusty Russell 2f1502abf4 cleanup: make 'u8 *features' and 'struct feature_set *fset' more explicit.
It's almost always "their_features" and "our_features" respectively, so
make those names clear.

Suggested-by: @cdecker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
Rusty Russell 28e3ffc66b plugins/fundchannel: make 'all' do the right thing for wumbo.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
Rusty Russell ca512e3cb2 plugins/pay: use feature set from lightningd to decode bolt11.
This means we correctly reject invoices with features we don't understand.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
Rusty Russell 8cb364dd28 libplugin: demarshal and stash the feature set given by lightningd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
Rusty Russell cf43e44378 common/features: don't use internal global.
Turns out that unnecessary: all callers can access the feature_set,
so make it much more like a normal primitive.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
darosior 7c0af81c21 bcli: use a more urgent feerate for HTLCs and penalty transactions
A CONSERVATIVE/3 target for them.

Some noisy changes to the tests as we had to update the estimatesmartfee
mock.

Changelog-Changed: We now use a higher feerate for resolving onchain HTLCs and for penalty transactions
2020-04-01 23:02:47 -05:00
Rusty Russell e940d953bd fundchannel_start: We can't deprecate 'satoshi' here, since 'amount' wasn't sent
So we can't tell people they should use amount, until v0.8.2 is
released.  Another 6 months before we can deprecated the 'satoshi'
field here :(

Fixes: d149ba2f3a
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON: `fundchannel_start` returns `amount` even when deprecated APIs are enabled.
Changelog-Deprecated: JSON: `fundchannel_start` `satoshi` field really deprecated now (use `amount`).
2020-03-30 12:47:01 +02:00
Rusty Russell 75838341a7 fundchannel/fundchannel_start: remove deprecated `satoshi` parameter
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: JSON: `fundchannel` and `fundchannel_start` `satoshi` parameter removed (renamed to `amount` in 0.7.3).
2020-03-30 12:47:01 +02:00
darosior 610aa0b8e3 bcli: register --dev-max-fee-multiplier on our side
That way we pass the real min_acceptable (SLOW/2) and max_acceptable
(URGENT * 10) feerates to lightningd.
2020-03-30 20:17:18 +10:30
darosior 902edf56e6 libplugin: allow u32 options 2020-03-30 20:17:18 +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
darosior 8e055a4506 bcli: remove a superfluous variable 2020-03-05 15:06:38 -06:00
Michael Schmoock d3ece69a1b fix: adds bcli plugin to check-source targets
Changelog-None
2020-03-04 14:04:51 +10:30
Rusty Russell 2aad3ffcf8 common: tal_dup_talarr() helper.
This is a common thing to do, so create a macro.

Unfortunately, it still needs the type arg, because the paramter may
be const, and the return cannot be, and C doesn't have a general
"(-const)" cast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-27 14:16:16 +10:30
Vasil Dimov 89ceb273f5 wire: remove towire_double()
Before this patch we used to send `double`s over the wire by just
copying them. This is not portable because the internal represenation
of a `double` is implementation specific.

Instead of this, multiply any floating-point numbers that come from
the outside (e.g. JSONs) by 1 million and round them to integers when
handling them.

* Introduce a new param_millionths() that expects a floating-point
  number and returns it multipled by 1000000 as an integer.

* Replace param_double() and param_percent() with param_millionths()

* Previously the riskfactor would be allowed to be negative, which must
  have been unintentional. This patch changes that to require a
  non-negative number.

Changelog-None
2020-02-27 09:07:04 +10:30
Vasil Dimov a754e4c6aa gitignore: extend with recently added build products
Changelog-None
2020-02-21 09:44:41 +01:00
darosior e7b0c24db2 libplugin: use a typesafe_cb for plugin_timer 2020-02-18 10:21:48 +10:30
Rusty Russell 5e2053feea pay: fix crash when we paystatus too soon.
If the attempt hasn't started yet, we can have an empty 'attempts' array
(while it's in listpeers, for example):

```
pay: plugins/pay.c:1457: json_paystatus: Assertion `tal_count(ps->attempts)' failed.
pay: FATAL SIGNAL 6 (version v0.8.1rc1-1-g946af3f)
0x55e895110543 send_backtrace
	common/daemon.c:39
0x55e8951105e9 crashdump
	common/daemon.c:52
0x7f92b0928f1f ???
	???:0
0x7f92b0928e97 ???
	???:0
0x7f92b092a800 ???
	???:0
0x7f92b091a399 ???
	???:0
0x7f92b091a411 ???
	???:0
0x55e895100012 json_paystatus
	plugins/pay.c:1457
0x55e895103aaa ld_command_handle
	plugins/libplugin.c:968
0x55e895103bd4 ld_read_json_one
	plugins/libplugin.c:1011
0x55e895103cd2 ld_read_json
	plugins/libplugin.c:1030
0x55e895124cbd next_plan
	ccan/ccan/io/io.c:59
0x55e89512583a do_plan
	ccan/ccan/io/io.c:407
0x55e895125878 io_ready
	ccan/ccan/io/io.c:417
0x55e895127a3e io_loop
	ccan/ccan/io/poll.c:445
0x55e895104593 plugin_main
	plugins/libplugin.c:1194
0x55e895100cbc main
	plugins/pay.c:1697
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-13 14:20:50 +10:30
Rusty Russell 7a178ebb7a plugins: libplugin don't insist on 'jsonrpc' field from lightningd.
Spark does this, for example:

{"method":"pay","params":["lnbc..."],"id":22}

Which doesn't have a jsonrpc field.  The result is that the command
doesn't terminate, there is nothing in the logs, stderr contains
"pay: JSON-RPC message does not contain "jsonrpc" field", and
from then on "Unknown command 'pay'".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-13 12:34:31 +10:30
darosior 5840e90ceb plugins/libplugin: don't crash if 'lightning-rpc' doesnt exist (yet)
We are going to initialize a plugin before its creation, so log as
UNUSUAL instead.

Also, `pay` and `fundchannel` inits are using rpc_delve(), so we need to
io_new_conn() (which sets the socket as non blocking) after calling the
plugin's init.
2020-02-12 11:45:07 +10:30
darosior c1009635ed plugins/bcli: register Bitcoin-related options 2020-02-12 11:45:07 +10:30
darosior f81cc9f552 plugins/bcli: wait for bitcoind to be warmed up at init
This is also taken and adapted from lightningd/bitcoind.

The call to 'getblockchaininfo' is replaced by 'echo' as we don't
make use of the result and the former can sometimes be slow (e.g. on
IBD).
2020-02-12 11:45:07 +10:30
darosior 70a79e3998 plugins/bcli: a new plugin for gathering Bitcoin data
Most is taken from lightningd/bitcoind and adapted. This currently
exposes 5 commands:
- `getchaininfo`, currently called at startup to check the network and
  whether we are on IBD.
- `getrawblockbyheight`, which basically does the `getblockhash` +
  `getblock` trick.
- `getfeerate`
- `sendrawtransaction`
- `getutxout`, used to gather infos about an output and currently used by
  `getfilteredblock` in `lightningd/bitcoind`.
2020-02-12 11:45:07 +10:30
darosior 3eb0f56f87 libplugin: generalize the plugin_timer callback type
We don't take the callback result into account, so it can better be void.
Having a general callback parameter is handy, because for bcli we want
to pass it the struct bcli.
2020-02-12 11:45:07 +10:30
darosior b0b55d36ef libplugin: add a 'still_pending' helper 2020-02-12 11:45:07 +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 b91433cb42 libplugin: use json_stream for all plugins' commands 2020-02-10 09:49:15 +10:30
darosior 2bff80e3de libplugin: use json_stream helpers for RPC calls
This adds helpers to start and send a jsonrpc request using json_stream
in order to benefit from the helpers.

This then simplifies existing plugins RPC requests by using json_stream
helpers.
2020-02-10 09:49:15 +10:30
darosior 0546728819 libplugin: use json_stream helpers for handle_getmanifest 2020-02-10 09:49:15 +10:30
darosior 45e9f53c6b libplugin: expose helpers to start and end a jsonrpc response
The usual json_stream starters and command_result enders.
2020-02-10 09:49:15 +10:30
darosior 4772025b5d libplugin don't expose the plugin struct 2020-02-05 17:05:56 +10:30
darosior b6b2e6727e libplugin: make deprecated_apis a global 2020-02-05 17:05:56 +10:30
darosior 02fe34ed95 libplugin: don't expose the rpc_conn struct 2020-02-04 13:24:32 +10:30
darosior b31e3b1541 libplugin: pass a pointer to plugin to send_outreq
autoclean needs to send outreqs from a timer cb, hence with cmd == NULL.
2020-02-04 13:24:32 +10:30
darosior c765a223f1 libplugin: use ccan/io for async Rpc requests 2020-02-04 13:24:32 +10:30
darosior 765626875e libplugin: use ccan/io for notifications 2020-02-04 13:24:32 +10:30
darosior 9ebfdf0b8c libplugin: add remaining globals to the global state
But not the outreqs helpers, which will be moved when passing
send_outreq_ to using ccan/io.
2020-02-04 13:24:32 +10:30
darosior 499dce1c38 libplugin: include the rpc conn into the global state
And rename the struct name, as it's now only used for RPC.
2020-02-04 13:24:32 +10:30
darosior 98e8aac75f libplugin: use ccan/io for response to plugin commands
This pass to json_stream helpers for commands outputs, but keeps
compatibility with existing plugins which use jout as of now, by not
starting/closing the "result"/"error" objects.
2020-02-04 13:24:32 +10:30
darosior 42cd23092c libplugin: use ccan/io for lightningd connections
Now we have streams and a global object, we can use them for io_plans.
This makes the logic closer from lightningd/plugin (it has been mostly
stolen from here), and simplifies the main.
This also allows plugins to use io_plans (thanks to the io_loop) for
asynchronous connections.

This commit only handle incoming commands.
2020-02-04 13:24:32 +10:30
darosior ddf14613d1 libplugin: introduce a top-level object
Having a global object is very handy to pass to `io_plan`s, which would
have otherwise required a whole bunch of new globals.
2020-02-04 13:24:32 +10:30
darosior 3510c29e5d common: move json_stream helpers to common/json
Now that we have json_stream in common/, we can move all the related
helpers from lightningd/json to common/json. This way everyone can
benefit of them (including libplugin, the plugins themselves,
potentially lightning-cli), not lightningd alone!

Note that the Makefile of the common/test/ had to be modified, because
the new helpers make use of common/wireaddr... Which turns out to
\#include <lightingd/lightningd.h> ! So we couldnt just include the .c
and add mocks if we redefined some structs (hello run-param).
2020-02-04 13:24:32 +10:30
Wladimir J. van der Laan e4c6fd89b7 Add missing `extern` qualifiers for gcc 10
GCC 10 defaults to `-fno-common`. no longer automatically sharing
global variable definitions, which makes it important to define
them in only one place (otherwise there will be duplicate definition
errors). Add `extern` qualifiers where (I think) is the best place for
them.
2020-02-02 12:59:17 +10:30
Vasil Dimov 55173a56b7 Use dedicated type for error codes
Before this patch we used `int` for error codes. The problem with
`int` is that we try to pass it to/from wire and the size of `int` is
not defined by the standard. So a sender with 4-byte `int` would write
4 bytes to the wire and a receiver with 2-byte `int` (for example) would
read just 2 bytes from the wire.

To resolve this:

* Introduce an error code type with a known size:
  `typedef s32 errcode_t`.

* Change all error code macros to constants of type `errcode_t`.
  Constants also play better with gdb - it would visualize the name of
  the constant instead of the numeric value.

* Change all functions that take error codes to take the new type
  `errcode_t` instead of `int`.

* Introduce towire / fromwire functions to send / receive the newly added
  type `errcode_t` and use it instead of `towire_int()`.

In addition:

* Remove the now unneeded `towire_int()`.

* Replace a hardcoded error code `-2` with a new constant
  `INVOICE_EXPIRED_DURING_WAIT` (903).

Changelog-Changed: The waitinvoice command would now return error code 903 to designate that the invoice expired during wait, instead of the previous -2
2020-01-31 06:02:47 +00:00
ZmnSCPxj a9f0f05eea pay: Implement retry in case of final CLTV being too soon for receiver.
Changelog-Fixed: Detect a previously non-permanent error (`final_cltv_too_soon`) that has been merged into a permanent error (`incorrect_or_unknown_payment_details`), and retry that failure case in `pay`.
2020-01-21 22:23:21 +01:00
ZmnSCPxj 6c0d7ca737 pay: Implement tracking of blockheight for starting payment attempts. 2020-01-21 22:23:21 +01:00
ZmnSCPxj e9aa690d44 pay: Factor out execution of `getroute` from starting of payment attempt. 2020-01-21 22:23:21 +01:00
Vasil Dimov 2ea91f834c Add the missing space between "if" and "("
Changelog-None
2020-01-06 12:57:59 +01:00
Vasil Dimov 76e5ed45a6 doc: fix wording in plugins/README.md
Changelog-None
2020-01-06 12:57:59 +01:00
lisa neigut 689dd28ddd funding: enable push_msat
it's that time of year (merry xmas!)

enables the ability to push_msat on fundchannel

Changelog-Added: RPC: `fundchannel` and `fundchannel_start` can now accept an optional parameter, `push_msat`, which will gift that amount of satoshis to the peer at channel open.
2019-12-24 12:04:01 -06:00
Rusty Russell 207689c274 plugins: listpays will now consolidate multi-part payments.
This won't usually be visible to the end-user, since the pay plugin doesn't
do multi-part yet (and mpp requires EXPERIMENTAL_FEATURES), but we're ready
once it does.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-12 15:03:53 +01:00
Rusty Russell f1bc0b21f1 plugins: listpays ignores pre-0.7.0 or manual sendpay payments w/ no bolt11.
The pay plugin has been supplying the bolt11 string since 0.7.0, so only
ancient "pay" commands would be omitted by this change.

You can create a no-bolt11 "sendpay" manually, but then you'll find it
in 'listsendpays'.

Changelog-Removed: JSON: `listpays` won't shown payments made via sendpay without a bolt11 string, or before 0.7.0.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-12 15:03:53 +01:00
darosior fcbd11f0c5 plugins/libplugin: hook support
Changelog-Added: plugins: libplugin now supports writing plugins which register to hooks
2019-12-09 16:18:28 +01:00
darosior 3371f0cf78 plugins/libplugin: notifications support
Changelog-Added: plugins: libplugin now supports writing plugin which registers to notifications
2019-12-09 16:18:28 +01:00
lisa neigut a30ee2b7cd fundchannel: attempt to connect before funding channel
Attempts to connect to peer before funding the channel
2019-12-04 15:32:31 -06:00
darosior ff412a6c9a plugins/fundchannel: try to connect to peer before funding
Changelog-Added: RPC: The 'fundchannel' command now tries to connect to the peer before funding the channel, no need to 'connect' before 'fundchannel' anymore !
2019-12-04 15:32:31 -06:00
Rusty Russell 18e9144675 plugins/pay: hand payment_secret from bolt11 through to sendpay.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-24 23:33:17 +00:00
lisa neigut 963a1da958 addr: handle P2SH/P2PKH in scriptpubkey encoding
Previously, returned null if a scriptpubkey was not Segwit; now
handles encoding to Base58 for other types.
2019-11-13 03:31:20 +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 16f5af00c7 common/json: add a helper for json to u16
As Rusty pointed out to me, the gossip protocol restricts cltvs to u16
so at least we'll use this helper for them.
2019-11-08 03:27:58 +00:00
darosior 5766231d98 pay: restore payment value randomization through shadow routing
When doing the random walk through the channel, we now add the fees
(both the base and the proportional one) for that channel in addition to
the cltv delta.

Changelog-Added: Payment amount fuzzing is restored, but through shadow routing.
2019-11-08 03:27:58 +00:00
Rusty Russell fe17acf07b TAGS: reformat to fix when PRINTF_FMT() used.
I was wondering why TAGS was missing some functions, and finally
tracked it down: PRINTF_FMT() confuses etags if it's at the start
of a function, and it ignores the rest of the file.

So we put PRINTF_FMT at the end, but that doesn't work for
*definitions*, only *declarations*.  So we remove it from definitions
and add gratuitous declarations in the few static places.1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-01 17:27:20 -05:00
Jorge Timón 61383408a4 pay: Return error when trying to pay to an invoice from unkown or different chain 2019-10-30 13:06:24 -05:00
trueptolemy d149ba2f3a JSON-API: `fundchannel_start` uses `amount` fieldname to replace `satoshi` 2019-10-09 16:51:42 -05:00
trueptolemy aafa16786d JSON-API: `fundchannel` uses `amount` fieldname to replace `satoshi` 2019-10-09 16:51:42 -05:00
Christian Decker 7283efa5b5 elements: Add amount_asset to support more than just plain satoshis
Currently the only source for amount_asset is the value getter on a tx output,
and we don't hand it too far around (mainly ignoring it if it isn't the
chain's main currency). Eventually we could bubble them up to the wallet, use
them to select outputs or actually support assets in the channels.

Since we don't hand them around too widely I thought it was ok for them to be
pass-by-value rather than having to allocate them and pass them around by
reference. They're just 41 bytes currently so the overhead should be ok.

Signed-off-by: Christian Decker <@cdecker>
2019-10-03 04:32:57 +00:00
Christian Decker d5f0c08a88 elements: Remove global is_elements variable in favor of chainparams
No need to keep duplicate globals.
2019-10-03 04:32:57 +00:00
Christian Decker 14247283b2 plugin: Tell the plugin which network we run on
The fundchannel plugin needs to know how to build a transaction, so we need to
tell it which chainparams to use. Also adds `chainparams` as a global, since
that seems to be the way to do things in plugins.
2019-10-03 04:32:57 +00:00
Rusty Russell 2a74d53841 Move gossip_constants.h into common/
Turns out we weren't checking the BOLT comments before, so they
needed an overhaul.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-25 04:01:56 +00:00
trueptolemy 765416f0ca cleanup: Use `json_out_add_u32` helper to add `max_hops` and `cltv` in `pay` plugin 2019-09-24 16:01:24 +02:00
trueptolemy 2d1a153975 plugins: Return `command_param_failed()` if `param()` fail 2019-09-19 01:07:11 +00:00
trueptolemy c737fa6b91 pay: Fix logic of the intereface `find_worst_channel` 2019-09-17 21:06:12 +02:00
trueptolemy bdbfbf7e55 fundchannel: Remove the link of `lightningd/json.h` 2019-09-17 21:05:51 +02:00
trueptolemy b4c6a5c0f0 plugins/.gitignore: Add `fundchannel` entry 2019-09-17 21:05:51 +02:00
trueptolemy 22e8d242fc pay: Exclude nodes if the failcode of `sendpay` has the NODE bit set 2019-09-16 12:22:06 +08:00
lisa neigut a35677fa0f fundchannel: use plugin; delete interior impl
Switch over to using the fundchannel plugin.
2019-09-11 23:56:27 +00:00
lisa neigut 548672ea0a fundchannel: populate max_funding from chainparams
Since we pull the chainparams out to get the funding_addr placeholder,
we can also get the max_funding now!
2019-09-11 23:56:27 +00:00
lisa neigut 42ef64941a fundchannel: have address work with any network
`txprepare` verifies that you're sending to an address on the
right network, so this builds a placeholder address for the
right network.
2019-09-11 23:56:27 +00:00
lisa neigut 7d069239aa fundchannel: only cap to 'max' if keyword 'all' passed in
in order to preserve current behavior, we cap at max if specified 'all';
otherwise we fail since the amount requested is larger than the
channel max capacity
2019-09-11 23:56:27 +00:00
lisa neigut d9843c1957 fundchannel: handle 'all' for satoshi amount
Previously, we'd fail on 'all'. `fundchannel_start` needs an amount
in order to start a funding transaction.

The way that we approach this is to first call `txprepare` with a
placeholder address and the 'all' amount; this will return the maximum
amount available. We then clamp this to the max_funding (currently
hardcoded, in the future we'd want to consult our/the peer's features) and
then use the amount on the output in the prepared transaction as the
funding amount. We then pass this amount to fundchannel_start,
after we've started it successfully we cancel the held placeholder
transaction and prepare a second transaction for the exact amount,
using the funding address that fundchannel_start passed back.
2019-09-11 23:56:27 +00:00
lisa neigut f155c61bdf fundchannel: cancel the fundchannel request if error
If txprepare hits an error, we need to cancel the pending request
with our peer.
2019-09-11 23:56:27 +00:00
lisa neigut 03a30c0981 fundchannel: wire in utxos
Allows a user to specify the utxo's they like to allow for a command.
2019-09-11 23:56:27 +00:00
lisa neigut f433f637ea plugins: add fundchannel plugin, as 'fc'
New plugin which mimics the functionality of the embedded 'fundchannel'.
2019-09-11 23:56:27 +00:00
lisa neigut 2fe490294e libplugin: new helper method for passing a raw error
Makes it easier to stash an error and then return it after another
RPC call has been made.
2019-09-11 23:56:27 +00:00
lisa neigut f784863603 libplugin: add required import
libplugin seems to need the time include, so move it up from pay.
2019-09-11 23:56:27 +00:00
Rusty Russell 884f4fa6d0 JSON: Remove description fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-06 14:19:14 +02:00
Rusty Russell acf3952acc JSON: remove handling of pre-Adelaide (B:T:N) short_channel_ids.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-06 14:19:14 +02:00
Rusty Russell a134062f98 bolt11: handle `9` fields for new features.
This implements https://github.com/lightningnetwork/lightning-rfc/pull/656

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-05 23:39:05 -05:00