mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-27 23:41:35 +00:00
ln: save remote's secrets in RevocationStore, not our secrets. call lnhtlc.receive_revocation
This commit is contained in:
parent
6c8bd2559b
commit
d1769472bd
2 changed files with 14 additions and 16 deletions
|
@ -37,7 +37,7 @@ from .util import PrintError, bh2u, print_error, bfh, profiler, xor_bytes
|
||||||
from .transaction import opcodes, Transaction
|
from .transaction import opcodes, Transaction
|
||||||
from .lnrouter import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error
|
from .lnrouter import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error
|
||||||
from .lightning_payencode.lnaddr import lndecode
|
from .lightning_payencode.lnaddr import lndecode
|
||||||
from .lnhtlc import UpdateAddHtlc, HTLCStateMachine
|
from .lnhtlc import UpdateAddHtlc, HTLCStateMachine, RevokeAndAck, SettleHtlc
|
||||||
|
|
||||||
from collections import namedtuple, defaultdict
|
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))
|
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()
|
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)
|
rev, _ = m.revoke_current_commitment()
|
||||||
their_revstore.add_next_entry(last_secret)
|
|
||||||
self.send_message(gen_msg("revoke_and_ack",
|
self.send_message(gen_msg("revoke_and_ack",
|
||||||
channel_id=chan.channel_id,
|
channel_id=chan.channel_id,
|
||||||
per_commitment_secret=last_secret,
|
per_commitment_secret=rev.per_commitment_secret,
|
||||||
next_per_commitment_point=next_point))
|
next_per_commitment_point=rev.next_per_commitment_point))
|
||||||
|
|
||||||
|
chan = m.state
|
||||||
|
|
||||||
print("waiting for update_fulfill")
|
print("waiting for update_fulfill")
|
||||||
|
|
||||||
|
@ -1053,7 +1054,6 @@ class Peer(PrintError):
|
||||||
commitment_signed_msg = await self.commitment_signed[chan.channel_id].get()
|
commitment_signed_msg = await self.commitment_signed[chan.channel_id].get()
|
||||||
|
|
||||||
chan, last_secret, _, next_point = self.derive_and_incr(chan)
|
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",
|
self.send_message(gen_msg("revoke_and_ack",
|
||||||
channel_id=chan.channel_id,
|
channel_id=chan.channel_id,
|
||||||
per_commitment_secret=last_secret,
|
per_commitment_secret=last_secret,
|
||||||
|
@ -1061,7 +1061,7 @@ class Peer(PrintError):
|
||||||
|
|
||||||
next_per_commitment_point = revoke_and_ack_msg["next_per_commitment_point"]
|
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)
|
msat_remote, msat_local)
|
||||||
|
|
||||||
sig_64 = sign_and_get_sig_string(bare_ctx, chan.local_config, chan.remote_config)
|
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
|
next_htlc_id=chan.local_state.next_htlc_id + 1
|
||||||
),
|
),
|
||||||
remote_state=chan.remote_state._replace(
|
remote_state=chan.remote_state._replace(
|
||||||
ctn=chan.remote_state.ctn + 2,
|
ctn=chan.remote_state.ctn + 1,
|
||||||
revocation_store=their_revstore,
|
revocation_store=their_revstore,
|
||||||
last_per_commitment_point=next_per_commitment_point,
|
last_per_commitment_point=next_per_commitment_point,
|
||||||
next_per_commitment_point=revoke_and_ack_msg["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, 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",
|
self.send_message(gen_msg("revoke_and_ack",
|
||||||
channel_id=channel_id,
|
channel_id=channel_id,
|
||||||
per_commitment_secret=last_secret,
|
per_commitment_secret=last_secret,
|
||||||
|
|
|
@ -8,7 +8,7 @@ from .crypto import sha256
|
||||||
from . import ecc
|
from . import ecc
|
||||||
|
|
||||||
SettleHtlc = namedtuple("SettleHtlc", ["htlc_id"])
|
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:
|
class UpdateAddHtlc:
|
||||||
def __init__(self, amount_msat, payment_hash, cltv_expiry, total_fee):
|
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:
|
if len(self.htlcs_in_remote) > 0:
|
||||||
print("CHECKING HTLC SIGS")
|
print("CHECKING HTLC SIGS")
|
||||||
assert len(self.local_commitment.outputs()) == 3 # TODO
|
assert len(self.local_commitment.outputs()) == 3 # TODO
|
||||||
we_receive = True # TODO
|
we_receive = True
|
||||||
payment_hash = self.htlcs_in_remote[0].payment_hash
|
payment_hash = self.htlcs_in_remote[0].payment_hash
|
||||||
amount_msat = self.htlcs_in_remote[0].amount_msat
|
amount_msat = self.htlcs_in_remote[0].amount_msat
|
||||||
cltv_expiry = self.htlcs_in_remote[0].cltv_expiry
|
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):
|
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")
|
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):
|
def revoke_current_commitment(self):
|
||||||
"""
|
"""
|
||||||
RevokeCurrentCommitment revokes the next lowest unrevoked commitment
|
RevokeCurrentCommitment revokes the next lowest unrevoked commitment
|
||||||
|
@ -182,15 +184,13 @@ class HTLCStateMachine(PrintError):
|
||||||
|
|
||||||
last_secret, this_point, next_point = self.points
|
last_secret, this_point, next_point = self.points
|
||||||
|
|
||||||
self.state.remote_state.revocation_store.add_next_entry(last_secret)
|
|
||||||
|
|
||||||
self.state = self.state._replace(
|
self.state = self.state._replace(
|
||||||
local_state=self.state.local_state._replace(
|
local_state=self.state.local_state._replace(
|
||||||
ctn=self.state.local_state.ctn + 1
|
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
|
@property
|
||||||
def points(self):
|
def points(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue