define channel.has_pending_changes method
This commit is contained in:
@@ -885,3 +885,8 @@ class Channel(Logger):
|
|||||||
def sweep_htlc(self, ctx:Transaction, htlc_tx: Transaction):
|
def sweep_htlc(self, ctx:Transaction, htlc_tx: Transaction):
|
||||||
# look at the output address, check if it matches
|
# look at the output address, check if it matches
|
||||||
return create_sweeptx_for_their_revoked_htlc(self, ctx, htlc_tx, self.sweep_address)
|
return create_sweeptx_for_their_revoked_htlc(self, ctx, htlc_tx, self.sweep_address)
|
||||||
|
|
||||||
|
def has_pending_changes(self, subject):
|
||||||
|
next_htlcs = self.hm.get_htlcs_in_next_ctx(subject)
|
||||||
|
latest_htlcs = self.hm.get_htlcs_in_latest_ctx(subject)
|
||||||
|
return not (next_htlcs == latest_htlcs and self.get_next_feerate(subject) == self.get_latest_feerate(subject))
|
||||||
|
|||||||
@@ -1011,16 +1011,12 @@ class Peer(Logger):
|
|||||||
def maybe_send_commitment(self, chan: Channel):
|
def maybe_send_commitment(self, chan: Channel):
|
||||||
# REMOTE should revoke first before we can sign a new ctx
|
# REMOTE should revoke first before we can sign a new ctx
|
||||||
if chan.hm.is_revack_pending(REMOTE):
|
if chan.hm.is_revack_pending(REMOTE):
|
||||||
return False
|
return
|
||||||
# if there are no changes, we will not (and must not) send a new commitment
|
# if there are no changes, we will not (and must not) send a new commitment
|
||||||
next_htlcs, latest_htlcs = chan.hm.get_htlcs_in_next_ctx(REMOTE), chan.hm.get_htlcs_in_latest_ctx(REMOTE)
|
if not chan.has_pending_changes(REMOTE):
|
||||||
if next_htlcs == latest_htlcs and chan.get_next_feerate(REMOTE) == chan.get_latest_feerate(REMOTE):
|
return
|
||||||
return False
|
|
||||||
self.logger.info(f'send_commitment. chan {chan.short_channel_id}. ctn: {chan.get_next_ctn(REMOTE)}. '
|
|
||||||
f'old number htlcs: {len(latest_htlcs)}, new number htlcs: {len(next_htlcs)}')
|
|
||||||
sig_64, htlc_sigs = chan.sign_next_commitment()
|
sig_64, htlc_sigs = chan.sign_next_commitment()
|
||||||
self.send_message("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs))
|
self.send_message("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs))
|
||||||
return True
|
|
||||||
|
|
||||||
async def await_remote(self, chan: Channel, ctn: int):
|
async def await_remote(self, chan: Channel, ctn: int):
|
||||||
"""Wait until remote 'ctn' gets revoked."""
|
"""Wait until remote 'ctn' gets revoked."""
|
||||||
@@ -1084,11 +1080,7 @@ class Peer(Logger):
|
|||||||
if chan.peer_state == peer_states.BAD:
|
if chan.peer_state == peer_states.BAD:
|
||||||
return
|
return
|
||||||
# make sure there were changes to the ctx, otherwise the remote peer is misbehaving
|
# make sure there were changes to the ctx, otherwise the remote peer is misbehaving
|
||||||
next_htlcs, latest_htlcs = chan.hm.get_htlcs_in_next_ctx(LOCAL), chan.hm.get_htlcs_in_latest_ctx(LOCAL)
|
if not chan.has_pending_changes(LOCAL):
|
||||||
self.logger.info(f'on_commitment_signed. chan {chan.short_channel_id}. ctn: {chan.get_next_ctn(LOCAL)}. '
|
|
||||||
f'old number htlcs: {len(latest_htlcs)}, new number htlcs: {len(next_htlcs)}')
|
|
||||||
if (next_htlcs == latest_htlcs
|
|
||||||
and chan.get_next_feerate(LOCAL) == chan.get_latest_feerate(LOCAL)):
|
|
||||||
# TODO if feerate changed A->B->A; so there were updates but the value is identical,
|
# TODO if feerate changed A->B->A; so there were updates but the value is identical,
|
||||||
# then it might be legal to send a commitment_signature
|
# then it might be legal to send a commitment_signature
|
||||||
# see https://github.com/lightningnetwork/lightning-rfc/pull/618
|
# see https://github.com/lightningnetwork/lightning-rfc/pull/618
|
||||||
@@ -1380,7 +1372,7 @@ class Peer(Logger):
|
|||||||
# wait until no more pending updates (bolt2)
|
# wait until no more pending updates (bolt2)
|
||||||
# TODO: stop sending updates during that time
|
# TODO: stop sending updates during that time
|
||||||
ctn = chan.get_latest_ctn(REMOTE)
|
ctn = chan.get_latest_ctn(REMOTE)
|
||||||
if self.maybe_send_commitment(chan):
|
if chan.has_pending_changes(REMOTE):
|
||||||
await self.await_remote(chan, ctn)
|
await self.await_remote(chan, ctn)
|
||||||
self.send_message('shutdown', channel_id=chan.channel_id, len=len(scriptpubkey), scriptpubkey=scriptpubkey)
|
self.send_message('shutdown', channel_id=chan.channel_id, len=len(scriptpubkey), scriptpubkey=scriptpubkey)
|
||||||
chan.set_state(channel_states.CLOSING)
|
chan.set_state(channel_states.CLOSING)
|
||||||
|
|||||||
Reference in New Issue
Block a user