Commit Graph

717 Commits

Author SHA1 Message Date
Vincenzo Palazzo bea6ea27e8 review 1/2: Fixed the doc missing details about formatting.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-22 16:23:24 +09:30
Vincenzo Palazzo 9d5c992fc8 plugin: Adding status to the pay plugin
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

Rebase

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-22 16:23:24 +09:30
Vincenzo Palazzo 98623aaff8 pyln-client: Adding parameter to the listpays rpc method.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-09-22 16:23:24 +09:30
Rusty Russell 2736e997f6 ccan: remove autodata.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-21 18:04:43 +02:00
Rusty Russell 24536c5561 common/autodata: use instead of ccan/autodata
This means it needs to be linked ~everywhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-21 18:04:43 +02:00
Rusty Russell 00a0d09340 tools/check-includes.sh: test that c files include their .h files.
This is best-practice (to ensure prototypes match up), but there were a
few places we didn't (at least, directly).  Make it a requirement,
either of form "foo.h" or <dir/foo.h>.

The noise is the change to our print templates.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Dustin Dettmer cdb93eefec resolve() appears broken on Python 3.7+
On my machine it should have produced:
/tmp/ltests-1p0v5z1j/.locks/lock-1631090663.1066182
but instead it produced:
/private/tmp/ltests-1p0v5z1j/.locks/lock-1631090663.105848

The mismatch resulted in a hang inside flock.

Path .resolve() seems to be causing problems for others as well. It appears the library was not meant to handle complex path situations and isn't maintained as such (see link reference).

Since we have already built a full path here anyway, the call to .resolve() appears redundant.

Tested on python 3.9.6 on my Mac OS X 11.4 (20F71), Xcode 12.5.1 (12E507)

Relevant discussion: https://discuss.python.org/t/pathlib-absolute-vs-resolve/2573
2021-09-10 11:55:50 +02:00
Rusty Russell 6ee8c40b29 closing: add option to set closing range.
This affects the range we offer even without quick-close, but it's
more critical for quick-close.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSONRPC: `close` now takes a `feerange` parameter to set min/max fee rates for mutual close.
2021-09-09 12:04:48 +09:30
Michael Schmoock e9b801d9c8 pyln-client/gossmap: adds testcase for half channels 2021-09-08 09:34:14 +09:30
Rusty Russell e8e7c4719f pyln-client: fix mypy warnings, fix and test deletion of a channel.
This only happens when a deletion is added by a running gossipd, so
we put a deletion at the end of the store to test it.

mypy noticed that this code was nonsensical, so clearly untested.

The testing noticed that making a nodeid from a string was also buggy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Michael Schmoock 125752118a pyln-client/gossmap: init GossmapNode and Id also with hexstring
also improves test coverage
Changelog-Added: pyln-client: routines for direct access to the gossip store as Gossmap
2021-09-08 09:34:14 +09:30
Michael Schmoock fa8e74a2ad pyln-client/gossmap: make node and node_id comparable with __lt__ and __eq__ 2021-09-08 09:34:14 +09:30
Michael Schmoock 47efea92c6 pyln-client/gossmap: let half channel have source and destination 2021-09-08 09:34:14 +09:30
Michael Schmoock 2bca76b6e9 pyln-client/gossmap: start internal function names with underscore _ 2021-09-08 09:34:14 +09:30
Michael Schmoock de6c593272 pyln-client/gossmap: have channels link to their nodes instead of id
This is likely easier for programmers and does not use more mem as we
already load all this.
2021-09-08 09:34:14 +09:30
Rusty Russell 4ad4ed8d17 pyln-client/gossmap: make test gossip_store include channel_updates, deletions.
Suggested-by: @mschmook
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 487facf1f0 pyln-client/gossmap: more fixes, make mypy happier.
Mainly fixing type annotations, but some real fixes:

1. GossmapHalfchannel.from_str() should be a classmethod.
2. update_channel had weird, unusable default values (fields can't be NULL,
   since we use it below).

[ There was one more occurence where isinstance should be used above
type() == xyz comparison. -- MS ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Michael Schmoock ba2bcac530 pyln-client/gossmap: Don't mix bytes and GossmapNodeId
Do not mix bytes and GossmapNodeId when accessing Gossmap.nodes dicts.

Therefore the definion got GossmapNodeId also needed to be pulled to the
beginning of the file.
2021-09-08 09:34:14 +09:30
Michael Schmoock ac27217114 pyln-client/gossmap: adds __repr__ functions 2021-09-08 09:34:14 +09:30
Michael Schmoock b60d3259bf pyln-client/gossmap: extend testcase 2021-09-08 09:34:14 +09:30
Michael Schmoock b6ed405d8c pyln-client/gossmap: adds channel satoshi capacity
This reads the `gossip_store_channel_amount` that always follows the
`channel_announcement` messages. Therefore it uses an internal variable
_last_scid to know what channel has been added last time.
2021-09-08 09:34:14 +09:30
Michael Schmoock c5c909acd3 pyln-client/gossmap: adds helpers to get channels and nodes 2021-09-08 09:34:14 +09:30
Michael Schmoock fd16535f68 pyln-client/gossmap: adds GossmapHalfchannel objects 2021-09-08 09:34:14 +09:30
Rusty Russell 75126a0997 pyln-client/gossmap: add NodeId class.
This is more efficient than converting them all to Pubkeys: about 3.8
seconds vs 5.4 seconds.  Usually treating them as raw bytes is what we
want anyway.

[ Fixup by Michael Schmoock <michael@schmoock.net> ]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 887fb38e06 pyln-client/gossmap: use ShortChannelId class from pyln.proto, if available.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 0ce473c656 pyln-proto: expose ShortChannelId and PublicKey.
They're generally useful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 4753ca4d35 pyln-client/gossmap: add a little documentation.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell e495462c50 pyln-client/gossmap: save deconstructed fields instead of raw msg bytes.
We have to parse them anyway, so why not make them accessible.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 1a5a26d659 pyln.client: new functionality to access Gossmap.
It doesn't do much work, but it does parse the gossmap file and extract
nodes and channels.

[ Fixup by Michael Schmoock <michael@schmoock.net> ]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 07d2639f51 pyln.client: don't try to use module inside setup.py.
This fails once it has dependencies (next patch): instead extract version
manually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-08 09:34:14 +09:30
Rusty Russell 6b8d3a05f5 pyln-spec: update to latest version of the spec.
Changelog-Changed: pyln-spec: updated to latest BOLT versions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-07 17:41:28 +09:30
Vincenzo Palazzo bc1eab8646 Skip following import and skip flask type to mypy code analysis.
As suggested in this issue https://github.com/python/mypy/issues/7484#issuecomment-529363083 we skip following import becuase with the recent version of mypy the __init__.py file make confusione inside the analysis (in the python issue it is unclear the main motivation of this issue. At list unclear to me).

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-08-30 12:12:32 +09:30
Vincenzo Palazzo b40812494d Move to minimum required mypy dependeces
This fix some dependencies error with lnprototest

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-08-30 12:12:32 +09:30
Michael Schmoock da0b159323 pylightning: fix requirements to work with pyln-client
Without this, we cannot pip install pylightning and pyln-client in the
same environment anymore, as it tries to pull in an incompatible version
of pyln-client.

Changelog-None
2021-08-26 10:13:01 +09:30
Christian Decker 0da87e7715 pyln: Fix up the mypy annotation for `init` self-disabling 2021-08-14 12:52:19 +09:30
Rusty Russell f5e08c3dae pyln-client: document and test that init can self-disable.
mypy says it returns None, but it actually doesn't have to!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-08-14 12:52:19 +09:30
Christian Decker 0112bbbeb7 pyln: Add E741 as excluded flake warnings
This is the ambiguous variable name warning which newer versions will
complain about.
2021-07-30 19:17:47 +02:00
Rusty Russell de12c540ee pyln.{proto,client,testing}: bump version numbers to match release.
I left pyln.proto.spec, since it's unchanged (and completely independent of
c-lightning anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-30 19:17:47 +02:00
Rusty Russell c0eba75b1d pyln.proto.message: add new BOLT12 fundamental types.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-30 19:17:47 +02:00
Rusty Russell 85b4400d8d pyln.proto.message: export two more symbols, remove unused __version__ from message.py
It gets the version of pyln.proto.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-30 19:17:47 +02:00
Christian Decker d732fa9724 pyln: Fix backward compat issue in `LightningRpc.close`
The issue is that the new keyword `force_lease_closed` was being set
even if the user didn't specify it, which results in breakage if this
new pyln version talks to older c-lightning nodes that don't have this
keyword yet. By setting the default to `None` it gets filtered out if
the user has not explicitly set it, but still retains the `True` /
`False` values if they did.

Changelog-None Issue is not present in released versions
2021-07-29 16:01:37 +09:30
Vincenzo Palazzo c52af08797 Moving dependencies to the minimum required
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2021-07-24 14:42:37 +09:30
niftynei 77d2c538b3 queryrates: make it dev-only
Since we now use 'compact_lease' to gate an open (if the rates have
changed, we fail), we no longer need to rely on query rates for figuring
things out, so we make it dev-only.

Changelog-Changed: JSON-API: queryrates is now developer only
2021-07-20 13:28:38 -04:00
niftynei f24bbac8d9 channel leases: pass expected lease rates around in compat form
We need to know what the lease we're expecting is. To do this
we pass around the hex encoded portion of the wire format.

We can use this passed in expected lease rates to confirm that the peer
is, in fact, using the same rates as what we have currently.

Changelog-Added: JSON-RPC: fundchannel, multifundchannel, and openchannel_init now accept a 'compact_lease' for any requested funds
2021-07-20 13:28:38 -04:00
niftynei f3b54a510b close: param to force-close a leased channel
By default, we won't close a channel that we leased to a peer.
You can override this with the `force_lease_closed` flag.

Changelog-Added: JSON-RPC: close now has parameter to force close a leased channel (option_will_fund)
2021-07-20 13:28:38 -04:00
niftynei 9ad40f2544 liquidity-ad: pipe `request_amt` all the way out to fundchannel
Changelog-Added: JSON-RPC: `fundchannel` now takes optional `request_amt` parameter
2021-07-20 13:28:38 -04:00
niftynei e41d2dc0e6 liquidity-ad: request amount, pass through to dualopend
Changelog-Experimental: EXPERIMENTAL-DUAL-FUND: JSON-RPC: openchannel_init now takes a `requested_amt`, which is an amount to request from peer
2021-07-20 13:28:38 -04:00
niftynei 13e4a72188 contrib: offer a liquidity-ad lease in developer mode 2021-07-20 13:28:38 -04:00
niftynei 376e6f8bd1 dual-funding: update fee_step to be a feerate
Using a 'feestep' is more restrictive than you'd want, instead we
enforce that the next feerate must be at least 1/64th more than the
last, but put no upper limit on it

Includes update to lnprototest changes

Contributed-By: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Changelog-EXPERIMENTAL: Protocol: Replaces init_rbf's `fee_step` for RBF of v2 opens with `funding_feerate_perkw`, breaking change
2021-07-19 16:13:24 -04:00
nathanael 3ebf2325f3 chore: add 3 gpg pubkeys of maintainers to the repository
changelog-none - closes #4393
2021-07-19 13:22:33 +09:30
Rusty Russell 4e881e56ce pytest: always provide payment_secret when making payments.
They're about to become compulsory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-14 14:38:00 -05:00
Michael Schmoock 89c45b379a pyln: rpc support for listchannels by destination 2021-07-14 14:34:00 -05:00
Rusty Russell 063366ed7e listinvoices: support listing by local offer_id.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-03 12:13:45 +09:30
Christian Decker 5f9e5d598e pytest: Add test for keysend extra-tlvs 2021-06-26 10:55:13 +09:30
Christian Decker a4e3773408 pyln: Add wrapper for the keysend command 2021-06-26 10:55:13 +09:30
Rusty Russell 74eeaa8213 doc/schemas: getsharedsecret, help, invoice, listchannels, listforwards
And a new "u8" type.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-25 09:49:33 +09:30
Rusty Russell edee0793d3 pyln.proto: fix receiving unknown fields in TLVs.
We can still convert these (e.g. k=1) to Python, by just using hex strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-24 19:46:38 +09:30
Rusty Russell ca3680246e pyln.proto: fix handling of subtypes in TLVs.
This was revealed by using lnprototest on channel_types.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-24 19:46:38 +09:30
Rusty Russell 35c8247b5f cleanup: remove unused pyln-spec symlinks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-24 19:46:38 +09:30
Antoine Poinsot 1643a61499 pyln-testing: check if process died after having read all logs
We would fail even if a process exited cleanly after having the line we
were looking for, because we checked if it died before reading the logs.

Co-Authored-by: Daniela Brozzoni <daniela@revault.dev>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-06-18 10:40:07 +09:30
Michael Schmoock a53aa1aaef pyln: adds a help text to start plugins manually
Changelog-None
2021-06-18 09:59:54 +09:30
Rusty Russell 50cb810bd0 pyln-client: revert old/new comparisons for getroute, listchannels, listnodes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell 9a2d73891b pyln-client: hack in test that listnodes returns the same old/new.
It sometimes fails because the two race, and sometimes because there's
randomness, but it generally works (and doesn't fail systemically).

We remove this before the final merge.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell 79299a4780 pyln-client: hack in test that listchannels returns the same old/new.
It sometimes fails because the two race, and sometimes because there's
randomness, but it generally works (and doesn't fail systemically).

We remove this before the final merge.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell d1ab5e3872 pyln-client: hack in test that getroute returns the same old/new.
It sometimes fails because the two race, and sometimes because there's
randomness, but it generally works (and doesn't fail systemically).

We remove this before the final merge.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-16 10:29:17 +09:30
Rusty Russell 67c03c02a0 pytest: speed up test_opening.py::test_funder_contribution_limits when !DEVELOPER
This test takes 695 seconds, because fundwallet waits for the wallet to
notice the tx, which takes 60 seconds if not DEVELOPER.  Do all the waiting
at once, and this speeds the test up to 153 seconds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-06-05 09:47:50 +09:30
Christian Decker 90ced7ecde libhsmd: Do not use the message as the peer ID... 2021-05-30 19:49:22 +09:30
Christian Decker e27ce7d5b6 libhsmd: Add a simple tx signature test 2021-05-30 19:49:22 +09:30
Christian Decker c6a3d30bec libhsmd: Always use gcc to configure and compile 2021-05-30 19:49:22 +09:30
Christian Decker 431683293f libhsmd: Correctly wrap with `tmpctx` management in libhsmd-python 2021-05-30 19:49:22 +09:30
Rusty Russell ea99a05249 pytest: add schema support for JSON responses.
This adds our first (basic) schema, and sews support into pyln-testing
so it will load schemas for any method for doc/schemas/{method}.schema.json.

All JSON responses in a test run are checked against the schema (if any).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-27 20:28:49 +09:30
Rusty Russell efe29c9db8 sendpsbt, fundpsbt, utxopsbt, reserveinputs, unreserveinputs: allow custom number of blocks to reserve.
Not an API break: reserve=true|false still works for fundpsbt and utxopsbt,
but we also allow a raw number in there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-26 15:08:01 +09:30
Christian Decker 6c67afeb03 make: Add CPPCHECK_OPTS to allow excluding files from the check
With swig we now have C files that are generated with tools that are
not under our control, so provide an escape hatch for them.
2021-05-15 09:31:12 +09:30
Christian Decker a4c19ba6ba libhsmd: Clean up the build descriptors for libhsmd_python 2021-05-15 09:31:12 +09:30
Christian Decker 7f15f86718 libhsmd: First working build script for libhsmd-python
Changelog-Added: libhsmd: Added python bindings for `libhsmd`
2021-05-15 09:31:12 +09:30
niftynei 3a2d602922 tests: add marker for v1/v2 channel opens
Tests that will only run when !EXPERIMENTAL_DUAL_FUND:

	@pytest.marker.openchannel('v1')
	def test_...()

Tests that will only run when EXPERIMENTAL_DUAL_FUND:

	@pytest.marker.openchannel('v2')
	def test_...()
2021-05-12 11:25:41 +09:30
niftynei 484d6bde83 tests: move EXP_DF into the testing utils 2021-05-12 11:25:41 +09:30
niftynei 09b5c906fd funder, startupregtest: fixup default config to be 100
Fails on start otherwise
2021-05-12 11:25:41 +09:30
Rusty Russell d8e68893f5 bcli: become less aggressive with onchain fee levels.
Users are more upset recently with the cost of unilateral closes
than they are the risk of being cheated.  While we complete our
anchor implementation so we can use low fees there, let's
get less aggressive (we already have 34 or 18 blocks to close
in the worst case).

The changes are:

- Commit transactions were "2 CONSERVATIVE" now "6 ECONOMICAL".
- HTLC resolution txs were "3 CONSERVATIVE" now "6 ECONOMICAL".
- Penalty txs were "3 CONSERVATIVE" now "12 ECONOMICAL".
- Normal txs were "4 ECONOMICAL" now "12 ECONOMICAL".

There can be no perfect levels, but we have had understandable
complaints recently about how high our default fee levels are.

Changelog-Changed: Protocol: channel feerates reduced to bitcoind's "6 block ECONOMICAL" rate.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-11 11:25:16 +09:30
Christian Decker 083b41f090 plugin: Add a list of notification topics registered by plugin
We will eventually start emitting and dispatching custom notifications
from plugins just like we dispatch internal notifications. In order to
get reasonable error messages we need to make sure that the topics
plugins are asking for were correctly registered. When doing this we
don't really care about whether the plugin that registered the
notification is still alive or not (it might have died, but
subscribers should stay up and running), so we keep a list of all
topics attached to the `struct plugins` which gathers global plugin
information.
2021-05-03 11:20:15 +09:30
niftynei 473067859f pyln-testing: use provided outnum instead of trying to find it
Dual-funded channels won't match the old amount check. Good news is
we're already returning the outnum so we just use that.
2021-05-03 11:06:10 +09:30
niftynei bc7875864b contrib: if you're in dev mode, use dual-funding (with matching)
If you're using the regtest node, turn on dual funding and
automatically attempt to dual fund at a 100% match for every channel
open that you do.
2021-05-03 11:06:10 +09:30
Rusty Russell 32d650f9df lightningd: don't abort on incorrect versions, but try to re-exec.
You still shouldn't do this (you could get some transient failures),
but at least you have a decent chance if you reinstall over a running
daemon, instead of getting confusing internal errors if message
formats have changed.

Changelog-Added: lightningd: we now try to restart if subdaemons are upgraded underneath us.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #4346
2021-04-24 13:56:58 +09:30
Rusty Russell 402f7f90c0 pytest: handle case where funding tx is not tx #1.
e.g. in test_closing_id we can get a spend from the first (closed) channel
in the same block as the open of the second.  Half the time, we'll choose
the wrong one as scid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-12 23:03:47 +02:00
Christian Decker 8e0d0c3e7b pyln: Pin mypy to version 0.790 since later has import path issues 2021-04-08 10:34:14 +09:30
Christian Decker 0dd57cbf3c pyln-spec: Clean up the setup.py files
This centralizes the setup.py file, and parametrizes it so it can
auto-detect which bolt we are building. It also uses trick 3 from [1]
to avoid importing the package itself during the manifest creation,
which'd cause an import error due to missing dependencies.

[1] https://packaging.python.org/guides/single-sourcing-package-version/
2021-04-08 10:34:14 +09:30
Christian Decker 6b0a7b173c pyln: Change the setup.py file not to import the package
This would lead to errors about missing dependencies when attempting
to install using `pyhon setup.py install`. This is because the
`setup.py` file effectively is the manifest file used to discover
which dependencies are needed, so when using it to detect dependencies
we obviously don't have them yet.

See https://packaging.python.org/guides/single-sourcing-package-version/
2021-04-08 10:34:14 +09:30
Rusty Russell fad4aee5da pyln: remove deprecated fundchannel/fundchannel_start variants.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: pyln: removed deprecated fundchannel/fundchannel_start `satoshi` arg.
2021-04-07 14:34:39 +09:30
Rusty Russell 0ed614d5c4 pyln: remove deprecated pay/sendpay variants.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: pyln: removed deprecated pay/sendpay `description` arg.
2021-04-07 14:34:39 +09:30
Rusty Russell 10dee030f1 pyln: remove deprecated close variant.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: pyln: removed deprecated close `force` variant.
2021-04-07 14:34:39 +09:30
niftynei cbde1f8158 pyln-proto: make an error message more detailed
Easier to figure out what's going wrong
2021-03-30 13:44:34 +10:30
niftynei 5142dc81f6 pyln-proto: write out length of arrays of subtypes to wire
We weren't writing out the length of a nested subtype's
dynamicarraylenght, now we do. The trick is to iterate through the
fields on a subtype (since the length field is added separately)
and to also iterate down through the otherfield values as we 'descend'
2021-03-30 13:44:34 +10:30
Rusty Russell dc44737fb8 python: handle psbt-version of fundchannel_complete, deprecate old.
I didn't change the callers yet, so I can test the backwards compat code
works.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:10:07 +10:30
Rene Pickhardt da2ee188f3 added the default bitcoin path for macos to startup_regtest.sh
[ Neatened shell script a little, removed unwanted submodule update --RR ]
2021-03-16 10:40:34 +10:30
niftynei 9776e23b83 contrib: add the dev- options to the config iff DEVELOPER=1 configured
We scan config.vars to figure out if you configured developer on or off.
If it's on, we add the dev-only options to the config.

Fixes: #4400
Reported-By: Jonathan Harvey-Buschel @jharveyb
2021-03-16 10:26:51 +10:30
niftynei bec96a6c5b df: add openchannel_abort command
Allows us to clean up an in-progress open that we won't be completing

Changelog-Added: EXPERIMENTAL JSON-RPC: Permit user-initiated aborting of in-progress opens. Only valid for not-yet-committed opens and RBF-attempts
2021-03-15 14:08:44 +10:30
Alexey Zagarin 43c46ceb2d Fix wallet creation in contrib/startup_regtest.sh 2021-03-15 12:16:38 +10:30
Christian Decker 1e6626ff43 pyln: Fix listfunds call defaulting to spent=False
The semantics don't change, since `lightningd` will use false as
default as well, however setting it to something other than `None`
causes the RPC library to include the parameter in the query, and
since the parameter was introduced only in 0.9.3 and pyln may be used
with older versions this then results in an error about an unknown
parameter.
Setting this to `None` makes sure pyln filters out the argument before
calling.

Changelog-Fixed: pyln: Fixed an error when calling `listfunds` with an older c-lightning version causing an error about an unknown `spent` parameter
2021-03-11 14:07:47 +10:30
Christian Decker ba083c8869 pyln: Plugins can be nice if invoked from CLI too
I had way too much fun with this and got a bit carried away with the
letter writing. The idea is to be helpful when users start the plugin
from the command line, rather than run it under the control of
lightningd. We also print detailed information about the user-visible
things such as the methods and options exposed by the plugin.

Changelog-Added: pyln: Plugins that are run from the command line print helpful information on how to configure c-lightning to include them and print metadata about what RPC methods and options are exposed.
Suggested-by: Rusty Russell <@rustyrussell>
2021-03-10 21:02:55 +10:30
niftynei 1e9a900918 df: start of RPC for bumping the fee!
Doesn't call into dualopend yet
2021-03-03 16:19:04 -06:00
Karol Hosiawa 7b72ea7061 Added listforwards test 2021-03-03 09:19:20 +10:30
Rusty Russell 8ad6972b25 contrib: make startup_regtest.sh work for modern bitcoind.
They need us to create a wallet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-25 14:44:03 +10:30
niftynei ea95ad9c12 fund/utxopsbt: flag 'excess_as_change' to add a change output for excess
In the case where you want a PSBT and also want the output to be added
as a change address, use `excess_as_change` = true.

Generates a change address to use. If you want to pay the excess
elsewhere, you will have to add separately.

Changelog-Added: JSON-RPC: Add new parameter `excess_as_change` to fundpsbt+utxopsbt
2021-02-04 13:25:34 -06:00
Rusty Russell f3159ec4ac pytest: detect warnings, too.
Since we turned many errors into warnings, we want our tests to fail
when they happen unexpectedly.  We make WARNING clear in the strings
we print, too, to help out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-04 12:02:52 +10:30
Michael Schmoock c8198d9820 pyln-testing: add `scids` param to `wait_for_htlcs` 2021-02-04 12:02:15 +10:30
Michael Schmoock d76ca6ed35 pyln-testing: improve `wait_for` a bit
This 'fixes' the `wait_for` helper by removing a pointless final
`time.sleep()`, thus potentially making the method return quicker.

The old code could have had three final states:
 - success() := True
 - Timeout and success() := True
 - Timeout and success() := False

The new code has just two final state:
 - success() := True
 - Timeout and success() := False

It ensures the final `time.sleep()` is just the right amount before timeout.
And more importantly making it more readable :-)

Changelog-None
2021-02-04 12:02:15 +10:30
Rusty Russell 3c5502426b lightningd: addgossip API to inject gossip messages.
Importantly, this is synchronous, so pay will be able to use it
reliably.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-02 13:44:01 +01:00
Christian Decker a5f16ab5b1 pyln: Catch OSError when cleaning up test directories 2021-01-29 10:29:09 +10:30
Christian Decker ea67710e01 pyln: Pretty print RPC calls in the testing framework
We are printing `repr(obj)` which is not pretty-printed, hard to read,
and can't even be copied and inspected to JSON tools. We now print the
JSONified and indented calls and responses for easier debugging based
on solely the logs (useful for CI!).

Changelog-Added: pyln-testing: The RPC client will now pretty-print requests and responses to facilitate log-based debugging.
2021-01-29 10:29:09 +10:30
Christian Decker cd9aa267b4 pyln: Adjust maximum load allowed by the throttler 2021-01-29 10:29:09 +10:30
Christian Decker 4c3ee04bb7 pyln: Use a fair FS lock to throttle node startups
We were getting a couple of starvations, so we need a fair filelock. I
also wasn't too happy with the lock as is, so I hand-coded it quickly.

Should be correct, but the overall timeout will tell us how well we
are doing on CI.
2021-01-29 10:29:09 +10:30
Christian Decker fc677e331a pyln: Update dependencies for all pyln packages
We were getting a number of incompatibility warning due to the
dependencies being expressed too rigidly. This losens the requirement
definitions to being compatible with a known good version, and while
we're at it we also bump all outdated requirements.
2021-01-29 10:29:09 +10:30
Christian Decker b447944285 gci: Add a tester Dockerfile 2021-01-29 10:29:09 +10:30
Christian Decker 6bed85bac2 pyln: Bump pyln version to 0.9.3 before publishing on PyPI
Let's just keep pyln synched up with the c-lightning version
2021-01-27 11:29:56 +01:00
Christian Decker 483579f8b6 pyln: Pin the mypy dependency to 0.790 since 0.800 has a regression 2021-01-26 15:45:13 +01:00
nicolas.dorier 3105a7a204 Fix dockerfiles 2021-01-26 15:03:35 +01:00
niftynei ea1895fc1e pyln-tests: tweak `fundbalancedchannel` to assume peer will match
we got rid of push_msats for dual funded channels. this assumes that hte
peer will match an equal amount of sats as ours (the df_accepter.py
plugin will do this)
2021-01-10 13:44:04 +01:00
niftynei f4b7904ce5 tests: don't enforce daemon name on opening logline 2021-01-10 13:44:04 +01:00
niftynei 3c1d90086f pyln-testing: add 'config' method to a node
Query for a config's value. If not set, returns 'none'
2021-01-10 13:44:04 +01:00
Christian Decker a91254de11 pyln: Add ammag key to onion keyset
This was missing, and is required to wrap error responses.
2021-01-08 19:28:30 +01:00
Rusty Russell 1a8978100e invoice: add ctlv option.
This is required if we want to create a "bouncer" plugin (in my copious free time!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `invoice` now takes an optional `cltv` parameter.
2021-01-08 10:45:56 +01:00
Christian Decker b6650425b9 pyln: Add notifications support to LightningRpc
Changelog-Added: pyln-client: Added support for command notifications to LightningRpc via the `notify` context-manager.
2021-01-07 08:32:40 +01:00
Christian Decker 84b3653606 pyln: Add command notification support for plugins
Changelog-Added: pyln-client: Plugin methods can now report progress or status via the `Request.notify` function
2021-01-07 08:32:40 +01:00
Christian Decker a1d33c3781 pytest: Add a test for `listinvoices`
We now have some more logic in the query, so let's test it
exhaustively.
2021-01-06 18:48:06 +01:00
Rusty Russell d41b383cf7 pyln-testing: suppress mypy on FileLock
3.0.12 here:
```
pyln/testing/utils.py:9: error: Cannot find implementation or library stub for module named 'filelock'
pyln/testing/utils.py:9: error: Cannot find implementation or library stub for module named 'filelock'
pyln/testing/utils.py:9: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-06 12:15:39 +01:00
niftynei e3a1d1a7f3 pyln-client: to_whole_satoshi returns the rounded up satoshi value
A fractional satoshi value isn't really useful; rounding up loses
precision but that's why you called "whole satoshi", wasn't it?

Changelog-Changed: pyln-client: Millisatoshi has new method, `to_whole_satoshi`; *rounds value up* to the nearest whole satoshi
2021-01-05 19:12:00 +01:00
niftynei cce0020568 pyln-client: add missing `min_witness_weight` to fundpsbt/utxopsbt
We need to use it for the 'df_accepter' plugin, so we get the feerate
correct.

Changelog-Added: pyln-client: `fundpsbt`/`utxopsbt` now support `min_witness_weight` param
2021-01-05 19:12:00 +01:00
Christian Decker dbb83a1bc3 pyln: Do not rstrip() the return value of .append()
This was causing the following error

```
Exception in thread Thread-553:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/tmp/cirrus-ci-build/contrib/pyln-testing/pyln/testing/utils.py", line 232, in tail
    self.err_logs.append(line.rstrip().decode('UTF-8', 'replace')).rstrip()
AttributeError: 'NoneType' object has no attribute 'rstrip'

[gw5] [ 33%] FAILED tests/test_misc.py::test_bitcoin_failure
```

Notice the second call to `.rstrip()` on the return value of `.append()`
2021-01-04 11:25:50 +01:00
Christian Decker 1ff57f07f8 pyln: Check that the stderr line is not none in pyln-testing tail
I stumbled over this in a test run and it seems benign.
2021-01-04 11:25:50 +01:00
Christian Decker 7e867e5ee6 pytest: Add throttler to limit load on the test system
Both my machine and apparently the CI tester machines regularly run
into issues with load on the system, causing timeouts (and
unresponsiveness). The throttler throttles the speed with which new
instances of c-lightning get started to avoid overloading. Since the
plugin used for parallelism when testing spawns multiple processes we
need to lock on the fs. Since we have that file open already, we'll
also write a couple of performance metics to it.
2021-01-04 11:25:50 +01:00
Christian Decker f2a0a4abfc pyln: Add logging to bitcoind RPC calls
Useful if we want to debug a bit better
2021-01-04 11:25:50 +01:00
Christian Decker 8b09ac38aa pyln: Log mempool when we generate blocks in BitcoinD fixture
We sometimes have very specific sequences of tx broadcasts and blocks
being generated to confirm them. If the confirmation is missed the
test can completely get out of sync. Make debugging this easier by
logging what we confirmed.
2021-01-04 11:25:50 +01:00
Karol Hosiawa 4a3dec660f Added spent option to listfunds in pyln-client 2020-12-22 13:00:02 +01:00
Rusty Russell 77478408f9 pyln: add RpcException for finer method failure control.
Allows caller to set code and exact message to be returned.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: pyln-client: plugins can now raise RpcException for finer control over error returns.
2020-12-16 12:37:14 +01:00
Rusty Russell d971e3de98 Plugin: support extra args to "start".
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: `start` command can now take plugin-specific parameters.
2020-12-15 09:28:56 +10:30
Rusty Russell 8a9976c4c1 plugins: support concatenation of multiple args.
"multi" means that specifying a parameter twice will append, not override.
Multi args are always given as a JSON array, even if only one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Plugins: new "multi" field allows an option to be specified multiple times.
2020-12-15 09:28:56 +10:30
Michael Schmoock 0a01111395 pytest: check millisatoshi by float raises
This only adds a test that currently makes sure its not possible
to init a Millisatoshi by a floating number.

Discussion:
As @gallizoltan points out, initialization with a float should be possible:
https://github.com/ElementsProject/lightning/pull/4273#discussion_r540369093

> Millisatoshi(5) / 2 currently works, and removes the half msat.
> So, I think Millisatoshi(5 / 2) should be the same.
2020-12-14 17:11:04 +01:00
Michael Schmoock bd13726db7 pytest: test mul and div units for Millisatoshi 2020-12-14 17:11:04 +01:00
Michael Schmoock fffc343dd7 pyln: fix Millisatoshi div with msat itself
Before this patch this fails: `Millisatoshi(42) / Millisatoshi(2)`
This is an operation that should return the ratio between the two
operands as a float number. Same goes for __floordiv__ operator `//`.

Changelog-None
2020-12-14 17:11:04 +01:00
Christian Decker f7cdf1dd98 pytest: Debug test_lockup_drain 2020-12-11 16:55:55 -06:00
Christian Decker 68d08fc7d7 pyln: Add TOR and SOCKS5 support in pyln.proto.wire.connect
I wanted to talk to TOR-based nodes, so here comes TOR support :-)
2020-12-11 11:39:18 +10:30
Christian Decker eacc54646f pyln: Remove deprecated txprepare variant
We promised to deprecate the old "destination satoshi feerate utxos"
variant some time on mid-2020 so let's do just that. `txprepare`
doesn't parse it either anymore.

Changelog-Changed: pyln: `txprepare` no longer supports the deprecated `destination satoshi feerate utxos` call format.
2020-12-09 06:56:21 +10:30
Michael Schmoock 362284981d plyn: use math.floor for msat mul and div 2020-12-08 13:48:14 +01:00
Michael Schmoock 565dc95a8e pyln: fix msat float multiplication 2020-12-08 13:48:14 +01:00
Michael Schmoock 2678cfb364 pyln: extend msat floating testcases
This adds two more xfail'ing testcases to show that the current way of
parsing Millisatoshi decimals is not yet optimal.

Changelog-None
2020-12-08 13:48:14 +01:00
Christian Decker 76124eb800 pyln: Replace undecodeable symbols when tailing logs
Logs may contain non-ASCII and non-UTF8 symbols, which crashes the
tailer. It's better to replace them with a glyph representing
undecodeable symbols instead, and handle the issue further up the
call-chain.
2020-12-04 18:34:12 -06:00
Christian Decker c9d24b1de2 pyln: Set the prefix in TailableProc
We rely on it when logging, but didn't set it in the class, rather we
did in the sub-classes. This proved to be rather annoying to search
since it'd just fail silently and not log any output.
2020-12-04 18:34:12 -06:00
Rusty Russell e4950db9a3 pytest: recreate wallet on bitcoind restart.
Doesn't seem to stick in master.  Andy Chow suggested we
simply turn off wallet on older versions, and always create/load.

```
[gw8] [ 40%] FAILED tests/test_misc.py::test_bitcoind_goes_backwards

============================================================= FAILURES ==============================================================
___________________________________________________ test_bitcoind_goes_backwards ____________________________________________________
[gw8] linux -- Python 3.8.5 /usr/bin/python3

node_factory = <pyln.testing.utils.NodeFactory object at 0x7f931859a760>
bitcoind = <pyln.testing.utils.BitcoinD object at 0x7f931865eee0>

    def test_bitcoind_goes_backwards(node_factory, bitcoind):
        """Check that we refuse to acknowledge bitcoind giving a shorter chain without explicit rescan"""
        l1 = node_factory.get_node(may_fail=True, allow_broken_log=True)

        bitcoind.generate_block(10)
        sync_blockheight(bitcoind, [l1])
        l1.stop()

        # Now shrink chain (invalidateblock leaves 'headers' field until restart)
        bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(105))
        # Restart without killing proxies
        bitcoind.rpc.stop()
        TailableProc.stop(bitcoind)
        bitcoind.start()

        # Will simply refuse to start.
        with pytest.raises(ValueError):
            l1.start()

        # Nor will it start with if we ask for a reindex of fewer blocks.
        l1.daemon.opts['rescan'] = 3

        with pytest.raises(ValueError):
            l1.start()

        # This will force it, however.
        l1.daemon.opts['rescan'] = -100
        l1.start()

        # Now mess with bitcoind at runtime.
>       bitcoind.generate_block(6)

tests/test_misc.py:1307:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
contrib/pyln-testing/pyln/testing/utils.py:399: in generate_block
    return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress())
contrib/pyln-testing/pyln/testing/utils.py:322: in f
    return proxy._call(name, *args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <bitcoin.rpc.RawProxy object at 0x7f93184f6a30>, service_name = 'getnewaddress', args = ()
postdata = '{"version": "1.1", "method": "getnewaddress", "params": [], "id": 1}'
headers = {'Authorization': b'Basic cnBjdXNlcjpycGNwYXNz', 'Content-type': 'application/json', 'Host': 'localhost', 'User-Agent': 'AuthServiceProxy/0.1'}
response = {'error': {'code': -18, 'message': 'No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)'}, 'id': 1, 'result': None}
```
2020-12-03 11:35:30 +01:00
Michael Schmoock 7bfb5f10c7 pyln: failing test msat from float str
We were not able to create pyln Millisatoshi from floats, e.g.:
 - "0.01btc"
 - "0.1sat"
 - ...

This adds a test that makes sure this won't happen again.
2020-12-02 10:37:31 +10:30
Michael Schmoock 83a21138b8 pyln: fix msat from float str
Changelog-fixed: pyln: parsing msat from a float string
2020-12-02 10:37:31 +10:30