Commit Graph

498 Commits

Author SHA1 Message Date
Christian Decker b1aed933e6 pyln: Plugin methods and hooks refuse to set results twice
We had a couple of instances where a plugin would be killed by `lightningd`
because we were returning a result of an exception twice, and it was hard to
trace down the logic error in the user plugin that caused that. This patch
adds a traceback the first time we return a result/exception, and raise an
exception with a stacktrace of the first termination when a second one comes
in.

This can still terminate the plugin, but the programmer gets a clear
indication where the result was set, and can potentially even recover from it.

Changelog-Added: pyln: Plugin method and hook requests prevent the plugin developer from accidentally setting the result multiple times, and will raise an exception detailing where the result was first set.
2020-10-13 20:52:48 +02:00
Christian Decker 556725c5ff pyln: Add logging handler that passes records to lightningd
It is often pretty usefuk to use the builtin logging module to debug things,
including libraries that a plugin may use. This adds a simple
`PluginLogHandler` that maps the python logging levels to the `lightningd`
logging levels, and formats the record in a way that it doesn't clutter up the
`lightningd` logs (no duplicate timestamps and levels).

This allow us to tweak the log level that is reported to `lightningd` simply
using the following

```python3
import logging
logging.basicConfig(level=logging.DEBUG)
```

Notice that in order for the logs to be displayed on the terminal or the
logfile, both the logging level in the plugin _and_ the `--log-level`
`lightningd` is running need to be adjusted (the python logging level only
controls which messages get forwarded to `lightningd`, it does not have the
power to overrule `lightningd` about what to actually display).

I chose `logging.INFO` as the default, since libraries have a tendency to spew
out everything in `logging.DEBUG` mode

Changelog-Added: pyln: Plugins have been integrated with the `logging` module for easier debugging and error reporting.
2020-10-13 20:52:14 +02:00
Rusty Russell a297c1b9a5 pytest: fix overzealous removal of directories on failure.
We were always deleting the directories.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-10-13 17:33:49 +02:00
Christian Decker ae9753df3a travis: Specify pytest-rerunfailures==9.1 to avoid regression
Seems the recently released version 9.1.1 has regressed, and isn't actually
rerunning failed tests. Pinning it to 9.1 seems to work however.
2020-10-13 14:30:45 +02:00
Christian Decker d5d41ef1a0 pyln: Remove any logging handlers at teardown to avoid logging error
Inspired by https://github.com/pytest-dev/pytest/issues/5502#issuecomment-647157873
2020-10-13 14:30:45 +02:00
fiatjaf 9c838cf953 pyln-client: listpayments -> listpays 2020-10-09 13:21:35 +10:30
Christian Decker 6f870dfe39 pytest: Don't give up on the first psql connection error
Since we start a new instance of postgres for each test we may end up swamped
and the startup can take a bit longer. So let's loop until we get a success.
2020-10-07 09:36:30 +10:30
Christian Decker 9021bb26d1 pyln: Decode process output once before storing it 2020-10-07 09:36:30 +10:30
Christian Decker b6053d7cd6 Fix pytest major version
They released version 6, which is causing some trouble apparently. So fix it
to v5.
2020-10-07 09:36:30 +10:30
Christian Decker 66dc3ed665 pyln: Add pytest to type ignores
Reported-by: Rusty Russell <@rustyrussell>
2020-10-07 09:36:30 +10:30
Christian Decker 8d8b807793 pytest: Make LightningNode.fund_channel more resilient
It was really flaky, especially under `test_mpp_interference_2`, most likely
due to multiple calls to `fund_channel`. This commit looks for the specific
txids in the `listfunds` output and the `getrawmempool` output, avoiding
strange artifacts from multiple calls.
2020-10-07 09:36:30 +10:30
Christian Decker cafaad741b pyln: Add type-annotations to pyln-proto 2020-09-28 09:19:46 +09:30
Christian Decker c498f949cc pyln: Add mypy typing exceptions for external dependencies
We don't control them, and starting to write type stubs for them is a
different can of worms.
2020-09-28 09:19:46 +09:30
Christian Decker 1d2c2b6aaf pyln: Parametrize and unify Makefiles for pyln package 2020-09-28 09:19:46 +09:30
Christian Decker 5809cc41f4 pytest: Reduce the db_provider fixture scope to function
For performance reasons we were starting one for each session, which caused
the same postgres DB to be re-used for multiple tests (all test run in the
same worker process), but this could lead to interactions if there is a
timeout or a test happens to touch the `db_provider`. It turns out that we
were only saving about 15 seconds on a 1250 second run anyway, which is a
small cost for increased test isolation.
2020-09-26 09:04:35 +09:30
Christian Decker 7e99a3b5fd pyln: Allow the base test directory to contain some files
We were not removing the base test directory if we had other files in there,
which was the case for postgres runs. This now explicitly check for `test_*`
directories which are an indicator of a failed test.
2020-09-26 09:04:35 +09:30
Christian Decker aeb5f969e2 pyln: Start each postgres DB in its own sub-directory
We had a couple of issues with workers dying and attempting to re-initialize
the database while it was already initialized. This will look for a free
directory and just start the DB in there, allowing workers to be better
isolated.
2020-09-26 09:04:35 +09:30
Antoine Poinsot 3382dafaee configure: allow to run clang with ASAN
Prefer adding LSAN_OPTIONS="suppressions=$PWD/tests/sanitizer_suppressions/lsan" when CC=clang instead.

Changelog-Added: build: clang build now supports --enable-address-sanitizer .
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-09-24 13:57:43 +09:30
Christian Decker a351b9bf2f pyln: Migrate from binascii.hexlify to bytes.hex
Suggested-by: Lisa <@niftynei>
2020-09-24 11:14:22 +09:30
Christian Decker 04462f6a64 pyln: Add code to unwrap an encrypted onion at the intended node
Changelog-Added: pyln-proto: Added pure python implementation of the sphinx onion creation and processing functionality.
2020-09-24 11:14:22 +09:30
Christian Decker e8dcd59b24 pyln: Add a warning that pyln-proto is not safe for production use 2020-09-24 11:14:22 +09:30
Christian Decker 96b182a084 pyln: Implement sphinx onion packet generation in python
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <@cdecker>
2020-09-24 11:14:22 +09:30
Christian Decker 668debb74f pyln: Rename LightningNode.fund_channel to fundchannel
It is inconsistent with the RPC method, which was bothering me for some time.
2020-09-23 14:45:12 +09:30
Christian Decker 8ecb157af6 pyln: Add type annotations to lightning.py 2020-09-23 14:45:12 +09:30
Christian Decker 49ec800a07 pyln: Add type-annotations to plugin.py
This should help users that have type-checking enabled.
2020-09-23 14:45:12 +09:30
Christian Decker d27da4d152 pyln: Fix two formatting string not matching parameters 2020-09-23 14:45:12 +09:30
Christian Decker 748caf91d3 pyln-client: Add support to monkey patch the JSONEncoder
Several times we had issues with plugins not being able to re-encode an RPC
result because they forgot to use the custom encoder class. This allows us to
patch the JSONEncoder when we start the RPC or the plugin and automagically
support classes that provide a `to_json` method.
2020-09-23 14:45:12 +09:30
Christian Decker 382230509b pyln: Add stubs to generate documentation for pyln-client 2020-09-23 14:45:12 +09:30
Rusty Russell 0a50301d51 pytest: don't test for memleaks under valgrind.
The next patch perturbed things enough that we suddenly started
getting (with --track-origins=yes):

Valgrind error file: valgrind-errors.120470
==120470== Use of uninitialised value of size 8
==120470==    at 0x14EBD5: htable_val (htable.c:150)
==120470==    by 0x14EC3C: htable_firstval_ (htable.c:165)
==120470==    by 0x14F583: htable_del_ (htable.c:349)
==120470==    by 0x11825D: pointer_referenced (memleak.c:65)
==120470==    by 0x118485: scan_for_pointers (memleak.c:121)
==120470==    by 0x118500: memleak_remove_region (memleak.c:130)
==120470==    by 0x118A30: call_memleak_helpers (memleak.c:257)
==120470==    by 0x118A8B: call_memleak_helpers (memleak.c:262)
==120470==    by 0x118A8B: call_memleak_helpers (memleak.c:262)
==120470==    by 0x118B25: memleak_find_allocations (memleak.c:278)
==120470==    by 0x10EB12: closing_dev_memleak (closingd.c:584)
==120470==    by 0x10F3E2: main (closingd.c:783)
==120470==  Uninitialised value was created by a heap allocation
==120470==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==120470==    by 0x1604E8: allocate (tal.c:250)
==120470==    by 0x160AA9: tal_alloc_ (tal.c:428)
==120470==    by 0x119BE0: new_per_peer_state (per_peer_state.c:24)
==120470==    by 0x11A101: fromwire_per_peer_state (per_peer_state.c:95)
==120470==    by 0x10FB7C: fromwire_closingd_init (closingd_wiregen.c:103)
==120470==    by 0x10ED15: main (closingd.c:626)
==120470==

This is because there is uninitialized padding at the end of struct
peer_state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
niftynei d0e42e2c36 contrib: make bitcoin polling and gossip propagation snappier
Faster stronger better local testing
2020-09-17 10:14:22 +09:30
Christian Decker a88073f6fb repro: Add missing Dockerfiles 2020-09-16 06:27:12 +09:30
Sergi Delgado Segura f1d5fdf323 pyln: Sets remote_pubkey for LightningConnection if node is not the initiator
Currently ``LightningConnection.remote_pubkey`` is set to ``None`` if the node is not the handshake initiator. This sets it to ``rs`` in act three from the receiver side
2020-09-12 15:06:08 +09:30
Christian Decker f5dd393113 pyln: Bump proto version to match pyln-bolt*
Since pyln-bolt* specify the 0.8.4 version which we didn't upload, and the
requirements.txt specify ==0.8.4, we need to backfill that version, even if we
could just bump it directly to 0.9.1.
2020-09-10 20:01:41 +09:30
Christian Decker bd811fbd1a pyln: Add safe fallback results for hooks
Hooks do not tolerate failures at all. If we return a JSON-RPC error to a hook
call the only thing the main daemon can really do is to crash. This commit
adds a mapping of error to a safe fallback result, including a warning to the
node operator that this should be addressed in the plugin. The warning is
reported as a `**BROKEN**` message, and should therefore fail any testing done
on the plugin.

Changelog-Fixed: pyln: Fixed HTLCs hanging indefinitely if the hook function raises an exception. A safe fallback result is now returned instead.
2020-09-10 10:27:24 +09:30
Michael Schmoock 218a9efaec pyln-testing: add get_channel_id helper 2020-09-10 10:24:06 +09:30
ZmnSCPxj jxPCSnmZ 277ff0f44c plugins/spender/multiwithdraw.c: Implement multiwithdraw command.
Fixes: #2679

Changelog-Added: JSON-RPC: New `multiwithdraw` command to batch multiple onchain sends in a single transaction.  Note it shuffles inputs and outputs, does not use BIP69.
2020-09-09 20:36:08 +09:30
Christian Decker d46d82eeff pyln-testing: Allow up to 1000 connections to postgresql in tests
This was causing some errors when testing with a lot of parallelism (30+ tests
in parallel)
2020-09-09 20:17:26 +09:30
niftynei b3cbb0b653 tests: plugin for dual-funding tests in ln-prototest
FIXME: requires wallycore
2020-09-09 19:54:20 +09:30
niftynei 171b9857de contrib: add ability to start/stop elements nodeset
sometimes it's handy to be able to get access to an elements daemon and
node set also
2020-09-09 16:49:25 +09:30
ZmnSCPxj jxPCSnmZ 45e1b3828a plugins/multifundchannel.c: Add minchannels flag to multifundchannel.
[ changed from best_effort binary to minchannels counter -- RR]
2020-09-09 16:45:56 +09:30
ZmnSCPxj jxPCSnmZ 9460838650 doc/, contrib/: Additional support etc. for multifundchannel. 2020-09-09 16:45:56 +09:30
Christian Decker 71e713c722 pyln-testing: Bump version to 0.9.0 and add Makefile for release 2020-08-30 20:03:42 +02:00
Christian Decker 0b50fd0f96 pyln-testing: Add a dummy test to check functionality 2020-08-30 20:03:42 +02:00
Christian Decker 81d8525d86 pyln: Make the pytest requirement less stringent 2020-08-30 20:03:42 +02:00
niftynei 26f116041c contrib: start_ln now creates variable number of nodes
Re-write start_ln such that we can create up to 10 nodes locally for
testing. Useful for scenarios where more than two nodes are needed

Changelog-Changed: contrib: startup_regtest.sh `startup_ln` now takes a number of nodes to create as a parameter
2020-08-28 14:27:56 +09:30
niftynei c8579b99d0 pyln-proto: use vals for subtype parsing 2020-08-27 10:20:16 +09:30
Christian Decker 437c411769 pyln-testing: Have LightningNode.fund_channel poll 2020-08-27 09:45:35 +09:30
Christian Decker 0431a29a26 pyln-testing: Poll for channel active instead of watching logs 2020-08-27 09:45:35 +09:30
ZmnSCPxj jxPCSnmZ 8c763bb7be contrib/pyln-testing/pyln/testing/utils.py: Add a fundbalancedchannel method to LightningNode, for when you want to Thanos your channels. 2020-08-26 09:29:46 +09:30
Sergi Delgado Segura 3edbacbb3c pyln: hexlify -> bytes.hex() in pyln.proto.wire 2020-08-26 06:09:53 +09:30
Sergi Delgado Segura 27e495efa5 pyln: Updates proto to use coincurve for Public and Private keys 2020-08-26 06:09:53 +09:30
nicolas.dorier 2e51f23a95 Add python to runtime docker image (arm32/64) 2020-08-24 20:23:25 +02:00
Rusty Russell 7435d50970 signpsbt: add signonly parameter to restrict/enforce what inputs to sign.
This is an extra safety check for dual funding, where we only want to sign
the inputs we provided!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `signpsbt` takes an optional `signonly` array to limit what inputs to sign.
2020-08-18 11:38:25 -05:00
Rusty Russell aab3808668 utxopsbt: let caller specify locktime, add tests and python binding.
Changelog-Added: JSON-RPC: `utxopsbt` takes a new `locktime` parameter
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-18 11:38:25 -05:00
Rusty Russell 14baaaa8ba fundpsbt: let caller specify locktime.
Required for dual funding where the opener sets it.

Changelog-Added: JSON-RPC: `fundpsbt` takes a new `locktime` parameter
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-18 11:38:25 -05:00
Rusty Russell 624df64330 pyln-client: allow commands and options to mark themselves deprecated.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: pyln-client: commands and options can now mark themselves deprecated.
2020-08-11 08:43:18 +09:30
Rusty Russell 4ce8f56327 pyln.client.plugin: set deprcated_apis based on getmanifest.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-11 08:43:18 +09:30
Rusty Russell 151bc47583 JSON-RPC: getmanifest passes allow-deprecated-apis flag.
This allows plugins to choose how to present things in getmanifest.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: plugins: `getmanifest` may now include "allow-deprecated-apis" boolean flag.
Changelog-Deprecated: plugins: `getmanifest` without any parameters; plugins should accept any parameters for future use.
2020-08-11 08:43:18 +09:30
Rusty Russell 01a82d38f7 pytest: add slow_test marker.
And when it's set, and we're SLOW_MACHINE, simply disable valgrind.

Since Travis (SLOW_MACHINE=1) only does VALGRIND=1 DEVELOPER=1 tests,
and VALGRIND=0 DEVELOPER=0 tests, it was missing tests which needed
DEVELOPER and !VALGRIND.

Instead, this demotes them to non-valgrind tests for SLOW_MACHINEs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 51aae9cce7 pytest: make valgrind a per-node option.
Next patch will turn it off for slow-marked tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 79278b880f pytest: optimize join_nodes a little.
We can query all the txids at once, rather than one at a time.

Doesn't make any measurable difference to full runtime testing here
though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 929fd3e2f6 pytest: make sure all nodes see funds using sync_blockheight
We might have funds prior to calling join_nodes(), so testing that
we've all seen the block is better.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 02b413a4dc pytest: make join_nodes / line_graph wait for updates in both dirs.
This is what fund_channel() does, which is more thorough than what
we were doing.  But since the order of the logs is undefined, we need
to be a little careful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 8f455c8b98 pytest: new join_nodes to allow you to get all the nodes then join some of them.
This lets you get_nodes() and join some later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-07 13:57:31 +02:00
Rusty Russell 06372e13d8 pyln.proto.message: don't let Message() init set implicit lengths.
We'll override them from field length anyway!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-08-06 17:53:25 +02:00
Antoine Poinsot 5b45334d93 pyln: allow to signal may_fail in get_node()
This or `expect_fail`, as it implies that, well, the node may fail.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-08-03 12:46:37 +09:30
Rusty Russell 1274d34822 lightningd: add --dev-no-version-checks, use if SLOW_MACHINE and VALGRIND
Reduces VALGRIND=1 node_factory.line_graph(5) time on my laptop from 42s to 36s.

This is simply because forking all the subdaemons just to check the
version is very expensive under valgrind.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-22 16:13:44 +02:00
Rusty Russell c85a433d9a pytest: reduce accuracy of valgrind if SLOW_MACHINE.
Reduces node_factory.line_graph(5) time on my laptop from 48s to 42s.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-22 16:13:44 +02:00
Rusty Russell 73a5f5b313 fundpsbt: make parameters more usable.
fundpsbt forces the caller to manually add their weight * feerate
to the satoshis they ask for.  That means no named feerates.

Instead, create a startweight parameter and do the calc for them
internally, and return the feerate we used (and, while we're at it,
the estimated final weight).

This API change is best done now, as it would otherwise have to
be appended as a parameter.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-17 13:53:46 +02:00
Rusty Russell 31d7e013bd pytest: test fundpsbt.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-15 18:49:02 +09:30
Rusty Russell 4ee527a59c pytest: test reserve and unreserve.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-07-15 18:49:02 +09:30
Christian Decker be9b55fcb5 pyln: Add a traceback if a hook or rpc method fails 2020-07-02 11:54:12 +02:00
Rusty Russell 74abd30da5 pyln-proto, pyln-spec: fix 'make prod-release' target.
rusty$ make prod-release
  make: *** No rule to make target 'test', needed by 'prod-release'.  Stop.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-29 18:01:12 +02:00
niftynei 9830c94778 rpc: new signpsbt + sendpsbt rpcs
Changelog-Added: JSON-RPC: new call `signpsbt` which will add the wallet's signatures to a provided psbt
Changelog-Added: JSON-RPC: new call `sendpsbt` which will finalize and send a signed PSBT
2020-06-29 16:10:05 +02:00
niftynei 103dce63ef reserve/unreserve input: new RPC commands for reserving inputs/outputs
Reserve and unreserve wallet UTXOs using a PSBT which includes those
inputs.

Note that currently we unreserve inputs everytime the node restarts.
This will be addressed in a future commit.

Changelog-Added: JSON-RPC: Adds two new rpc methods, `reserveinputs` and `unreserveinputs`, which allow for reserving or unreserving wallet UTXOs
2020-06-29 16:10:05 +02:00
Rusty Russell 8ee8161fb4 pyln-spec: add .gitignore file for build detritus.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 447231f52e pyln.spec.bolt*: change version numbering to include specific csv subversion.
Now they look like 1.0.1.137, so you can explicitly depend on a csv change
(without caring about a textual change).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 1c1c3349b4 pyln.spec.bolt*: unify setups.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 450fb43612 pyln.spec.bolt*: test-release and prod-release targets, fix requirements.txt
We depend on packages, not modules within them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 93ae190c19 pyln.proto: bump version to 0.8.3.
Changelog-Changed: pyln.proto version now 0.8.3 to indicate pyln.proto.message
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 014ede0585 pyln.proto: fix test-release target
1. version was 0.0.2 in setup.py, which means we didn't get the dist/ files we expected.
2. We need 'bdist_wheel' to make the .whl file.
3. --no-site-packaged was apparently removed in 0.20.0, and was default long before that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 902d8f7dab pyln.proto.message: remove incorrect fundamental types now spec update.
See 9e8e29af9b

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 41e914fb37 pyln.proto.message, pyln.proto.spec*: do magic to expose mypy types.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 11a0de877e pyln.proto.message: more mypy fixes.
This includes some real bugfixes, since it noticed some places we were
being loose with different types!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 3882e8bdf7 pyln.spec.bolt*: make these separate packages, so versions can change indep.
They're almost entirely autogenerated, and we use symlinks into the
top directory to reduce replication.

They can't be under pyln.spec.message, because a package can't also
be a namespace.

We also add fulltext and desc fields, and exclude our "gen" files from
flake8, since the spec quotes contain weird whitespace.

Changelog-Added: Python: pyln.spec.bolt{1,2,4,7} packages.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 013eced4ce pyln.proto: fix package list in setup.py
Remove non-existant pyln.proto.bolts.  bolts will have separate setup.py, so we
can rev the versions individually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-25 10:08:58 +02:00
Rusty Russell 02338a6b25 pyln.proto.message: add to_py() operation.
This delivers the message contents in a much friendlier form for
manipulation: in particular, it makes it easy to compare two
messages without having to know all the message type internals.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-16 16:17:52 +02:00
Rusty Russell ee76504e53 pyln.proto.message: fix handling of ... with subtypes.
This time, with a test!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-16 16:17:52 +02:00
Rusty Russell 2309a7a561 pyln.proto.message: don't leave 'None' in dict for missing fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-16 16:17:52 +02:00
Christian Decker 5bb1fd4205 pyln-proto: Add Makefile targets for releases 2020-06-15 16:14:53 +02:00
Christian Decker 48cee3c3d2 pyln: Bump version to 0.8.2 in order to match with binary distro
Keeping them out of sync seems like a great way to create confusion. Let's
sync them up whenever possible.
2020-06-15 16:14:53 +02:00
Rusty Russell aaefbe2e9e pyln.proto.message: fix handling of missing optional fields.
If they don't exist, that's OK. These will eventually be going away
from the spec, but there are still some in gossip messages for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell fd3ea91b44 pyln.proto.message: expose array types, add set_field for Message class.
Exposing the array types is required for our dummyrunner in the lnprototest suite, since
it wants to be able to generate fake fields.

The set_field is similarly useful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell f52065201b pyln.proto.message.*: add type annotations.
Other changes along the way:

1. In a couple of places we passed None as a dummy for for
   `otherfields` where {} is just as good.
2. Turned bytes into hex for errors.
3. Remove nonsensical (unused) get_tlv_by_number() function from MessageNamespace
4. Renamed unrelated-but-overlapping `field_from_csv` and
   `type_from_csv` static methods, since mypy thought they should have
   the same type.
5. Unknown tlv fields are placed in dict as strings, not ints, for
   type simplicity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell da070e73b2 pyln.proto.message.*: Add Makefile to do mypy checks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell acfeaebb62 pyln.proto.message: allow fields with options to be missing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell ee6c58cbd5 pyln.proto.message: export more.
FieldType lets you make new field types, and split_field helps with
parsing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell b33dc9847c pyln.proto.message: python-fluency feedback from @darosior
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell 8f38bc7230 pyln.proto.message: support adding two namespaces.
They must not have duplicate names!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00
Rusty Russell 85bb93618b new modules: pyln.proto.message.{bolt1,bolt2,bolt4,bolt7}
These are autogenerated, but now they export their own
MessageNamespace, as well as the raw csv.

They also expose their SubtypeTypes, MessageTypes and TlvStreamTypes,
though in theory these could clash (they don't for now, and it'd be
kinda awkward if they did).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-06-12 15:35:35 +02:00