Skip to content

Commit

Permalink
Merge pull request #27 from Samourai-Wallet/fix_pushtx_orchestrator
Browse files Browse the repository at this point in the history
rework external loop of Orchestrator
  • Loading branch information
kenshin-samourai authored Jul 3, 2019
2 parents 7024190 + 36c4216 commit 40f90a2
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pushtx/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,21 @@ class Orchestrator {

Logger.info(`Block ${height} ${blockHash}`)

// Retrieve the transactions triggered by this block
let txs = await db.getActivatedScheduledTransactions(height)

while (txs && txs.length > 0) {
let rpcConnOk = true
let nbTxsPushed
let rpcConnOk = true

do {
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) {
let hasParentTx = (tx.schParentTxid != null) && (tx.schParentTxid != '')
let parentTx = null

// Check if previous transaction has been confirmed
if (hasParentTx) {
try {
Expand Down Expand Up @@ -132,20 +137,15 @@ class Orchestrator {
// Delete the transaction
try {
await db.deleteScheduledTransaction(tx.schTxid)
// Count the transaction as successfully processed
nbTxsPushed++
} catch(e) {
const msg = 'A problem was met while trying to delete a scheduled transaction'
Logger.error(e, `Orchestrator.onBlockHash() : ${msg}`)
}
}
}

// 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)
}
} while (rpcConnOk && nbTxsPushed > 0)

} catch(e) {
Logger.error(e, 'Orchestrator.onBlockHash() : Error')
Expand Down

0 comments on commit 40f90a2

Please sign in to comment.