Skip to content

Commit

Permalink
Merge pull request #106 from hodlforjesus/fb-detailed-rewards
Browse files Browse the repository at this point in the history
Improved cron block locking
  • Loading branch information
hodlforjesus authored Jun 2, 2019
2 parents eeaa2cf + 4830b03 commit 7aeb7fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions cron/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function syncBlocks(start, stop, clean = false) {
let vinsCount = 0;
let voutsCount = 0;

// Notice how we're ensuring to only use a single rpc call with forEachSeries()
await forEachSeries(block.txs, async (txhash) => {
const rpctx = await util.getTX(txhash, true);

Expand Down Expand Up @@ -157,6 +158,7 @@ async function update() {

// If nothing to do then exit.
if (dbHeight >= rpcHeight) {
locker.unlock(type); // Be sure to properly unlock cron
return;
}
// If starting from genesis skip.
Expand All @@ -165,16 +167,12 @@ async function update() {
}

await syncBlocks(dbHeight, rpcHeight, clean);

locker.unlock(type); // It is important that we keep proper lock during syncing otherwise there will be blockchain data corruption and we can't be sure of integrity
} catch (err) {
console.log(err);
code = 1;
} finally {
try {
locker.unlock(type);
} catch (err) {
console.log(err);
code = 1;
}
exit(code);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/locker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const lock = (type) => {
if (found) {
throw new Error(`
Lock found for '${ type }', cron may already be running.
If not already running remove ${ type }.cron_lock and try again.
If not already running 'rm ${p}' to remove 'tmp/${ type }.cron_lock' file and try again.
`);
}

Expand Down

0 comments on commit 7aeb7fc

Please sign in to comment.