mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
channel_reestablish: assume that DLP is enabled, because we require it
This commit is contained in:
parent
e42e17779d
commit
69ef9aa3d7
2 changed files with 20 additions and 29 deletions
|
@ -728,28 +728,21 @@ class Peer(Logger):
|
||||||
oldest_unrevoked_remote_ctn = chan.get_oldest_unrevoked_ctn(REMOTE)
|
oldest_unrevoked_remote_ctn = chan.get_oldest_unrevoked_ctn(REMOTE)
|
||||||
latest_remote_ctn = chan.get_latest_ctn(REMOTE)
|
latest_remote_ctn = chan.get_latest_ctn(REMOTE)
|
||||||
next_remote_ctn = chan.get_next_ctn(REMOTE)
|
next_remote_ctn = chan.get_next_ctn(REMOTE)
|
||||||
|
assert self.localfeatures & LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
|
||||||
# send message
|
# send message
|
||||||
dlp_enabled = self.localfeatures & LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
|
if oldest_unrevoked_remote_ctn == 0:
|
||||||
if dlp_enabled:
|
last_rev_secret = 0
|
||||||
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)
|
|
||||||
else:
|
else:
|
||||||
self.send_message(
|
last_rev_index = oldest_unrevoked_remote_ctn - 1
|
||||||
"channel_reestablish",
|
last_rev_secret = chan.revocation_store.retrieve_secret(RevocationStore.START_INDEX - last_rev_index)
|
||||||
channel_id=chan_id,
|
latest_secret, latest_point = chan.get_secret_and_point(LOCAL, latest_local_ctn)
|
||||||
next_local_commitment_number=next_local_ctn,
|
self.send_message(
|
||||||
next_remote_revocation_number=oldest_unrevoked_remote_ctn)
|
"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 '
|
self.logger.info(f'channel_reestablish: sent channel_reestablish with '
|
||||||
f'(next_local_ctn={next_local_ctn}, '
|
f'(next_local_ctn={next_local_ctn}, '
|
||||||
f'oldest_unrevoked_remote_ctn={oldest_unrevoked_remote_ctn})')
|
f'oldest_unrevoked_remote_ctn={oldest_unrevoked_remote_ctn})')
|
||||||
|
@ -823,8 +816,7 @@ class Peer(Logger):
|
||||||
# option_data_loss_protect
|
# option_data_loss_protect
|
||||||
def are_datalossprotect_fields_valid() -> bool:
|
def are_datalossprotect_fields_valid() -> bool:
|
||||||
if their_local_pcp is None or their_claim_of_our_last_per_commitment_secret is None:
|
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 False
|
||||||
return not dlp_enabled
|
|
||||||
if their_oldest_unrevoked_remote_ctn > 0:
|
if their_oldest_unrevoked_remote_ctn > 0:
|
||||||
our_pcs, __ = chan.get_secret_and_point(LOCAL, their_oldest_unrevoked_remote_ctn - 1)
|
our_pcs, __ = chan.get_secret_and_point(LOCAL, their_oldest_unrevoked_remote_ctn - 1)
|
||||||
else:
|
else:
|
||||||
|
@ -845,14 +837,12 @@ class Peer(Logger):
|
||||||
|
|
||||||
if not are_datalossprotect_fields_valid():
|
if not are_datalossprotect_fields_valid():
|
||||||
raise RemoteMisbehaving("channel_reestablish: data loss protect fields invalid")
|
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:
|
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
|
chan.peer_state = peer_states.BAD
|
||||||
return
|
return
|
||||||
elif should_close_we_are_ahead:
|
elif should_close_we_are_ahead:
|
||||||
|
|
|
@ -85,6 +85,7 @@ class MockLNWallet:
|
||||||
self.logs = defaultdict(list)
|
self.logs = defaultdict(list)
|
||||||
self.wallet = MockWallet()
|
self.wallet = MockWallet()
|
||||||
self.localfeatures = LnLocalFeatures(0)
|
self.localfeatures = LnLocalFeatures(0)
|
||||||
|
self.localfeatures |= LnLocalFeatures.OPTION_DATA_LOSS_PROTECT_OPT
|
||||||
self.pending_payments = defaultdict(asyncio.Future)
|
self.pending_payments = defaultdict(asyncio.Future)
|
||||||
|
|
||||||
def get_invoice_status(self, key):
|
def get_invoice_status(self, key):
|
||||||
|
|
Loading…
Add table
Reference in a new issue