Skip to content

Commit 32cb69e

Browse files
m-schmoockrustyrussell
authored andcommitted
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.
1 parent f19c43f commit 32cb69e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

contrib/pyln-client/pyln/client/gossmap.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#! /usr/bin/python3
22

3-
from pyln.spec.bolt7 import (channel_announcement, channel_update,
4-
node_announcement)
3+
from pyln.spec.bolt7 import (channel_announcement,
4+
channel_update,
5+
node_announcement,
6+
gossip_store_channel_amount)
57
from pyln.proto import ShortChannelId, PublicKey
68
from typing import Any, Dict, List, Optional
79

@@ -60,8 +62,7 @@ def __init__(self,
6062
self.node2_id = node2_id
6163
self.updates_fields: List[Optional[Dict[str, Any]]] = [None, None]
6264
self.updates_offset: List[Optional[int]] = [None, None]
63-
64-
self.capacity = None # TODO: where do we get this?
65+
self.satoshis = None
6566
self.half_channels: List[GossmapHalfchannel] = [None, None]
6667

6768
def update_channel(self,
@@ -135,6 +136,7 @@ def __init__(self, store_filename: str = "gossip_store"):
135136
self.store_buf = bytes()
136137
self.nodes: Dict[bytes, GossmapNode] = {}
137138
self.channels: Dict[ShortChannelId, GossmapChannel] = {}
139+
self._last_scid: str = None
138140
version = self.store_file.read(1)
139141
if version[0] != GOSSIP_STORE_VERSION:
140142
raise ValueError("Invalid gossip store version {}".format(version))
@@ -156,6 +158,7 @@ def _new_channel(self,
156158
if node2_id not in self.nodes:
157159
self.nodes[node2_id] = GossmapNode(node2_id)
158160

161+
self._last_scid = scid
159162
self.channels[scid] = c
160163
self.nodes[node1_id].channels.append(c)
161164
self.nodes[node2_id].channels.append(c)
@@ -179,6 +182,11 @@ def add_channel(self, rec: bytes, off: int, is_private: bool):
179182
GossmapNodeId(fields['node_id_1']), GossmapNodeId(fields['node_id_2']),
180183
is_private)
181184

185+
def _set_channel_amount(self, rec: bytes):
186+
""" Sets channel capacity of last added channel """
187+
fields = gossip_store_channel_amount.read(io.BytesIO(rec[2:]), {})
188+
self.channels[self._last_scid].satoshis = fields['satoshis']
189+
182190
def get_channel(self, short_channel_id: ShortChannelId):
183191
""" Resolves a channel by its short channel id """
184192
if type(short_channel_id) == str:
@@ -252,6 +260,8 @@ def refresh(self):
252260
self.add_channel(rec, off, False)
253261
elif rectype == WIRE_GOSSIP_STORE_PRIVATE_CHANNEL:
254262
self.add_channel(rec[2 + 8 + 2:], off + 2 + 8 + 2, True)
263+
elif rectype == gossip_store_channel_amount.number:
264+
self._set_channel_amount(rec)
255265
elif rectype == channel_update.number:
256266
self.update_channel(rec, off)
257267
elif rectype == WIRE_GOSSIP_STORE_PRIVATE_UPDATE:

contrib/pyln-spec/bolt7/pyln/spec/bolt7/csv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@
8080
"msgdata,gossip_timestamp_filter,chain_hash,chain_hash,",
8181
"msgdata,gossip_timestamp_filter,first_timestamp,u32,",
8282
"msgdata,gossip_timestamp_filter,timestamp_range,u32,",
83+
"msgtype,gossip_store_channel_amount,4101",
84+
"msgdata,gossip_store_channel_amount,satoshis,u64,",
8385
]

0 commit comments

Comments
 (0)