Browse Source

lnhtlc: also check received htlcs when validating commitment sigs

regtest_lnd
Janus 6 years ago
committed by SomberNight
parent
commit
8241ba14ee
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 21
      electrum/lnhtlc.py

21
electrum/lnhtlc.py

@ -316,13 +316,21 @@ class HTLCStateMachine(PrintError):
_, this_point, _ = self.points _, this_point, _ = self.points
if len(self.htlcs_in_remote) > 0 and len(pending_local_commitment.outputs()) == 3: if len(pending_local_commitment.outputs()) >= 3:
print("CHECKING HTLC SIGS") print("CHECKING HTLC SIGS")
assert len(pending_local_commitment.outputs()) == 3
if len(self.htlcs_in_remote) > 0:
assert len(self.htlcs_in_remote) == 1
we_receive = True we_receive = True
payment_hash = self.htlcs_in_remote[0].payment_hash htlc = self.htlcs_in_remote[0]
amount_msat = self.htlcs_in_remote[0].amount_msat elif len(self.htlcs_in_local) > 0:
cltv_expiry = self.htlcs_in_remote[0].cltv_expiry assert len(self.htlcs_in_local) == 1
htlc_tx = make_htlc_tx_with_open_channel(self, this_point, True, we_receive, amount_msat, cltv_expiry, payment_hash, pending_local_commitment, 0) we_receive = False
htlc = self.htlcs_in_local[0]
else:
assert False
htlc_tx = make_htlc_tx_with_open_channel(self, this_point, True, we_receive, htlc.amount_msat, htlc.cltv_expiry, htlc.payment_hash, pending_local_commitment, 0)
pre_hash = Hash(bfh(htlc_tx.serialize_preimage(0))) pre_hash = Hash(bfh(htlc_tx.serialize_preimage(0)))
remote_htlc_pubkey = derive_pubkey(self.remote_config.htlc_basepoint.pubkey, this_point) remote_htlc_pubkey = derive_pubkey(self.remote_config.htlc_basepoint.pubkey, this_point)
if not ecc.verify_signature(remote_htlc_pubkey, htlc_sigs[0], pre_hash): if not ecc.verify_signature(remote_htlc_pubkey, htlc_sigs[0], pre_hash):
@ -451,9 +459,6 @@ class HTLCStateMachine(PrintError):
amount_msat = self.local_state.amount_msat + (received_this_batch - sent_this_batch) amount_msat = self.local_state.amount_msat + (received_this_batch - sent_this_batch)
) )
self.balance(LOCAL)
self.balance(REMOTE)
for pending_fee in self.fee_mgr: for pending_fee in self.fee_mgr:
if pending_fee.is_proposed(): if pending_fee.is_proposed():
if self.constraints.is_initiator: if self.constraints.is_initiator:

Loading…
Cancel
Save