miner: pass ts.

This commit is contained in:
Christopher Jeffrey 2016-12-14 10:43:32 -08:00
parent a9a0f638eb
commit aa46fb2df2
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 3 additions and 10 deletions

View File

@ -338,6 +338,7 @@ Miner.prototype.createBlock = co(function* createBlock(tip, address) {
attempt = new MinerBlock({ attempt = new MinerBlock({
tip: tip, tip: tip,
version: version, version: version,
ts: ts,
bits: target, bits: target,
locktime: locktime, locktime: locktime,
flags: this.chain.state.flags, flags: this.chain.state.flags,

View File

@ -49,6 +49,7 @@ function MinerBlock(options) {
this.tip = options.tip; this.tip = options.tip;
this.version = options.version; this.version = options.version;
this.ts = options.ts;
this.height = options.tip.height + 1; this.height = options.tip.height + 1;
this.bits = options.bits; this.bits = options.bits;
this.target = btcutils.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32); this.target = btcutils.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32);
@ -122,7 +123,7 @@ MinerBlock.prototype._init = function _init() {
block.version = this.version; block.version = this.version;
block.prevBlock = this.tip.hash; block.prevBlock = this.tip.hash;
block.merkleRoot = constants.NULL_HASH; block.merkleRoot = constants.NULL_HASH;
block.ts = Math.max(this.network.now(), this.tip.ts + 1); block.ts = this.ts;
block.bits = this.bits; block.bits = this.bits;
block.nonce = 0; block.nonce = 0;
@ -231,8 +232,6 @@ MinerBlock.prototype.updateCoinbase = function updateCoinbase() {
*/ */
MinerBlock.prototype.updateNonce = function updateNonce() { MinerBlock.prototype.updateNonce = function updateNonce() {
this.block.ts = Math.max(this.network.now(), this.tip.ts + 1);
// Overflow the nonce and increment the extraNonce. // Overflow the nonce and increment the extraNonce.
this.block.nonce = 0; this.block.nonce = 0;
this.extraNonce.iaddn(1); this.extraNonce.iaddn(1);
@ -256,9 +255,6 @@ MinerBlock.prototype.updateMerkle = function updateMerkle() {
if (this.witness) if (this.witness)
this.updateCommitment(); this.updateCommitment();
// Update timestamp.
this.block.ts = Math.max(this.network.now(), this.tip.ts + 1);
// Recalculate merkle root. // Recalculate merkle root.
this.block.merkleRoot = this.block.createMerkleRoot('hex'); this.block.merkleRoot = this.block.createMerkleRoot('hex');
}; };
@ -387,8 +383,6 @@ MinerBlock.prototype.mine = function mine() {
// Track how long we've been at it. // Track how long we've been at it.
this.begin = util.now(); this.begin = util.now();
assert(this.block.ts > this.tip.ts);
for (;;) { for (;;) {
nonce = this.findNonce(); nonce = this.findNonce();
@ -414,8 +408,6 @@ MinerBlock.prototype.mineAsync = co(function* mineAsync() {
// Track how long we've been at it. // Track how long we've been at it.
this.begin = util.now(); this.begin = util.now();
assert(this.block.ts > this.tip.ts);
for (;;) { for (;;) {
nonce = yield this.findNonceAsync(); nonce = yield this.findNonceAsync();