diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index 4031f59359..d380e65d4b 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -77,7 +77,11 @@ export class Blockchain implements Contracts.Blockchain.Blockchain { const blocks = (job as ProcessBlocksJob).getBlocks(); this.logger.error( - `Failed to process ${blocks.length.toLocaleString()} blocks from height ${blocks[0].height.toLocaleString()} in queue.`, + `Failed to process ${Utils.pluralize( + "block", + blocks.length, + true, + )} from height ${blocks[0].height.toLocaleString()} in queue.`, ); }); } diff --git a/packages/core-blockchain/src/process-blocks-job.ts b/packages/core-blockchain/src/process-blocks-job.ts index 863fcddf8d..ef28009383 100644 --- a/packages/core-blockchain/src/process-blocks-job.ts +++ b/packages/core-blockchain/src/process-blocks-job.ts @@ -147,7 +147,9 @@ export class ProcessBlocksJob implements Contracts.Kernel.QueueJob { await this.blockRepository.saveBlocks(acceptedBlocks); } catch (error) { this.logger.error( - `Could not save ${acceptedBlocks.length.toLocaleString()} blocks to database : ${error.stack}`, + `Could not save ${Utils.pluralize("block", acceptedBlocks.length, true)}) to database : ${ + error.stack + }`, ); await this.revertBlocks(acceptedBlocks); diff --git a/packages/core-blockchain/src/processor/handlers/unchained-handler.ts b/packages/core-blockchain/src/processor/handlers/unchained-handler.ts index 1562f2ce02..a35e349be5 100644 --- a/packages/core-blockchain/src/processor/handlers/unchained-handler.ts +++ b/packages/core-blockchain/src/processor/handlers/unchained-handler.ts @@ -127,7 +127,13 @@ export class UnchainedHandler implements BlockHandler { // NOTE: This isn't really elegant, but still better than spamming the log with // useless `not ready to accept` messages. if (this.blockchain.getQueue().size() > 0) { - this.logger.debug(`Discarded ${this.blockchain.getQueue().size()} chunks of downloaded blocks.`); + this.logger.debug( + `Discarded ${Utils.pluralize( + "chunk", + this.blockchain.getQueue().size(), + true, + )} of downloaded blocks.`, + ); } // If we consecutively fail to accept the same block, our chain is likely forked. In this diff --git a/packages/core-p2p/src/network-monitor.ts b/packages/core-p2p/src/network-monitor.ts index df131e714e..f4077c0598 100644 --- a/packages/core-p2p/src/network-monitor.ts +++ b/packages/core-p2p/src/network-monitor.ts @@ -134,7 +134,7 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor { max = Math.min(peers.length, peerCount); } - this.logger.info(`Checking ${max} peers`); + this.logger.info(`Checking ${Utils.pluralize("peer", max, true)}`); const peerErrors = {}; // we use Promise.race to cut loose in case some communicator.ping() does not resolve within the delay @@ -172,11 +172,13 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor { for (const key of Object.keys(peerErrors)) { const peerCount = peerErrors[key].length; - this.logger.debug(`Removed ${peerCount} ${Utils.pluralize("peer", peerCount)} because of "${key}"`); + this.logger.debug(`Removed ${Utils.pluralize("peer", peerCount, true)} because of "${key}"`); } if (this.initializing) { - this.logger.info(`${max - unresponsivePeers} of ${max} peers on the network are responsive`); + this.logger.info( + `${max - unresponsivePeers} of ${Utils.pluralize("peer", max, true)} on the network are responsive`, + ); this.logger.info(`Median Network Height: ${this.getNetworkHeight().toLocaleString()}`); } } @@ -263,7 +265,7 @@ export class NetworkMonitor implements Contracts.P2P.NetworkMonitor { } public async refreshPeersAfterFork(): Promise { - this.logger.info(`Refreshing ${this.repository.getPeers().length} peers after fork.`); + this.logger.info(`Refreshing ${Utils.pluralize("peer", this.repository.getPeers().length, true)} after fork.`); await this.cleansePeers({ forcePing: true }); } diff --git a/packages/core-snapshots/src/database-service.ts b/packages/core-snapshots/src/database-service.ts index aff198bbdd..dc31206fe1 100644 --- a/packages/core-snapshots/src/database-service.ts +++ b/packages/core-snapshots/src/database-service.ts @@ -49,7 +49,11 @@ export class SnapshotDatabaseService implements Database.DatabaseService { public async truncate(): Promise { this.logger.info( - `Clearing: ${await this.blockRepository.fastCount()} blocks, ${await this.transactionRepository.fastCount()} transactions, ${await this.roundRepository.fastCount()} rounds`, + `Clearing: ${Utils.pluralize("block", await this.blockRepository.fastCount(), true)}, ${Utils.pluralize( + "transaction", + await this.transactionRepository.fastCount(), + true, + )}, ${Utils.pluralize("round", await this.roundRepository.fastCount(), true)}`, ); await this.blockRepository.truncate(); @@ -75,7 +79,11 @@ export class SnapshotDatabaseService implements Database.DatabaseService { const meta = this.prepareMetaData(options, dumpRage); this.logger.info( - `Start running dump for ${dumpRage.blocksCount} blocks, ${dumpRage.roundsCount} rounds and ${dumpRage.transactionsCount} transactions`, + `Start running dump for ${Utils.pluralize("block", dumpRage.blocksCount, true)}, ${Utils.pluralize( + "round", + dumpRage.roundsCount, + true, + )} and ${Utils.pluralize("transaction", dumpRage.transactionsCount, true)}`, ); this.filesystem.setSnapshot(meta.folder); diff --git a/packages/core-snapshots/src/snapshot-service.ts b/packages/core-snapshots/src/snapshot-service.ts index 5f353b432d..69bd8113f2 100644 --- a/packages/core-snapshots/src/snapshot-service.ts +++ b/packages/core-snapshots/src/snapshot-service.ts @@ -50,7 +50,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService { meta = await this.filesystem.readMetaData(); } catch (e) { this.logger.error( - `Metadata for snapshot ${options.blocks} of network ${options.network} is not valid.`, + `Metadata for snapshot ${options.blocks} of network ${options.network} are not valid.`, ); return; } @@ -62,9 +62,11 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService { await this.database.restore(meta!, { truncate: !!options.truncate }); this.logger.info( - `Successfully restore ${meta!.blocks.count.toLocaleString()} blocks, ${meta!.transactions.count.toLocaleString()} transactions, ${ - meta!.rounds.count - } rounds`, + `Successfully restore ${Utils.pluralize("block", meta!.blocks.count, true)}, ${Utils.pluralize( + "transaction", + meta!.transactions.count, + true, + )}, ${Utils.pluralize("round", meta!.rounds.count, true)}`, ); } catch (err) { this.logger.error(`RESTORE failed.`); @@ -90,7 +92,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService { meta = await this.filesystem.readMetaData(); } catch (e) { this.logger.error( - `Metadata for snapshot ${options.blocks} of network ${options.network} is not valid.`, + `Metadata for snapshot ${options.blocks} of network ${options.network} are not valid.`, ); }