miner: better block timestamp creation.
This commit is contained in:
parent
4d6b1e652d
commit
c02f19a288
@ -277,32 +277,33 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) {
|
|||||||
if (!tip)
|
if (!tip)
|
||||||
tip = this.chain.tip;
|
tip = this.chain.tip;
|
||||||
|
|
||||||
assert(tip);
|
if (!address)
|
||||||
|
address = this.getAddress();
|
||||||
|
|
||||||
if (version === -1)
|
if (version === -1)
|
||||||
version = yield this.chain.computeBlockVersion(tip);
|
version = yield this.chain.computeBlockVersion(tip);
|
||||||
|
|
||||||
ts = Math.max(this.network.now(), tip.ts + 1);
|
if (this.chain.state.hasMTP()) {
|
||||||
locktime = ts;
|
locktime = yield tip.getMedianTime();
|
||||||
|
ts = Math.max(this.network.now(), locktime + 1);
|
||||||
|
} else {
|
||||||
|
ts = Math.max(this.network.now(), tip.ts + 1);
|
||||||
|
locktime = ts;
|
||||||
|
}
|
||||||
|
|
||||||
target = yield this.chain.getTarget(ts, tip);
|
target = yield this.chain.getTarget(ts, tip);
|
||||||
|
|
||||||
if (this.chain.state.hasMTP())
|
|
||||||
locktime = yield tip.getMedianTime();
|
|
||||||
|
|
||||||
if (!address)
|
|
||||||
address = this.getAddress();
|
|
||||||
|
|
||||||
attempt = new MinerBlock({
|
attempt = new MinerBlock({
|
||||||
|
network: this.network,
|
||||||
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,
|
||||||
address: address,
|
address: address,
|
||||||
coinbaseFlags: this.options.coinbaseFlags,
|
coinbaseFlags: this.options.coinbaseFlags,
|
||||||
witness: this.chain.state.hasWitness(),
|
witness: this.chain.state.hasWitness(),
|
||||||
network: this.network,
|
|
||||||
weight: this.options.reservedWeight,
|
weight: this.options.reservedWeight,
|
||||||
sigops: this.options.reservedSigops
|
sigops: this.options.reservedSigops
|
||||||
});
|
});
|
||||||
|
|||||||
@ -52,6 +52,7 @@ function MinerBlock(options) {
|
|||||||
this.tip = options.tip;
|
this.tip = options.tip;
|
||||||
this.version = options.version;
|
this.version = options.version;
|
||||||
this.height = options.tip.height + 1;
|
this.height = options.tip.height + 1;
|
||||||
|
this.ts = options.ts;
|
||||||
this.bits = options.bits;
|
this.bits = options.bits;
|
||||||
this.target = consensus.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32);
|
this.target = consensus.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32);
|
||||||
this.locktime = options.locktime;
|
this.locktime = options.locktime;
|
||||||
@ -129,7 +130,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 = encoding.NULL_HASH;
|
block.merkleRoot = encoding.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;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user