tSave remote policy of chanel in wallet file (for private channels) - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 35761d1241dbf2685f3fe2d7ee0c4795daec4260 DIR parent 1612bca4c81981e67ead24eef7d8ae4301d8ecf4 HTML Author: ThomasV <thomasv@electrum.org> Date: Sun, 8 Sep 2019 19:14:22 +0200 Save remote policy of chanel in wallet file (for private channels) Diffstat: M electrum/lnchannel.py | 2 ++ M electrum/lnpeer.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) --- DIR diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py t@@ -136,6 +136,7 @@ class Channel(Logger): self.onion_keys = str_bytes_dict_from_save(state.get('onion_keys', {})) self.force_closed = state.get('force_closed') self.data_loss_protect_remote_pcp = str_bytes_dict_from_save(state.get('data_loss_protect_remote_pcp', {})) + self.remote_update = bfh(state.get('remote_update')) if state.get('remote_update') else None log = state.get('log') self.hm = HTLCManager(log=log, t@@ -616,6 +617,7 @@ class Channel(Logger): "onion_keys": str_bytes_dict_to_save(self.onion_keys), "force_closed": self.force_closed, "data_loss_protect_remote_pcp": str_bytes_dict_to_save(self.data_loss_protect_remote_pcp), + "remote_update": self.remote_update.hex() if self.remote_update else None } return to_save DIR diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py t@@ -209,8 +209,15 @@ class Peer(Logger): self.gossip_queue.put_nowait(('channel_announcement', payload)) def on_channel_update(self, payload): + self.maybe_save_remote_update(payload) self.gossip_queue.put_nowait(('channel_update', payload)) + def maybe_save_remote_update(self, payload): + for chan in self.channels.values(): + if chan.short_channel_id == payload['short_channel_id']: + chan.remote_update = payload['raw'] + self.logger.info("saved remote_update") + def on_announcement_signatures(self, payload): channel_id = payload['channel_id'] chan = self.channels[payload['channel_id']] t@@ -576,6 +583,7 @@ class Peer(Logger): "remote_config": remote_config, "local_config": local_config, "constraints": ChannelConstraints(capacity=funding_sat, is_initiator=True, funding_txn_minimum_depth=funding_txn_minimum_depth), + "remote_update": None, } chan = Channel(chan_dict, sweep_address=self.lnworker.sweep_address, t@@ -660,6 +668,7 @@ class Peer(Logger): ), "local_config": local_config, "constraints": ChannelConstraints(capacity=funding_sat, is_initiator=False, funding_txn_minimum_depth=min_depth), + "remote_update": None, } chan = Channel(chan_dict, sweep_address=self.lnworker.sweep_address, t@@ -1008,7 +1017,13 @@ class Peer(Logger): # peer may have sent us a channel update for the incoming direction previously pending_channel_update = self.orphan_channel_updates.get(chan.short_channel_id) if pending_channel_update: - self.channel_db.add_channel_update(pending_channel_update) + chan.remote_update = pending_channel_update['raw'] + # add remote update with a fresh timestamp + if chan.remote_update: + now = int(time.time()) + remote_update_decoded = decode_msg(chan.remote_update)[1] + remote_update_decoded['timestamp'] = now.to_bytes(4, byteorder="big") + self.channel_db.add_channel_update(remote_update_decoded) def get_outgoing_gossip_channel_update_for_chan(self, chan: Channel) -> bytes: if chan._outgoing_channel_update is not None: t@@ -1136,6 +1151,7 @@ class Peer(Logger): blacklist = False if categorized_chan_upds.good: self.logger.info("applied channel update on our db") + self.maybe_save_remote_update(payload) elif categorized_chan_upds.orphaned: # maybe it is a private channel (and data in invoice was outdated) self.logger.info("maybe channel update is for private channel?")