1
0

lnworker.try_force_closing: changed to not be async (and renamed)

This is to ensure that the channel is "immediately" set to FORCE_CLOSING.
(previously it took at least one event loop iteration)
This commit is contained in:
SomberNight
2022-02-21 18:09:45 +01:00
parent b268877d53
commit 556b98736e
3 changed files with 13 additions and 8 deletions

View File

@@ -1052,7 +1052,7 @@ class Peer(Logger):
fut.set_exception(RemoteMisbehaving("remote ahead of us"))
elif we_are_ahead:
self.logger.warning(f"channel_reestablish ({chan.get_id_for_log()}): we are ahead of remote! trying to force-close.")
asyncio.ensure_future(self.lnworker.try_force_closing(chan.channel_id))
self.lnworker.schedule_force_closing(chan.channel_id)
fut.set_exception(RemoteMisbehaving("we are ahead of remote"))
else:
# all good
@@ -1382,7 +1382,7 @@ class Peer(Logger):
self.logger.info(f"on_update_fail_malformed_htlc. chan {chan.get_id_for_log()}. "
f"htlc_id {htlc_id}. failure_code={failure_code}")
if failure_code & OnionFailureCodeMetaFlag.BADONION == 0:
asyncio.ensure_future(self.lnworker.try_force_closing(chan.channel_id))
self.lnworker.schedule_force_closing(chan.channel_id)
raise RemoteMisbehaving(f"received update_fail_malformed_htlc with unexpected failure code: {failure_code}")
reason = OnionRoutingFailure(code=failure_code, data=payload["sha256_of_onion"])
chan.receive_fail_htlc(htlc_id, error_bytes=None, reason=reason)
@@ -1404,7 +1404,7 @@ class Peer(Logger):
if chan.get_state() != ChannelState.OPEN:
raise RemoteMisbehaving(f"received update_add_htlc while chan.get_state() != OPEN. state was {chan.get_state()!r}")
if cltv_expiry > bitcoin.NLOCKTIME_BLOCKHEIGHT_MAX:
asyncio.ensure_future(self.lnworker.try_force_closing(chan.channel_id))
self.lnworker.schedule_force_closing(chan.channel_id)
raise RemoteMisbehaving(f"received update_add_htlc with cltv_expiry > BLOCKHEIGHT_MAX. value was {cltv_expiry}")
# add htlc
chan.receive_htlc(htlc, onion_packet)