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