Skip to content

Commit

Permalink
Merge pull request #1818 from micahriggan/fix/benchmark-logging
Browse files Browse the repository at this point in the history
fix(node): fix some logging
  • Loading branch information
micahriggan authored Dec 23, 2018
2 parents d8dea8b + de7d4ba commit 8a9050a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/bitcore-node/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Transaction extends BaseModel<ITransaction> {
// 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]);
}
}

Expand Down
18 changes: 15 additions & 3 deletions packages/bitcore-node/test/benchmark/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function* generateBlocks(blockCount: number, blockSizeMb: number) {
}
}

function preGenerateBlocks(blockCount: number, blockSizeMb: number) {
const blocks = new Array<BitcoinBlockType>();
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 : '';
Expand Down Expand Up @@ -109,11 +117,15 @@ function startBenchmarkDatabase() {

async function benchmark(blockCount: number, blockSizeMb: number) {
await resetDatabase();
console.log('Generating blocks');
const blocks = preGenerateBlocks(blockCount, blockSizeMb);
const startTime = new Date();
for (let block of generateBlocks(blockCount, blockSizeMb)) {
console.log('Adding block', block.hash);
console.log('Adding blocks');
for (let block of blocks) {
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;
Expand All @@ -123,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());

0 comments on commit 8a9050a

Please sign in to comment.