miner: mining and rpc changes.
This commit is contained in:
parent
b025f5c241
commit
65ddc563d6
@ -1365,8 +1365,11 @@ RPC.prototype.__submitwork = co(function* _submitwork(data) {
|
||||
try {
|
||||
yield this.chain.add(block);
|
||||
} catch (err) {
|
||||
if (err.type === 'VerifyError')
|
||||
if (err.type === 'VerifyError') {
|
||||
this.logger.warning('RPC block rejected: %s (%s).',
|
||||
block.rhash(), err.reason);
|
||||
return false;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -1454,8 +1457,11 @@ RPC.prototype.__submitblock = co(function* submitblock(block) {
|
||||
try {
|
||||
yield this.chain.add(block);
|
||||
} catch (err) {
|
||||
if (err.type === 'VerifyError')
|
||||
if (err.type === 'VerifyError') {
|
||||
this.logger.warning('RPC block rejected: %s (%s).',
|
||||
block.rhash(), err.reason);
|
||||
return 'rejected: ' + err.reason;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -1666,13 +1672,14 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
|
||||
sigops: tx.getSigopsCost() / scale | 0,
|
||||
weight: tx.getWeight()
|
||||
};
|
||||
} else {
|
||||
template.coinbaseaux = {
|
||||
flags: attempt.coinbaseFlags.toString('hex')
|
||||
};
|
||||
template.coinbasevalue = attempt.coinbase.getOutputValue();
|
||||
}
|
||||
|
||||
template.coinbaseaux = {
|
||||
flags: attempt.coinbaseFlags.toString('hex')
|
||||
};
|
||||
|
||||
template.coinbasevalue = attempt.coinbase.getOutputValue();
|
||||
|
||||
if (attempt.witness) {
|
||||
tx = attempt.coinbase;
|
||||
output = tx.outputs[tx.outputs.length - 1];
|
||||
|
||||
@ -306,21 +306,29 @@ Miner.prototype._onStop = function _onStop() {
|
||||
|
||||
Miner.prototype.createBlock = co(function* createBlock(tip, address) {
|
||||
var version = this.version;
|
||||
var ts, attempt, target, locktime;
|
||||
var now = this.network.now();
|
||||
var ts, locktime, median, target, attempt;
|
||||
|
||||
if (!tip)
|
||||
tip = this.chain.tip;
|
||||
|
||||
assert(tip);
|
||||
|
||||
ts = Math.max(this.network.now(), tip.ts + 1);
|
||||
ts = Math.max(now, tip.ts + 1);
|
||||
locktime = ts;
|
||||
|
||||
target = yield this.chain.getTargetAsync(ts, tip);
|
||||
|
||||
if (version === -1)
|
||||
version = yield this.chain.computeBlockVersion(tip);
|
||||
|
||||
// Cheat on testnet.
|
||||
// if (this.network.difficultyReset) {
|
||||
// median = yield tip.getMedianTimeAsync();
|
||||
// ts = cheat(tip.ts, median, now);
|
||||
// locktime = ts;
|
||||
// }
|
||||
|
||||
target = yield this.chain.getTargetAsync(ts, tip);
|
||||
|
||||
if (this.chain.state.hasMTP())
|
||||
locktime = yield tip.getMedianTimeAsync();
|
||||
|
||||
@ -540,6 +548,24 @@ function cmpRate(a, b) {
|
||||
return a.rate - b.rate;
|
||||
}
|
||||
|
||||
function cheat(prevTime, now, medianTime) {
|
||||
var resetTime = prevTime + (20 * 60);
|
||||
|
||||
// Already easy.
|
||||
if (now <= resetTime)
|
||||
return medianTime + 1;
|
||||
|
||||
// time-too-new - 30 min
|
||||
if (resetTime > now + (1.5 * 60 * 60))
|
||||
return medianTime + 1;
|
||||
|
||||
// time-too-old
|
||||
if (resetTime <= medianTime)
|
||||
return medianTime + 1;
|
||||
|
||||
return resetTime;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user