@ -78,7 +78,7 @@ class BlockchainProcessor extends AbstractProcessor {
* /
* /
async catchupIBDMode ( ) {
async catchupIBDMode ( ) {
try {
try {
Logger . info ( 'Tracker Startup (IBD mode)' )
Logger . info ( 'Tracker : Tracker Startup (IBD mode)' )
const info = await this . client . getblockchaininfo ( )
const info = await this . client . getblockchaininfo ( )
const daemonNbBlocks = info . blocks
const daemonNbBlocks = info . blocks
@ -91,7 +91,7 @@ class BlockchainProcessor extends AbstractProcessor {
// If no header or block loaded by bitcoind => try later
// If no header or block loaded by bitcoind => try later
if ( daemonNbHeaders == 0 || daemonNbBlocks == 0 ) {
if ( daemonNbHeaders == 0 || daemonNbBlocks == 0 ) {
Logger . info ( 'New attempt scheduled in 30s (waiting for block headers)' )
Logger . info ( 'Tracker : New attempt scheduled in 30s (waiting for block headers)' )
return util . delay ( 30000 ) . then ( ( ) => {
return util . delay ( 30000 ) . then ( ( ) => {
return this . catchupIBDMode ( )
return this . catchupIBDMode ( )
} )
} )
@ -101,7 +101,7 @@ class BlockchainProcessor extends AbstractProcessor {
// If blocks need to be downloaded by bitcoind => try later
// If blocks need to be downloaded by bitcoind => try later
if ( daemonNbBlocks - 1 <= dbMaxHeight ) {
if ( daemonNbBlocks - 1 <= dbMaxHeight ) {
Logger . info ( 'New attempt scheduled in 10s (waiting for blocks)' )
Logger . info ( 'Tracker : New attempt scheduled in 10s (waiting for blocks)' )
return util . delay ( 10000 ) . then ( ( ) => {
return util . delay ( 10000 ) . then ( ( ) => {
return this . catchupIBDMode ( )
return this . catchupIBDMode ( )
} )
} )
@ -110,7 +110,7 @@ class BlockchainProcessor extends AbstractProcessor {
} else {
} else {
const blockRange = _ . range ( dbMaxHeight + 1 , daemonNbBlocks + 1 )
const blockRange = _ . range ( dbMaxHeight + 1 , daemonNbBlocks + 1 )
Logger . info ( ` Sync ${ blockRange . length } blocks ` )
Logger . info ( ` Tracker : Sync ${ blockRange . length } blocks ` )
await util . seriesCall ( blockRange , async height => {
await util . seriesCall ( blockRange , async height => {
try {
try {
@ -118,13 +118,13 @@ class BlockchainProcessor extends AbstractProcessor {
const header = await this . client . getblockheader ( blockHash , true )
const header = await this . client . getblockheader ( blockHash , true )
prevBlockId = await this . processBlockHeader ( header , prevBlockId )
prevBlockId = await this . processBlockHeader ( header , prevBlockId )
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.catchupIBDMode()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.catchupIBDMode()' )
process . exit ( )
process . exit ( )
}
}
} , 'Tracker syncing' , true )
} , 'Tracker syncing' , true )
// Schedule a new iteration (in case more blocks need to be loaded)
// Schedule a new iteration (in case more blocks need to be loaded)
Logger . info ( 'Start a new iteration' )
Logger . info ( 'Tracker : Start a new iteration' )
return this . catchupIBDMode ( )
return this . catchupIBDMode ( )
}
}
@ -134,7 +134,7 @@ class BlockchainProcessor extends AbstractProcessor {
}
}
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.catchupIBDMode()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.catchupIBDMode()' )
throw e
throw e
}
}
}
}
@ -149,7 +149,7 @@ class BlockchainProcessor extends AbstractProcessor {
* /
* /
async catchupNormalMode ( ) {
async catchupNormalMode ( ) {
try {
try {
Logger . info ( 'Tracker Startup (normal mode)' )
Logger . info ( 'Tracker : Tracker Startup (normal mode)' )
const info = await this . client . getblockchaininfo ( )
const info = await this . client . getblockchaininfo ( )
const daemonNbBlocks = info . blocks
const daemonNbBlocks = info . blocks
@ -162,7 +162,7 @@ class BlockchainProcessor extends AbstractProcessor {
// Compute blocks range to be processed
// Compute blocks range to be processed
const blockRange = _ . range ( highest . blockHeight , daemonNbBlocks + 1 )
const blockRange = _ . range ( highest . blockHeight , daemonNbBlocks + 1 )
Logger . info ( ` Sync ${ blockRange . length } blocks ` )
Logger . info ( ` Tracker : Sync ${ blockRange . length } blocks ` )
// Process the blocks
// Process the blocks
return util . seriesCall ( blockRange , async height => {
return util . seriesCall ( blockRange , async height => {
@ -171,13 +171,13 @@ class BlockchainProcessor extends AbstractProcessor {
const header = await this . client . getblockheader ( hash )
const header = await this . client . getblockheader ( hash )
return this . processBlock ( header )
return this . processBlock ( header )
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.catchupNormalMode()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.catchupNormalMode()' )
process . exit ( )
process . exit ( )
}
}
} , 'Tracker syncing' , true )
} , 'Tracker syncing' , true )
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.catchupNormalMode()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.catchupNormalMode()' )
}
}
}
}
@ -196,11 +196,11 @@ class BlockchainProcessor extends AbstractProcessor {
this . onBlockHash ( message )
this . onBlockHash ( message )
break
break
default :
default :
Logger . info ( topic . toString ( ) )
Logger . info ( ` Tracker : ${ topic . toString ( ) } ` )
}
}
} )
} )
Logger . info ( 'Listening for blocks' )
Logger . info ( 'Tracker : Listening for blocks' )
}
}
/ * *
/ * *
@ -241,11 +241,11 @@ class BlockchainProcessor extends AbstractProcessor {
try {
try {
const header = await this . client . getblockheader ( blockHash , true )
const header = await this . client . getblockheader ( blockHash , true )
Logger . info ( ` Block # ${ header . height } ${ blockHash } ` )
Logger . info ( ` Tracker : Block #${ header . height } ${ blockHash } ` )
// Grab all headers between this block and last known
// Grab all headers between this block and last known
headers = await this . chainBacktrace ( [ header ] )
headers = await this . chainBacktrace ( [ header ] )
} catch ( err ) {
} catch ( err ) {
Logger . error ( err , ` BlockchainProcessor.onBlockHash() : error in getblockheader( ${ blockHash } ) ` )
Logger . error ( err , ` Tracker : BlockchainProcessor.onBlockHash() : error in getblockheader(${ blockHash } ) ` )
}
}
if ( headers == null )
if ( headers == null )
@ -267,7 +267,7 @@ class BlockchainProcessor extends AbstractProcessor {
} )
} )
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.onBlockHash()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.onBlockHash()' )
} finally {
} finally {
// Release the semaphor
// Release the semaphor
await this . _ onBlockHashSemaphor . release ( )
await this . _ onBlockHashSemaphor . release ( )
@ -285,7 +285,7 @@ class BlockchainProcessor extends AbstractProcessor {
const deepest = headers [ headers . length - 1 ]
const deepest = headers [ headers . length - 1 ]
if ( headers . length > 1 )
if ( headers . length > 1 )
Logger . info ( ` chainBacktrace @ height ${ deepest . height } , ${ headers . length } blocks ` )
Logger . info ( ` Tracker : chainBacktrace @ height ${ deepest . height } , ${ headers . length } blocks ` )
// Look for previous block in the database
// Look for previous block in the database
const block = await db . getBlockByHash ( deepest . previousblockhash )
const block = await db . getBlockByHash ( deepest . previousblockhash )
@ -313,7 +313,7 @@ class BlockchainProcessor extends AbstractProcessor {
if ( txs . length > 0 ) {
if ( txs . length > 0 ) {
// Cancel confirmation of transactions included in reorg'd blocks
// Cancel confirmation of transactions included in reorg'd blocks
Logger . info ( ` Backtrace: unconfirm ${ txs . length } transactions in reorg ` )
Logger . info ( ` Tracker : Backtrace: unconfirm ${ txs . length } transactions in reorg ` )
const txids = txs . map ( t => t . txnTxid )
const txids = txs . map ( t => t . txnTxid )
await db . unconfirmTransactions ( txids )
await db . unconfirmTransactions ( txids )
}
}
@ -345,12 +345,12 @@ class BlockchainProcessor extends AbstractProcessor {
// Process the blocks
// Process the blocks
return util . seriesCall ( blockRange , async height => {
return util . seriesCall ( blockRange , async height => {
try {
try {
Logger . info ( ` Rescanning block ${ height } ` )
Logger . info ( ` Tracker : Rescanning block ${ height } ` )
const hash = await this . client . getblockhash ( height )
const hash = await this . client . getblockhash ( height )
const header = await this . client . getblockheader ( hash )
const header = await this . client . getblockheader ( hash )
return this . processBlock ( header )
return this . processBlock ( header )
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.rescan()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.rescan()' )
throw e
throw e
}
}
} , 'Tracker rescan' , true )
} , 'Tracker rescan' , true )
@ -379,7 +379,7 @@ class BlockchainProcessor extends AbstractProcessor {
} catch ( e ) {
} catch ( e ) {
// The show must go on.
// The show must go on.
// TODO: further notification that this block did not check out
// TODO: further notification that this block did not check out
Logger . error ( e , 'BlockchainProcessor.processBlock()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.processBlock()' )
}
}
}
}
@ -394,7 +394,7 @@ class BlockchainProcessor extends AbstractProcessor {
const block = new Block ( null , header )
const block = new Block ( null , header )
return block . checkBlockHeader ( prevBlockID )
return block . checkBlockHeader ( prevBlockID )
} catch ( e ) {
} catch ( e ) {
Logger . error ( e , 'BlockchainProcessor.processBlockHeader()' )
Logger . error ( e , 'Tracker : BlockchainProcessor.processBlockHeader()' )
throw e
throw e
}
}
}
}