electrum

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

commit 8573dd3b6a692a9d50c161b69a945cb26def43bf
parent 605d6ff5cafd8c4e8e502e9cda93819280fa3efa
Author: Janus <ysangkok@gmail.com>
Date:   Fri,  6 Jul 2018 22:54:26 +0200

ln: revoke before sending bare ctx in pay(), remove subtraction of trimmed amt from fee

Diffstat:
Mlib/lnbase.py | 9++++++---
Mlib/lnhtlc.py | 17++++-------------
Mlib/lnutil.py | 3+--
3 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -563,7 +563,6 @@ class Peer(PrintError): max_accepted_htlcs=int.from_bytes(payload["max_accepted_htlcs"], 'big') ) funding_txn_minimum_depth = int.from_bytes(payload['minimum_depth'], 'big') - print('remote dust limit', remote_config.dust_limit_sat) assert remote_config.dust_limit_sat < 600 assert int.from_bytes(payload['htlc_minimum_msat'], 'big') < 600 * 1000 assert remote_config.max_htlc_value_in_flight_msat >= 198 * 1000 * 1000, remote_config.max_htlc_value_in_flight_msat @@ -571,7 +570,6 @@ class Peer(PrintError): self.print_error('funding_txn_minimum_depth', funding_txn_minimum_depth) # create funding tx redeem_script = funding_output_script(local_config, remote_config) - print("REDEEM SCRIPT", redeem_script) funding_address = bitcoin.redeem_script_to_address('p2wsh', redeem_script) funding_output = (bitcoin.TYPE_ADDRESS, funding_address, funding_sat) funding_tx = wallet.mktx([funding_output], password, config, 1000) @@ -866,6 +864,7 @@ class Peer(PrintError): self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=1, htlc_signature=htlc_sigs[0])) while (await self.commitment_signed[chan.channel_id].get())["htlc_signature"] != b"": self.revoke(chan) + # TODO process above commitment transactions await self.receive_revoke(chan) chan.fail_htlc(htlc) sig_64, htlc_sigs = chan.sign_next_commitment() @@ -878,12 +877,15 @@ class Peer(PrintError): failure_coro.cancel() update_fulfill_htlc_msg = fulfill_coro.result() - chan.receive_htlc_settle(update_fulfill_htlc_msg["payment_preimage"], int.from_bytes(update_fulfill_htlc_msg["id"], "big")) + preimage = update_fulfill_htlc_msg["payment_preimage"] + chan.receive_htlc_settle(preimage, int.from_bytes(update_fulfill_htlc_msg["id"], "big")) while (await self.commitment_signed[chan.channel_id].get())["htlc_signature"] != b"": self.revoke(chan) # TODO process above commitment transactions + self.revoke(chan) + bare_ctx = chan.make_commitment(chan.remote_state.ctn + 1, False, chan.remote_state.next_per_commitment_point, msat_remote, msat_local) @@ -893,6 +895,7 @@ class Peer(PrintError): await self.receive_revoke(chan) self.lnworker.save_channel(chan) + return bh2u(preimage) async def receive_revoke(self, m): revoke_and_ack_msg = await self.revoke_and_ack[m.channel_id].get() diff --git a/lib/lnhtlc.py b/lib/lnhtlc.py @@ -417,13 +417,10 @@ class HTLCStateMachine(PrintError): local_htlc_pubkey = derive_pubkey(self.local_config.htlc_basepoint.pubkey, this_point) local_revocation_pubkey = derive_blinded_pubkey(self.local_config.revocation_basepoint.pubkey, this_point) - trimmed = 0 - with PendingFeerateApplied(self): htlcs_in_local = [] for htlc in self.htlcs_in_local: if htlc.amount_msat // 1000 - HTLC_SUCCESS_WEIGHT * (self.remote_state.feerate // 1000) < self.remote_config.dust_limit_sat: - trimmed += htlc.amount_msat // 1000 continue htlcs_in_local.append( ( make_received_htlc(local_revocation_pubkey, local_htlc_pubkey, remote_htlc_pubkey, htlc.payment_hash, htlc.cltv_expiry), htlc.amount_msat + htlc.total_fee)) @@ -431,14 +428,13 @@ class HTLCStateMachine(PrintError): htlcs_in_remote = [] for htlc in self.htlcs_in_remote: if htlc.amount_msat // 1000 - HTLC_TIMEOUT_WEIGHT * (self.remote_state.feerate // 1000) < self.remote_config.dust_limit_sat: - trimmed += htlc.amount_msat // 1000 continue htlcs_in_remote.append( ( make_offered_htlc(local_revocation_pubkey, local_htlc_pubkey, remote_htlc_pubkey, htlc.payment_hash), htlc.amount_msat + htlc.total_fee)) commit = self.make_commitment(self.remote_state.ctn + 1, False, this_point, - remote_msat - total_fee_remote, local_msat - total_fee_local, htlcs_in_local + htlcs_in_remote, trimmed) + remote_msat - total_fee_remote, local_msat - total_fee_local, htlcs_in_local + htlcs_in_remote) return commit @property @@ -453,13 +449,10 @@ class HTLCStateMachine(PrintError): local_htlc_pubkey = derive_pubkey(self.local_config.htlc_basepoint.pubkey, this_point) remote_revocation_pubkey = derive_blinded_pubkey(self.remote_config.revocation_basepoint.pubkey, this_point) - trimmed = 0 - with PendingFeerateApplied(self): htlcs_in_local = [] for htlc in self.htlcs_in_local: if htlc.amount_msat // 1000 - HTLC_TIMEOUT_WEIGHT * (self.local_state.feerate // 1000) < self.local_config.dust_limit_sat: - trimmed += htlc.amount_msat // 1000 continue htlcs_in_local.append( ( make_offered_htlc(remote_revocation_pubkey, remote_htlc_pubkey, local_htlc_pubkey, htlc.payment_hash), htlc.amount_msat + htlc.total_fee)) @@ -467,14 +460,13 @@ class HTLCStateMachine(PrintError): htlcs_in_remote = [] for htlc in self.htlcs_in_remote: if htlc.amount_msat // 1000 - HTLC_SUCCESS_WEIGHT * (self.local_state.feerate // 1000) < self.local_config.dust_limit_sat: - trimmed += htlc.amount_msat // 1000 continue htlcs_in_remote.append( ( make_received_htlc(remote_revocation_pubkey, remote_htlc_pubkey, local_htlc_pubkey, htlc.payment_hash, htlc.cltv_expiry), htlc.amount_msat + htlc.total_fee)) commit = self.make_commitment(self.local_state.ctn + 1, True, this_point, - local_msat - total_fee_local, remote_msat - total_fee_remote, htlcs_in_local + htlcs_in_remote, trimmed) + local_msat - total_fee_local, remote_msat - total_fee_remote, htlcs_in_local + htlcs_in_remote) return commit def gen_htlc_indices(self, subject, just_unsettled=True): @@ -579,7 +571,7 @@ class HTLCStateMachine(PrintError): def __str__(self): return self.serialize() - def make_commitment(chan, ctn, for_us, pcp, local_msat, remote_msat, htlcs=[], trimmed=0): + def make_commitment(chan, ctn, for_us, pcp, local_msat, remote_msat, htlcs=[]): conf = chan.local_config if for_us else chan.remote_config other_conf = chan.local_config if not for_us else chan.remote_config payment_pubkey = derive_pubkey(other_conf.payment_basepoint.pubkey, pcp) @@ -602,5 +594,4 @@ class HTLCStateMachine(PrintError): chan.local_state.feerate if for_us else chan.remote_state.feerate, for_us, chan.constraints.is_initiator, - htlcs=htlcs, - trimmed=trimmed) + htlcs=htlcs) diff --git a/lib/lnutil.py b/lib/lnutil.py @@ -228,7 +228,7 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, delayed_pubkey, to_self_delay, funding_txid, funding_pos, funding_sat, local_amount, remote_amount, dust_limit_sat, local_feerate, for_us, we_are_initiator, - htlcs, trimmed=0): + htlcs): pubkeys = sorted([bh2u(local_funding_pubkey), bh2u(remote_funding_pubkey)]) payments = [payment_basepoint, remote_payment_basepoint] @@ -256,7 +256,6 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remote_address = bitcoin.pubkey_to_address('p2wpkh', bh2u(remote_payment_pubkey)) # TODO trim htlc outputs here while also considering 2nd stage htlc transactions fee = local_feerate * overall_weight(len(htlcs)) - fee -= trimmed * 1000 assert type(fee) is int we_pay_fee = for_us == we_are_initiator to_local_amt = local_amount - (fee if we_pay_fee else 0)