commit 2e23ecb3ca88e4e90d695fc9840f07eb8c65cdce
parent 73a17c93eec0badb918137c47f2b688c2dc874b8
Author: Janus <ysangkok@gmail.com>
Date: Mon, 14 May 2018 15:41:55 +0200
lnbase: verify commitment tx'es again
Diffstat:
2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/lib/lnbase.py b/lib/lnbase.py
@@ -1005,7 +1005,10 @@ class Peer(PrintError):
nonlocal chan
last_small_num = chan.local_state.ctn
next_small_num = last_small_num + 2
+ this_small_num = last_small_num + 1
last_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-last_small_num-1)
+ this_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-this_small_num-1)
+ this_point = secret_to_pubkey(int.from_bytes(this_secret, 'big'))
next_secret = get_per_commitment_secret_from_seed(chan.local_state.per_commitment_secret_seed, 2**48-next_small_num-1)
next_point = secret_to_pubkey(int.from_bytes(next_secret, 'big'))
chan = chan._replace(
@@ -1013,7 +1016,7 @@ class Peer(PrintError):
ctn=chan.local_state.ctn + 1
)
)
- return last_secret, next_point
+ return last_secret, this_point, next_point
their_revstore = chan.remote_state.revocation_store
@@ -1031,12 +1034,12 @@ class Peer(PrintError):
assert amount_msat // 1000 == expected_received_sat
payment_hash = htlc["payment_hash"]
- last_secret, next_point = derive_and_incr()
+ last_secret, this_point, next_point = derive_and_incr()
- remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, next_point)
- local_htlc_pubkey = derive_pubkey(chan.local_config.htlc_basepoint.pubkey, next_point)
+ remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, this_point)
+ local_htlc_pubkey = derive_pubkey(chan.local_config.htlc_basepoint.pubkey, this_point)
- remote_revocation_pubkey = derive_blinded_pubkey(chan.remote_config.revocation_basepoint.pubkey, next_point)
+ remote_revocation_pubkey = derive_blinded_pubkey(chan.remote_config.revocation_basepoint.pubkey, this_point)
htlcs_in_local = [
(
@@ -1045,29 +1048,29 @@ class Peer(PrintError):
)
]
- new_commitment = make_commitment_using_open_channel(chan, chan.local_state.ctn, True, next_point,
+ new_commitment = make_commitment_using_open_channel(chan, chan.local_state.ctn, True, this_point,
chan.local_state.amount_sat,
chan.remote_state.amount_sat - expected_received_sat,
htlcs_in_local)
preimage_hex = new_commitment.serialize_preimage(0)
pre_hash = bitcoin.Hash(bfh(preimage_hex))
- #if not bitcoin.verify_signature(chan.remote_config.multisig_key.pubkey, commitment_signed_msg["signature"], pre_hash):
- # raise Exception('failed verifying signature of our updated commitment transaction')
+ if not bitcoin.verify_signature(chan.remote_config.multisig_key.pubkey, commitment_signed_msg["signature"], pre_hash):
+ raise Exception('failed verifying signature of our updated commitment transaction')
htlc_sigs_len = len(commitment_signed_msg["htlc_signature"])
- #if htlc_sigs_len != 64:
- # raise Exception("unexpected number of htlc signatures: " + str(htlc_sigs_len))
+ if htlc_sigs_len != 64:
+ raise Exception("unexpected number of htlc signatures: " + str(htlc_sigs_len))
- htlc_tx = make_htlc_tx_with_open_channel(chan, next_point, True, True, amount_msat, cltv_expiry, payment_hash, new_commitment, 0)
+ htlc_tx = make_htlc_tx_with_open_channel(chan, this_point, True, True, amount_msat, cltv_expiry, payment_hash, new_commitment, 0)
pre_hash = bitcoin.Hash(bfh(htlc_tx.serialize_preimage(0)))
- remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, next_point)
- #if not bitcoin.verify_signature(remote_htlc_pubkey, commitment_signed_msg["htlc_signature"], pre_hash):
- # raise Exception("failed verifying signature an HTLC tx spending from one of our commit tx'es HTLC outputs")
+ remote_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, this_point)
+ if not bitcoin.verify_signature(remote_htlc_pubkey, commitment_signed_msg["htlc_signature"], pre_hash):
+ raise Exception("failed verifying signature an HTLC tx spending from one of our commit tx'es HTLC outputs")
print("SENDING FIRST REVOKE AND ACK")
- #their_revstore.add_next_entry(last_secret)
+ their_revstore.add_next_entry(last_secret)
self.send_message(gen_msg("revoke_and_ack",
channel_id=channel_id,
@@ -1128,9 +1131,9 @@ class Peer(PrintError):
# TODO check commitment_signed results
- last_secret, next_point = derive_and_incr()
+ last_secret, _, next_point = derive_and_incr()
- #their_revstore.add_next_entry(last_secret)
+ their_revstore.add_next_entry(last_secret)
print("SENDING SECOND REVOKE AND ACK")
self.send_message(gen_msg("revoke_and_ack",
diff --git a/lib/tests/test_lnbase_online.py b/lib/tests/test_lnbase_online.py
@@ -100,8 +100,8 @@ if __name__ == "__main__":
peer = Peer(host, port, pubkey, privkey, request_initial_sync=False, network=network)
network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), network.asyncio_loop))
- funding_satoshis = 1000000
- push_msat = 610000000
+ funding_satoshis = 2000000
+ push_msat = 1000000000
# run blocking test
async def async_test():