Skip to content

Commit bac055c

Browse files
authored
remodel paid actions schema (#2084)
* basic wip schema additions * WIP execution logic * invoice wrapping/creation flow * conceptually working state machine * lots of state machine work * more declaritive payIn modules * refactor zap * wip approach to retries * decent retry logic * conceptually coherent modules and retry logic * wip * wip * wip * some work on clientside payins * make custodial purchase of cowboy credits work * make custodial donations work * working intitialization for proxy payments * wip payIn worker parts * fixes to state machine * more concise error block for invoice creation * successful proxy payment * custodial item creation * small improvements to item payins * make item update action work * make vanilla custodial zaps not fail * make custodial downzaps work * custodial boost without benefactor + share payout logic * update untested payIns with new abstractions * add todo about dealing with row-level deadlocks * add another option for dealing with row-level deadlocks * more comments about deadlocks * add initial solutions for payIn deadlocks * custodial poll vote pay in (+ post creation) * invite gift pay in works * custodial territory create/update payIn working * territory unarchive * territory billing works * improve withdrawals * squash db migrations * make autowithdraw work * bolt11 drop through payOutBolt11 * pessimistic qr payment happy path working * improve invoice status * fix optimistic responses for payIn * fix boost describe * fix itemCreate describe * cancel payInBolt11 * pessimistic item creation and anon create/edits * migrate cron bolt11 check * payment state presentation * immutable-ish custodial retries for item creation - manual with function UI * fix edit timer * wip non-custodial retries * improvements and fixes to manual retries * fix pessimistic actions * convert poll vote to pessimistic payIn * fixes for poll voting and pessimistic payIns * notification dot for failed payIns * resolver/worker upgrade to payins (excepting satistics and wallets pages) * fix comment recent sorting * wip satsstics * mtokens after rather than before * format cost differently * more UI improvements * fix commenting cache update * basic transaction page * more transaction work * nearly there transaction and satistics pages * use decimal in tables * improve satistics/transaction views again * wip autoretry * auto retries * untested rewards port to pay ins * refinements * notifications for payments and withdrawals, start deleting stuff * delete unused invoice fragments * todoing: checkPayInInvoiceCreation job * fix master merge * fix rewards queries * todoing: incoming invoices are always a multiple of 1000msats * todoing: audit comment todos * todoing: add asserts on pay in creation * more comments for custodial spending logic * todoing: squash migrations, refine schema, add constraints on sats values, triggers on dependent fields * payin skeletons * todoing: subtree exclusion for private fields * fix up rewards a bit * fix routing fee refund and handle overpaid invoices * handle territory switching items * fix fee button on sub change * routing fee privacy * make media uploads a composable payin, other fixes and refinements * enhancements * begin deleting paidAction code * fallback to CCs on relatively terminal failures * todoing: wallet logs (untested), lnurl-withdrawal (also untested) * migrate to payin 1st pass * add migration todo * update readme * create ledger entries for custodial refunds on failure, support crazy payIn queries, add indices * distinguish custodial refunds from premtive payments in statistics * squash pay in schema additions * improvments to satistics, other fixes * refinemenets * cursor bot's suggestions * unsatisfying checkpoint: temp tables for mapping and small batches are not enough * try reorganizing migrations * try full migration * make migrations fast * fixes * migration and other fixes * check for invoice creation on pessmistic pay ins * small fixes * vibed tests - most working (not reviewed) * vibed tests all passing (not reviewed) * separate view and funcs * simple aggregates for pay ins * fix pay in aggregate group mask * replace view aggregations with incremental idempotent refresh tables (no charts yet) * wip new aggregates (nearly done) * fix missing referral acts * finish aggregates * make sure there's always a payOut for subs * fix satistics pagination * make defunct referrals query not throw * remove a debug log stmt and improve sankey margin * fix a smattering of stuff * fix github runners * improve deadlock minimization * improve comments related to hypothetical pipelining * fix cache updating on retries * fix cache updates for retries * run onPayError when performing retry/fallback * fix retry cache updates * within autoretry window, display optimistic states even on SSR * make pending boost show on retries * cache fixes for retries * fix missing payouts when obtaining locks onPaid * fix timezone in analytics charts * remove referral counts for this pr * use hourly granularity for active rewards page * fix territory billing autorenew * for sankey return relations of beneficiary payouts * fix time range for chart time/type grid * fix outdated satistics link * some fixes for rewards * fix up rewards * pedantic pending checks and refine edge case transitions * lint fixes * call the right onPaidSideEffects function * fix send/receive order on satistics page * transition beneficiaries with benefactor * fix payInBolt11 in sankey for invoice overpay spillover * fix paid manual retry display in notifications * suppress hydration warning of territory header * fix msats spending when full mcredits can be spent in partial custodial payment * relieve unecessary, routine lock contention pressure outside of payIns * fix missing noncustodial paid side effect call * rearrange analytics charts * allow territory billing to be adjusted to shorter duration * fix editting unpaid items * fix skip lock notification optimizations * fix wait controller calls * mute invoice expire timer * fix proxy payment notification * enforce wallet fallback limit in failure notifications * return error enum on wrap failures * include territory when cloning on retry * refine retry behavior of noncustodial zaps * refine/ugly failing receiver zap cases * fix boost msats/sats conversion * refine rewards * fix territory item sort * fix and refine state machine edge cases * minor cleanup * remove debug log statements * fix some of the aggregates * remove log statement * remove unused fragment and debug log * remove cache logging * fix poll count for unpaid pay ins * fix upload threshold * create special check for pending withdrawals * suppress hydration warning of poll text * remove defunct comment
1 parent 6762fc0 commit bac055c

File tree

227 files changed

+16741
-8187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+16741
-8187
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ In addition, we run other critical services the above services interact with lik
537537

538538
To ensure stackers balances are kept sane, some wallet updates are run in [serializable transactions](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE) at the database level. Because early versions of prisma had relatively poor support for transactions most wallet touching code is written in [plpgsql](https://www.postgresql.org/docs/current/plpgsql.html) stored procedures and can be found in the `prisma/migrations` folder.
539539

540-
*UPDATE*: Most wallet updates are now run in [read committed](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-READ-COMMITTED) transactions. See `api/paidAction/README.md` for more information.
540+
*UPDATE*: Most wallet updates are now run in [read committed](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-READ-COMMITTED) transactions. See `api/payIn/README.md` for more information.
541541

542542
<br>
543543

api/lnd/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { cachedFetcher } from '@/lib/fetch'
22
import { toPositiveNumber } from '@/lib/format'
33
import { authenticatedLndGrpc } from '@/lib/lnd'
44
import { getIdentity, getHeight, getWalletInfo, getNode, getPayment, parsePaymentRequest } from 'ln-service'
5-
import { datePivot } from '@/lib/time'
6-
import { LND_PATHFINDING_TIMEOUT_MS } from '@/lib/constants'
75

86
const lnd = global.lnd || authenticatedLndGrpc({
97
cert: process.env.LND_CERT,
@@ -179,13 +177,11 @@ export const getNodeSockets = cachedFetcher(async function fetchNodeSockets ({ l
179177
}
180178
})
181179

182-
export async function getPaymentOrNotSent ({ id, lnd, createdAt }) {
180+
export async function getPaymentOrNotSent ({ id, lnd }) {
183181
try {
184182
return await getPayment({ id, lnd })
185183
} catch (err) {
186-
if (err[1] === 'SentPaymentNotFound' &&
187-
createdAt < datePivot(new Date(), { milliseconds: -LND_PATHFINDING_TIMEOUT_MS * 2 })) {
188-
// if the payment is older than 2x timeout, but not found in LND, we can assume it errored before lnd stored it
184+
if (err[1] === 'SentPaymentNotFound') {
189185
return { notSent: true, is_failed: true }
190186
} else {
191187
throw err

api/paidAction/README.md

Lines changed: 0 additions & 371 deletions
This file was deleted.

api/paidAction/boost.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

api/paidAction/buyCredits.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

api/paidAction/donate.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

api/paidAction/downZap.js

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)