Skip to content

Commit f4ec079

Browse files
authored
Merge pull request #1070 from PayButton/fix/timeout-prisma
fix: timeout prisma, mempool race conditions & freezing of tx processing upon erroring
2 parents 08a5f41 + 399c465 commit f4ec079

File tree

17 files changed

+1336
-338
lines changed

17 files changed

+1336
-338
lines changed

constants/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const HUMAN_READABLE_DATE_FORMAT = 'YYYY-MM-DD'
166166

167167
export const PRICE_API_DATE_FORMAT = 'YYYY-MM-DD'
168168
export const PRICE_API_TIMEOUT = 40 * 1000 // 40 seconds
169-
export const PRICE_API_MAX_RETRIES = 3
169+
export const PRICE_API_MAX_RETRIES = 1
170170

171171
export const SYNC_TXS_JOBS_MAX_RETRIES = 3
172172
export const SYNC_TXS_JOBS_RETRY_DELAY = 2000
@@ -277,9 +277,9 @@ export const MEMPOOL_PROCESS_DELAY = 100
277277
// On chronik, the max allowed is 200
278278
export const CHRONIK_FETCH_N_TXS_PER_PAGE = 200
279279

280-
export const INITIAL_ADDRESS_SYNC_FETCH_CONCURRENTLY = 512
281-
export const TX_EMIT_BATCH_SIZE = 10_000 // for our generator, not chronik
282-
export const DB_COMMIT_BATCH_SIZE = 10_000 // tamanho dos lotes para commit no DB
280+
export const INITIAL_ADDRESS_SYNC_FETCH_CONCURRENTLY = 128
281+
export const TX_EMIT_BATCH_SIZE = 2_000 // for our generator, not chronik
282+
export const DB_COMMIT_BATCH_SIZE = 2_000 // tamanho dos lotes para commit no DB
283283

284284
export const TRIGGER_POST_CONCURRENCY = 100
285285
export const TRIGGER_EMAIL_CONCURRENCY = 100

jobs/initJobs.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ import { syncCurrentPricesWorker, syncBlockchainAndPricesWorker, cleanupClientPa
77
EventEmitter.defaultMaxListeners = 20
88

99
const main = async (): Promise<void> => {
10+
// --- force fresh start ---
1011
const pricesQueue = new Queue('pricesSync', { connection: redisBullMQ })
12+
const blockchainQueue = new Queue('blockchainSync', { connection: redisBullMQ })
13+
const cleanupQueue = new Queue('clientPaymentCleanup', { connection: redisBullMQ })
14+
15+
await pricesQueue.obliterate({ force: true })
16+
await blockchainQueue.obliterate({ force: true })
17+
await cleanupQueue.obliterate({ force: true })
18+
1119
await pricesQueue.add('syncCurrentPrices',
1220
{},
1321
{
@@ -21,18 +29,23 @@ const main = async (): Promise<void> => {
2129

2230
await syncCurrentPricesWorker(pricesQueue.name)
2331

24-
const blockchainQueue = new Queue('blockchainSync', { connection: redisBullMQ })
25-
await blockchainQueue.add('syncBlockchainAndPrices', {}, { jobId: 'syncBlockchainAndPrices' })
32+
await blockchainQueue.add('syncBlockchainAndPrices',
33+
{},
34+
{
35+
jobId: 'syncBlockchainAndPrices',
36+
removeOnComplete: true,
37+
removeOnFail: true
38+
}
39+
)
2640
await syncBlockchainAndPricesWorker(blockchainQueue.name)
2741

28-
const cleanupQueue = new Queue('clientPaymentCleanup', { connection: redisBullMQ })
29-
3042
await cleanupQueue.add(
3143
'cleanupClientPayments',
3244
{},
3345
{
3446
jobId: 'cleanupClientPayments',
35-
removeOnFail: false,
47+
removeOnComplete: true,
48+
removeOnFail: true,
3649
repeat: {
3750
every: CLIENT_PAYMENT_EXPIRATION_TIME
3851
}

jobs/workers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ export const syncBlockchainAndPricesWorker = async (queueName: string): Promise<
5656
})
5757

5858
worker.on('failed', (job, err) => {
59-
if (job != null) {
60-
console.error(`job ${job.id as string}: FAILED — ${err.message}`)
61-
}
59+
void (async () => {
60+
if (job != null) {
61+
console.error(`job ${job.id as string}: FAILED — ${err.message}`)
62+
}
63+
await multiBlockchainClient.destroy()
64+
})()
6265
})
6366
}
6467

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"xecaddrjs": "^0.0.1"
7373
},
7474
"devDependencies": {
75-
"@types/jest": "^27.5.1",
75+
"@types/jest": "^30.0.0",
7676
"@types/node": "^12.0.12",
7777
"@types/nodemailer": "^6.4.16",
7878
"@types/react": "^16.9.44",

prisma-local/seeds/prices.csv

Lines changed: 480 additions & 2 deletions
Large diffs are not rendered by default.

prisma-local/seeds/prices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function createPricesFile (): Promise<void> {
3333
const prices: PriceFileData[] = []
3434

3535
await Promise.all(Object.values(NETWORK_TICKERS).map(async (networkTicker) => {
36-
const pricesByNetworkTicker = await getAllPricesByNetworkTicker(networkTicker)
36+
const pricesByNetworkTicker = await getAllPricesByNetworkTicker(networkTicker, true)
3737

3838
pricesByNetworkTicker?.forEach(price => {
3939
if (isEmpty(price.Price_in_CAD) || isEmpty(price.Price_in_USD)) { throw new Error(`Price came back with at least one quote empty from API: ${JSON.stringify(price)}`) }

prisma-local/seeds/productionTxs.csv

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131466,4 +131466,8 @@ fe95acd641f4ced15eb81dbfeb508124c322f8ca6cbb8e1868ea6024fcba3574,1000119.19,1754
131466131466
baba23425aa5e5bb5c3b2b1b3e9a7f30dd4fe333f58be276700be85ff2cf49f0,1000023.22,1754861586,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131467131467
39c84db94eb3c7d9e9b9307060a840ba36dbefeb4add2713f81f911d7bcc3a3f,1000152.16,1754861467,d1266537-9c17-4ec5-b09f-b05a81811c60,truefb2dce1149b2a9a1722954c931964a061704a06910682e6ddd6f676e1c01e0af,1000043.31,1754947609,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131468131468
2db424bd1ae48962d0a2eea6bdf6d21fa02af129e7d54d8ecda02511d7d3760a,1000131.92,1754946651,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131469-
eedd73ccf42e75872329a68f2cc0a98513bf58ad0fe8c2314c5a7ea5bb3430a3,1000035.45,1754946080,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131469+
eedd73ccf42e75872329a68f2cc0a98513bf58ad0fe8c2314c5a7ea5bb3430a3,1000035.45,1754946080,d1266537-9c17-4ec5-b09f-b05a81811c60,true924125cf4bb5cbe292d7a1f9a78ea2b03daeac23af8d5b51e8f122ca6dc21ebb,1000030.75,1761165795,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131470+
298aa89e9d0e352492386d4e35f1f53135e6e79d6abdd2043cfcb73ef4e73fec,1000000,1761165132,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131471+
746ad0dde27297c0c29f0e844b488fd06abdc5091e678a2a0e1b0b5c1d5efbd1,1000036.53,1761165079,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131472+
d0180fa8ffb28760f64bdadb2fd7289196f003cd27a2adcee6e6419e848c1597,1000000,1761164173,d1266537-9c17-4ec5-b09f-b05a81811c60,true
131473+
f9f64587e7f7b11f771e130455b59fd84e5a3422215ac1f08505418fd395dc07,1000068.28,1761164139,d1266537-9c17-4ec5-b09f-b05a81811c60,true7e6312169483006fec8d6d1d9d4311c82f3334be4c58fe4a188cbc9e088de75c,1000716.35,1761169691,d1266537-9c17-4ec5-b09f-b05a81811c60,true

scripts/updateAllPriceConnections.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ async function fixMisconnectedTxs (): Promise<void> {
5858
select: {
5959
price: {
6060
select: {
61-
timestamp: true
61+
timestamp: true,
62+
networkId: true
6263
}
6364
}
6465
}

0 commit comments

Comments
 (0)