From 716806a8735717597ab7fecc8a9aaaae3ec93306 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 16 Aug 2024 15:58:38 +0900 Subject: [PATCH 1/2] Log stack trace for file handling errors --- common/file-util.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/file-util.js b/common/file-util.js index 2ab4f2087..85557f792 100644 --- a/common/file-util.js +++ b/common/file-util.js @@ -257,7 +257,7 @@ class FileUtil { }); }); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err.stack}`); return false; } } @@ -288,7 +288,7 @@ class FileUtil { }); }); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err.stack}`); return null; } } @@ -299,7 +299,7 @@ class FileUtil { const zippedFs = fs.readFileSync(filePath); return FileUtil.buildObjectFromChunks(JSON.parse(zlib.gunzipSync(zippedFs).toString()).docs); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err.stack}`); return null; } } @@ -314,7 +314,7 @@ class FileUtil { const zippedFs = fs.readFileSync(filePath); return JSON.parse(zlib.gunzipSync(zippedFs).toString()); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err.stack}`); return null; } } @@ -325,7 +325,7 @@ class FileUtil { const fileStr = fs.readFileSync(filePath); return JSON.parse(fileStr); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err.stack}`); return null; } } @@ -399,7 +399,7 @@ class FileUtil { try { return Number(fs.readFileSync(h2nPath).toString()); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${h2nPath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${h2nPath}: ${err.stack}`); return -1; } } From 48efb6f0689e3f4b43bda068b6a2854fc24c0028 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 16 Aug 2024 15:59:37 +0900 Subject: [PATCH 2/2] Log stack trace for the errors in starting blockchainn nodes --- node/index.js | 70 ++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/node/index.js b/node/index.js index 8c4a53860..4efe3202e 100644 --- a/node/index.js +++ b/node/index.js @@ -361,43 +361,49 @@ class BlockchainNode { startNode(isFirstNode) { const LOG_HEADER = 'startNode'; - // 1. Initialize DB (with the latest snapshot, if it exists) - logger.info( - `[${LOG_HEADER}] Initializing DB with bootstrap snapshot from ${this.bootstrapSnapshotSource}..`); - const startingDb = DB.create( - StateVersions.EMPTY, StateVersions.START, this.bc, true, this.bootstrapSnapshotBlockNumber, - this.stateManager); - startingDb.initDb(this.bootstrapSnapshot); + try { + // 1. Initialize DB (with the latest snapshot, if it exists) + logger.info( + `[${LOG_HEADER}] Initializing DB with bootstrap snapshot from ${this.bootstrapSnapshotSource}..`); + const startingDb = DB.create( + StateVersions.EMPTY, StateVersions.START, this.bc, true, this.bootstrapSnapshotBlockNumber, + this.stateManager); + startingDb.initDb(this.bootstrapSnapshot); - // 2. Initialize the blockchain, starting from `bootstrapSnapshotBlockNumber`. - logger.info( - `[${LOG_HEADER}] Initializing blockchain with bootstrap snapshot from ${this.bootstrapSnapshotSource}..`); - const snapshotChunkSize = this.getBlockchainParam('resource/snapshot_chunk_size'); - const wasBlockDirEmpty = this.bc.initBlockchain( - isFirstNode, this.bootstrapSnapshot, this.snapshotDir, snapshotChunkSize); - - // 3. Execute the chain on the DB and finalize it. - logger.info(`[${LOG_HEADER}] Executing chains on DB if needed..`); - const isGenesisStart = (isFirstNode && wasBlockDirEmpty); - if (!wasBlockDirEmpty || isGenesisStart || NodeConfigs.SYNC_MODE === SyncModeOptions.PEER) { - if (!this.loadAndExecuteChainOnDb( - this.bootstrapSnapshotBlockNumber, startingDb.stateVersion, isGenesisStart)) { - return false; + // 2. Initialize the blockchain, starting from `bootstrapSnapshotBlockNumber`. + logger.info( + `[${LOG_HEADER}] Initializing blockchain with bootstrap snapshot from ${this.bootstrapSnapshotSource}..`); + const snapshotChunkSize = this.getBlockchainParam('resource/snapshot_chunk_size'); + const wasBlockDirEmpty = this.bc.initBlockchain( + isFirstNode, this.bootstrapSnapshot, this.snapshotDir, snapshotChunkSize); + + // 3. Execute the chain on the DB and finalize it. + logger.info(`[${LOG_HEADER}] Executing chains on DB if needed..`); + const isGenesisStart = (isFirstNode && wasBlockDirEmpty); + if (!wasBlockDirEmpty || isGenesisStart || NodeConfigs.SYNC_MODE === SyncModeOptions.PEER) { + if (!this.loadAndExecuteChainOnDb( + this.bootstrapSnapshotBlockNumber, startingDb.stateVersion, isGenesisStart)) { + return false; + } } - } - // 4. Execute transactions from the pool. - logger.info(`[${LOG_HEADER}] Executing the transaction from the tx pool..`); - this.db.executeTransactionList( - this.tp.getValidTransactions(null, this.stateManager.getFinalVersion()), false, true, - this.bc.lastBlockNumber() + 1, this.bc.lastBlockTimestamp()); + // 4. Execute transactions from the pool. + logger.info(`[${LOG_HEADER}] Executing the transaction from the tx pool..`); + this.db.executeTransactionList( + this.tp.getValidTransactions(null, this.stateManager.getFinalVersion()), false, true, + this.bc.lastBlockNumber() + 1, this.bc.lastBlockTimestamp()); - // 5. Node status changed: READY_TO_START -> CHAIN_SYNCING. - this.state = BlockchainNodeStates.CHAIN_SYNCING; - logger.info(`[${LOG_HEADER}] Now node in CHAIN_SYNCING state!`); + // 5. Node status changed: READY_TO_START -> CHAIN_SYNCING. + this.state = BlockchainNodeStates.CHAIN_SYNCING; + logger.info(`[${LOG_HEADER}] Now node in CHAIN_SYNCING state!`); - // 6. Reset bootstrap snapshot. - this.resetBootstrapSnapshot(); + // 6. Reset bootstrap snapshot. + this.resetBootstrapSnapshot(); + } catch (err) { + logger.error( + `[${LOG_HEADER}] Failed to start node with error: ${err} (${err.stack})`); + return false; + } return true; }