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