chain: log state updates after db write.
This commit is contained in:
parent
e025902405
commit
0530c8f80f
@ -192,7 +192,7 @@ Chain.prototype._init = function _init() {
|
||||
*/
|
||||
|
||||
Chain.prototype._open = co(function* open() {
|
||||
var tip;
|
||||
var tip, state;
|
||||
|
||||
this.logger.info('Chain is loading.');
|
||||
|
||||
@ -218,7 +218,9 @@ Chain.prototype._open = co(function* open() {
|
||||
|
||||
this.logger.memory();
|
||||
|
||||
this.state = yield this.getDeploymentState();
|
||||
state = yield this.getDeploymentState();
|
||||
|
||||
this.setDeploymentState(state);
|
||||
|
||||
this.logger.memory();
|
||||
|
||||
@ -455,11 +457,8 @@ Chain.prototype.getDeployments = co(function* getDeployments(block, prev) {
|
||||
// not have a signature. See:
|
||||
// 6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192
|
||||
// 9c08a4d78931342b37fd5f72900fb9983087e6f46c4a097d8a1f52c74e28eaf6
|
||||
if (block.ts >= constants.block.BIP16_TIME) {
|
||||
if (block.ts >= constants.block.BIP16_TIME)
|
||||
state.flags |= constants.flags.VERIFY_P2SH;
|
||||
if (!this.state.hasP2SH())
|
||||
this.logger.warning('P2SH has been activated.');
|
||||
}
|
||||
|
||||
// Only allow version 2 blocks (coinbase height)
|
||||
// once the majority of blocks are using it.
|
||||
@ -484,33 +483,21 @@ Chain.prototype.getDeployments = co(function* getDeployments(block, prev) {
|
||||
}
|
||||
|
||||
// Coinbase heights are now enforced (bip34).
|
||||
if (height >= this.network.block.bip34height) {
|
||||
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).
|
||||
if (height >= this.network.block.bip66height) {
|
||||
if (height >= this.network.block.bip66height)
|
||||
state.flags |= constants.flags.VERIFY_DERSIG;
|
||||
if (!this.state.hasBIP66())
|
||||
this.logger.warning('BIP66 has been activated.');
|
||||
}
|
||||
|
||||
// CHECKLOCKTIMEVERIFY is now usable (bip65)
|
||||
if (height >= this.network.block.bip65height) {
|
||||
if (height >= this.network.block.bip65height)
|
||||
state.flags |= constants.flags.VERIFY_CHECKLOCKTIMEVERIFY;
|
||||
if (!this.state.hasCLTV())
|
||||
this.logger.warning('BIP65 has been activated.');
|
||||
}
|
||||
|
||||
// Segregrated witness is now usable (bip141 - segnet3)
|
||||
if (this.options.witness && this.network.oldWitness) {
|
||||
if (height >= this.network.block.bip141height) {
|
||||
if (height >= this.network.block.bip141height)
|
||||
state.flags |= constants.flags.VERIFY_WITNESS;
|
||||
if (!this.state.hasWitness())
|
||||
this.logger.warning('Segwit has been activated.');
|
||||
}
|
||||
}
|
||||
|
||||
if (this.network.oldWitness)
|
||||
@ -523,18 +510,13 @@ Chain.prototype.getDeployments = co(function* getDeployments(block, prev) {
|
||||
state.flags |= constants.flags.VERIFY_CHECKSEQUENCEVERIFY;
|
||||
state.lockFlags |= constants.flags.VERIFY_SEQUENCE;
|
||||
state.lockFlags |= constants.flags.MEDIAN_TIME_PAST;
|
||||
if (!this.state.hasCSV())
|
||||
this.logger.warning('CSV has been activated.');
|
||||
}
|
||||
|
||||
// Segregrated witness is now usable (bip141 - segnet4)
|
||||
active = yield this.isActive(prev, 'witness');
|
||||
if (active) {
|
||||
if (this.options.witness) {
|
||||
if (this.options.witness)
|
||||
state.flags |= constants.flags.VERIFY_WITNESS;
|
||||
if (!this.state.hasWitness())
|
||||
this.logger.warning('Segwit has been activated.');
|
||||
}
|
||||
// BIP147
|
||||
state.flags |= constants.flags.VERIFY_NULLDUMMY;
|
||||
}
|
||||
@ -542,6 +524,36 @@ Chain.prototype.getDeployments = co(function* getDeployments(block, prev) {
|
||||
return state;
|
||||
});
|
||||
|
||||
/**
|
||||
* Set a new deployment state.
|
||||
* @param {DeploymentState} state
|
||||
*/
|
||||
|
||||
Chain.prototype.setDeploymentState = function setDeploymentState(state) {
|
||||
if (!this.state.hasP2SH() && state.hasP2SH())
|
||||
this.logger.warning('P2SH has been activated.');
|
||||
|
||||
if (!this.state.hasBIP34() && state.hasBIP34())
|
||||
this.logger.warning('BIP34 has been activated.');
|
||||
|
||||
if (!this.state.hasBIP66() && state.hasBIP66())
|
||||
this.logger.warning('BIP66 has been activated.');
|
||||
|
||||
if (!this.state.hasCLTV() && state.hasCLTV())
|
||||
this.logger.warning('BIP65 has been activated.');
|
||||
|
||||
if (!this.state.hasWitness() && state.hasWitness())
|
||||
this.logger.warning('Segwit has been activated.');
|
||||
|
||||
if (!this.state.hasCSV() && state.hasCSV())
|
||||
this.logger.warning('CSV has been activated.');
|
||||
|
||||
if (!this.state.hasWitness() && state.hasWitness())
|
||||
this.logger.warning('Segwit has been activated.');
|
||||
|
||||
this.state = state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine whether to check block for duplicate txids in blockchain
|
||||
* history (BIP30). If we're on a chain that has bip34 activated, we
|
||||
@ -900,8 +912,8 @@ Chain.prototype.reconnect = co(function* reconnect(entry) {
|
||||
|
||||
this.tip = entry;
|
||||
this.height = entry.height;
|
||||
this.state = result.state;
|
||||
this.bestHeight = entry.height;
|
||||
this.setDeploymentState(result.state);
|
||||
|
||||
this.emit('tip', entry);
|
||||
this.emit('reconnect', entry, block);
|
||||
@ -962,7 +974,7 @@ Chain.prototype.setBestChain = co(function* setBestChain(entry, block, prev) {
|
||||
// Expose the new state.
|
||||
this.tip = entry;
|
||||
this.height = entry.height;
|
||||
this.state = result.state;
|
||||
this.setDeploymentState(result.state);
|
||||
|
||||
this.emit('tip', entry);
|
||||
});
|
||||
@ -1024,13 +1036,16 @@ Chain.prototype.reset = co(function* reset(block) {
|
||||
|
||||
Chain.prototype._reset = co(function* reset(block, silent) {
|
||||
var tip = yield this.db.reset(block);
|
||||
var state;
|
||||
|
||||
// Reset state.
|
||||
this.tip = tip;
|
||||
this.height = tip.height;
|
||||
this.state = yield this.getDeploymentState();
|
||||
this.synced = this.isFull(true);
|
||||
|
||||
state = yield this.getDeploymentState();
|
||||
this.setDeploymentState(state);
|
||||
|
||||
this.emit('tip', tip);
|
||||
|
||||
if (!silent)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user