electrum

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

commit d1769472bd9ce43c81fbf9d34e7c7e3cec3bb1b0
parent 6c8bd2559b72fa302007287a213768e28558ebad
Author: Janus <ysangkok@gmail.com>
Date:   Thu, 14 Jun 2018 15:34:51 +0200

ln: save remote's secrets in RevocationStore, not our secrets. call lnhtlc.receive_revocation

Diffstat:
Mlib/lnbase.py | 20+++++++++-----------
Mlib/lnhtlc.py | 10+++++-----
2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/lib/lnbase.py b/lib/lnbase.py @@ -37,7 +37,7 @@ from .util import PrintError, bh2u, print_error, bfh, profiler, xor_bytes from .transaction import opcodes, Transaction from .lnrouter import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error from .lightning_payencode.lnaddr import lndecode -from .lnhtlc import UpdateAddHtlc, HTLCStateMachine +from .lnhtlc import UpdateAddHtlc, HTLCStateMachine, RevokeAndAck, SettleHtlc from collections import namedtuple, defaultdict @@ -1036,14 +1036,15 @@ class Peer(PrintError): self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=1, htlc_signature=htlc_sig)) revoke_and_ack_msg = await self.revoke_and_ack[chan.channel_id].get() - # TODO check revoke_and_ack results + m.receive_revocation(RevokeAndAck(revoke_and_ack_msg["per_commitment_secret"], revoke_and_ack_msg["next_per_commitment_point"])) - chan, last_secret, _, next_point = self.derive_and_incr(chan) - their_revstore.add_next_entry(last_secret) + rev, _ = m.revoke_current_commitment() self.send_message(gen_msg("revoke_and_ack", channel_id=chan.channel_id, - per_commitment_secret=last_secret, - next_per_commitment_point=next_point)) + per_commitment_secret=rev.per_commitment_secret, + next_per_commitment_point=rev.next_per_commitment_point)) + + chan = m.state print("waiting for update_fulfill") @@ -1053,7 +1054,6 @@ class Peer(PrintError): commitment_signed_msg = await self.commitment_signed[chan.channel_id].get() chan, last_secret, _, next_point = self.derive_and_incr(chan) - their_revstore.add_next_entry(last_secret) self.send_message(gen_msg("revoke_and_ack", channel_id=chan.channel_id, per_commitment_secret=last_secret, @@ -1061,7 +1061,7 @@ class Peer(PrintError): next_per_commitment_point = revoke_and_ack_msg["next_per_commitment_point"] - bare_ctx = make_commitment_using_open_channel(chan, chan.remote_state.ctn + 2, False, next_per_commitment_point, + bare_ctx = make_commitment_using_open_channel(chan, chan.remote_state.ctn + 1, False, next_per_commitment_point, msat_remote, msat_local) sig_64 = sign_and_get_sig_string(bare_ctx, chan.local_config, chan.remote_config) @@ -1077,7 +1077,7 @@ class Peer(PrintError): next_htlc_id=chan.local_state.next_htlc_id + 1 ), remote_state=chan.remote_state._replace( - ctn=chan.remote_state.ctn + 2, + ctn=chan.remote_state.ctn + 1, revocation_store=their_revstore, last_per_commitment_point=next_per_commitment_point, next_per_commitment_point=revoke_and_ack_msg["next_per_commitment_point"], @@ -1155,8 +1155,6 @@ class Peer(PrintError): chan, last_secret, _, next_point = self.derive_and_incr(chan) - chan.remote_state.revocation_store.add_next_entry(last_secret) - self.send_message(gen_msg("revoke_and_ack", channel_id=channel_id, per_commitment_secret=last_secret, diff --git a/lib/lnhtlc.py b/lib/lnhtlc.py @@ -8,7 +8,7 @@ from .crypto import sha256 from . import ecc SettleHtlc = namedtuple("SettleHtlc", ["htlc_id"]) -RevokeAndAck = namedtuple("RevokeAndAck", ["height", "per_commitment_secret", "next_per_commitment_point"]) +RevokeAndAck = namedtuple("RevokeAndAck", ["per_commitment_secret", "next_per_commitment_point"]) class UpdateAddHtlc: def __init__(self, amount_msat, payment_hash, cltv_expiry, total_fee): @@ -157,7 +157,7 @@ class HTLCStateMachine(PrintError): if len(self.htlcs_in_remote) > 0: print("CHECKING HTLC SIGS") assert len(self.local_commitment.outputs()) == 3 # TODO - we_receive = True # TODO + we_receive = True payment_hash = self.htlcs_in_remote[0].payment_hash amount_msat = self.htlcs_in_remote[0].amount_msat cltv_expiry = self.htlcs_in_remote[0].cltv_expiry @@ -167,6 +167,8 @@ class HTLCStateMachine(PrintError): if not ecc.verify_signature(remote_htlc_pubkey, htlc_sigs[0], pre_hash): raise Exception("failed verifying signature an HTLC tx spending from one of our commit tx'es HTLC outputs") + # TODO check htlc in htlcs_in_local + def revoke_current_commitment(self): """ RevokeCurrentCommitment revokes the next lowest unrevoked commitment @@ -182,15 +184,13 @@ class HTLCStateMachine(PrintError): last_secret, this_point, next_point = self.points - self.state.remote_state.revocation_store.add_next_entry(last_secret) - self.state = self.state._replace( local_state=self.state.local_state._replace( ctn=self.state.local_state.ctn + 1 ) ) - return RevokeAndAck(self.state.local_state.ctn - 1, last_secret, next_point), "current htlcs" + return RevokeAndAck(last_secret, next_point), "current htlcs" @property def points(self):