lnworker: use booleans for enable_htlc_settle, enable_htlc_forwarding
This commit is contained in:
@@ -1077,8 +1077,7 @@ class Commands:
|
|||||||
|
|
||||||
@command('wn')
|
@command('wn')
|
||||||
async def enable_htlc_settle(self, b: bool, wallet: Abstract_Wallet = None):
|
async def enable_htlc_settle(self, b: bool, wallet: Abstract_Wallet = None):
|
||||||
e = wallet.lnworker.enable_htlc_settle
|
wallet.lnworker.enable_htlc_settle = b
|
||||||
e.set() if b else e.clear()
|
|
||||||
|
|
||||||
@command('n')
|
@command('n')
|
||||||
async def clear_ln_blacklist(self):
|
async def clear_ln_blacklist(self):
|
||||||
|
|||||||
@@ -1828,7 +1828,7 @@ class Peer(Logger):
|
|||||||
error_reason = e
|
error_reason = e
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
preimage, fw_info, error_bytes = await self.process_unfulfilled_htlc(
|
preimage, fw_info, error_bytes = self.process_unfulfilled_htlc(
|
||||||
chan=chan,
|
chan=chan,
|
||||||
htlc=htlc,
|
htlc=htlc,
|
||||||
forwarding_info=forwarding_info,
|
forwarding_info=forwarding_info,
|
||||||
@@ -1840,7 +1840,8 @@ class Peer(Logger):
|
|||||||
unfulfilled[htlc_id] = local_ctn, remote_ctn, onion_packet_hex, fw_info
|
unfulfilled[htlc_id] = local_ctn, remote_ctn, onion_packet_hex, fw_info
|
||||||
elif preimage or error_reason or error_bytes:
|
elif preimage or error_reason or error_bytes:
|
||||||
if preimage:
|
if preimage:
|
||||||
await self.lnworker.enable_htlc_settle.wait()
|
if not self.lnworker.enable_htlc_settle:
|
||||||
|
continue
|
||||||
self.fulfill_htlc(chan, htlc.htlc_id, preimage)
|
self.fulfill_htlc(chan, htlc.htlc_id, preimage)
|
||||||
elif error_bytes:
|
elif error_bytes:
|
||||||
self.fail_htlc(
|
self.fail_htlc(
|
||||||
@@ -1880,7 +1881,7 @@ class Peer(Logger):
|
|||||||
await group.spawn(htlc_switch_iteration())
|
await group.spawn(htlc_switch_iteration())
|
||||||
await group.spawn(self.got_disconnected.wait())
|
await group.spawn(self.got_disconnected.wait())
|
||||||
|
|
||||||
async def process_unfulfilled_htlc(
|
def process_unfulfilled_htlc(
|
||||||
self, *,
|
self, *,
|
||||||
chan: Channel,
|
chan: Channel,
|
||||||
htlc: UpdateAddHtlc,
|
htlc: UpdateAddHtlc,
|
||||||
@@ -1919,7 +1920,8 @@ class Peer(Logger):
|
|||||||
is_trampoline=True)
|
is_trampoline=True)
|
||||||
else:
|
else:
|
||||||
# trampoline- HTLC we are supposed to forward, but haven't forwarded yet
|
# trampoline- HTLC we are supposed to forward, but haven't forwarded yet
|
||||||
await self.lnworker.enable_htlc_forwarding.wait()
|
if not self.lnworker.enable_htlc_forwarding:
|
||||||
|
return None, None, None
|
||||||
self.maybe_forward_trampoline(
|
self.maybe_forward_trampoline(
|
||||||
chan=chan,
|
chan=chan,
|
||||||
htlc=htlc,
|
htlc=htlc,
|
||||||
@@ -1936,7 +1938,8 @@ class Peer(Logger):
|
|||||||
|
|
||||||
elif not forwarding_info:
|
elif not forwarding_info:
|
||||||
# HTLC we are supposed to forward, but haven't forwarded yet
|
# HTLC we are supposed to forward, but haven't forwarded yet
|
||||||
await self.lnworker.enable_htlc_forwarding.wait()
|
if not self.lnworker.enable_htlc_forwarding:
|
||||||
|
return None, None, None
|
||||||
next_chan_id, next_htlc_id = self.maybe_forward_htlc(
|
next_chan_id, next_htlc_id = self.maybe_forward_htlc(
|
||||||
htlc=htlc,
|
htlc=htlc,
|
||||||
processed_onion=processed_onion)
|
processed_onion=processed_onion)
|
||||||
|
|||||||
@@ -602,10 +602,8 @@ class LNWallet(LNWorker):
|
|||||||
self.sweep_address = wallet.get_new_sweep_address_for_channel()
|
self.sweep_address = wallet.get_new_sweep_address_for_channel()
|
||||||
self.logs = defaultdict(list) # type: Dict[str, List[HtlcLog]] # key is RHASH # (not persisted)
|
self.logs = defaultdict(list) # type: Dict[str, List[HtlcLog]] # key is RHASH # (not persisted)
|
||||||
# used in tests
|
# used in tests
|
||||||
self.enable_htlc_settle = asyncio.Event()
|
self.enable_htlc_settle = True
|
||||||
self.enable_htlc_settle.set()
|
self.enable_htlc_forwarding = True
|
||||||
self.enable_htlc_forwarding = asyncio.Event()
|
|
||||||
self.enable_htlc_forwarding.set()
|
|
||||||
|
|
||||||
# note: accessing channels (besides simple lookup) needs self.lock!
|
# note: accessing channels (besides simple lookup) needs self.lock!
|
||||||
self._channels = {} # type: Dict[bytes, Channel]
|
self._channels = {} # type: Dict[bytes, Channel]
|
||||||
|
|||||||
@@ -140,10 +140,8 @@ class MockLNWallet(Logger, NetworkRetryManager[LNPeerAddr]):
|
|||||||
chan.lnworker = self
|
chan.lnworker = self
|
||||||
self._peers = {} # bytes -> Peer
|
self._peers = {} # bytes -> Peer
|
||||||
# used in tests
|
# used in tests
|
||||||
self.enable_htlc_settle = asyncio.Event()
|
self.enable_htlc_settle = True
|
||||||
self.enable_htlc_settle.set()
|
self.enable_htlc_forwarding = True
|
||||||
self.enable_htlc_forwarding = asyncio.Event()
|
|
||||||
self.enable_htlc_forwarding.set()
|
|
||||||
self.received_mpp_htlcs = dict()
|
self.received_mpp_htlcs = dict()
|
||||||
self.sent_htlcs = defaultdict(asyncio.Queue)
|
self.sent_htlcs = defaultdict(asyncio.Queue)
|
||||||
self.sent_htlcs_routes = dict()
|
self.sent_htlcs_routes = dict()
|
||||||
@@ -790,7 +788,7 @@ class TestPeer(TestCaseForTestnet):
|
|||||||
if mpp_invoice:
|
if mpp_invoice:
|
||||||
graph.w_d.features |= LnFeatures.BASIC_MPP_OPT
|
graph.w_d.features |= LnFeatures.BASIC_MPP_OPT
|
||||||
if not bob_forwarding:
|
if not bob_forwarding:
|
||||||
graph.w_b.enable_htlc_forwarding.clear()
|
graph.w_b.enable_htlc_forwarding = False
|
||||||
if alice_uses_trampoline:
|
if alice_uses_trampoline:
|
||||||
if graph.w_a.network.channel_db:
|
if graph.w_a.network.channel_db:
|
||||||
graph.w_a.network.channel_db.stop()
|
graph.w_a.network.channel_db.stop()
|
||||||
@@ -803,7 +801,7 @@ class TestPeer(TestCaseForTestnet):
|
|||||||
result, log = await graph.w_a.pay_invoice(pay_req, attempts=attempts)
|
result, log = await graph.w_a.pay_invoice(pay_req, attempts=attempts)
|
||||||
if not bob_forwarding:
|
if not bob_forwarding:
|
||||||
# reset to previous state, sleep 2s so that the second htlc can time out
|
# reset to previous state, sleep 2s so that the second htlc can time out
|
||||||
graph.w_b.enable_htlc_forwarding.set()
|
graph.w_b.enable_htlc_forwarding = True
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
if result:
|
if result:
|
||||||
self.assertEqual(PR_PAID, graph.w_d.get_payment_status(lnaddr.paymenthash))
|
self.assertEqual(PR_PAID, graph.w_d.get_payment_status(lnaddr.paymenthash))
|
||||||
@@ -855,7 +853,7 @@ class TestPeer(TestCaseForTestnet):
|
|||||||
graph.w_d.TIMEOUT_SHUTDOWN_FAIL_PENDING_HTLCS = 3
|
graph.w_d.TIMEOUT_SHUTDOWN_FAIL_PENDING_HTLCS = 3
|
||||||
async def pay():
|
async def pay():
|
||||||
graph.w_d.features |= LnFeatures.BASIC_MPP_OPT
|
graph.w_d.features |= LnFeatures.BASIC_MPP_OPT
|
||||||
graph.w_b.enable_htlc_forwarding.clear() # Bob will hold forwarded HTLCs
|
graph.w_b.enable_htlc_forwarding = False # Bob will hold forwarded HTLCs
|
||||||
assert graph.w_a.network.channel_db is not None
|
assert graph.w_a.network.channel_db is not None
|
||||||
lnaddr, pay_req = await self.prepare_invoice(graph.w_d, include_routing_hints=True, amount_msat=amount_to_pay)
|
lnaddr, pay_req = await self.prepare_invoice(graph.w_d, include_routing_hints=True, amount_msat=amount_to_pay)
|
||||||
try:
|
try:
|
||||||
@@ -892,7 +890,7 @@ class TestPeer(TestCaseForTestnet):
|
|||||||
w2.network.config.set_key('dynamic_fees', False)
|
w2.network.config.set_key('dynamic_fees', False)
|
||||||
w1.network.config.set_key('fee_per_kb', 5000)
|
w1.network.config.set_key('fee_per_kb', 5000)
|
||||||
w2.network.config.set_key('fee_per_kb', 1000)
|
w2.network.config.set_key('fee_per_kb', 1000)
|
||||||
w2.enable_htlc_settle.clear()
|
w2.enable_htlc_settle = False
|
||||||
lnaddr, pay_req = run(self.prepare_invoice(w2))
|
lnaddr, pay_req = run(self.prepare_invoice(w2))
|
||||||
async def pay():
|
async def pay():
|
||||||
await asyncio.wait_for(p1.initialized, 1)
|
await asyncio.wait_for(p1.initialized, 1)
|
||||||
@@ -911,7 +909,7 @@ class TestPeer(TestCaseForTestnet):
|
|||||||
gath.cancel()
|
gath.cancel()
|
||||||
async def set_settle():
|
async def set_settle():
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
w2.enable_htlc_settle.set()
|
w2.enable_htlc_settle = True
|
||||||
gath = asyncio.gather(pay(), set_settle(), p1._message_loop(), p2._message_loop(), p1.htlc_switch(), p2.htlc_switch())
|
gath = asyncio.gather(pay(), set_settle(), p1._message_loop(), p2._message_loop(), p1.htlc_switch(), p2.htlc_switch())
|
||||||
async def f():
|
async def f():
|
||||||
await gath
|
await gath
|
||||||
|
|||||||
Reference in New Issue
Block a user