miner: update curtime. see #160.
This commit is contained in:
parent
4b212aff8e
commit
b372715c88
@ -1256,7 +1256,7 @@ RPC.prototype._createTemplate = co(function* _createTemplate(version, coinbase,
|
|||||||
bits: util.hex32(attempt.bits),
|
bits: util.hex32(attempt.bits),
|
||||||
noncerange: '00000000ffffffff',
|
noncerange: '00000000ffffffff',
|
||||||
curtime: attempt.ts,
|
curtime: attempt.ts,
|
||||||
mintime: attempt.ts,
|
mintime: attempt.mtp + 1,
|
||||||
maxtime: attempt.ts + 7200,
|
maxtime: attempt.ts + 7200,
|
||||||
expires: attempt.ts + 7200,
|
expires: attempt.ts + 7200,
|
||||||
sigoplimit: consensus.MAX_BLOCK_SIGOPS_COST / scale | 0,
|
sigoplimit: consensus.MAX_BLOCK_SIGOPS_COST / scale | 0,
|
||||||
@ -2153,7 +2153,9 @@ RPC.prototype.getTemplate = co(function* getTemplate() {
|
|||||||
|
|
||||||
this.bindChain();
|
this.bindChain();
|
||||||
|
|
||||||
if (!attempt) {
|
if (attempt) {
|
||||||
|
this.miner.updateTime(attempt);
|
||||||
|
} else {
|
||||||
attempt = yield this.miner.createBlock();
|
attempt = yield this.miner.createBlock();
|
||||||
this.attempt = attempt;
|
this.attempt = attempt;
|
||||||
this.lastActivity = util.now();
|
this.lastActivity = util.now();
|
||||||
@ -2169,6 +2171,7 @@ RPC.prototype.updateWork = co(function* updateWork() {
|
|||||||
this.bindChain();
|
this.bindChain();
|
||||||
|
|
||||||
if (attempt) {
|
if (attempt) {
|
||||||
|
this.miner.updateTime(attempt);
|
||||||
if (++this.nonce2 === 0x100000000) {
|
if (++this.nonce2 === 0x100000000) {
|
||||||
this.nonce2 = 0;
|
this.nonce2 = 0;
|
||||||
this.nonce1++;
|
this.nonce1++;
|
||||||
|
|||||||
@ -151,6 +151,7 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) {
|
|||||||
ts: ts,
|
ts: ts,
|
||||||
bits: target,
|
bits: target,
|
||||||
locktime: locktime,
|
locktime: locktime,
|
||||||
|
mtp: mtp,
|
||||||
flags: this.chain.state.flags,
|
flags: this.chain.state.flags,
|
||||||
address: address,
|
address: address,
|
||||||
coinbaseFlags: this.options.coinbaseFlags,
|
coinbaseFlags: this.options.coinbaseFlags,
|
||||||
@ -192,6 +193,15 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) {
|
|||||||
return attempt;
|
return attempt;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update block timestamp.
|
||||||
|
* @param {BlockTemplate} attempt
|
||||||
|
*/
|
||||||
|
|
||||||
|
Miner.prototype.updateTime = function updateTime(attempt) {
|
||||||
|
attempt.ts = Math.max(this.network.now(), attempt.mtp + 1);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a cpu miner job.
|
* Create a cpu miner job.
|
||||||
* @method
|
* @method
|
||||||
|
|||||||
@ -42,6 +42,7 @@ function BlockTemplate(options) {
|
|||||||
this.bits = 0;
|
this.bits = 0;
|
||||||
this.target = encoding.ZERO_HASH;
|
this.target = encoding.ZERO_HASH;
|
||||||
this.locktime = 0;
|
this.locktime = 0;
|
||||||
|
this.mtp = 0;
|
||||||
this.flags = 0;
|
this.flags = 0;
|
||||||
this.coinbaseFlags = DUMMY;
|
this.coinbaseFlags = DUMMY;
|
||||||
this.witness = false;
|
this.witness = false;
|
||||||
@ -100,6 +101,11 @@ BlockTemplate.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.locktime = options.locktime;
|
this.locktime = options.locktime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.mtp != null) {
|
||||||
|
assert(typeof options.mtp === 'number');
|
||||||
|
this.mtp = options.mtp;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.flags != null) {
|
if (options.flags != null) {
|
||||||
assert(typeof options.flags === 'number');
|
assert(typeof options.flags === 'number');
|
||||||
this.flags = options.flags;
|
this.flags = options.flags;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user