diff --git a/docker-compose.yml b/docker-compose.yml index 48ec6fe..52fe713 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,7 +58,7 @@ services: healthcheck: test: TTL_MINUTES_PREGEN_XPOP=${TTL_MINUTES_PREGEN_XPOP:-60} TTL_DAYS_XPOP_SOURCE_FILES=${TTL_DAYS_XPOP_SOURCE_FILES:-30} sh /cleanup.sh interval: ${TTL_MINUTES_CLEANUP_INTERVAL:-60}m - retries: 0 + retries: 10 timeout: 55m volumes: nginxcache: diff --git a/lib/onTransaction.mjs b/lib/onTransaction.mjs index 60f810c..45fcc52 100644 --- a/lib/onTransaction.mjs +++ b/lib/onTransaction.mjs @@ -2,6 +2,7 @@ import { writeFile } from 'fs' import { dirExists } from './dirExists.mjs' import { ledgerIndexToFolders } from './ledgerIndexToFolders.mjs' import { xpopGenerate } from './xpopGenerate.mjs' +import { createDirectory } from './createDirectory.mjs' import { waitForLedgerReady } from './events/ledgerReady.mjs' import { emit } from '../bin/webserver.mjs' import 'dotenv/config' @@ -68,48 +69,53 @@ const onTransaction = async ({ networkId, txHash: tx.hash, }) - if (await dirExists(xpopBinaryDir)) { - const xpopWritten = await new Promise(resolve => { - writeFile(xpopBinaryDir + '/' + tx.hash, Buffer.from(xpopBinary, 'utf8'), err => { - if (err) { - console.log('Error writing binary XPOP', err) - resolve(false) - } else { - console.log('Wrote binary xPOP: ' + xpopBinaryDir + '/' + tx.hash) - resolve(true) - } - }) + + + if (!(await dirExists(xpopBinaryDir))) { + console.log('(Re-) creating /store/xpop directory') + await createDirectory('store/xpop') + } + + const xpopWritten = await new Promise(resolve => { + writeFile(xpopBinaryDir + '/' + tx.hash, Buffer.from(xpopBinary, 'utf8'), err => { + if (err) { + console.log('Error writing binary XPOP', err) + resolve(false) + } else { + console.log('Wrote binary xPOP: ' + xpopBinaryDir + '/' + tx.hash) + resolve(true) + } }) - if (xpopWritten) { - console.log(' ### EMIT XPOP READY FOR', tx?.Account, Number(tx.Sequence), tx.hash) + }) + if (xpopWritten) { + console.log(' ### EMIT XPOP READY FOR', tx?.Account, Number(tx.Sequence), tx.hash) - txCount++ + txCount++ - return await emit({ - account: tx?.Account, - sequence: tx.Sequence, - origin: { - tx: tx.hash, - networkId: networkId, - ledgerIndex: transaction.ledger_index, - burn: tx?.Fee, - }, - destination: { - networkId: tx?.OperationLimit, - }, - ...( - process.env?.URL_PREFIX - ? { - xpop: { - binary: `${process.env.URL_PREFIX}/xpop/${tx.hash}`, - source: `${process.env.URL_PREFIX}/${networkId}/${ledgerIndexToFolders(transaction.ledger_index)}/`, - blob: xpopBinary, - } + return await emit({ + account: tx?.Account, + sequence: tx.Sequence, + origin: { + tx: tx.hash, + networkId: networkId, + ledgerIndex: transaction.ledger_index, + burn: tx?.Fee, + }, + destination: { + networkId: tx?.OperationLimit, + }, + ...( + process.env?.URL_PREFIX + ? { + xpop: { + binary: `${process.env.URL_PREFIX}/xpop/${tx.hash}`, + source: `${process.env.URL_PREFIX}/${networkId}/${ledgerIndexToFolders(transaction.ledger_index)}/`, + blob: xpopBinary, } - : {} - ) - }) - } + } + : {} + ) + }) } } }