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),
|
||||
noncerange: '00000000ffffffff',
|
||||
curtime: attempt.ts,
|
||||
mintime: attempt.ts,
|
||||
mintime: attempt.mtp + 1,
|
||||
maxtime: attempt.ts + 7200,
|
||||
expires: attempt.ts + 7200,
|
||||
sigoplimit: consensus.MAX_BLOCK_SIGOPS_COST / scale | 0,
|
||||
@ -2153,7 +2153,9 @@ RPC.prototype.getTemplate = co(function* getTemplate() {
|
||||
|
||||
this.bindChain();
|
||||
|
||||
if (!attempt) {
|
||||
if (attempt) {
|
||||
this.miner.updateTime(attempt);
|
||||
} else {
|
||||
attempt = yield this.miner.createBlock();
|
||||
this.attempt = attempt;
|
||||
this.lastActivity = util.now();
|
||||
@ -2169,6 +2171,7 @@ RPC.prototype.updateWork = co(function* updateWork() {
|
||||
this.bindChain();
|
||||
|
||||
if (attempt) {
|
||||
this.miner.updateTime(attempt);
|
||||
if (++this.nonce2 === 0x100000000) {
|
||||
this.nonce2 = 0;
|
||||
this.nonce1++;
|
||||
|
||||
@ -151,6 +151,7 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) {
|
||||
ts: ts,
|
||||
bits: target,
|
||||
locktime: locktime,
|
||||
mtp: mtp,
|
||||
flags: this.chain.state.flags,
|
||||
address: address,
|
||||
coinbaseFlags: this.options.coinbaseFlags,
|
||||
@ -192,6 +193,15 @@ Miner.prototype._createBlock = co(function* createBlock(tip, address) {
|
||||
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.
|
||||
* @method
|
||||
|
||||
@ -42,6 +42,7 @@ function BlockTemplate(options) {
|
||||
this.bits = 0;
|
||||
this.target = encoding.ZERO_HASH;
|
||||
this.locktime = 0;
|
||||
this.mtp = 0;
|
||||
this.flags = 0;
|
||||
this.coinbaseFlags = DUMMY;
|
||||
this.witness = false;
|
||||
@ -100,6 +101,11 @@ BlockTemplate.prototype.fromOptions = function fromOptions(options) {
|
||||
this.locktime = options.locktime;
|
||||
}
|
||||
|
||||
if (options.mtp != null) {
|
||||
assert(typeof options.mtp === 'number');
|
||||
this.mtp = options.mtp;
|
||||
}
|
||||
|
||||
if (options.flags != null) {
|
||||
assert(typeof options.flags === 'number');
|
||||
this.flags = options.flags;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user