Commit Graph

5434 Commits

Author SHA1 Message Date
Rusty Russell 177cfd9edc common: json_to_msat and json_to_sat helpers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 03:44:44 +00:00
Rusty Russell a25e22737c common/json_tok: add param_msat / param_sat.
The current param_sat accepts "any": rename and move that to invoice.c
where it's called.  We rename it to param_msat_or_any and invoice.c
is our first (trivial) amount_msat user.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 03:44:44 +00:00
Rusty Russell 023923e6a8 amount: minor comment and text improvements and remove unused function.
Reported-by: @niftynei
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 1d1fcc41b8 db: add amount functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 7fad7bccba common/amount: new types struct amount_msat and struct amount_sat.
They're generally used pass-by-copy (unusual for C structs, but
convenient they're basically u64) and all possibly problematic
operations return WARN_UNUSED_RESULT bool to make you handle the
over/underflow cases.

The new #include in json.h means we bolt11.c sees the amount.h definition
of MSAT_PER_BTC, so delete its local version.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 269dbe585c wire: move short_channel formatting functions into bitcoin/short_channel_id
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell ebca6e1ea3 update-mocks: make sure we can find json_add functions.
These are on start of line, which is unexpected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 175c869b6b update-mocks: handle NO_NULL_ARGS and NON_NULL_ARGS functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 1c542bcd08 pylightning: prepare plugin for parameters to getmanifest.
We might still add these in future, so I think we should allow for it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 53423e8a55 lightningd: re-enable IO logging for JSON output.
Hex format is terrible, but sometimes it's the only way to tell WTF is
going on.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Rusty Russell 19d13f1781 type_to_string: return const char *.
Always be const if you can.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-21 00:44:57 +00:00
Christian Decker 9b721ceca7 plugin: Add docs for hooks
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01: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
Christian Decker 2c443cc0fd plugin: Parse and react to the result of the peer_connected hook
Final step for the `peer_connected` hook, we parse the result and act
accordingly. Currently we just close the underlying connection, but we
may want to clean up peers that did not end up with a channel.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Christian Decker ff0ddee56e json: Add utility to add a null-member
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Christian Decker b5085a9c17 hooks: Serialize the peer that connected as hook call payload
The format is very similar to the one for `listpeers` except we only
list a single channel, and we list the actual netaddr that connected
instead of all known from gossip.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Christian Decker 828d088d60 moveonly: Move the channel details into json_add_channel
This used to be inline, but we want to pass channels to hooks as well,
so we just extract this into its own function.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Christian Decker bccb8db974 wire: derive_channel_id should accept const struct *bitcoin_txid
It's not modifying anything in the txid itself, just mashing it up
with the txout index.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Christian Decker ca3db290ba plugin: Add `connected` hook
This hook is used to let a plugin decide whether we should continue
with the connection normally, or whether we should be dropping the
connection. Possible use-cases include policy enforcement (dropping
connections based on previous interactions), draining a node by
allowing only peers with an active channel to reconnect, or
temporarily preventing a channel from making progress.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-20 15:37:59 +01:00
Rusty Russell 5f0b065622 channeld: handle funding_locked message before reestablish.
LND seems to do this occasionally, though fixed in new versions.  Workaround
in the meantime.

I tested this by hacking our code to send it prematurely, and this worked.

Fixes: #2219
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-20 14:07:04 +01:00
Conor Scott 3b68e29bbd Ignore generated python and pylightning files 2019-02-19 19:11:49 +01:00
Rusty Russell 7a1d13a77e pytest: make test_pay_direct more robust.
We had occasional failures, because the fuzz could overwhelm the difference
in routes.  Increasing the amount to 2,000,000 millisatoshis makes the
riskfactor 53msat (2000000 * 14 * 10 / 5259600) which is always greater
than the worst-case fuzz of 5% on the fee of 1002msat.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-18 15:32:22 +01:00
Rusty Russell cb6a97152e pytest: fix race in test_pay_direct.
I got a spurious failure because the final node gave a CLTV error and
so it decided to use a different channel.  It should probably handle
this corner case better, but meanwhile make the test robust.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-18 15:32:22 +01:00
Rusty Russell 41be796e0e pytest: add simple test for --daemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-18 12:01:06 +01:00
Rusty Russell 8c22b91a70 lightningd: activate crashlog before forking off as daemon.
This avoids cases like #2348 where the user gets *no* clue as to what
went wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-18 12:01:06 +01:00
Christian Decker a405c22fc9 daemon: Fix issue 2348, db->filenam not being correctly initialized
We were not correctly allocating the `db->filename`, failing to copy the
null-terminator. This was causing and error when reopening the database after
the call to `fork()`.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Reported-by: Sean McNally <@sfmcnally>
Changelog-fixed: Fixed a crash when running in daemon-mode due to db filename overrun
2019-02-18 12:01:06 +01:00
Michael Schmoock 3db534580c doc: add configure --enable-dev in testing chapter
As a newbie, I forgot to re-enable the dev options that are required to run the tests...
2019-02-18 02:42:29 +00:00
Christian Decker a77e9b2a05 docs: Fix two permanent redirects
Courtesy of `sphinx-build -b linkchecker doc`

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-18 02:42:29 +00:00
Christian Decker 0e34b9ac0e readme: Add a readthedocs badge to show that we have nice docs :-)
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-18 02:42:29 +00:00
Christian Decker e11ddfc992 docs: Add configuration for the sphinx documentation generator
This just takes the existing documentation, and generates a nice HTML
version we can point users to. The documentation is automatically
generated on every commit to `master` and will be deployed here:

https://lightning.readthedocs.io/

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-18 02:42:29 +00:00
Christian Decker 886700454d docs: Consolidating header hierarchy slightly
This is a preparatory step for the automatic documentation generation
that is going to use `sphinx-doc`. Each document should include a top
level header that matches the name and scope of the document and all
following headers should be of a lower level than the top-level
header.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-18 02:42:29 +00:00
Christian Decker ac6d9b34cc pylightning: Correctly return the remainder of a message back
We read a JSON message from the buffer, after converting it from raw bytes to
UTF-8, and returning the remainder of the byte array back to the
caller. However the return value of `raw_decode` refers to symbols in the
UTF-8 decoded string, not the raw bytes underlying byte-array, which means
that if we have multi-byte encoded UTF-8 symbols in the byte-array we end up
with a misaligned offset and will return part of the message as
remainder. This would then end up being interpreted as the result of the next
call.

This could not be exploited currently since we use a socket only for a single
JSON-RPC call and will close the connection afterwards, but since we want to
eventually recycle connections for multiple calls, this could have been very
dangerous.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Reported-by: Corné Plooy <@bitonic-cjp>
2019-02-18 02:10:43 +00:00
Michael Schmoock 302a78f4eb fix: add inline exception for recent cppcheck false positive 2019-02-18 01:06:01 +00:00
Michael Schmoock 5c0d658b30 fix: change type of config->fee_per_satoshi to uint32
This patch will properly set fee_per_satoshi to _unsigned_ integer,
as support for negative fees was removed from overall design.

This change does not break any tests, so I assume its
better this way.
2019-02-18 00:17:31 +00:00
Alekos Filini 21afe1c0f4 doc: fix the command to cross-compile libgmp 2019-02-18 00:09:20 +00:00
Christian Decker 59fa47bf64 pytest: Mark the worst gossip offenders as developer-only tests
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-18 00:06:02 +00:00
Simon Vrouwe 201dd3ce0c doc: improve explanation of getroute command 2019-02-17 21:48:24 +01:00
Simon Vrouwe 4fe60ee769 doc: fundchannel command, clarify optional `feerate`
mentioned in issue #2354
2019-02-17 21:48:24 +01:00
Simon Vrouwe 872c0c90b9 remove trailing space in logline and small coding style fix 2019-02-17 21:48:24 +01:00
Simon Vrouwe 34e40b9383 lightningd/json_dev_forget_channel: clarify message when both peer_id and scid are given
mentioned in issue #2298
2019-02-17 21:48:24 +01:00
Simon Vrouwe b66d6a0d55 lightningd/json_fundchannel: use json_add_string to add hex_tx to response, similar as in json_withdraw 2019-02-17 21:48:24 +01:00
Richard Bondi 503360143a fix crash with lightning charge and plugin opts (#2358)
* fix crash with lightning charge and plugin opts
2019-02-17 21:44:10 +01:00
Mark Beckwith 3e4a3bafc3 doc: fix connect manpage parameter names and...
also fixed grammar and consistency with other manpages.

The names are now the same as what json_connect() expects.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
2019-02-11 18:28:45 +01:00
Rusty Russell b99293fbb6 short_channel_id: don't accept :-separated in JSON if --allow-deprecated-apis=false
We need to still accept it when parsing the database, but this flag
should allow upgrade testing for devs building on top

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-08 16:52:30 -08:00
Rusty Russell d413fc7e9b configure: use system libbase58 if available.
Also one less headache for reproducible builds.  But unlike
libsodium, this only seems common in Ubuntu.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-08 01:10:17 +00:00
Rusty Russell 21fd8f7eaa configure: use system libsodium if available and modern.
Also one less headache for reproducible builds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-08 01:10:17 +00:00
Rusty Russell 2db84d6653 tools/check-setup_locale.sh: don't get caught by main in non-C files.
We're about to put one in configure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-08 01:10:17 +00:00
Rusty Russell e857229de4 tools: make build-release more friendly.
You can now override sanity checks for testing, and also
specify exactly what to build.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-08 01:10:17 +00:00
Christian Decker b7222531fe pytest: Stabilize the test_pay_direct test
It was waiting for a remote channel, but not for all the interesting
channels we want to check. It can sometimes happen that further away
channels are added before closer ones are added, depending on
propagation path, flush timers and bitcoind poll timers. This now just
checks for all channels, which also reduces the ambiguity of whether
we selected a path solely because we were lacking alternatives.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-02-08 01:08:44 +00:00
Conor Scott 960664337f pylightning: handle method introspection more generally.
[ I just cut & paste from @conscott's comment on GitHub -- RR ]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00