Browse Source

Merge pull request #27 from Samourai-Wallet/fix_pushtx_orchestrator

rework external loop of Orchestrator
feat-mydojo_upgrade_explorer
kenshin samourai 5 years ago
committed by GitHub
parent
commit
40f90a29a1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      pushtx/orchestrator.js

28
pushtx/orchestrator.js

@ -82,16 +82,21 @@ class Orchestrator {
Logger.info(`Block ${height} ${blockHash}`) Logger.info(`Block ${height} ${blockHash}`)
// Retrieve the transactions triggered by this block let nbTxsPushed
let txs = await db.getActivatedScheduledTransactions(height) let rpcConnOk = true
while (txs && txs.length > 0) { do {
let rpcConnOk = true nbTxsPushed = 0
// Retrieve the transactions triggered by this block
let txs = await db.getActivatedScheduledTransactions(height)
if (!(txs && txs.length > 0))
break
for (let tx of txs) { for (let tx of txs) {
let hasParentTx = (tx.schParentTxid != null) && (tx.schParentTxid != '') let hasParentTx = (tx.schParentTxid != null) && (tx.schParentTxid != '')
let parentTx = null let parentTx = null
// Check if previous transaction has been confirmed // Check if previous transaction has been confirmed
if (hasParentTx) { if (hasParentTx) {
try { try {
@ -132,20 +137,15 @@ class Orchestrator {
// Delete the transaction // Delete the transaction
try { try {
await db.deleteScheduledTransaction(tx.schTxid) await db.deleteScheduledTransaction(tx.schTxid)
// Count the transaction as successfully processed
nbTxsPushed++
} catch(e) { } catch(e) {
const msg = 'A problem was met while trying to delete a scheduled transaction' const msg = 'A problem was met while trying to delete a scheduled transaction'
Logger.error(e, `Orchestrator.onBlockHash() : ${msg}`) Logger.error(e, `Orchestrator.onBlockHash() : ${msg}`)
} }
} }
} }
} while (rpcConnOk && nbTxsPushed > 0)
// If a connection issue was detected, then stop the loop
if (!rpcConnOk)
break
// Check if more transactions have to be pushed
txs = await db.getActivatedScheduledTransactions(height)
}
} catch(e) { } catch(e) {
Logger.error(e, 'Orchestrator.onBlockHash() : Error') Logger.error(e, 'Orchestrator.onBlockHash() : Error')

Loading…
Cancel
Save