lnchannel: rm sweep_info cache
- was added when functions in lnsweep returned already signed tx, and signing is expensive - get_ctx_sweep_info does not presign anymore - cache invalidation is difficult here - e.g. not only on new blocks, but we should e.g. also invalidate the cache when learning new preimages
This commit is contained in:
@@ -185,7 +185,6 @@ class HTLCWithStatus(NamedTuple):
|
|||||||
class AbstractChannel(Logger, ABC):
|
class AbstractChannel(Logger, ABC):
|
||||||
storage: Union['StoredDict', dict]
|
storage: Union['StoredDict', dict]
|
||||||
config: Dict[HTLCOwner, Union[LocalConfig, RemoteConfig]]
|
config: Dict[HTLCOwner, Union[LocalConfig, RemoteConfig]]
|
||||||
_sweep_info: Dict[str, Dict[str, 'SweepInfo']]
|
|
||||||
lnworker: Optional['LNWallet']
|
lnworker: Optional['LNWallet']
|
||||||
channel_id: bytes
|
channel_id: bytes
|
||||||
short_channel_id: Optional[ShortChannelID] = None
|
short_channel_id: Optional[ShortChannelID] = None
|
||||||
@@ -193,6 +192,7 @@ class AbstractChannel(Logger, ABC):
|
|||||||
node_id: bytes # note that it might not be the full 33 bytes; for OCB it is only the prefix
|
node_id: bytes # note that it might not be the full 33 bytes; for OCB it is only the prefix
|
||||||
should_request_force_close: bool = False
|
should_request_force_close: bool = False
|
||||||
_state: ChannelState
|
_state: ChannelState
|
||||||
|
_who_closed: Optional[int] = None # HTLCOwner (1 or -1). 0 means "unknown"
|
||||||
|
|
||||||
def set_short_channel_id(self, short_id: ShortChannelID) -> None:
|
def set_short_channel_id(self, short_id: ShortChannelID) -> None:
|
||||||
self.short_channel_id = short_id
|
self.short_channel_id = short_id
|
||||||
@@ -304,22 +304,27 @@ class AbstractChannel(Logger, ABC):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_ctx_sweep_info(self, ctx: Transaction) -> Tuple[bool, Dict[str, SweepInfo]]:
|
def get_ctx_sweep_info(self, ctx: Transaction) -> Tuple[bool, Dict[str, SweepInfo]]:
|
||||||
txid = ctx.txid()
|
our_sweep_info = self.create_sweeptxs_for_our_ctx(ctx)
|
||||||
is_local = False
|
their_sweep_info = self.create_sweeptxs_for_their_ctx(ctx)
|
||||||
if self._sweep_info.get(txid) is None:
|
if our_sweep_info:
|
||||||
our_sweep_info = self.create_sweeptxs_for_our_ctx(ctx)
|
sweep_info = our_sweep_info
|
||||||
their_sweep_info = self.create_sweeptxs_for_their_ctx(ctx)
|
who_closed = LOCAL
|
||||||
if our_sweep_info:
|
elif their_sweep_info:
|
||||||
is_local = True
|
sweep_info = their_sweep_info
|
||||||
self._sweep_info[txid] = our_sweep_info
|
who_closed = REMOTE
|
||||||
|
else:
|
||||||
|
sweep_info = {}
|
||||||
|
who_closed = 0
|
||||||
|
if self._who_closed != who_closed: # mostly here to limit log spam
|
||||||
|
self._who_closed = who_closed
|
||||||
|
if who_closed == LOCAL:
|
||||||
self.logger.info(f'we (local) force closed')
|
self.logger.info(f'we (local) force closed')
|
||||||
elif their_sweep_info:
|
elif who_closed == REMOTE:
|
||||||
self._sweep_info[txid] = their_sweep_info
|
|
||||||
self.logger.info(f'they (remote) force closed.')
|
self.logger.info(f'they (remote) force closed.')
|
||||||
else:
|
else:
|
||||||
self._sweep_info[txid] = {}
|
self.logger.info(f'not sure who closed. maybe co-op close?')
|
||||||
self.logger.info(f'not sure who closed.')
|
is_local_ctx = who_closed == LOCAL
|
||||||
return is_local, self._sweep_info[txid]
|
return is_local_ctx, sweep_info
|
||||||
|
|
||||||
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[str, SweepInfo]:
|
def maybe_sweep_htlcs(self, ctx: Transaction, htlc_tx: Transaction) -> Dict[str, SweepInfo]:
|
||||||
return {}
|
return {}
|
||||||
@@ -569,7 +574,6 @@ class ChannelBackup(AbstractChannel):
|
|||||||
self.name = None
|
self.name = None
|
||||||
self.cb = cb
|
self.cb = cb
|
||||||
self.is_imported = isinstance(self.cb, ImportedChannelBackupStorage)
|
self.is_imported = isinstance(self.cb, ImportedChannelBackupStorage)
|
||||||
self._sweep_info = {}
|
|
||||||
self.storage = {} # dummy storage
|
self.storage = {} # dummy storage
|
||||||
self._state = ChannelState.OPENING
|
self._state = ChannelState.OPENING
|
||||||
self.node_id = cb.node_id if self.is_imported else cb.node_id_prefix
|
self.node_id = cb.node_id if self.is_imported else cb.node_id_prefix
|
||||||
@@ -782,7 +786,6 @@ class Channel(AbstractChannel):
|
|||||||
# ^ htlc_id -> onion_packet_hex, forwarding_key
|
# ^ htlc_id -> onion_packet_hex, forwarding_key
|
||||||
self._state = ChannelState[state['state']]
|
self._state = ChannelState[state['state']]
|
||||||
self.peer_state = PeerState.DISCONNECTED
|
self.peer_state = PeerState.DISCONNECTED
|
||||||
self._sweep_info = {}
|
|
||||||
self._outgoing_channel_update = None # type: Optional[bytes]
|
self._outgoing_channel_update = None # type: Optional[bytes]
|
||||||
self.revocation_store = RevocationStore(state["revocation_store"])
|
self.revocation_store = RevocationStore(state["revocation_store"])
|
||||||
self._can_send_ctx_updates = True # type: bool
|
self._can_send_ctx_updates = True # type: bool
|
||||||
|
|||||||
@@ -59,11 +59,6 @@ class LNWatcher(Logger, EventListener):
|
|||||||
|
|
||||||
@event_listener
|
@event_listener
|
||||||
async def on_event_blockchain_updated(self, *args):
|
async def on_event_blockchain_updated(self, *args):
|
||||||
# we invalidate the cache on each new block because
|
|
||||||
# some processes affect the list of sweep transactions
|
|
||||||
# (hold invoice preimage revealed, MPP completed, etc)
|
|
||||||
for chan in self.lnworker.channels.values():
|
|
||||||
chan._sweep_info.clear()
|
|
||||||
await self.trigger_callbacks()
|
await self.trigger_callbacks()
|
||||||
|
|
||||||
@event_listener
|
@event_listener
|
||||||
|
|||||||
Reference in New Issue
Block a user