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)
|
||||
tip = this.chain.tip;
|
||||
|
||||
assert(tip);
|
||||
if (!address)
|
||||
address = this.getAddress();
|
||||
|
||||
if (version === -1)
|
||||
version = yield this.chain.computeBlockVersion(tip);
|
||||
|
||||
ts = Math.max(this.network.now(), tip.ts + 1);
|
||||
locktime = ts;
|
||||
if (this.chain.state.hasMTP()) {
|
||||
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);
|
||||
|
||||
if (this.chain.state.hasMTP())
|
||||
locktime = yield tip.getMedianTime();
|
||||
|
||||
if (!address)
|
||||
address = this.getAddress();
|
||||
|
||||
attempt = new MinerBlock({
|
||||
network: this.network,
|
||||
tip: tip,
|
||||
version: version,
|
||||
ts: ts,
|
||||
bits: target,
|
||||
locktime: locktime,
|
||||
flags: this.chain.state.flags,
|
||||
address: address,
|
||||
coinbaseFlags: this.options.coinbaseFlags,
|
||||
witness: this.chain.state.hasWitness(),
|
||||
network: this.network,
|
||||
weight: this.options.reservedWeight,
|
||||
sigops: this.options.reservedSigops
|
||||
});
|
||||
|
||||
@ -52,6 +52,7 @@ function MinerBlock(options) {
|
||||
this.tip = options.tip;
|
||||
this.version = options.version;
|
||||
this.height = options.tip.height + 1;
|
||||
this.ts = options.ts;
|
||||
this.bits = options.bits;
|
||||
this.target = consensus.fromCompact(this.bits).toArrayLike(Buffer, 'le', 32);
|
||||
this.locktime = options.locktime;
|
||||
@ -129,7 +130,7 @@ MinerBlock.prototype._init = function _init() {
|
||||
block.version = this.version;
|
||||
block.prevBlock = this.tip.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.nonce = 0;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user