stackernews / stacker.news

Internet communities that pay you Bitcoin
https://stacker.news
MIT License
403 stars 105 forks source link

Donate sats forwarded to anon #1233

Closed ekzyis closed 2 weeks ago

ekzyis commented 2 weeks ago

Description

Fix #1232 by donating any sats forwarded to anon.

Diff of item_act function:

@@ -61,6 +61,11 @@ BEGIN
             UPDATE users
             SET msats = msats + fwd_msats, "stackedMsats" = "stackedMsats" + fwd_msats
             WHERE id = fwd_entry."userId";
+
+            IF fwd_entry."userId" = 27 THEN
+                -- anon forwards go to rewards as donations
+                PERFORM donate((fwd_msats / 1000)::INTEGER, "fwd_entry"."userId");
+            END IF;
         END LOOP;

         -- Give OP any remaining msats after forwards have been applied

Additional Context

I initially wanted to include anon forwards in anon's stack in rewards. However, after looking in the code and considering the required changes, I think it's better to simply show them as donations.

I considered following approaches:

1. no changes to rewards query

In item_act, pretend that anon was zapped instead of adding forwarded sats to anon's balance. This would mean adding a row to ItemAct. But this would then mean that for anon forwards, three ItemAct rows are inserted (2x TIP + FEE) with their msats sum being higher than the zap itself. This might break some assumptions in queries but decreasing the amount of msats for the original TIP might as well.

So this approach seems to complicated for this requirement.

2. changes to rewards query

We could add a column forwarded to the Donations table. Donations as part of anon forwards are marked with forwarded whereas normal donations are not. We then query the rows with forwarded set separately as part of anon's stack in the rewards query. This is a lot simpler but adds a column to Donations for something very specific.

Checklist

Are your changes backwards compatible? Please answer below:

Yes

Did you QA this? Could we deploy this straight to production? Please answer below:

tACK 3ca6fe1e

For frontend changes: Tested on mobile? Please answer below:

Did you introduce any new environment variables? If so, call them out explicitly here:

No

ekzyis commented 2 weeks ago

Only 5016 sats were forwarded to anon:

SELECT SUM(msats * pct / 100) FROM "ItemForward"
JOIN "Item" ON "Item"."id" = "ItemForward"."itemId"
WHERE "ItemForward"."userId" = 27;

-- returns 5,015,980 as of today

Since anon zaps were included in rewards, rewards only missed these 5k sats.

ekzyis commented 2 weeks ago

Closing because this conflicts with #1195 so we will wait for #1195