Skip to content

Commit

Permalink
lnchannel: add more debug logging for ctx/htlc sigs
Browse files Browse the repository at this point in the history
related: #8191
  • Loading branch information
SomberNight committed Feb 13, 2023
1 parent 4a91213 commit faea1e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
25 changes: 20 additions & 5 deletions electrum/lnchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,10 +988,11 @@ def sign_next_commitment(self) -> Tuple[bytes, Sequence[bytes]]:
"""
# 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'),
Expand Down Expand Up @@ -1039,8 +1040,12 @@ def receive_new_commitment(self, sig: bytes, htlc_sigs: Sequence[bytes]) -> None
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)

Expand Down Expand Up @@ -1077,10 +1082,20 @@ def _verify_htlc_sig(self, *, htlc: UpdateAddHtlc, htlc_sig: bytes, htlc_directi
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
Expand Down
1 change: 1 addition & 0 deletions electrum/lnpeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ async def channel_establishment_flow(

# <- 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:
Expand Down

0 comments on commit faea1e6

Please sign in to comment.