1
0

Set channel state to OPENING as soon as we receive 'funding_signed',

instead of when the funding transaction has been broadcast, because
we have no reliable way to know when it will be broadcast.
This commit is contained in:
ThomasV
2020-02-27 15:22:22 +01:00
parent d04b8c05e2
commit 34400c0710
3 changed files with 4 additions and 8 deletions

View File

@@ -64,7 +64,7 @@ if TYPE_CHECKING:
class channel_states(IntEnum):
PREOPENING = 0 # Initial negotiation. Channel will not be reestablished
OPENING = 1 # Channel will be reestablished. (per BOLT2)
# - Funding node: has broadcast the funding tx.
# - Funding node: has received funding_signed (can broadcast the funding tx)
# - Non-funding node: has sent the funding_signed message.
FUNDED = 2 # Funding tx was mined (requires min_depth and tx verification)
OPEN = 3 # both parties have sent funding_locked

View File

@@ -605,6 +605,8 @@ class Peer(Logger):
remote_sig = payload['signature']
chan.receive_new_commitment(remote_sig, [])
chan.open_with_first_pcp(remote_per_commitment_point, remote_sig)
chan.set_state(channel_states.OPENING)
self.lnworker.add_new_channel(chan)
return chan, funding_tx
def create_channel_storage(self, channel_id, outpoint, local_config, remote_config, constraints):

View File

@@ -684,9 +684,6 @@ class LNWallet(LNWorker):
await self.force_close_channel(chan.channel_id)
return
if chan.get_state() == channel_states.PREOPENING:
chan.set_state(channel_states.OPENING)
if chan.get_state() == channel_states.OPENING:
if chan.short_channel_id is None:
self.save_short_chan_id(chan)
@@ -775,14 +772,11 @@ class LNWallet(LNWorker):
funding_sat=funding_sat,
push_msat=push_sat * 1000,
temp_channel_id=os.urandom(32))
self.add_new_channel(chan)
self.network.trigger_callback('channels_updated', self.wallet)
self.wallet.add_transaction(funding_tx) # save tx as local into the wallet
self.wallet.set_label(funding_tx.txid(), _('Open channel'))
if funding_tx.is_complete():
# TODO make more robust (timeout low? server returns error?)
await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), LN_P2P_NETWORK_TIMEOUT)
chan.set_state(channel_states.OPENING)
await self.network.try_broadcasting(funding_tx, 'open_channel')
return chan, funding_tx
def add_channel(self, chan):