chain: comments.

This commit is contained in:
Christopher Jeffrey 2016-11-17 04:12:25 -08:00
parent 39aee21030
commit 09f449167f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -315,7 +315,8 @@ Chain.prototype.verify = co(function* verify(block, prev) {
if (this.options.spv)
return this.state;
// Skip any blocks below the last checkpoint.
// Skip any blocks below the
// last checkpoint.
if (!this.options.witness) {
// We can't skip this with segwit
// enabled since the block may have
@ -330,7 +331,7 @@ Chain.prototype.verify = co(function* verify(block, prev) {
ancestors = yield prev.getRetargetAncestors();
medianTime = prev.getMedianTime(ancestors);
// Ensure the timestamp is correct
// Ensure the timestamp is correct.
if (block.ts <= medianTime) {
throw new VerifyError(block,
'invalid',
@ -338,6 +339,7 @@ Chain.prototype.verify = co(function* verify(block, prev) {
0);
}
// Ensure the POW is what we expect.
if (block.bits !== this.getTarget(block, prev, ancestors)) {
throw new VerifyError(block,
'invalid',
@ -345,9 +347,11 @@ Chain.prototype.verify = co(function* verify(block, prev) {
100);
}
// Get the new deployment state.
state = yield this.getDeployments(block, prev);
// Make sure the height contained in the coinbase is correct.
// Make sure the height contained
// in the coinbase is correct.
if (state.hasBIP34()) {
if (block.getCoinbaseHeight() !== height) {
throw new VerifyError(block,
@ -412,12 +416,11 @@ Chain.prototype.verify = co(function* verify(block, prev) {
// Get timestamp for tx.isFinal().
ts = state.hasMTP() ? medianTime : block.ts;
// Check all transactions
// Transactions must be finalized with
// regards to nSequence and nLockTime.
for (i = 0; i < block.txs.length; i++) {
tx = block.txs[i];
// Transactions must be finalized with
// regards to nSequence and nLockTime.
if (!tx.isFinal(height, ts)) {
throw new VerifyError(block,
'invalid',
@ -478,14 +481,14 @@ Chain.prototype.getDeployments = co(function* getDeployments(block, prev) {
throw new VerifyError(block, 'obsolete', 'bad-version', 0);
}
// Make sure the height contained in the coinbase is correct.
// Coinbase heights are now enforced (bip34).
if (height >= this.network.block.bip34height) {
state.bip34 = true;
if (!this.state.hasBIP34())
this.logger.warning('BIP34 has been activated.');
}
// Signature validation is now enforced (bip66)
// Signature validation is now enforced (bip66).
if (height >= this.network.block.bip66height) {
state.flags |= constants.flags.VERIFY_DERSIG;
if (!this.state.hasBIP66())
@ -708,10 +711,12 @@ Chain.prototype.verifyInputs = co(function* verifyInputs(block, prev, state) {
*/
Chain.prototype.checkHeight = function checkHeight(hash) {
if (this.db.hasCache(hash))
return this.db.getCache(hash).height;
var entry = this.db.getCache(hash);
return -1;
if (!entry)
return -1;
return entry.height;
};
/**
@ -849,7 +854,6 @@ Chain.prototype.disconnect = co(function* disconnect(entry) {
this.tip = prev;
this.height = prev.height;
this.bestHeight = prev.height;
this.emit('tip', prev);
@ -895,7 +899,6 @@ Chain.prototype.reconnect = co(function* reconnect(entry) {
this.tip = entry;
this.height = entry.height;
this.state = result.state;
this.bestHeight = entry.height;
this.emit('tip', entry);