Skip to content

Commit a68aeb2

Browse files
rustyrussellcdecker
authored andcommitted
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 <[email protected]>
1 parent bd59394 commit a68aeb2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

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

33
from pyln.spec.bolt7 import (channel_announcement, channel_update,
44
node_announcement)
5-
from typing import Dict, List, Optional
5+
from typing import Any, Dict, List, Optional
66

77
import io
88
import struct
@@ -39,25 +39,25 @@ class point(bytes):
3939

4040
class GossmapChannel(object):
4141
def __init__(self,
42-
announce: bytes,
42+
fields: Dict[str, Any],
4343
announce_offset: int,
4444
scid,
4545
node1_id: point,
4646
node2_id: point,
4747
is_private: bool):
48-
self.announce = announce
48+
self.fields = fields
4949
self.announce_offset = announce_offset
5050
self.is_private = is_private
5151
self.scid = scid
5252
self.node1_id = node1_id
5353
self.node2_id = node2_id
54-
self.updates: List[Optional[bytes]] = [None, None]
54+
self.updates_fields: List[Optional[Dict[str, Any]]] = [None, None]
5555
self.updates_offset: List[Optional[int]] = [None, None]
5656

5757

5858
class GossmapNode(object):
5959
def __init__(self, node_id: point):
60-
self.announce = None
60+
self.announce_fields: Optional[Dict[str, Any]] = None
6161
self.announce_offset = None
6262
self.channels = []
6363
self.node_id = node_id
@@ -78,13 +78,13 @@ def __init__(self, store_filename: str = "gossip_store"):
7878
self.refresh()
7979

8080
def _new_channel(self,
81-
announce: bytes,
81+
fields: Dict[str, Any],
8282
announce_offset: int,
8383
scid: short_channel_id,
8484
node1_id: point,
8585
node2_id: point,
8686
is_private: bool):
87-
c = GossmapChannel(announce, announce_offset,
87+
c = GossmapChannel(fields, announce_offset,
8888
scid, node1_id, node2_id,
8989
is_private)
9090
if node1_id not in self.nodes:
@@ -110,20 +110,20 @@ def _del_channel(self, scid: short_channel_id):
110110

111111
def add_channel(self, rec: bytes, off: int, is_private: bool):
112112
fields = channel_announcement.read(io.BytesIO(rec[2:]), {})
113-
self._new_channel(rec, off, fields['short_channel_id'],
113+
self._new_channel(fields, off, fields['short_channel_id'],
114114
fields['node_id_1'], fields['node_id_2'],
115115
is_private)
116116

117117
def update_channel(self, rec: bytes, off: int):
118118
fields = channel_update.read(io.BytesIO(rec[2:]), {})
119119
direction = fields['message_flags'] & 1
120120
c = self.channels[fields['short_channel_id']]
121-
c.updates[direction] = rec
121+
c.updates_fields[direction] = fields
122122
c.updates_offset = off
123123

124124
def add_node_announcement(self, rec: bytes, off: int):
125125
fields = node_announcement.read(io.BytesIO(rec[2:]), {})
126-
self.nodes[fields['node_id']].announce = rec
126+
self.nodes[fields['node_id']].announce_fields = fields
127127
self.nodes[fields['node_id']].announce_offset = off
128128

129129
def reopen_store(self):

0 commit comments

Comments
 (0)