Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/core-blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,16 @@ export class Blockchain implements blockchain.IBlockchain {
while (this.state.getLastBlock().data.height >= newHeight + 1) {
const removalBlockId = this.state.getLastBlock().data.id;
const removalBlockHeight = this.state.getLastBlock().data.height.toLocaleString();
logger.printTracker("Removing block", count++, max, `ID: ${removalBlockId}, height: ${removalBlockHeight}`);

logger.info(`Removing block ${count++} of ${max} - ID: ${removalBlockId}, height: ${removalBlockHeight}`);

await deleteLastBlock();
}

// Commit delete blocks
await this.database.commitQueuedQueries();

logger.stopTracker(`${pluralize("block", max, true)} removed`, count, max);
logger.info(`Removed ${count} ${pluralize("block", max, true)}`);

await this.database.deleteRound(previousRound + 1);
}
Expand All @@ -316,10 +317,7 @@ export class Blockchain implements blockchain.IBlockchain {

// If the current chain height is H and we will be removing blocks [N, H],
// then blocksToRemove[] will contain blocks [N - 1, H - 1].
const blocksToRemove = await this.database.getBlocks(
this.state.getLastBlock().data.height - nblocks,
nblocks,
);
const blocksToRemove = await this.database.getBlocks(this.state.getLastBlock().data.height - nblocks, nblocks);

const revertLastBlock = async () => {
// tslint:disable-next-line:no-shadowed-variable
Expand Down
9 changes: 1 addition & 8 deletions packages/core-blockchain/src/utils/tick-sync-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ export function tickSyncTracker(blockCount, count) {
secDecimalDigits: 0,
});

logger.printTracker(
"Fast Sync",
tracker.percent,
100,
`(${blocksDownloaded} of ${networkHeight} blocks - Est. ${timeLeft})`,
);
logger.info(`Synchronising In Progress (${blocksDownloaded} of ${networkHeight} blocks - Est. ${timeLeft})`);
}

if (tracker.percent === 100) {
tracker = null;

logger.stopTracker("Fast Sync", 100, 100);
}
}
17 changes: 8 additions & 9 deletions packages/core-database-postgres/src/spv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,30 @@ export class SPV {
public async build(height) {
this.activeDelegates = config.getMilestone(height).activeDelegates;

logger.printTracker("SPV", 1, 8, "Received Transactions");
logger.info("SPV Step 1 of 8: Received Transactions");
await this.__buildReceivedTransactions();

logger.printTracker("SPV", 2, 8, "Block Rewards");
logger.info("SPV Step 2 of 8: Block Rewards");
await this.__buildBlockRewards();

logger.printTracker("SPV", 3, 8, "Last Forged Blocks");
logger.info("SPV Step 3 of 8: Last Forged Blocks");
await this.__buildLastForgedBlocks();

logger.printTracker("SPV", 4, 8, "Sent Transactions");
logger.info("SPV Step 4 of 8: Sent Transactions");
await this.__buildSentTransactions();

logger.printTracker("SPV", 5, 8, "Second Signatures");
logger.info("SPV Step 5 of 8: Second Signatures");
await this.__buildSecondSignatures();

logger.printTracker("SPV", 6, 8, "Votes");
logger.info("SPV Step 6 of 8: Votes");
await this.__buildVotes();

logger.printTracker("SPV", 7, 8, "Delegates");
logger.info("SPV Step 7 of 8: Delegates");
await this.__buildDelegates();

logger.printTracker("SPV", 8, 8, "MultiSignatures");
logger.info("SPV Step 8 of 8: MultiSignatures");
await this.__buildMultisignatures();

logger.stopTracker("SPV", 8, 8);
logger.info(`SPV rebuild finished, wallets in memory: ${Object.keys(this.walletManager.byAddress).length}`);
logger.info(`Number of registered delegates: ${Object.keys(this.walletManager.byUsername).length}`);

Expand Down
20 changes: 0 additions & 20 deletions packages/core-interfaces/src/core-logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ export interface ILogger {
*/
verbose(message: string): void;

/**
* Print the progress tracker.
* @param {String} title
* @param {Number} current
* @param {Number} max
* @param {String} postTitle
* @param {Number} figures
* @return {void}
*/
printTracker(title: string, current: number, max: number, postTitle?: string, figures?: number): void;

/**
* Stop the progress tracker.
* @param {String} title
* @param {Number} current
* @param {Number} max
* @return {void}
*/
stopTracker(title: string, current: number, max: number): void;

/**
* Suppress console output.
* @param {Boolean}
Expand Down
25 changes: 0 additions & 25 deletions packages/core-logger-winston/__tests__/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,6 @@ describe("Logger", () => {
});
});

describe("printTracker", () => {
it("should print the tracker", () => {
logger.printTracker("test_title", 50, 100, "done");
logger.printTracker("second_tracker", 0, 100, null);

expect(message).toMatch(/test_title/);
expect(message).toMatch(/=========================/);
expect(message).toMatch(/50/);
expect(message).toMatch(/done/);
message = null;
});
});

describe("stopTracker", () => {
it("should stop the tracker", () => {
logger.stopTracker("test_title", 50, 100);
logger.stopTracker("second_tracker", 101, 100);

expect(message).toMatch(/test_title/);
expect(message).toMatch(/=========================/);
expect(message).toMatch(/100/);
message = null;
});
});

describe("suppressConsoleOutput", () => {
it("should suppress console output", () => {
logger.suppressConsoleOutput(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/core-logger-winston/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const defaults = {
constructor: "Console",
options: {
level: process.env.CORE_LOG_LEVEL || "debug",
format: formatter(true, true),
format: formatter(true),
stderrLevels: ["error", "warn"],
},
},
Expand All @@ -15,7 +15,7 @@ export const defaults = {
constructor: "DailyRotateFile",
options: {
level: process.env.CORE_LOG_LEVEL || "debug",
format: formatter(false, true),
format: formatter(false),
filename: process.env.CORE_LOG_FILE || `${process.env.CORE_PATH_LOG}/%DATE%.log`,
datePattern: "YYYY-MM-DD",
zippedArchive: true,
Expand Down
60 changes: 0 additions & 60 deletions packages/core-logger-winston/src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import isEmpty from "lodash/isEmpty";
import { inspect } from "util";
import * as winston from "winston";

let tracker = null;

export class WinstonLogger extends AbstractLogger {
public logger: any;

Expand Down Expand Up @@ -69,64 +67,6 @@ export class WinstonLogger extends AbstractLogger {
this.createLog("verbose", message);
}

/**
* Print the progress tracker.
* @param {String} title
* @param {Number} current
* @param {Number} max
* @param {String} postTitle
* @param {Number} figures
* @return {void}
*/
public printTracker(title: string, current: number, max: number, postTitle?: string, figures?: number): void {
const progress = (100 * current) / max;

let line = "\u{1b}[0G ";
line += title.blue;
line += " [";
line += "=".repeat(Math.floor(progress / 2)).green;
line += `${" ".repeat(Math.ceil(50 - progress / 2))}] `;
line += `${progress.toFixed(figures || 0)}% `;

if (postTitle) {
line += `${postTitle} `;
}

process.stdout.write(line);

tracker = line;
}

/**
* Stop the progress tracker.
* @param {String} title
* @param {Number} current
* @param {Number} max
* @return {void}
*/
public stopTracker(title: string, current: number, max: number): void {
let progress = (100 * current) / max;

if (progress > 100) {
progress = 100;
}

let line = "\u{1b}[0G ";
line += title.blue;
line += " [";
line += "=".repeat(progress / 2).green;
line += `${" ".repeat(50 - progress / 2)}] `;
line += `${progress.toFixed(0)}% `;

if (progress === max) {
line += "✔️";
}

line += " \n";
process.stdout.write(line);
tracker = null;
}

/**
* Suppress console output.
* @param {Boolean}
Expand Down
7 changes: 2 additions & 5 deletions packages/core-logger-winston/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { format } from "winston";

const { colorize, combine, timestamp, printf } = format;

const formatter = (colorOutput: boolean = true, makeReadable: boolean = true) =>
const formatter = (colorOutput: boolean = true) =>
combine(
colorize(),
timestamp(),
Expand Down Expand Up @@ -38,10 +38,7 @@ const formatter = (colorOutput: boolean = true, makeReadable: boolean = true) =>

const dateTime = dayjs(info.timestamp).format("YYYY-MM-DD HH:mm:ss");

const dateTimeAndLevel = `[${dateTime}][${level}]:`;
const lineSpacer = makeReadable ? " ".repeat(Math.abs(dateTimeAndLevel.length - 50) + 1) : "";

return `[${dateTime}][${level}]${lineSpacer}: ${message}`;
return `[${dateTime}][${level}]: ${message}`;
}),
);

Expand Down
8 changes: 0 additions & 8 deletions packages/core-logger/__tests__/__stubs__/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ export class Logger extends AbstractLogger {
//
}

public printTracker(title: string, current: number, max: number, postTitle: string, figures: number): void {
//
}

public stopTracker(title: string, current: number, max: number): void {
//
}

public suppressConsoleOutput(suppress: boolean): void {
//
}
Expand Down
26 changes: 0 additions & 26 deletions packages/core-logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,6 @@ export abstract class AbstractLogger implements Logger.ILogger {
*/
public abstract verbose(message: any): void;

/**
* Print the progress tracker.
* @param {String} title
* @param {Number} current
* @param {Number} max
* @param {String} postTitle
* @param {Number} figures
* @return {void}
*/
public abstract printTracker(
title: string,
current: number,
max: number,
postTitle?: string,
figures?: number,
): void;

/**
* Stop the progress tracker.
* @param {String} title
* @param {Number} current
* @param {Number} max
* @return {void}
*/
public abstract stopTracker(title: string, current: number, max: number): void;

/**
* Suppress console output.
* @param {Boolean}
Expand Down
6 changes: 0 additions & 6 deletions packages/core-p2p/src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ export class Monitor implements P2P.IMonitor {
*/
public async cleanPeers(fast = false, forcePing = false) {
const keys = Object.keys(this.peers);
let count = 0;
let unresponsivePeers = 0;
const pingDelay = fast ? 1500 : localConfig.get("globalTimeout");
const max = keys.length;
Expand All @@ -243,10 +242,6 @@ export class Monitor implements P2P.IMonitor {
const peer = this.getPeer(ip);
try {
await peer.ping(pingDelay, forcePing);

if (this.initializing) {
logger.printTracker("Peers Discovery", ++count, max);
}
} catch (error) {
unresponsivePeers++;

Expand All @@ -262,7 +257,6 @@ export class Monitor implements P2P.IMonitor {
);

if (this.initializing) {
logger.stopTracker("Peers Discovery", max, max);
logger.info(`${max - unresponsivePeers} of ${max} peers on the network are responsive`);
logger.info(`Median Network Height: ${this.getNetworkHeight().toLocaleString()}`);
logger.info(`Network PBFT status: ${this.getPBFTForgingStatus()}`);
Expand Down