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

listpeerchannels: split conversion into stages #5825

Merged
merged 14 commits into from Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions contrib/pyln-client/pyln/client/lightning.py
Expand Up @@ -1070,6 +1070,16 @@ def listpeers(self, peerid=None, level=None):
}
return self.call("listpeers", payload)

def listpeerchannels(self, peer_id=None):
"""
Show current peers channels, and if the {peer_id} is specified
all the channels for the peer are returned.
"""
payload = {
"id": peer_id,
}
return self.call("listpeerchannels", payload)

def listsendpays(self, bolt11=None, payment_hash=None, status=None):
"""Show all sendpays results, or only for `bolt11` or `payment_hash`."""
payload = {
Expand Down
32 changes: 16 additions & 16 deletions contrib/pyln-testing/pyln/testing/utils.py
Expand Up @@ -148,8 +148,8 @@ def mine_funding_to_announce(bitcoind, nodes, num_blocks=5, wait_for_mempool=0):


def wait_channel_quiescent(n1, n2):
wait_for(lambda: only_one(only_one(n1.rpc.listpeers(n2.info['id'])['peers'])['channels'])['htlcs'] == [])
wait_for(lambda: only_one(only_one(n2.rpc.listpeers(n1.info['id'])['peers'])['channels'])['htlcs'] == [])
wait_for(lambda: only_one(n1.rpc.listpeerchannels(n2.info['id'])['channels'])['htlcs'] == [])
wait_for(lambda: only_one(n2.rpc.listpeerchannels(n1.info['id'])['channels'])['htlcs'] == [])


def get_tx_p2wsh_outnum(bitcoind, tx, amount):
Expand Down Expand Up @@ -1038,37 +1038,36 @@ def channel_state(self, other):
yet.

"""
peers = self.rpc.listpeers(other.info['id'])['peers']
if not peers or 'channels' not in peers[0]:
peerchannels = self.rpc.listpeerchannels(other.info['id'])['channels']
if not peerchannels:
return None
channel = peers[0]['channels'][0]
channel = peerchannels[0]
return channel['state']

def get_channel_scid(self, other):
"""Get the short_channel_id for the channel to the other node.
"""
peers = self.rpc.listpeers(other.info['id'])['peers']
if not peers or 'channels' not in peers[0]:
peerchannels = self.rpc.listpeerchannels(other.info['id'])['channels']
if not peerchannels:
return None
channel = peers[0]['channels'][0]
channel = peerchannels[0]
return channel['short_channel_id']

def get_channel_id(self, other):
"""Get the channel_id for the channel to the other node.
"""
peers = self.rpc.listpeers(other.info['id'])['peers']
if not peers or 'channels' not in peers[0]:
channels = self.rpc.listpeerchannels(other.info['id'])['channels']
if len(channels) == 0:
return None
channel = peers[0]['channels'][0]
return channel['channel_id']
return channels[0]['channel_id']

def is_channel_active(self, chanid):
channels = self.rpc.listchannels(chanid)['channels']
active = [(c['short_channel_id'], c['channel_flags']) for c in channels if c['active']]
return (chanid, 0) in active and (chanid, 1) in active

def wait_for_channel_onchain(self, peerid):
txid = only_one(only_one(self.rpc.listpeers(peerid)['peers'])['channels'])['scratch_txid']
txid = only_one(self.rpc.listpeerchannels(peerid)['channels'])['scratch_txid']
wait_for(lambda: txid in self.bitcoin.rpc.getrawmempool())

def wait_channel_active(self, chanid):
Expand Down Expand Up @@ -1102,11 +1101,12 @@ def wait_for_htlcs(self, scids=None):
peers = self.rpc.listpeers()['peers']
for p, peer in enumerate(peers):
if 'channels' in peer:
for c, channel in enumerate(peer['channels']):
channels_peer = self.rpc.listpeerchannels(peer['id'])
for c, channel in enumerate(channels_peer['channels']):
if scids is not None and channel['short_channel_id'] not in scids:
continue
if 'htlcs' in channel:
wait_for(lambda: len(self.rpc.listpeers()['peers'][p]['channels'][c]['htlcs']) == 0)
wait_for(lambda: len(self.rpc.listpeerchannels(peer["id"])['channels'][c]['htlcs']) == 0)

# This sends money to a directly connected peer
def pay(self, dst, amt, label=None):
Expand All @@ -1126,7 +1126,7 @@ def pay(self, dst, amt, label=None):
assert len(invoices) == 1 and invoices[0]['status'] == 'unpaid'

# Pick first normal channel.
scid = [c['short_channel_id'] for c in only_one(self.rpc.listpeers(dst_id)['peers'])['channels']
scid = [c['short_channel_id'] for c in self.rpc.listpeerchannels(dst_id)['channels']
if c['state'] == 'CHANNELD_NORMAL'][0]

routestep = {
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Expand Up @@ -58,6 +58,7 @@ MANPAGES := doc/lightning-cli.1 \
doc/lightning-listoffers.7 \
doc/lightning-listpays.7 \
doc/lightning-listpeers.7 \
doc/lightning-listpeerchannels.7 \
doc/lightning-listsendpays.7 \
doc/lightning-makesecret.7 \
doc/lightning-multifundchannel.7 \
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Expand Up @@ -85,6 +85,7 @@ Core Lightning Documentation
lightning-listnodes <lightning-listnodes.7.md>
lightning-listoffers <lightning-listoffers.7.md>
lightning-listpays <lightning-listpays.7.md>
lightning-listpeerchannels <lightning-listpeerchannels.7.md>
lightning-listpeers <lightning-listpeers.7.md>
lightning-listsendpays <lightning-listsendpays.7.md>
lightning-listtransactions <lightning-listtransactions.7.md>
Expand Down