chain: refactor tx validation.
This commit is contained in:
parent
960d144455
commit
8c923179dc
@ -604,7 +604,7 @@ Chain.prototype.checkInputs = co(function* checkInputs(block, prev, state) {
|
||||
var sigops = 0;
|
||||
var jobs = [];
|
||||
var ret = new VerifyResult();
|
||||
var i, view, tx, valid, result;
|
||||
var i, view, tx, valid;
|
||||
|
||||
if (this.options.spv)
|
||||
return;
|
||||
@ -677,16 +677,13 @@ Chain.prototype.checkInputs = co(function* checkInputs(block, prev, state) {
|
||||
return view;
|
||||
|
||||
// Verify all txs in parallel.
|
||||
result = yield Promise.all(jobs);
|
||||
valid = yield spawn.every(jobs);
|
||||
|
||||
for (i = 0; i < result.length; i++) {
|
||||
valid = result[i];
|
||||
if (!valid) {
|
||||
throw new VerifyError(block,
|
||||
'invalid',
|
||||
'mandatory-script-verify-flag-failed',
|
||||
100);
|
||||
}
|
||||
if (!valid) {
|
||||
throw new VerifyError(block,
|
||||
'invalid',
|
||||
'mandatory-script-verify-flag-failed',
|
||||
100);
|
||||
}
|
||||
|
||||
// Make sure the miner isn't trying to conjure more coins.
|
||||
@ -1075,7 +1072,7 @@ Chain.prototype._add = co(function* add(block) {
|
||||
}
|
||||
|
||||
// Special case for genesis block.
|
||||
if (this.isGenesis(block))
|
||||
if (hash === this.network.genesis.hash)
|
||||
break;
|
||||
|
||||
// Validate the block we want to add.
|
||||
@ -1861,13 +1858,15 @@ Chain.prototype.getState = co(function* getState(prev, id) {
|
||||
if (block.hasBit(deployment))
|
||||
count++;
|
||||
|
||||
if (count >= threshold) {
|
||||
state = constants.thresholdStates.LOCKED_IN;
|
||||
break;
|
||||
}
|
||||
|
||||
block = yield block.getPrevious();
|
||||
assert(block);
|
||||
}
|
||||
|
||||
if (count >= threshold)
|
||||
state = constants.thresholdStates.LOCKED_IN;
|
||||
|
||||
break;
|
||||
case constants.thresholdStates.LOCKED_IN:
|
||||
state = constants.thresholdStates.ACTIVE;
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./utils');
|
||||
var every;
|
||||
|
||||
/**
|
||||
* Execute an instantiated generator.
|
||||
@ -272,6 +273,25 @@ function promisify(func, ctx) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute each promise and
|
||||
* have them pass a truth test.
|
||||
* @param {Promise[]} jobs
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
every = co(function* every(jobs) {
|
||||
var result = yield Promise.all(jobs);
|
||||
var i;
|
||||
|
||||
for (i = 0; i < result.length; i++) {
|
||||
if (!result[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
/*
|
||||
* This drives me nuts.
|
||||
*/
|
||||
@ -302,5 +322,6 @@ exports.timeout = timeout;
|
||||
exports.wrap = wrap;
|
||||
exports.call = call;
|
||||
exports.promisify = promisify;
|
||||
exports.every = every;
|
||||
|
||||
module.exports = spawn;
|
||||
|
||||
@ -1832,6 +1832,7 @@ TXDB.prototype.getSpentCoin = co(function* getSpentCoin(spent, prevout) {
|
||||
coin = bcoin.coin.fromRaw(data);
|
||||
coin.hash = prevout.hash;
|
||||
coin.index = prevout.index;
|
||||
|
||||
return coin;
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user