Skip to content

Conversation

@iWarpBTC
Copy link
Contributor

@iWarpBTC iWarpBTC commented Jun 20, 2023

If an invoice payment failed (for example an over-limit payment is attempted, or just there's no route) this is still recorded as a spent hit and it may deplete the daily limit. This PR fixes it.

Also now payment request of precisely maxWithdrawable amount doesn't pass since this is probably a PoS error or stealing, not a common payment.

@gorrdy
Copy link
Contributor

gorrdy commented Jun 22, 2023

Tried it and it's working as expected.

@gimme
Copy link

gimme commented Jul 13, 2023

If an invoice payment failed (for example an over-limit payment is attempted, or just there's no route) this is still recorded as a spent hit and it may deplete the daily limit. This PR fixes it.

I don't see the code that fixes this.

Also now payment request of precisely maxWithdrawable amount doesn't pass since this is probably a PoS error or stealing, not a common payment.

Could you create a separate PR or issue for this? I think it needs some discussion.

@gorrdy
Copy link
Contributor

gorrdy commented Jul 13, 2023

You can see the code that fixes sit here. It is pretty straight forward.
https://github.com/lnbits/boltcards/pull/4/files

@gimme
Copy link

gimme commented Jul 13, 2023

I can only see the code for the unrelated issue, not what the title claims to fix.

@gorrdy
Copy link
Contributor

gorrdy commented Jul 21, 2023

Basically what this PR does is that it checks if the amount in invoice is lower than the card limit.

Currently it tries to do the payment but the payment obviously fails (if higher than the card limit). This would be ok but it also counts the amount as spent which is

  1. not true
  2. the payment counts to the daily limit - other payments may not go through because of the previous failed payment.

It doesn't make sense to try payment that i guaranteed to fail (above card tx limit). That's why there is the if statement at the beginning. Also it resolves the point 2. It won't mark the hit as spend.

if invoice.amount_msat < card.tx_limit * 1000:
         hit = await spend_hit(id=hit.id, amount=int(invoice.amount_msat / 1000))
         assert hit
         try:
             await pay_invoice(
                 wallet_id=card.wallet,
                 payment_request=pr,
                 max_sat=card.tx_limit,
                 extra={"tag": "boltcard", "hit": hit.id},
             )
             return {"status": "OK"}
         except Exception as exc:
             return {"status": "ERROR", "reason": f"Payment failed - {exc}"}
     else:
         return {"status": "ERROR", "reason": "Amount exceeds card limit"}

@gimme
Copy link

gimme commented Jul 21, 2023

Oh, I see what you mean, but it doesn't fix if the payment fails for another reason than tx limit (e.g., like you mentioned, if there's no route).

@gorrdy
Copy link
Contributor

gorrdy commented Jul 21, 2023

This is true but it is not that big of a deal if the payment is reasonable amount. The problem is someone can disable your bolt card/bolt ring for a day just by a simple tap and requesting more sats than allowed.

It is not a big deal if there is 10k sats more of 300k daily limit spent... But this should also be resolved, that's right.

@iWarpBTC
Copy link
Contributor Author

I believeI believe it would be quite safe to "unspent" a hit when an Exception occurs?

@gimme
Copy link

gimme commented Jul 21, 2023

It should be pretty simple to only add the hit if the payment succeeds.

Otherwise, I guess it's fine to fix this first, but I still think we shouldn't prevent requests for precisely maxWithdrawable without more discussion about that.

@gimme
Copy link

gimme commented Jul 21, 2023

I believeI believe it would be quite safe to "unspent" a hit when an Exception occurs?

Yes, I think so

@bota87
Copy link

bota87 commented Jan 18, 2025

What's blocking the merge of this PR?

@prusnak
Copy link
Collaborator

prusnak commented Jan 19, 2025

What's blocking the merge of this PR?

It needs to be rebased on top of the current main branch. Are you up for the task?

@bota87
Copy link

bota87 commented Jan 19, 2025

It needs to be rebased on top of the current main branch. Are you up for the task?

Not really (I don't know python) but I tried anyway.
The rebased version is here but I don't know the workflow to add commits to this PR nor if I have permissions to do so

@CabtonWithaK
Copy link

issue still persists

state before
image

for example unsuccesful payment/withdrawal in Wallet of Satoshi
image

image

state after
image

AS IS: both for "daily limit reached" or "internal invoices only" the boltcard scan is recorded and counts for the daily limit
TO BE: both for "daily limit reached" or "internal invoices only" the boltcard scan is recorded , but it does NOT count for the daily limit

suggestion: It's a good thing every scan is recorded, but maybe some property can store the consequent payment/withdrawal was succesful or not. This would allow for checking acurately wether the daily spent limit was reached or not.

@talvasconcelos
Copy link
Collaborator

Closes #55
Closes #48

@talvasconcelos
Copy link
Collaborator

@iWarpBTC and @bota87 , could you please test the PR again?

I rebased and fixed a couple of things. Should be ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants