mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
special case receiving payment after fee update, fee update injector
This commit is contained in:
parent
6742654681
commit
67c69d7042
3 changed files with 45 additions and 11 deletions
|
@ -411,7 +411,7 @@ class Peer(PrintError):
|
|||
f(payload)
|
||||
|
||||
def on_error(self, payload):
|
||||
self.print_error("error", payload)
|
||||
self.print_error("error", payload["data"].decode("ascii"))
|
||||
|
||||
def on_ping(self, payload):
|
||||
l = int.from_bytes(payload['num_pong_bytes'], 'big')
|
||||
|
@ -897,8 +897,7 @@ class Peer(PrintError):
|
|||
|
||||
self.revoke(chan)
|
||||
|
||||
while (await self.commitment_signed[chan.channel_id].get())["htlc_signature"] != b"":
|
||||
pass
|
||||
commitment_signed_msg = await self.commitment_signed[chan.channel_id].get()
|
||||
# TODO process above commitment transactions
|
||||
|
||||
bare_ctx = chan.make_commitment(chan.remote_state.ctn + 1, False, chan.remote_state.next_per_commitment_point,
|
||||
|
@ -909,6 +908,12 @@ class Peer(PrintError):
|
|||
|
||||
await self.receive_revoke(chan)
|
||||
|
||||
if commitment_signed_msg["htlc_signature"] == b"":
|
||||
# this happens when we send dust amounts
|
||||
print("CHANNEL WILL BREAK") # TODO
|
||||
else:
|
||||
commitment_signed_msg = await self.commitment_signed[chan.channel_id].get()
|
||||
|
||||
self.lnworker.save_channel(chan)
|
||||
return bh2u(preimage)
|
||||
|
||||
|
@ -969,11 +974,36 @@ class Peer(PrintError):
|
|||
sig_64 = sign_and_get_sig_string(bare_ctx, chan.local_config, chan.remote_config)
|
||||
self.send_message(gen_msg("commitment_signed", channel_id=channel_id, signature=sig_64, num_htlcs=0))
|
||||
|
||||
await self.receive_revoke(chan)
|
||||
revoke_coro = asyncio.ensure_future(self.revoke_and_ack[chan.channel_id].get())
|
||||
commit_coro = asyncio.ensure_future(self.commitment_signed[chan.channel_id].get())
|
||||
_done, _pending = await asyncio.wait([revoke_coro, commit_coro], return_when=FIRST_COMPLETED)
|
||||
|
||||
assert (await self.receive_commitment(chan)) == 0
|
||||
def process_commit(commitment_signed_msg):
|
||||
data = commitment_signed_msg["htlc_signature"]
|
||||
htlc_sigs = [data[i:i+64] for i in range(0, len(data), 64)]
|
||||
chan.receive_new_commitment(commitment_signed_msg["signature"], htlc_sigs)
|
||||
def process_revoke(revoke_and_ack_msg):
|
||||
chan.receive_revocation(RevokeAndAck(revoke_and_ack_msg["per_commitment_secret"], revoke_and_ack_msg["next_per_commitment_point"]))
|
||||
|
||||
self.revoke(chan)
|
||||
if commit_coro.done():
|
||||
# this branch is taken with lnd after a fee update (initiated by us, of course)
|
||||
|
||||
# TODO process_commit(commit_coro.result())
|
||||
await asyncio.wait([revoke_coro])
|
||||
process_revoke(revoke_coro.result())
|
||||
self.revoke(chan)
|
||||
await self.receive_commitment(chan)
|
||||
self.revoke(chan)
|
||||
sig_64, htlc_sigs = chan.sign_next_commitment()
|
||||
|
||||
self.send_message(gen_msg("commitment_signed", channel_id=chan.channel_id, signature=sig_64, num_htlcs=len(htlc_sigs), htlc_signature=b"".join(htlc_sigs)))
|
||||
await self.receive_revoke(chan)
|
||||
elif revoke_coro.done():
|
||||
process_revoke(revoke_coro.result())
|
||||
|
||||
await asyncio.wait([commit_coro])
|
||||
process_commit(commit_coro.result())
|
||||
self.revoke(chan)
|
||||
|
||||
self.lnworker.save_channel(chan)
|
||||
|
||||
|
|
|
@ -287,17 +287,15 @@ class HTLCStateMachine(PrintError):
|
|||
last_secret, this_point, next_point = self.points
|
||||
|
||||
new_local_feerate = self.local_state.feerate
|
||||
new_remote_feerate = self.remote_state.feerate
|
||||
|
||||
if self.pending_fee is not None:
|
||||
if not self.constraints.is_initiator and (self.pending_fee.progress & FUNDEE_SIGNED):
|
||||
new_local_feerate = self.pending_fee.rate
|
||||
self.remote_state=self.remote_state._replace(
|
||||
feerate=self.pending_fee.rate
|
||||
)
|
||||
new_local_feerate = new_remote_feerate = self.pending_fee.rate
|
||||
self.pending_fee = None
|
||||
print("FEERATE CHANGE COMPLETE (non-initiator)")
|
||||
if self.constraints.is_initiator and (self.pending_fee.progress & FUNDER_SIGNED):
|
||||
new_local_feerate = self.pending_fee.rate
|
||||
new_local_feerate = new_remote_feerate = self.pending_fee.rate
|
||||
self.pending_fee = None
|
||||
print("FEERATE CHANGE COMPLETE (initiator)")
|
||||
|
||||
|
@ -305,6 +303,9 @@ class HTLCStateMachine(PrintError):
|
|||
ctn=self.local_state.ctn + 1,
|
||||
feerate=new_local_feerate
|
||||
)
|
||||
self.remote_state=self.remote_state._replace(
|
||||
feerate=new_remote_feerate
|
||||
)
|
||||
|
||||
self.local_commitment = self.pending_local_commitment
|
||||
|
||||
|
|
|
@ -146,6 +146,9 @@ class LNWorker(PrintError):
|
|||
async def _open_channel_coroutine(self, node_id, local_amount_sat, push_sat, password):
|
||||
peer = self.peers[node_id]
|
||||
openingchannel = await peer.channel_establishment_flow(self.wallet, self.config, password, local_amount_sat + push_sat, push_sat * 1000, temp_channel_id=os.urandom(32))
|
||||
if not openingchannel:
|
||||
self.print_error("Channel_establishment_flow returned None")
|
||||
return
|
||||
self.save_channel(openingchannel)
|
||||
self.network.lnwatcher.watch_channel(openingchannel, self.on_channel_utxos)
|
||||
self.on_channels_updated()
|
||||
|
|
Loading…
Add table
Reference in a new issue