1
0

LN cooperative close: avoid address-reuse (#6590)

Previously if we coop-closed multiple channels in the same session,
they would reuse the wallet address.
This commit is contained in:
ghost43
2020-09-15 15:37:47 +00:00
committed by GitHub
parent fc89c8ffa9
commit 3eba26b398
4 changed files with 28 additions and 7 deletions

View File

@@ -145,7 +145,7 @@ class AbstractChannel(Logger, ABC):
config: Dict[HTLCOwner, Union[LocalConfig, RemoteConfig]]
_sweep_info: Dict[str, Dict[str, 'SweepInfo']]
lnworker: Optional['LNWallet']
sweep_address: str
_fallback_sweep_address: str
channel_id: bytes
funding_outpoint: Outpoint
node_id: bytes
@@ -307,6 +307,20 @@ class AbstractChannel(Logger, ABC):
if self.get_state() == ChannelState.CLOSED and not keep_watching:
self.set_state(ChannelState.REDEEMED)
@property
def sweep_address(self) -> str:
# TODO: in case of unilateral close with pending HTLCs, this address will be reused
addr = None
if self.is_static_remotekey_enabled():
our_payment_pubkey = self.config[LOCAL].payment_basepoint.pubkey
addr = make_commitment_output_to_remote_address(our_payment_pubkey)
if addr is None:
addr = self._fallback_sweep_address
assert addr
if self.lnworker:
assert self.lnworker.wallet.is_mine(addr)
return addr
@abstractmethod
def is_initiator(self) -> bool:
pass
@@ -367,6 +381,10 @@ class AbstractChannel(Logger, ABC):
"""
pass
@abstractmethod
def is_static_remotekey_enabled(self) -> bool:
pass
class ChannelBackup(AbstractChannel):
"""
@@ -383,7 +401,7 @@ class ChannelBackup(AbstractChannel):
Logger.__init__(self)
self.cb = cb
self._sweep_info = {}
self.sweep_address = sweep_address
self._fallback_sweep_address = sweep_address
self.storage = {} # dummy storage
self._state = ChannelState.OPENING
self.config = {}
@@ -485,7 +503,7 @@ class Channel(AbstractChannel):
self.name = name
Logger.__init__(self)
self.lnworker = lnworker
self.sweep_address = sweep_address
self._fallback_sweep_address = sweep_address
self.storage = state
self.db_lock = self.storage.db.lock if self.storage.db else threading.RLock()
self.config = {}