From da5ede5b850d8f00eb27894b7a3a5453b3b50f36 Mon Sep 17 00:00:00 2001 From: Micah Riggan Date: Sat, 22 Dec 2018 01:28:52 -0500 Subject: [PATCH 1/2] fix(node): fix some logging benchmark and negative fee are too verbose --- packages/bitcore-node/src/models/transaction.ts | 2 +- packages/bitcore-node/test/benchmark/benchmark.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/bitcore-node/src/models/transaction.ts b/packages/bitcore-node/src/models/transaction.ts index 5ff50fda448..408e70a14bf 100644 --- a/packages/bitcore-node/src/models/transaction.ts +++ b/packages/bitcore-node/src/models/transaction.ts @@ -224,7 +224,7 @@ export class Transaction extends BaseModel { // TODO: Fee is negative for mempool txs fee = groupedSpends[txid].total - groupedMints[txid].total; if (fee < 0) { - console.error(txid, groupedSpends[txid], groupedMints[txid]); + logger.debug('negative fee', txid, groupedSpends[txid], groupedMints[txid]); } } diff --git a/packages/bitcore-node/test/benchmark/benchmark.ts b/packages/bitcore-node/test/benchmark/benchmark.ts index 07cbcc3fd5f..f72a9500dd9 100644 --- a/packages/bitcore-node/test/benchmark/benchmark.ts +++ b/packages/bitcore-node/test/benchmark/benchmark.ts @@ -110,10 +110,12 @@ function startBenchmarkDatabase() { async function benchmark(blockCount: number, blockSizeMb: number) { await resetDatabase(); const startTime = new Date(); + console.log('Adding blocks'); for (let block of generateBlocks(blockCount, blockSizeMb)) { - console.log('Adding block', block.hash); + process.stdout.write('.'); await BlockModel.addBlock({ block, chain: 'BENCH', network: 'MARK', initialSyncComplete: false }); } + process.stdout.write('\n'); const endTime = new Date(); const time = endTime.getTime() - startTime.getTime(); const seconds = time / 1000; From de7d4baee6235dded5ea64590c9463aa6a934672 Mon Sep 17 00:00:00 2001 From: Micah Riggan Date: Sat, 22 Dec 2018 01:46:21 -0500 Subject: [PATCH 2/2] Pre-Generating the blocks --- packages/bitcore-node/test/benchmark/benchmark.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/bitcore-node/test/benchmark/benchmark.ts b/packages/bitcore-node/test/benchmark/benchmark.ts index f72a9500dd9..d074435bfbb 100644 --- a/packages/bitcore-node/test/benchmark/benchmark.ts +++ b/packages/bitcore-node/test/benchmark/benchmark.ts @@ -21,6 +21,14 @@ function* generateBlocks(blockCount: number, blockSizeMb: number) { } } +function preGenerateBlocks(blockCount: number, blockSizeMb: number) { + const blocks = new Array(); + for (let block of generateBlocks(blockCount, blockSizeMb)) { + blocks.push(block); + } + return blocks; +} + function generateBlock(blockSizeMb: number, previousBlock?: BitcoinBlockType): BitcoinBlockType { const txAmount = 100000; const prevHash = previousBlock ? previousBlock.hash : ''; @@ -109,9 +117,11 @@ function startBenchmarkDatabase() { async function benchmark(blockCount: number, blockSizeMb: number) { await resetDatabase(); + console.log('Generating blocks'); + const blocks = preGenerateBlocks(blockCount, blockSizeMb); const startTime = new Date(); console.log('Adding blocks'); - for (let block of generateBlocks(blockCount, blockSizeMb)) { + for (let block of blocks) { process.stdout.write('.'); await BlockModel.addBlock({ block, chain: 'BENCH', network: 'MARK', initialSyncComplete: false }); } @@ -125,6 +135,6 @@ async function benchmark(blockCount: number, blockSizeMb: number) { } startBenchmarkDatabase() - .then(() => benchmark(160, 1)) + .then(() => benchmark(80, 1)) .then(() => benchmark(5, 32)) .then(() => process.exit());