mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 07:51:27 +00:00
do not use short_channel_id as state, use channel state for that.
display it as soon as the funding tx is mined.
This commit is contained in:
parent
8f41aeb783
commit
74517c88ad
2 changed files with 15 additions and 16 deletions
|
@ -135,6 +135,9 @@ class AbstractChannel(Logger):
|
|||
return str(scid)
|
||||
return self.channel_id.hex()
|
||||
|
||||
def short_id_for_GUI(self) -> str:
|
||||
return format_short_channel_id(self.short_channel_id)
|
||||
|
||||
def set_state(self, state: channel_states) -> None:
|
||||
""" set on-chain state """
|
||||
old_state = self._state
|
||||
|
@ -147,6 +150,9 @@ class AbstractChannel(Logger):
|
|||
def get_state(self) -> channel_states:
|
||||
return self._state
|
||||
|
||||
def is_funded(self):
|
||||
return self.get_state() >= channel_states.FUNDED
|
||||
|
||||
def is_open(self):
|
||||
return self.get_state() == channel_states.OPEN
|
||||
|
||||
|
@ -244,12 +250,12 @@ class AbstractChannel(Logger):
|
|||
def update_funded_state(self, funding_txid, funding_height):
|
||||
self.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp)
|
||||
self.delete_closing_height()
|
||||
if funding_height.conf>0:
|
||||
self.set_short_channel_id(ShortChannelID.from_components(
|
||||
funding_height.height, funding_height.txpos, self.funding_outpoint.output_index))
|
||||
if self.get_state() == channel_states.OPENING:
|
||||
if self.is_funding_tx_mined(funding_height):
|
||||
self.set_state(channel_states.FUNDED)
|
||||
self.set_short_channel_id(ShortChannelID.from_components(
|
||||
funding_height.height, funding_height.txpos, self.funding_outpoint.output_index))
|
||||
self.logger.info(f"save_short_channel_id: {self.short_channel_id}")
|
||||
|
||||
def update_closed_state(self, funding_txid, funding_height, closing_txid, closing_height, keep_watching):
|
||||
self.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp)
|
||||
|
@ -333,15 +339,12 @@ class ChannelBackup(AbstractChannel):
|
|||
def get_funding_address(self):
|
||||
return self.cb.funding_address
|
||||
|
||||
def short_id_for_GUI(self) -> str:
|
||||
return 'BACKUP'
|
||||
|
||||
def is_initiator(self):
|
||||
return self.cb.is_initiator
|
||||
|
||||
def get_state_for_GUI(self):
|
||||
cs = self.get_state()
|
||||
return cs.name
|
||||
return 'BACKUP, ' + cs.name
|
||||
|
||||
def get_oldest_unrevoked_ctn(self, who):
|
||||
return -1
|
||||
|
@ -401,9 +404,6 @@ class Channel(AbstractChannel):
|
|||
self._receive_fail_reasons = {} # type: Dict[int, BarePaymentAttemptLog]
|
||||
self._ignore_max_htlc_value = False # used in tests
|
||||
|
||||
def short_id_for_GUI(self) -> str:
|
||||
return format_short_channel_id(self.short_channel_id)
|
||||
|
||||
def is_initiator(self):
|
||||
return self.constraints.is_initiator
|
||||
|
||||
|
|
|
@ -886,11 +886,10 @@ class Peer(Logger):
|
|||
return
|
||||
|
||||
chan.peer_state = peer_states.GOOD
|
||||
# note: chan.short_channel_id being set implies the funding txn is already at sufficient depth
|
||||
if their_next_local_ctn == next_local_ctn == 1 and chan.short_channel_id:
|
||||
if chan.is_funded() and their_next_local_ctn == next_local_ctn == 1:
|
||||
self.send_funding_locked(chan)
|
||||
# checks done
|
||||
if chan.config[LOCAL].funding_locked_received and chan.short_channel_id:
|
||||
if chan.is_funded() and chan.config[LOCAL].funding_locked_received:
|
||||
self.mark_open(chan)
|
||||
self.network.trigger_callback('channel', chan)
|
||||
if chan.get_state() == channel_states.CLOSING:
|
||||
|
@ -903,7 +902,7 @@ class Peer(Logger):
|
|||
get_per_commitment_secret_from_seed(chan.config[LOCAL].per_commitment_secret_seed, per_commitment_secret_index), 'big'))
|
||||
# note: if funding_locked was not yet received, we might send it multiple times
|
||||
self.send_message("funding_locked", channel_id=channel_id, next_per_commitment_point=per_commitment_point_second)
|
||||
if chan.config[LOCAL].funding_locked_received and chan.short_channel_id:
|
||||
if chan.is_funded() and chan.config[LOCAL].funding_locked_received:
|
||||
self.mark_open(chan)
|
||||
|
||||
def on_funding_locked(self, chan: Channel, payload):
|
||||
|
@ -913,7 +912,7 @@ class Peer(Logger):
|
|||
chan.config[REMOTE].next_per_commitment_point = their_next_point
|
||||
chan.config[LOCAL].funding_locked_received = True
|
||||
self.lnworker.save_channel(chan)
|
||||
if chan.short_channel_id:
|
||||
if chan.is_funded():
|
||||
self.mark_open(chan)
|
||||
|
||||
def on_network_update(self, chan: Channel, funding_tx_depth: int):
|
||||
|
@ -970,7 +969,7 @@ class Peer(Logger):
|
|||
)
|
||||
|
||||
def mark_open(self, chan: Channel):
|
||||
assert chan.short_channel_id is not None
|
||||
assert chan.is_funded()
|
||||
# only allow state transition from "FUNDED" to "OPEN"
|
||||
old_state = chan.get_state()
|
||||
if old_state == channel_states.OPEN:
|
||||
|
|
Loading…
Add table
Reference in a new issue