@@ -361,43 +361,49 @@ class BlockchainNode {
361
361
startNode ( isFirstNode ) {
362
362
const LOG_HEADER = 'startNode' ;
363
363
364
- // 1. Initialize DB (with the latest snapshot, if it exists)
365
- logger . info (
366
- `[${ LOG_HEADER } ] Initializing DB with bootstrap snapshot from ${ this . bootstrapSnapshotSource } ..` ) ;
367
- const startingDb = DB . create (
368
- StateVersions . EMPTY , StateVersions . START , this . bc , true , this . bootstrapSnapshotBlockNumber ,
369
- this . stateManager ) ;
370
- startingDb . initDb ( this . bootstrapSnapshot ) ;
364
+ try {
365
+ // 1. Initialize DB (with the latest snapshot, if it exists)
366
+ logger . info (
367
+ `[${ LOG_HEADER } ] Initializing DB with bootstrap snapshot from ${ this . bootstrapSnapshotSource } ..` ) ;
368
+ const startingDb = DB . create (
369
+ StateVersions . EMPTY , StateVersions . START , this . bc , true , this . bootstrapSnapshotBlockNumber ,
370
+ this . stateManager ) ;
371
+ startingDb . initDb ( this . bootstrapSnapshot ) ;
371
372
372
- // 2. Initialize the blockchain, starting from `bootstrapSnapshotBlockNumber`.
373
- logger . info (
374
- `[${ LOG_HEADER } ] Initializing blockchain with bootstrap snapshot from ${ this . bootstrapSnapshotSource } ..` ) ;
375
- const snapshotChunkSize = this . getBlockchainParam ( 'resource/snapshot_chunk_size' ) ;
376
- const wasBlockDirEmpty = this . bc . initBlockchain (
377
- isFirstNode , this . bootstrapSnapshot , this . snapshotDir , snapshotChunkSize ) ;
378
-
379
- // 3. Execute the chain on the DB and finalize it.
380
- logger . info ( `[${ LOG_HEADER } ] Executing chains on DB if needed..` ) ;
381
- const isGenesisStart = ( isFirstNode && wasBlockDirEmpty ) ;
382
- if ( ! wasBlockDirEmpty || isGenesisStart || NodeConfigs . SYNC_MODE === SyncModeOptions . PEER ) {
383
- if ( ! this . loadAndExecuteChainOnDb (
384
- this . bootstrapSnapshotBlockNumber , startingDb . stateVersion , isGenesisStart ) ) {
385
- return false ;
373
+ // 2. Initialize the blockchain, starting from `bootstrapSnapshotBlockNumber`.
374
+ logger . info (
375
+ `[${ LOG_HEADER } ] Initializing blockchain with bootstrap snapshot from ${ this . bootstrapSnapshotSource } ..` ) ;
376
+ const snapshotChunkSize = this . getBlockchainParam ( 'resource/snapshot_chunk_size' ) ;
377
+ const wasBlockDirEmpty = this . bc . initBlockchain (
378
+ isFirstNode , this . bootstrapSnapshot , this . snapshotDir , snapshotChunkSize ) ;
379
+
380
+ // 3. Execute the chain on the DB and finalize it.
381
+ logger . info ( `[${ LOG_HEADER } ] Executing chains on DB if needed..` ) ;
382
+ const isGenesisStart = ( isFirstNode && wasBlockDirEmpty ) ;
383
+ if ( ! wasBlockDirEmpty || isGenesisStart || NodeConfigs . SYNC_MODE === SyncModeOptions . PEER ) {
384
+ if ( ! this . loadAndExecuteChainOnDb (
385
+ this . bootstrapSnapshotBlockNumber , startingDb . stateVersion , isGenesisStart ) ) {
386
+ return false ;
387
+ }
386
388
}
387
- }
388
389
389
- // 4. Execute transactions from the pool.
390
- logger . info ( `[${ LOG_HEADER } ] Executing the transaction from the tx pool..` ) ;
391
- this . db . executeTransactionList (
392
- this . tp . getValidTransactions ( null , this . stateManager . getFinalVersion ( ) ) , false , true ,
393
- this . bc . lastBlockNumber ( ) + 1 , this . bc . lastBlockTimestamp ( ) ) ;
390
+ // 4. Execute transactions from the pool.
391
+ logger . info ( `[${ LOG_HEADER } ] Executing the transaction from the tx pool..` ) ;
392
+ this . db . executeTransactionList (
393
+ this . tp . getValidTransactions ( null , this . stateManager . getFinalVersion ( ) ) , false , true ,
394
+ this . bc . lastBlockNumber ( ) + 1 , this . bc . lastBlockTimestamp ( ) ) ;
394
395
395
- // 5. Node status changed: READY_TO_START -> CHAIN_SYNCING.
396
- this . state = BlockchainNodeStates . CHAIN_SYNCING ;
397
- logger . info ( `[${ LOG_HEADER } ] Now node in CHAIN_SYNCING state!` ) ;
396
+ // 5. Node status changed: READY_TO_START -> CHAIN_SYNCING.
397
+ this . state = BlockchainNodeStates . CHAIN_SYNCING ;
398
+ logger . info ( `[${ LOG_HEADER } ] Now node in CHAIN_SYNCING state!` ) ;
398
399
399
- // 6. Reset bootstrap snapshot.
400
- this . resetBootstrapSnapshot ( ) ;
400
+ // 6. Reset bootstrap snapshot.
401
+ this . resetBootstrapSnapshot ( ) ;
402
+ } catch ( err ) {
403
+ logger . error (
404
+ `[${ LOG_HEADER } ] Failed to start node with error: ${ err } (${ err . stack } )` ) ;
405
+ return false ;
406
+ }
401
407
402
408
return true ;
403
409
}
0 commit comments