-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Automated retries #1776
Open
ekzyis
wants to merge
10
commits into
master
Choose a base branch
from
automated-retries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Automated retries #1776
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b781b0
Poll failed invoices with visibility timeout
ekzyis e7e144c
Don't return intermediate failed invoices
ekzyis 40328dd
Don't retry too old invoices
ekzyis 3fbb57f
Retry invoices on client
ekzyis 305448e
Only attempt payment 3 times
ekzyis bc31ffa
Fix fallbacks during last retry
ekzyis 42019eb
Rename retry column to paymentAttempt
ekzyis 1c35c5f
Fix no index used
ekzyis 98b6447
Resolve TODOs
ekzyis 15c799d
Use expiring locks
ekzyis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
prisma/migrations/20250107084543_automated_retries/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- AlterTable | ||
ALTER TABLE "Invoice" ADD COLUMN "paymentAttempt" INTEGER NOT NULL DEFAULT 0; | ||
ALTER TABLE "Invoice" ADD COLUMN "lockedAt" TIMESTAMP(3); | ||
CREATE INDEX "Invoice_cancelledAt_idx" ON "Invoice"("cancelledAt"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { useMe } from '@/components/me' | ||
import { SET_WALLET_PRIORITY, WALLETS } from '@/fragments/wallet' | ||
import { SSR } from '@/lib/constants' | ||
import { FAILED_INVOICES, SET_WALLET_PRIORITY, WALLETS } from '@/fragments/wallet' | ||
import { NORMAL_POLL_INTERVAL, SSR } from '@/lib/constants' | ||
import { useApolloClient, useMutation, useQuery } from '@apollo/client' | ||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react' | ||
import { getStorageKey, getWalletByType, walletPrioritySort, canSend, isConfigured, upsertWalletVariables, siftConfig, saveWalletLocally } from './common' | ||
import useVault from '@/components/vault/use-vault' | ||
import walletDefs from '@/wallets/client' | ||
import { generateMutation } from './graphql' | ||
import { useWalletPayment } from './payment' | ||
import useInvoice from '@/components/use-invoice' | ||
|
||
const WalletsContext = createContext({ | ||
wallets: [] | ||
|
@@ -204,7 +206,9 @@ export function WalletsProvider ({ children }) { | |
removeLocalWallets | ||
}} | ||
> | ||
{children} | ||
<RetryHandler> | ||
{children} | ||
</RetryHandler> | ||
Comment on lines
+209
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For example, we could put all providers for the carousel (price, block height, chain fee) into the same component. |
||
</WalletsContext.Provider> | ||
) | ||
} | ||
|
@@ -221,7 +225,36 @@ export function useWallet (name) { | |
export function useSendWallets () { | ||
const { wallets } = useWallets() | ||
// return all enabled wallets that are available and can send | ||
return wallets | ||
return useMemo(() => wallets | ||
.filter(w => !w.def.isAvailable || w.def.isAvailable()) | ||
.filter(w => w.config?.enabled && canSend(w)) | ||
.filter(w => w.config?.enabled && canSend(w)), [wallets]) | ||
} | ||
|
||
function RetryHandler ({ children }) { | ||
const failedInvoices = useFailedInvoices() | ||
const waitForWalletPayment = useWalletPayment() | ||
const invoiceHelper = useInvoice() | ||
|
||
useEffect(() => { | ||
(async () => { | ||
for (const invoice of failedInvoices) { | ||
const newInvoice = await invoiceHelper.retry(invoice) | ||
waitForWalletPayment(newInvoice).catch(console.error) | ||
} | ||
})() | ||
}, [failedInvoices, invoiceHelper, waitForWalletPayment]) | ||
|
||
return children | ||
} | ||
|
||
function useFailedInvoices () { | ||
const wallets = useSendWallets() | ||
|
||
const { data } = useQuery(FAILED_INVOICES, { | ||
pollInterval: NORMAL_POLL_INTERVAL, | ||
skip: wallets.length === 0, | ||
notifyOnNetworkStatusChange: true | ||
}) | ||
|
||
return data?.failedInvoices ?? [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
useMemo
and the one inuseSendWallets
is pretty important since it avoids thatwaitForWalletPayment
changes between renders which would mean that we run theuseEffect
for retries with the same failed invoices multiple times.In general, this means it is very important that
waitForWalletPayment
is stable across renders.