electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit f6995b99d9741a515347f734835d820102c90d83
parent 6c67ad24f30b5c6ead21b98b2fb5fc228fb703fd
Author: Janus <ysangkok@gmail.com>
Date:   Thu, 17 May 2018 18:12:21 +0200

lnbase: calculate cltv_expiry for onion_packet correctly

Diffstat:
Mlib/lnbase.py | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -1062,7 +1062,7 @@ class Peer(PrintError): while not is_synced(wallet.network): await asyncio.sleep(1) print("sleeping more") - cltv_expiry = wallet.get_local_height() + chan.remote_config.to_self_delay + height = wallet.get_local_height() assert sat > 0, "sat is not positive" amount_msat = sat * 1000 @@ -1087,15 +1087,19 @@ class Peer(PrintError): route = self.path_finder.create_route_from_path(path, our_pubkey) hops_data = [] - substract = (len(route))*9 - for route_edge in route: - hops_data += [OnionHopsDataSingle(OnionPerHop(route_edge.short_channel_id, amount_msat.to_bytes(8, "big"), (cltv_expiry+(len(route))*9-substract).to_bytes(4, "big")))] - substract -= 9 + next_hop_cltv_expiry = sum(route_edge.channel_policy.cltv_expiry_delta for route_edge in route[1:]) + computed_cltv_expiry = height + 9 # TODO use c tag in invoice (min_final_cltv_expiry) + print("traversing route") + for idx, route_edge in enumerate(route): + print("unused delta", route_edge.channel_policy.cltv_expiry_delta) + hops_data += [OnionHopsDataSingle(OnionPerHop(route_edge.short_channel_id, amount_msat.to_bytes(8, "big"), computed_cltv_expiry.to_bytes(4, "big")))] associated_data = payment_hash self.secret_key = os.urandom(32) self.node_keys = [x.node_id for x in route] onion = new_onion_packet(self.node_keys, self.secret_key, hops_data, associated_data) + cltv_expiry = height + next_hop_cltv_expiry + 9 # TODO use min_final_cltv_expiry + self.send_message(gen_msg("update_add_htlc", channel_id=chan.channel_id, id=chan.local_state.next_htlc_id, cltv_expiry=cltv_expiry, amount_msat=amount_msat, payment_hash=payment_hash, onion_routing_packet=onion.to_bytes())) their_local_htlc_pubkey = derive_pubkey(chan.remote_config.htlc_basepoint.pubkey, chan.remote_state.next_per_commitment_point)