electrum

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

commit 0dfc9e512b6ca711395f22426993486c4899d2d1
parent d6f62d4e7f3e703f584ad8b8fac6fe5468c487ce
Author: Janus <ysangkok@gmail.com>
Date:   Mon, 22 Oct 2018 21:50:13 +0200

fix co-op close

Diffstat:
Melectrum/lnchan.py | 19++++++++++++-------
Melectrum/lnutil.py | 4++--
2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/electrum/lnchan.py b/electrum/lnchan.py @@ -17,7 +17,7 @@ from .lnutil import secret_to_pubkey, derive_privkey, derive_pubkey, derive_blin from .lnutil import sign_and_get_sig_string, privkey_to_pubkey, make_htlc_tx_witness from .lnutil import make_htlc_tx_with_open_channel, make_commitment, make_received_htlc, make_offered_htlc from .lnutil import HTLC_TIMEOUT_WEIGHT, HTLC_SUCCESS_WEIGHT -from .lnutil import funding_output_script, LOCAL, REMOTE, HTLCOwner, make_closing_tx, make_outputs +from .lnutil import funding_output_script, LOCAL, REMOTE, HTLCOwner, make_closing_tx, make_commitment_outputs from .lnutil import ScriptHtlc, SENT, RECEIVED, PaymentFailure, calc_onchain_fees from .transaction import Transaction, TxOutput, construct_witness from .simple_config import SimpleConfig, FEERATE_FALLBACK_STATIC_FEE @@ -390,7 +390,8 @@ class Channel(PrintError): for prev_txid, encumbered_tx in encumbered_sweeptxs: if prev_txid is None: prev_txid = ctx.txid() - self.lnwatcher.add_sweep_tx(outpoint, prev_txid, encumbered_tx.to_json()) + if encumbered_tx is not None: + self.lnwatcher.add_sweep_tx(outpoint, prev_txid, encumbered_tx.to_json()) def process_new_revocation_secret(self, per_commitment_secret: bytes): if not self.lnwatcher: @@ -716,7 +717,10 @@ class Channel(PrintError): if fee_sat is None: fee_sat = self.pending_local_fee - _, outputs = make_outputs(fee_sat * 1000, True, + _, outputs = make_commitment_outputs({ + LOCAL: fee_sat * 1000 if self.constraints.is_initiator else 0, + REMOTE: fee_sat * 1000 if not self.constraints.is_initiator else 0, + }, self.config[LOCAL].amount_msat, self.config[REMOTE].amount_msat, (TYPE_SCRIPT, bh2u(local_script)), @@ -724,10 +728,11 @@ class Channel(PrintError): [], self.config[LOCAL].dust_limit_sat) closing_tx = make_closing_tx(self.config[LOCAL].multisig_key.pubkey, - self.config[REMOTE].multisig_key.pubkey, - # TODO hardcoded we_are_initiator: - True, *self.funding_outpoint, self.constraints.capacity, - outputs) + self.config[REMOTE].multisig_key.pubkey, + funding_txid=self.funding_outpoint.txid, + funding_pos=self.funding_outpoint.output_index, + funding_sat=self.constraints.capacity, + outputs=outputs) der_sig = bfh(closing_tx.sign_txin(0, self.config[LOCAL].multisig_key.privkey)) sig = ecc.sig_string_from_der_sig(der_sig[:-1]) diff --git a/electrum/lnutil.py b/electrum/lnutil.py @@ -347,7 +347,7 @@ RECEIVED = HTLCOwner.RECEIVED LOCAL = HTLCOwner.LOCAL REMOTE = HTLCOwner.REMOTE -def make_outputs(fees_per_participant: Mapping[HTLCOwner, int], local_amount: int, remote_amount: int, +def make_commitment_outputs(fees_per_participant: Mapping[HTLCOwner, int], local_amount: int, remote_amount: int, local_tupl, remote_tupl, htlcs: List[ScriptHtlc], dust_limit_sat: int) -> Tuple[List[TxOutput], List[TxOutput]]: to_local_amt = local_amount - fees_per_participant[LOCAL] to_local = TxOutput(*local_tupl, to_local_amt // 1000) @@ -392,7 +392,7 @@ def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remote_address = make_commitment_output_to_remote_address(remote_payment_pubkey) # TODO trim htlc outputs here while also considering 2nd stage htlc transactions - htlc_outputs, c_outputs_filtered = make_outputs(fees_per_participant, local_amount, remote_amount, + htlc_outputs, c_outputs_filtered = make_commitment_outputs(fees_per_participant, local_amount, remote_amount, (bitcoin.TYPE_ADDRESS, local_address), (bitcoin.TYPE_ADDRESS, remote_address), htlcs, dust_limit_sat) assert sum(x.value for x in c_outputs_filtered) <= funding_sat