fix: Increase transaction confirmation timeout to 60s for Alchemy Growth

- Alchemy Growth (10,000 CU/s) can handle longer confirmation waits
- Increased timeout from 30s to 60s in both openPosition() and closePosition()
- Added debug logging to execute endpoint to trace hang points
- Configured dual RPC: Alchemy primary (transactions), Helius fallback (subscriptions)
- Previous 30s timeout was causing premature failures during Solana congestion
- This should resolve 'Transaction was not confirmed in 30.00 seconds' errors

Related: User reported n8n webhook returning 500 with timeout error
This commit is contained in:
mindesbunister
2025-11-14 20:42:59 +01:00
parent 6dccea5d91
commit 78ab9e1a94
3 changed files with 42 additions and 10 deletions

View File

@@ -146,11 +146,18 @@ export async function openPosition(
console.log(`📝 Transaction submitted: ${txSig}`)
// CRITICAL: Confirm transaction actually executed on-chain
console.log('⏳ Confirming transaction on-chain...')
console.log('⏳ Confirming transaction on-chain (60s timeout for Alchemy Growth)...')
const connection = driftService.getConnection()
try {
const confirmation = await connection.confirmTransaction(txSig, 'confirmed')
// Increased timeout from 30s to 60s for Alchemy Growth reliability
// Alchemy Growth (10,000 CU/s) can handle longer waits without timing out
const confirmationPromise = connection.confirmTransaction(txSig, 'confirmed')
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Transaction confirmation timeout')), 60000)
)
const confirmation = await Promise.race([confirmationPromise, timeoutPromise]) as any
if (confirmation.value.err) {
console.error(`❌ Transaction failed on-chain:`, confirmation.value.err)
@@ -558,13 +565,14 @@ export async function closePosition(
// CRITICAL: Confirm transaction on-chain to prevent phantom closes
// BUT: Use timeout to prevent API hangs during network congestion
console.log('⏳ Confirming transaction on-chain (30s timeout)...')
console.log('⏳ Confirming transaction on-chain (60s timeout for Alchemy Growth)...')
const connection = driftService.getConnection()
try {
// Increased timeout from 30s to 60s for Alchemy Growth reliability
const confirmationPromise = connection.confirmTransaction(txSig, 'confirmed')
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Transaction confirmation timeout')), 30000)
setTimeout(() => reject(new Error('Transaction confirmation timeout')), 60000)
)
const confirmation = await Promise.race([confirmationPromise, timeoutPromise]) as any
@@ -577,7 +585,7 @@ export async function closePosition(
console.log('✅ Transaction confirmed on-chain')
} catch (timeoutError: any) {
if (timeoutError.message === 'Transaction confirmation timeout') {
console.warn('⚠️ Transaction confirmation timed out after 30s')
console.warn('⚠️ Transaction confirmation timed out after 60s')
console.warn(' Order may still execute - check Drift UI')
console.warn(` Transaction signature: ${txSig}`)
// Continue anyway - order was submitted and will likely execute
@@ -654,7 +662,7 @@ export async function closePosition(
async function retryWithBackoff<T>(
fn: () => Promise<T>,
maxRetries: number = 3,
baseDelay: number = 5000 // Increased from 2s to 5s: 5s → 10s → 20s progression
baseDelay: number = 8000 // Increased from 5s to 8s: 8s → 16s → 32s progression for better RPC recovery
): Promise<T> {
const startTime = Date.now()