|
|
@ -728,28 +728,21 @@ class Peer(Logger): |
|
|
|
oldest_unrevoked_remote_ctn = chan.get_oldest_unrevoked_ctn(REMOTE) |
|
|
|
latest_remote_ctn = chan.get_latest_ctn(REMOTE) |
|
|
|
next_remote_ctn = chan.get_next_ctn(REMOTE) |
|
|
|
assert self.localfeatures & LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT |
|
|
|
# send message |
|
|
|
dlp_enabled = self.localfeatures & LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT |
|
|
|
if dlp_enabled: |
|
|
|
if oldest_unrevoked_remote_ctn == 0: |
|
|
|
last_rev_secret = 0 |
|
|
|
else: |
|
|
|
last_rev_index = oldest_unrevoked_remote_ctn - 1 |
|
|
|
last_rev_secret = chan.revocation_store.retrieve_secret(RevocationStore.START_INDEX - last_rev_index) |
|
|
|
latest_secret, latest_point = chan.get_secret_and_point(LOCAL, latest_local_ctn) |
|
|
|
self.send_message( |
|
|
|
"channel_reestablish", |
|
|
|
channel_id=chan_id, |
|
|
|
next_local_commitment_number=next_local_ctn, |
|
|
|
next_remote_revocation_number=oldest_unrevoked_remote_ctn, |
|
|
|
your_last_per_commitment_secret=last_rev_secret, |
|
|
|
my_current_per_commitment_point=latest_point) |
|
|
|
if oldest_unrevoked_remote_ctn == 0: |
|
|
|
last_rev_secret = 0 |
|
|
|
else: |
|
|
|
self.send_message( |
|
|
|
"channel_reestablish", |
|
|
|
channel_id=chan_id, |
|
|
|
next_local_commitment_number=next_local_ctn, |
|
|
|
next_remote_revocation_number=oldest_unrevoked_remote_ctn) |
|
|
|
last_rev_index = oldest_unrevoked_remote_ctn - 1 |
|
|
|
last_rev_secret = chan.revocation_store.retrieve_secret(RevocationStore.START_INDEX - last_rev_index) |
|
|
|
latest_secret, latest_point = chan.get_secret_and_point(LOCAL, latest_local_ctn) |
|
|
|
self.send_message( |
|
|
|
"channel_reestablish", |
|
|
|
channel_id=chan_id, |
|
|
|
next_local_commitment_number=next_local_ctn, |
|
|
|
next_remote_revocation_number=oldest_unrevoked_remote_ctn, |
|
|
|
your_last_per_commitment_secret=last_rev_secret, |
|
|
|
my_current_per_commitment_point=latest_point) |
|
|
|
self.logger.info(f'channel_reestablish: sent channel_reestablish with ' |
|
|
|
f'(next_local_ctn={next_local_ctn}, ' |
|
|
|
f'oldest_unrevoked_remote_ctn={oldest_unrevoked_remote_ctn})') |
|
|
@ -823,8 +816,7 @@ class Peer(Logger): |
|
|
|
# option_data_loss_protect |
|
|
|
def are_datalossprotect_fields_valid() -> bool: |
|
|
|
if their_local_pcp is None or their_claim_of_our_last_per_commitment_secret is None: |
|
|
|
# if DLP was enabled, absence of fields is not OK |
|
|
|
return not dlp_enabled |
|
|
|
return False |
|
|
|
if their_oldest_unrevoked_remote_ctn > 0: |
|
|
|
our_pcs, __ = chan.get_secret_and_point(LOCAL, their_oldest_unrevoked_remote_ctn - 1) |
|
|
|
else: |
|
|
@ -845,14 +837,12 @@ class Peer(Logger): |
|
|
|
|
|
|
|
if not are_datalossprotect_fields_valid(): |
|
|
|
raise RemoteMisbehaving("channel_reestablish: data loss protect fields invalid") |
|
|
|
else: |
|
|
|
if dlp_enabled and should_close_they_are_ahead: |
|
|
|
self.logger.warning(f"channel_reestablish: remote is ahead of us! luckily DLP is enabled. remote PCP: {bh2u(their_local_pcp)}") |
|
|
|
# data_loss_protect_remote_pcp is used in lnsweep |
|
|
|
chan.set_data_loss_protect_remote_pcp(their_next_local_ctn - 1, their_local_pcp) |
|
|
|
self.lnworker.save_channel(chan) |
|
|
|
|
|
|
|
if should_close_they_are_ahead: |
|
|
|
self.logger.warning(f"channel_reestablish: remote is ahead of us! They should force-close.") |
|
|
|
self.logger.warning(f"channel_reestablish: remote is ahead of us! They should force-close. Remote PCP: {bh2u(their_local_pcp)}") |
|
|
|
# data_loss_protect_remote_pcp is used in lnsweep |
|
|
|
chan.set_data_loss_protect_remote_pcp(their_next_local_ctn - 1, their_local_pcp) |
|
|
|
self.lnworker.save_channel(chan) |
|
|
|
chan.peer_state = peer_states.BAD |
|
|
|
return |
|
|
|
elif should_close_we_are_ahead: |
|
|
|