mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
factorize channel opening code into chan.open_with_first_pcp
This commit is contained in:
parent
c3f6351922
commit
a7d37b72db
2 changed files with 8 additions and 9 deletions
|
@ -198,6 +198,12 @@ class Channel(PrintError):
|
||||||
if self.sweep_address is not None:
|
if self.sweep_address is not None:
|
||||||
self.remote_sweeptxs = create_sweeptxs_for_their_latest_ctx(self, self.remote_commitment, self.sweep_address)
|
self.remote_sweeptxs = create_sweeptxs_for_their_latest_ctx(self, self.remote_commitment, self.sweep_address)
|
||||||
|
|
||||||
|
def open_with_first_pcp(self, remote_pcp, remote_sig):
|
||||||
|
self.remote_commitment_to_be_revoked = self.pending_commitment(REMOTE)
|
||||||
|
self.config[REMOTE] = self.config[REMOTE]._replace(ctn=0, current_per_commitment_point=remote_pcp, next_per_commitment_point=None)
|
||||||
|
self.config[LOCAL] = self.config[LOCAL]._replace(ctn=0, current_commitment_signature=remote_sig)
|
||||||
|
self.set_state('OPENING')
|
||||||
|
|
||||||
def set_state(self, state: str):
|
def set_state(self, state: str):
|
||||||
if self._state == 'FORCE_CLOSING':
|
if self._state == 'FORCE_CLOSING':
|
||||||
assert state == 'FORCE_CLOSING', 'new state was not FORCE_CLOSING: ' + state
|
assert state == 'FORCE_CLOSING', 'new state was not FORCE_CLOSING: ' + state
|
||||||
|
|
|
@ -405,10 +405,7 @@ class Peer(PrintError):
|
||||||
chan.receive_new_commitment(remote_sig, [])
|
chan.receive_new_commitment(remote_sig, [])
|
||||||
# broadcast funding tx
|
# broadcast funding tx
|
||||||
await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), 1)
|
await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), 1)
|
||||||
chan.remote_commitment_to_be_revoked = chan.pending_commitment(REMOTE)
|
chan.open_with_first_pcp(self, remote_per_commitment_point, remote_sig)
|
||||||
chan.config[REMOTE] = chan.config[REMOTE]._replace(ctn=0, current_per_commitment_point=remote_per_commitment_point, next_per_commitment_point=None)
|
|
||||||
chan.config[LOCAL] = chan.config[LOCAL]._replace(ctn=0, current_commitment_signature=remote_sig, got_sig_for_next=False)
|
|
||||||
chan.set_state('OPENING')
|
|
||||||
chan.set_remote_commitment()
|
chan.set_remote_commitment()
|
||||||
chan.set_local_commitment(chan.current_commitment(LOCAL))
|
chan.set_local_commitment(chan.current_commitment(LOCAL))
|
||||||
return chan
|
return chan
|
||||||
|
@ -472,7 +469,6 @@ class Peer(PrintError):
|
||||||
next_htlc_id = 0,
|
next_htlc_id = 0,
|
||||||
reserve_sat = remote_reserve_sat,
|
reserve_sat = remote_reserve_sat,
|
||||||
htlc_minimum_msat=int.from_bytes(payload['htlc_minimum_msat'], 'big'), # TODO validate
|
htlc_minimum_msat=int.from_bytes(payload['htlc_minimum_msat'], 'big'), # TODO validate
|
||||||
|
|
||||||
next_per_commitment_point=payload['first_per_commitment_point'],
|
next_per_commitment_point=payload['first_per_commitment_point'],
|
||||||
current_per_commitment_point=None,
|
current_per_commitment_point=None,
|
||||||
revocation_store=their_revocation_store,
|
revocation_store=their_revocation_store,
|
||||||
|
@ -492,10 +488,7 @@ class Peer(PrintError):
|
||||||
channel_id=channel_id,
|
channel_id=channel_id,
|
||||||
signature=sig_64,
|
signature=sig_64,
|
||||||
)
|
)
|
||||||
chan.set_state('OPENING')
|
chan.open_with_first_pcp(self, payload['first_per_commitment_point'], remote_sig)
|
||||||
chan.remote_commitment_to_be_revoked = chan.pending_commitment(REMOTE)
|
|
||||||
chan.config[REMOTE] = chan.config[REMOTE]._replace(ctn=0, current_per_commitment_point=payload['first_per_commitment_point'], next_per_commitment_point=None)
|
|
||||||
chan.config[LOCAL] = chan.config[LOCAL]._replace(ctn=0, current_commitment_signature=remote_sig)
|
|
||||||
self.lnworker.save_channel(chan)
|
self.lnworker.save_channel(chan)
|
||||||
self.lnwatcher.watch_channel(chan.get_funding_address(), chan.funding_outpoint.to_str())
|
self.lnwatcher.watch_channel(chan.get_funding_address(), chan.funding_outpoint.to_str())
|
||||||
self.lnworker.on_channels_updated()
|
self.lnworker.on_channels_updated()
|
||||||
|
|
Loading…
Add table
Reference in a new issue