move maybe_save_short_chan_id to lnchannel
This commit is contained in:
@@ -1105,6 +1105,33 @@ class Channel(Logger):
|
|||||||
else:
|
else:
|
||||||
self.update_closed_state(funding_txid, funding_height, closing_txid, closing_height, keep_watching)
|
self.update_closed_state(funding_txid, funding_height, closing_txid, closing_height, keep_watching)
|
||||||
|
|
||||||
|
def is_funding_tx_mined(self, funding_height):
|
||||||
|
"""
|
||||||
|
Checks if Funding TX has been mined. If it has, save the short channel ID in chan;
|
||||||
|
if it's also deep enough, also save to disk.
|
||||||
|
Returns tuple (mined_deep_enough, num_confirmations).
|
||||||
|
"""
|
||||||
|
funding_txid = self.funding_outpoint.txid
|
||||||
|
funding_idx = self.funding_outpoint.output_index
|
||||||
|
conf = funding_height.conf
|
||||||
|
if conf < self.constraints.funding_txn_minimum_depth:
|
||||||
|
self.logger.info(f"funding tx is still not at sufficient depth. actual depth: {conf}")
|
||||||
|
return False
|
||||||
|
assert conf > 0
|
||||||
|
# check funding_tx amount and script
|
||||||
|
funding_tx = self.lnworker.lnwatcher.db.get_transaction(funding_txid)
|
||||||
|
if not funding_tx:
|
||||||
|
self.logger.info(f"no funding_tx {funding_txid}")
|
||||||
|
return False
|
||||||
|
outp = funding_tx.outputs()[funding_idx]
|
||||||
|
redeem_script = funding_output_script(self.config[REMOTE], self.config[LOCAL])
|
||||||
|
funding_address = redeem_script_to_address('p2wsh', redeem_script)
|
||||||
|
funding_sat = self.constraints.capacity
|
||||||
|
if not (outp.address == funding_address and outp.value == funding_sat):
|
||||||
|
self.logger.info('funding outpoint mismatch')
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def update_unfunded_state(self):
|
def update_unfunded_state(self):
|
||||||
self.delete_funding_height()
|
self.delete_funding_height()
|
||||||
self.delete_closing_height()
|
self.delete_closing_height()
|
||||||
@@ -1136,10 +1163,11 @@ class Channel(Logger):
|
|||||||
self.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp)
|
self.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp)
|
||||||
self.delete_closing_height()
|
self.delete_closing_height()
|
||||||
if self.get_state() == channel_states.OPENING:
|
if self.get_state() == channel_states.OPENING:
|
||||||
if self.short_channel_id is None:
|
if self.is_funding_tx_mined(funding_height):
|
||||||
self.lnworker.maybe_save_short_chan_id(self, funding_height)
|
|
||||||
if self.short_channel_id:
|
|
||||||
self.set_state(channel_states.FUNDED)
|
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):
|
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)
|
self.save_funding_height(funding_txid, funding_height.height, funding_height.timestamp)
|
||||||
|
|||||||
@@ -659,36 +659,6 @@ class LNWallet(LNWorker):
|
|||||||
self.wallet.save_db()
|
self.wallet.save_db()
|
||||||
self.network.trigger_callback('channel', chan)
|
self.network.trigger_callback('channel', chan)
|
||||||
|
|
||||||
def maybe_save_short_chan_id(self, chan, funding_height):
|
|
||||||
"""
|
|
||||||
Checks if Funding TX has been mined. If it has, save the short channel ID in chan;
|
|
||||||
if it's also deep enough, also save to disk.
|
|
||||||
Returns tuple (mined_deep_enough, num_confirmations).
|
|
||||||
"""
|
|
||||||
funding_txid = chan.funding_outpoint.txid
|
|
||||||
funding_idx = chan.funding_outpoint.output_index
|
|
||||||
conf = funding_height.conf
|
|
||||||
if conf < chan.constraints.funding_txn_minimum_depth:
|
|
||||||
self.logger.info(f"funding tx is still not at sufficient depth. actual depth: {conf}")
|
|
||||||
return
|
|
||||||
assert conf > 0
|
|
||||||
# check funding_tx amount and script
|
|
||||||
funding_tx = self.lnwatcher.db.get_transaction(funding_txid)
|
|
||||||
if not funding_tx:
|
|
||||||
self.logger.info(f"no funding_tx {funding_txid}")
|
|
||||||
return
|
|
||||||
outp = funding_tx.outputs()[funding_idx]
|
|
||||||
redeem_script = funding_output_script(chan.config[REMOTE], chan.config[LOCAL])
|
|
||||||
funding_address = redeem_script_to_address('p2wsh', redeem_script)
|
|
||||||
funding_sat = chan.constraints.capacity
|
|
||||||
if not (outp.address == funding_address and outp.value == funding_sat):
|
|
||||||
self.logger.info('funding outpoint mismatch')
|
|
||||||
return
|
|
||||||
chan.set_short_channel_id(ShortChannelID.from_components(
|
|
||||||
funding_height.height, funding_height.txpos, chan.funding_outpoint.output_index))
|
|
||||||
self.logger.info(f"save_short_channel_id: {chan.short_channel_id}")
|
|
||||||
self.save_channel(chan)
|
|
||||||
|
|
||||||
def channel_by_txo(self, txo):
|
def channel_by_txo(self, txo):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
channels = list(self.channels.values())
|
channels = list(self.channels.values())
|
||||||
@@ -696,7 +666,6 @@ class LNWallet(LNWorker):
|
|||||||
if chan.funding_outpoint.to_str() == txo:
|
if chan.funding_outpoint.to_str() == txo:
|
||||||
return chan
|
return chan
|
||||||
|
|
||||||
|
|
||||||
async def on_channel_update(self, chan):
|
async def on_channel_update(self, chan):
|
||||||
|
|
||||||
if chan.get_state() == channel_states.OPEN and chan.should_be_closed_due_to_expiring_htlcs(self.network.get_local_height()):
|
if chan.get_state() == channel_states.OPEN and chan.should_be_closed_due_to_expiring_htlcs(self.network.get_local_height()):
|
||||||
|
|||||||
Reference in New Issue
Block a user