-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow zapping, posting and commenting without funds or an account #336
Conversation
c089690
to
444ebf7
Compare
An alternative to rewriting a lot of the code/data models to be user-less is creating an The minimal code rewrite flow for anon zapping might be: pay invoice to Implementing anon posting/commenting will likely be a lot easier if user-less actions are done this way afaict. We'd also get fee escalation for the |
1809a02
to
87ec14a
Compare
Done 👍
I did this by adding a column I also had to update the
-- https://www.postgresql.org/docs/current/queries-with.html New state with proxy anon user instead of deep invoice integration (87ec14a): 2023-07-12.00-15-49.mp4 |
It looks pretty good on first glance. We have quite a few options for making it generic that we might want to consider before merging (so that we can support a wide variety of anonymous actions). Options for storing on backend and waiting for payment
Options for only sending to backend when payment confirmedThere's only really one way to do this (which might indicate it's the right way):
IMO the server-side versions seem very complicated if we're going to allow anons to really use SN. The client-side version isn't atomic but we can cache the invoice hashes so that they can be retried on the rare failure cases (and possibly even refunded in extreme cases). |
Another "dimension" of generic that we might want to consider is allowing logged in users to keep a zero/low balance and pay/zap only when they perform actions. Most of the generic options above are consistent with that though I think. |
That does indeed sound good. I'll update the code to work like this |
The only gotcha I can see with this approach is post/comment fee escalation race conditions, e.g. I pay when there isn't another recent anon post, but before I submit my mutation another anon submits theirs, and then my mutation fails because I paid But as we discussed elsewhere, perhaps we just make anon posts/comments 1000 sats or something and disable fee escalation. |
b179e70
to
a9ffee3
Compare
a9ffee3 now uses attached invoice ids as a proof of payment when sending a mutation. To prevent double spends, the invoice is deleted inside the same transaction. It's missing code for the following though:
|
ae4ea73
to
c13105b
Compare
Added commenting and posting as anons (links, discussions and polls) now and disabled fee escalation for the anon user. I have set anon comment fees to 100 and post fees to 1000. TODO:
no showcase video since Github limits uploads to 10MB and my video was too long lol. I'll may upload them to my own server and put a link here edit: added these TODOs to the issue description |
I realized that double spends are still possible since you can use existing payment hashes (which were used for depositing) to pay for stuff since the backend only checks if there was a paid invoice with that payment hash to allow actions. So we need to use a different method than deletion to check if an invoice was already spent edit: Okay, just tested it using a deposit payment hash with
So I forgot that the postgres function So we can continue to use invoice deletion. For example, the following works but 50k sats are correctly deducted from my balance while doing so:
|
c89090b
to
4e3be48
Compare
note: I haven't looked at the code If a user is logged in, we could prevent them from using payment hashes. Instead, their paid invoice always goes to their balance, and they always spend from their balance. |
I thought I am done now but I think there is one thing missing: I am going to create a showcase video with all features soon and upload it to my own server. Creating these videos also helps me in making sure everything works as expected |
You'd just skip adding them to values in worker/trust.js:160 |
db994c0
to
d92701c
Compare
Any errors thrown here are already objects of shape { message: string }
I stumbled across this while checking if anons can edit their items. I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error: Variable "$amount" of required type "Int!" was not provided. I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
Closes #266
Current state (444ebf7):(outdated)2023-06-28.05-27-07.mp4
TODO:
Fix missing apollo cache update after an invoice was paid(outdated)stop polling invoice after confirmation since it will be deleted shortly after(using(mhh, the user may see "<div>error</div>" rendered for a very short amount of time before the modal is closed and the mutation is executed... this could confuse users so should be prevented)skip
seemed to throw a bigger error and the current "invoice not found" error is only logged to console so I think stopping the query is not needed 🤔)replace invoice deletion with a different method to make sure invoices are not double-spentitemRepetition
costs are not properly updated@huumn, this is ready for review now (82d94b2)
here are some showcase videos: https://files.ekzyis.com/public/sn/266-zaps-without-account/
001.mp4 shows the changes for anon users
002.mp4 shows the error handling
003.mp4 shows that stackers can now pay invoices if they don't have enough funds
TODO: