From faea1e6e1a0798176850a159062ab90979c0339f Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 13 Feb 2023 01:23:47 +0000 Subject: [PATCH] lnchannel: add more debug logging for ctx/htlc sigs related: https://github.com/spesmilo/electrum/issues/8191 --- electrum/lnchannel.py | 25 ++++++++++++++++++++----- electrum/lnpeer.py | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py index 2328e191a..6bf73ff52 100644 --- a/electrum/lnchannel.py +++ b/electrum/lnchannel.py @@ -988,10 +988,11 @@ class Channel(AbstractChannel): """ # TODO: when more channel types are supported, this method should depend on channel type next_remote_ctn = self.get_next_ctn(REMOTE) - self.logger.info(f"sign_next_commitment {next_remote_ctn}") + self.logger.info(f"sign_next_commitment. ctn={next_remote_ctn}") pending_remote_commitment = self.get_next_commitment(REMOTE) sig_64 = sign_and_get_sig_string(pending_remote_commitment, self.config[LOCAL], self.config[REMOTE]) + self.logger.debug(f"sign_next_commitment. {pending_remote_commitment.serialize()=}. {sig_64.hex()=}") their_remote_htlc_privkey_number = derive_privkey( int.from_bytes(self.config[LOCAL].htlc_basepoint.privkey, 'big'), @@ -1039,8 +1040,12 @@ class Channel(AbstractChannel): pre_hash = sha256d(bfh(preimage_hex)) if not ecc.verify_signature(self.config[REMOTE].multisig_key.pubkey, sig, pre_hash): raise LNProtocolWarning( - f'failed verifying signature of our updated commitment transaction: ' - f'{bh2u(sig)} preimage is {preimage_hex}, rawtx: {pending_local_commitment.serialize()}') + f'failed verifying signature for our updated commitment transaction. ' + f'sig={sig.hex()}. ' + f'pre_hash={pre_hash.hex()}. ' + f'pubkey={self.config[REMOTE].multisig_key.pubkey}. ' + f'ctx={pending_local_commitment.serialize()} ' + ) htlc_sigs_string = b''.join(htlc_sigs) @@ -1077,10 +1082,20 @@ class Channel(AbstractChannel): commit=ctx, ctx_output_idx=ctx_output_idx, htlc=htlc) - pre_hash = sha256d(bfh(htlc_tx.serialize_preimage(0))) + preimage_hex = htlc_tx.serialize_preimage(0) + pre_hash = sha256d(bfh(preimage_hex)) remote_htlc_pubkey = derive_pubkey(self.config[REMOTE].htlc_basepoint.pubkey, pcp) if not ecc.verify_signature(remote_htlc_pubkey, htlc_sig, pre_hash): - raise LNProtocolWarning(f'failed verifying HTLC signatures: {htlc} {htlc_direction}, rawtx: {htlc_tx.serialize()}') + raise LNProtocolWarning( + f'failed verifying HTLC signatures: {htlc=}, {htlc_direction=}. ' + f'htlc_tx={htlc_tx.serialize()}. ' + f'htlc_sig={htlc_sig.hex()}. ' + f'remote_htlc_pubkey={remote_htlc_pubkey.hex()}. ' + f'pre_hash={pre_hash.hex()}. ' + f'ctx={ctx.serialize()}. ' + f'ctx_output_idx={ctx_output_idx}. ' + f'ctn={ctn}. ' + ) def get_remote_htlc_sig_for_htlc(self, *, htlc_relative_idx: int) -> bytes: data = self.config[LOCAL].current_htlc_signatures diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 24e4c3de4..b69f1783c 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -767,6 +767,7 @@ class Peer(Logger): # <- accept_channel payload = await self.wait_for_message('accept_channel', temp_channel_id) + self.logger.debug(f"received accept_channel for temp_channel_id={temp_channel_id.hex()}. {payload=}") remote_per_commitment_point = payload['first_per_commitment_point'] funding_txn_minimum_depth = payload['minimum_depth'] if funding_txn_minimum_depth <= 0: