Browse Source

increase timeouts for http wallets when stuff may take more than 5 seconds.

before we were using requests which had no default timeouts, but httpx has a
default timeout of 5 seconds. should have noticed that earlier.

when the timeout expires we are left with a pending payment on the db with a
temporary checking_id so we can never know if it was completed or not.

this is still an issue, because technically a lightning payment may take 2 weeks
or more, and we must have a way to dispatch a payment and check for it later.

that should be the default (and we already do check for the payment status later,
so half of the work is done), but on the other hand backends like lnpay and
opennode do not give us a checking_id before the thing is already settled.
atmext
fiatjaf 4 years ago
parent
commit
0dc60d4795
  1. 1
      lnbits/wallets/lndrest.py
  2. 6
      lnbits/wallets/lnpay.py
  3. 14
      lnbits/wallets/lntxbot.py
  4. 14
      lnbits/wallets/opennode.py
  5. 7
      lnbits/wallets/spark.py

1
lnbits/wallets/lndrest.py

@ -86,6 +86,7 @@ class LndRestWallet(Wallet):
headers=self.auth,
verify=self.cert,
json={"payment_request": bolt11},
timeout=180,
)
if r.is_error:

6
lnbits/wallets/lnpay.py

@ -21,7 +21,7 @@ class LNPayWallet(Wallet):
def status(self) -> StatusResponse:
url = f"{self.endpoint}/wallet/{self.wallet_key}"
try:
r = httpx.get(url, headers=self.auth)
r = httpx.get(url, headers=self.auth, timeout=60)
except (httpx.ConnectError, httpx.RequestError):
return StatusResponse(f"Unable to connect to '{url}'", 0)
@ -52,6 +52,7 @@ class LNPayWallet(Wallet):
f"{self.endpoint}/wallet/{self.wallet_key}/invoice",
headers=self.auth,
json=data,
timeout=60,
)
ok, checking_id, payment_request, error_message = (
r.status_code == 201,
@ -68,9 +69,10 @@ class LNPayWallet(Wallet):
def pay_invoice(self, bolt11: str) -> PaymentResponse:
r = httpx.post(
url=f"{self.endpoint}/wallet/{self.wallet_key}/withdraw",
f"{self.endpoint}/wallet/{self.wallet_key}/withdraw",
headers=self.auth,
json={"payment_request": bolt11},
timeout=180,
)
try:

14
lnbits/wallets/lntxbot.py

@ -17,7 +17,11 @@ class LntxbotWallet(Wallet):
self.auth = {"Authorization": f"Basic {key}"}
def status(self) -> StatusResponse:
r = httpx.get(f"{self.endpoint}/balance", headers=self.auth)
r = httpx.get(
f"{self.endpoint}/balance",
headers=self.auth,
timeout=40,
)
try:
data = r.json()
except:
@ -41,6 +45,7 @@ class LntxbotWallet(Wallet):
url=f"{self.endpoint}/addinvoice",
headers=self.auth,
json=data,
timeout=40,
)
if r.is_error:
@ -57,7 +62,12 @@ class LntxbotWallet(Wallet):
return InvoiceResponse(True, data["payment_hash"], data["pay_req"], None)
def pay_invoice(self, bolt11: str) -> PaymentResponse:
r = httpx.post(url=f"{self.endpoint}/payinvoice", headers=self.auth, json={"invoice": bolt11})
r = httpx.post(
url=f"{self.endpoint}/payinvoice",
headers=self.auth,
json={"invoice": bolt11},
timeout=40,
)
if r.is_error:
try:

14
lnbits/wallets/opennode.py

@ -22,7 +22,11 @@ class OpenNodeWallet(Wallet):
def status(self) -> StatusResponse:
try:
r = httpx.get(f"{self.endpoint}/v1/account/balance", headers=self.auth)
r = httpx.get(
f"{self.endpoint}/v1/account/balance",
headers=self.auth,
timeout=40,
)
except (httpx.ConnectError, httpx.RequestError):
return StatusResponse(f"Unable to connect to '{self.endpoint}'", 0)
@ -46,6 +50,7 @@ class OpenNodeWallet(Wallet):
"description": memo or "",
"callback_url": url_for("webhook_listener", _external=True),
},
timeout=40,
)
if r.is_error:
@ -58,7 +63,12 @@ class OpenNodeWallet(Wallet):
return InvoiceResponse(True, checking_id, payment_request, None)
def pay_invoice(self, bolt11: str) -> PaymentResponse:
r = httpx.post(f"{self.endpoint}/v2/withdrawals", headers=self.auth, json={"type": "ln", "address": bolt11})
r = httpx.post(
f"{self.endpoint}/v2/withdrawals",
headers=self.auth,
json={"type": "ln", "address": bolt11},
timeout=180,
)
if r.is_error:
error_message = r.json()["message"]

7
lnbits/wallets/spark.py

@ -32,7 +32,12 @@ class SparkWallet(Wallet):
else:
params = {}
r = httpx.post(self.url + "/rpc", headers={"X-Access": self.token}, json={"method": key, "params": params})
r = httpx.post(
self.url + "/rpc",
headers={"X-Access": self.token},
json={"method": key, "params": params},
timeout=40,
)
try:
data = r.json()
except:

Loading…
Cancel
Save