From f8b4750d9000b2978a68e61ccfa1c323c7bb61f5 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 14 Dec 2016 10:59:17 -0800 Subject: [PATCH] Revert "miner: pass ts." This reverts commit aa46fb2df2ed887b8e844ea2dbae75b77d18d739. --- lib/mining/miner.js | 1 - lib/mining/minerblock.js | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mining/miner.js b/lib/mining/miner.js index 75b56eb8..c107d2a8 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -338,7 +338,6 @@ Miner.prototype.createBlock = co(function* createBlock(tip, address) { attempt = new MinerBlock({ tip: tip, version: version, - ts: ts, bits: target, locktime: locktime, flags: this.chain.state.flags, diff --git a/lib/mining/minerblock.js b/lib/mining/minerblock.js index 511378ff..4e4664ea 100644 --- a/lib/mining/minerblock.js +++ b/lib/mining/minerblock.js @@ -49,7 +49,6 @@ function MinerBlock(options) { this.tip = options.tip; this.version = options.version; - this.ts = options.ts; this.height = options.tip.height + 1; this.bits = options.bits; this.target = btcutils.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32); @@ -123,7 +122,7 @@ MinerBlock.prototype._init = function _init() { block.version = this.version; block.prevBlock = this.tip.hash; block.merkleRoot = constants.NULL_HASH; - block.ts = this.ts; + block.ts = Math.max(this.network.now(), this.tip.ts + 1); block.bits = this.bits; block.nonce = 0; @@ -232,6 +231,8 @@ MinerBlock.prototype.updateCoinbase = function updateCoinbase() { */ MinerBlock.prototype.updateNonce = function updateNonce() { + this.block.ts = Math.max(this.network.now(), this.tip.ts + 1); + // Overflow the nonce and increment the extraNonce. this.block.nonce = 0; this.extraNonce.iaddn(1); @@ -255,6 +256,9 @@ MinerBlock.prototype.updateMerkle = function updateMerkle() { if (this.witness) this.updateCommitment(); + // Update timestamp. + this.block.ts = Math.max(this.network.now(), this.tip.ts + 1); + // Recalculate merkle root. this.block.merkleRoot = this.block.createMerkleRoot('hex'); }; @@ -383,6 +387,8 @@ MinerBlock.prototype.mine = function mine() { // Track how long we've been at it. this.begin = util.now(); + assert(this.block.ts > this.tip.ts); + for (;;) { nonce = this.findNonce(); @@ -408,6 +414,8 @@ MinerBlock.prototype.mineAsync = co(function* mineAsync() { // Track how long we've been at it. this.begin = util.now(); + assert(this.block.ts > this.tip.ts); + for (;;) { nonce = yield this.findNonceAsync();