Skip to content

Commit 21e10fe

Browse files
committed
gossmap: use ShortChannelId class from pyln.proto, if available.
Signed-off-by: Rusty Russell <[email protected]>
1 parent a7b2b24 commit 21e10fe

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pyln.spec.bolt7 import (channel_announcement, channel_update,
44
node_announcement)
5+
from pyln.proto import ShortChannelId
56
from typing import Any, Dict, List, Optional
67

78
import io
@@ -28,11 +29,6 @@ def __init__(self, buf: bytes):
2829
self.length = (length & GOSSIP_STORE_LEN_MASK)
2930

3031

31-
# FIXME!
32-
class short_channel_id(int):
33-
pass
34-
35-
3632
class point(bytes):
3733
pass
3834

@@ -75,7 +71,7 @@ def __init__(self, store_filename: str = "gossip_store"):
7571
self.store_file = open(store_filename, "rb")
7672
self.store_buf = bytes()
7773
self.nodes: Dict[point, GossmapNode] = {}
78-
self.channels: Dict[short_channel_id, GossmapChannel] = {}
74+
self.channels: Dict[ShortChannelId, GossmapChannel] = {}
7975
version = self.store_file.read(1)
8076
if version[0] != GOSSIP_STORE_VERSION:
8177
raise ValueError("Invalid gossip store version {}".format(version))
@@ -85,7 +81,7 @@ def __init__(self, store_filename: str = "gossip_store"):
8581
def _new_channel(self,
8682
fields: Dict[str, Any],
8783
announce_offset: int,
88-
scid: short_channel_id,
84+
scid: ShortChannelId,
8985
node1_id: point,
9086
node2_id: point,
9187
is_private: bool):
@@ -101,7 +97,7 @@ def _new_channel(self,
10197
self.nodes[node1_id].channels.append(c)
10298
self.nodes[node2_id].channels.append(c)
10399

104-
def _del_channel(self, scid: short_channel_id):
100+
def _del_channel(self, scid: ShortChannelId):
105101
c = self.channels[scid]
106102
n1 = self.nodes[c.node1_id]
107103
n2 = self.nodes[c.node2_id]
@@ -115,14 +111,15 @@ def _del_channel(self, scid: short_channel_id):
115111

116112
def add_channel(self, rec: bytes, off: int, is_private: bool):
117113
fields = channel_announcement.read(io.BytesIO(rec[2:]), {})
118-
self._new_channel(fields, off, fields['short_channel_id'],
114+
self._new_channel(fields, off,
115+
ShortChannelId.from_int(fields['short_channel_id']),
119116
fields['node_id_1'], fields['node_id_2'],
120117
is_private)
121118

122119
def update_channel(self, rec: bytes, off: int):
123120
fields = channel_update.read(io.BytesIO(rec[2:]), {})
124121
direction = fields['message_flags'] & 1
125-
c = self.channels[fields['short_channel_id']]
122+
c = self.channels[ShortChannelId.from_int(fields['short_channel_id'])]
126123
c.updates_fields[direction] = fields
127124
c.updates_offset = off
128125

0 commit comments

Comments
 (0)