Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyln.client gossmap support #4582

Merged
merged 23 commits into from
Sep 8, 2021

Conversation

rustyrussell
Copy link
Contributor

This is a minimal implementation; it probably wants some more helpers to make it less painful to use.

@m-schmoock ?

@m-schmoock
Copy link
Collaborator

Thanks, will have a look..

@cdecker
Copy link
Member

cdecker commented Jun 21, 2021

Rebased on top of master to see if the CI failure was caused by the merge-base.

@cdecker
Copy link
Member

cdecker commented Jun 21, 2021

I have absolutely no idea how changes in the pyln libs can cause peer_exp_wiregen.h to be regenerated... Tried it a couple of times locally and could reproduce.

@m-schmoock
Copy link
Collaborator

@cdecker
Strange. Found that in the logs too:
(it trieds to get Gossmap which pulls in pyln.spec.bolt7 import (channel_announcement, channel_update, ..)
Still I dont get the wiregen update...

+ pip3 install --user -U -r requirements.txt
Processing ./contrib/pyln-client
  DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
   pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
    ERROR: Command errored out with exit status 1:
     command: /opt/hostedtoolcache/Python/3.6.13/x64/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-53ma3np9/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-53ma3np9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-usrh6h8g
         cwd: /tmp/pip-req-build-53ma3np9/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-53ma3np9/setup.py", line 2, in <module>
        from pyln import client
      File "/tmp/pip-req-build-53ma3np9/pyln/client/__init__.py", line 3, in <module>
        from .gossmap import Gossmap
      File "/tmp/pip-req-build-53ma3np9/pyln/client/gossmap.py", line 3, in <module>
        from pyln.spec.bolt7 import (channel_announcement, channel_update,
    ModuleNotFoundError: No module named 'pyln.spec'
    ----------------------------------------
WARNING: Discarding file:///home/runner/work/lightning/lightning/contrib/pyln-client. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

@rustyrussell
Copy link
Contributor Author

Actually, experimental builds always regen (we don't ship the exp_ files).

It's the pip install failure that causes it to abort, not installing mako, and get upset.

@fiatjaf
Copy link
Contributor

fiatjaf commented Jul 7, 2021

Does this mean we can add new channels to the gossip map while gossipd is running and they will be picked up automatically?

@rustyrussell rustyrussell force-pushed the guilt/pyln-gossmap branch 3 times, most recently from 7c4665f to eaf5911 Compare August 16, 2021 01:16
Copy link
Collaborator

@m-schmoock m-schmoock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thing I noted...

contrib/pyln-client/setup.py Outdated Show resolved Hide resolved
@m-schmoock
Copy link
Collaborator

@rustyrussell
Sorry for not being able to run this yet. This is what I did:
I manged to install bolt specs manually by going toi their directories, i.e.

cd contrib/pyln-spec/bolt1
python3 setup.py install --user

This was only doable after upgrading to newest pip sudo pip install --upgrade pip. Still the command errors in the end, but the bolt package installs anyway:

....
Copying pyln_bolt1-1.0.1.137-py3.9.egg to /home/will/.local/lib/python3.9/site-packages
pyln-bolt1 1.0.1.137 is already the active version in easy-install.pth

Installed /home/will/.local/lib/python3.9/site-packages/pyln_bolt1-1.0.1.137-py3.9.egg
Processing dependencies for pyln-bolt1==1.0.1.137
Searching for pyln.proto>=0.9.3
Reading https://pypi.org/simple/pyln.proto/
No local packages or working download links found for pyln.proto>=0.9.3
error: Could not find suitable distribution for Requirement.parse('pyln.proto>=0.9.3')

This can be ignored as I am able to install pyln-proto also manually by source. Not nice though. What I find strange that under the quoted URL https://pypi.org/simple/pyln.proto/ there is a version 0.9.3 °_° ?

When I then run the gossmap testcase it still complains about pyln.spec module missing maybe because I only have the bolts and not the pyln.spec 'parent module' ?:

../../cln/contrib/pyln-client/pyln/client/__init__.py:3: in <module>
    from .gossmap import Gossmap, GossmapNode, GossmapChannel, GossmapNodeId
../../cln/contrib/pyln-client/pyln/client/gossmap.py:3: in <module>
    from pyln.spec.bolt7 import (channel_announcement, channel_update,
E   ModuleNotFoundError: No module named 'pyln.spec'

@m-schmoock
Copy link
Collaborator

m-schmoock commented Aug 21, 2021

@rustyrussell
Ok, I got pyln-spec 'working' by manually copying it into my python environment. The setup.py does not work for me or I don't know how...

@m-schmoock
Copy link
Collaborator

@rustyrussell
I Added some additions by PR rustyrussell#7 into your repo

@rustyrussell rustyrussell marked this pull request as ready for review August 26, 2021 00:44
@rustyrussell rustyrussell force-pushed the guilt/pyln-gossmap branch 2 times, most recently from 626a6d3 to ef38730 Compare August 26, 2021 01:10

class GossmapHalfchannel(object):
"""One direction of a GossmapChannel."""
def __init__(self, channel: 'GossmapChannel', direction: int,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that forward declaration was possible. Had to look it up myself to know why you put that in quotes :D

@m-schmoock
Copy link
Collaborator

Again I added more stuff in coop/wip/pr rustyrussell#8

Also:

Does this mean we can add new cannels to the gossip map while gossipd is running and they will be picked up automatically?

@rustyrussell you thumb-upped this question. Are we really going to push back changes to gossmap back to the gossipd daemon?

@m-schmoock
Copy link
Collaborator

m-schmoock commented Aug 26, 2021

Question:
Do we want the structure like currently implemented: Gossmap -> list[node] -> list[channel] -> [half_channel_1, half_channel_2]
Or do we want it more like flat structure of lightning-cli listchannels list[half_channel] or do we want both by keeping current and adding iterator functions?

@rustyrussell
Copy link
Contributor Author

Again I added more stuff in coop/wip/pr rustyrussell#8

Also:

Does this mean we can add new cannels to the gossip map while gossipd is running and they will be picked up automatically?

@rustyrussell you thumb-upped this question. Are we really going to push back changes to gossmap back to the gossipd daemon?

No, I misread! You can use addgossip to send gossip messages to gossipd, and it will add it to the store if it accepts them though.

@rustyrussell
Copy link
Contributor Author

Question:
Do we want the structure like currently implemented: Gossmap -> list[node] -> list[channel] -> [half_channel_1, half_channel_2]
Or do we want it more like flat structure of lightning-cli listchannels list[half_channel] or do we want both by keeping current and adding iterator functions?

The current structure is more useful: the JSON style of listchannels makes for a lot of redundancy.

rustyrussell and others added 6 commits September 7, 2021 13:39
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
They're generally useful.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…ilable.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
@rustyrussell
Copy link
Contributor Author

Updated on top of #4763

Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only a small nit, by the way, excited to have the gossip map in here.

Fancy stuff can happens.

@@ -1 +1,2 @@
recommonmark>=0.7.*
pyln-bolt7
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to fix the version here with >= latest one? Maybe pip can take the decision to use the old one if in the system there is an older version?

So we are putting here some dependencies that can cause errors in production, I will preferer to have a pyln-bolt7>=1.0.2.186

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, theres something about the pyln-spec dependency.

I put the gossip_store_channel_amount into the bolt7 spec package, not sure if I was supposed to, see 32cb69e. but the one that will be installed with pip is still the old one which results in:

ImportError: cannot import name 'gossip_store_channel_amount' from 'pyln.spec.bolt7' 

So we need to put bolt7 >= 1.0.2.187 (last digit incremented) since the 186 does not have the gossip_store_channel_amount in its csv

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

187 is not released yet, but it will be the one with the changes we made in this branch... not sure how we handle something like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the pypi upload, even though we hadn't merged, because I needed it to fix lnprototest...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that change, it's completely wrong!

I will fix that a different way tomorrow...

@m-schmoock
Copy link
Collaborator

Added another testcase for the half channel stuff... no bugs detected.

@rustyrussell rustyrussell marked this pull request as draft September 7, 2021 10:03
m-schmoock and others added 12 commits September 8, 2021 06:24
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.
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.
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>
…deletions.

Suggested-by: @mschmook
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This is likely easier for programmers and does not use more mem as we
already load all this.
also improves test coverage
Changelog-Added: pyln-client: routines for direct access to the gossip store as Gossmap
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>
@rustyrussell rustyrussell marked this pull request as ready for review September 7, 2021 20:58
@rustyrussell
Copy link
Contributor Author

OK, I removed the change to the spec package, re-running CI now.

@m-schmoock
Copy link
Collaborator

just re-added the commit for the half channel testcase that got missed by rebasing....

@m-schmoock
Copy link
Collaborator

ACK 56cac76

@rustyrussell rustyrussell merged commit e9b801d into ElementsProject:master Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants