Invalidate cache of sweep_info on each new block
Add regtest test for swapserver_forceclose
This commit is contained in:
@@ -414,6 +414,16 @@ class LNWalletWatcher(LNWatcher):
|
||||
self.lnworker = lnworker
|
||||
LNWatcher.__init__(self, lnworker.wallet.adb, network)
|
||||
|
||||
@event_listener
|
||||
async def on_event_blockchain_updated(self, *args):
|
||||
# overload parent method with cache invalidation
|
||||
# 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()
|
||||
|
||||
def diagnostic_name(self):
|
||||
return f"{self.lnworker.wallet.diagnostic_name()}-LNW"
|
||||
|
||||
@@ -441,6 +451,7 @@ class LNWalletWatcher(LNWatcher):
|
||||
chan_id_for_log = chan.get_id_for_log()
|
||||
# detect who closed and set sweep_info
|
||||
sweep_info_dict = chan.sweep_ctx(closing_tx)
|
||||
self.logger.info(f"do_breach_remedy: {[x.name for x in sweep_info_dict.values()]}")
|
||||
keep_watching = False if sweep_info_dict else not self.is_deeply_mined(closing_tx.txid())
|
||||
# create and broadcast transaction
|
||||
for prevout, sweep_info in sweep_info_dict.items():
|
||||
|
||||
@@ -89,6 +89,9 @@ class TestLightningSwapserver(TestLightning):
|
||||
def test_swapserver_success(self):
|
||||
self.run_shell(['swapserver_success'])
|
||||
|
||||
def test_swapserver_forceclose(self):
|
||||
self.run_shell(['swapserver_forceclose'])
|
||||
|
||||
def test_swapserver_refund(self):
|
||||
self.run_shell(['swapserver_refund'])
|
||||
|
||||
|
||||
@@ -229,6 +229,27 @@ if [[ $1 == "swapserver_success" ]]; then
|
||||
fi
|
||||
|
||||
|
||||
if [[ $1 == "swapserver_forceclose" ]]; then
|
||||
wait_for_balance alice 1
|
||||
echo "alice opens channel"
|
||||
bob_node=$($bob nodeid)
|
||||
channel=$($alice open_channel $bob_node 0.15 --password='')
|
||||
new_blocks 3
|
||||
wait_until_channel_open alice
|
||||
echo "alice initiates swap"
|
||||
dryrun=$($alice reverse_swap 0.02 dryrun)
|
||||
onchain_amount=$(echo $dryrun| jq -r ".onchain_amount")
|
||||
swap=$($alice reverse_swap 0.02 $onchain_amount)
|
||||
echo $swap | jq
|
||||
funding_txid=$(echo $swap| jq -r ".funding_txid")
|
||||
$bob close_channel --force $channel
|
||||
new_blocks 1
|
||||
wait_until_spent $funding_txid 0 # alice reveals preimage
|
||||
new_blocks 1
|
||||
wait_for_balance bob 0.999
|
||||
fi
|
||||
|
||||
|
||||
if [[ $1 == "swapserver_refund" ]]; then
|
||||
$alice setconfig test_swapserver_refund true
|
||||
wait_for_balance alice 1
|
||||
|
||||
Reference in New Issue
Block a user