Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ async def execute_payment() -> str:
True # currently required by nip 47 specs, might change in future
)
payment_status: PaymentStatus | None = None
poll_interval = 0.5
max_poll_interval = 5.0
poll_attempts = 0
max_poll_attempts = 120 # ~2 minutes total with backoff
while wait_for_preimage:
payment_status = await check_transaction_status(wallet_id, payment_hash)
if payment_status.success:
Expand All @@ -122,7 +126,14 @@ async def execute_payment() -> str:
},
"in_budget": in_budget,
}
await asyncio.sleep(0.05)
poll_attempts += 1
if poll_attempts >= max_poll_attempts:
logger.warning(
f"Gave up waiting for preimage after {poll_attempts} attempts"
)
break
await asyncio.sleep(poll_interval)
poll_interval = min(poll_interval * 1.5, max_poll_interval)
if not payment_status:
raise Exception("Payment status not found")
return {
Expand Down