do not try to reestablish channels in PREOPENING state (per BOLT2).
This commit is contained in:
@@ -62,9 +62,11 @@ if TYPE_CHECKING:
|
|||||||
# Note: these states are persisted by name (for a given channel) in the wallet file,
|
# Note: these states are persisted by name (for a given channel) in the wallet file,
|
||||||
# so consider doing a wallet db upgrade when changing them.
|
# so consider doing a wallet db upgrade when changing them.
|
||||||
class channel_states(IntEnum):
|
class channel_states(IntEnum):
|
||||||
PREOPENING = 0 # negotiating
|
PREOPENING = 0 # Initial negotiation. Channel will not be reestablished
|
||||||
OPENING = 1 # awaiting funding tx
|
OPENING = 1 # Channel will be reestablished. (per BOLT2)
|
||||||
FUNDED = 2 # funded (requires min_depth and tx verification)
|
# - Funding node: has 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
|
OPEN = 3 # both parties have sent funding_locked
|
||||||
FORCE_CLOSING = 4 # force-close tx has been broadcast
|
FORCE_CLOSING = 4 # force-close tx has been broadcast
|
||||||
CLOSING = 5 # closing negotiation
|
CLOSING = 5 # closing negotiation
|
||||||
@@ -283,7 +285,6 @@ class Channel(Logger):
|
|||||||
self.config[LOCAL].current_commitment_signature=remote_sig
|
self.config[LOCAL].current_commitment_signature=remote_sig
|
||||||
self.hm.channel_open_finished()
|
self.hm.channel_open_finished()
|
||||||
self.peer_state = peer_states.GOOD
|
self.peer_state = peer_states.GOOD
|
||||||
self.set_state(channel_states.OPENING)
|
|
||||||
|
|
||||||
def set_state(self, state):
|
def set_state(self, state):
|
||||||
""" set on-chain state """
|
""" set on-chain state """
|
||||||
@@ -344,7 +345,7 @@ class Channel(Logger):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def should_try_to_reestablish_peer(self) -> bool:
|
def should_try_to_reestablish_peer(self) -> bool:
|
||||||
return self._state < channel_states.CLOSED and self.peer_state == peer_states.DISCONNECTED
|
return channel_states.PREOPENING < self._state < channel_states.CLOSED and self.peer_state == peer_states.DISCONNECTED
|
||||||
|
|
||||||
def get_funding_address(self):
|
def get_funding_address(self):
|
||||||
script = funding_output_script(self.config[LOCAL], self.config[REMOTE])
|
script = funding_output_script(self.config[LOCAL], self.config[REMOTE])
|
||||||
|
|||||||
@@ -611,6 +611,7 @@ class Peer(Logger):
|
|||||||
remote_sig = payload['signature']
|
remote_sig = payload['signature']
|
||||||
chan.receive_new_commitment(remote_sig, [])
|
chan.receive_new_commitment(remote_sig, [])
|
||||||
chan.open_with_first_pcp(remote_per_commitment_point, remote_sig)
|
chan.open_with_first_pcp(remote_per_commitment_point, remote_sig)
|
||||||
|
chan.set_state(channel_states.OPENING)
|
||||||
return chan, funding_tx
|
return chan, funding_tx
|
||||||
|
|
||||||
def create_channel_storage(self, channel_id, outpoint, local_config, remote_config, constraints):
|
def create_channel_storage(self, channel_id, outpoint, local_config, remote_config, constraints):
|
||||||
@@ -726,6 +727,7 @@ class Peer(Logger):
|
|||||||
async def reestablish_channel(self, chan: Channel):
|
async def reestablish_channel(self, chan: Channel):
|
||||||
await self.initialized
|
await self.initialized
|
||||||
chan_id = chan.channel_id
|
chan_id = chan.channel_id
|
||||||
|
assert channel_states.PREOPENING < chan.get_state() < channel_states.CLOSED
|
||||||
if chan.peer_state != peer_states.DISCONNECTED:
|
if chan.peer_state != peer_states.DISCONNECTED:
|
||||||
self.logger.info('reestablish_channel was called but channel {} already in state {}'
|
self.logger.info('reestablish_channel was called but channel {} already in state {}'
|
||||||
.format(chan_id, chan.get_state()))
|
.format(chan_id, chan.get_state()))
|
||||||
|
|||||||
@@ -764,6 +764,7 @@ class LNWallet(LNWorker):
|
|||||||
if funding_tx.is_complete():
|
if funding_tx.is_complete():
|
||||||
# TODO make more robust (timeout low? server returns error?)
|
# TODO make more robust (timeout low? server returns error?)
|
||||||
await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), LN_P2P_NETWORK_TIMEOUT)
|
await asyncio.wait_for(self.network.broadcast_transaction(funding_tx), LN_P2P_NETWORK_TIMEOUT)
|
||||||
|
chan.set_state(channel_states.OPENING)
|
||||||
return chan, funding_tx
|
return chan, funding_tx
|
||||||
|
|
||||||
def add_channel(self, chan):
|
def add_channel(self, chan):
|
||||||
|
|||||||
Reference in New Issue
Block a user