expose chain deployment state.
This commit is contained in:
parent
196f3ca861
commit
3def705d35
@ -35,8 +35,7 @@ var VerifyError = bcoin.errors.VerifyError;
|
||||
* @property {Number} bestHeight
|
||||
* @property {ChainEntry?} tip
|
||||
* @property {Number} height
|
||||
* @property {Boolean} segwitActive
|
||||
* @property {Boolean} csvActive
|
||||
* @property {DeploymentState} state
|
||||
* @property {Object} orphan - Orphan map.
|
||||
* @emits Chain#open
|
||||
* @emits Chain#error
|
||||
@ -77,8 +76,7 @@ function Chain(options) {
|
||||
this.tip = null;
|
||||
this.height = -1;
|
||||
this.synced = false;
|
||||
this.segwitActive = null;
|
||||
this.csvActive = null;
|
||||
this.state = new DeploymentState();
|
||||
this.stateCache = {};
|
||||
|
||||
this.orphan = {
|
||||
@ -219,10 +217,10 @@ Chain.prototype._open = function open(callback) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (self.csvActive)
|
||||
if (self.state.hasCSV())
|
||||
self.logger.info('CSV is active.');
|
||||
|
||||
if (self.segwitActive)
|
||||
if (self.state.hasWitness())
|
||||
self.logger.info('Segwit is active.');
|
||||
|
||||
self.logger.memory();
|
||||
@ -475,7 +473,7 @@ Chain.prototype.verify = function verify(block, prev, callback) {
|
||||
|
||||
// Skip the genesis block. Skip all blocks in spv mode.
|
||||
if (this.options.spv || this.isGenesis(block))
|
||||
return callback(null, new DeploymentState());
|
||||
return callback(null, this.state);
|
||||
|
||||
// Ensure it's not an orphan
|
||||
if (!prev) {
|
||||
@ -511,9 +509,8 @@ Chain.prototype.verify = function verify(block, prev, callback) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
// Expose the state of csv and segwit globally.
|
||||
self.csvActive = state.hasCSV();
|
||||
self.segwitActive = state.hasWitness();
|
||||
// Expose the state globally.
|
||||
self.state = state;
|
||||
|
||||
// Can't verify any further when merkleblock or headers.
|
||||
if (self.options.spv)
|
||||
@ -2258,9 +2255,6 @@ Chain.prototype.computeBlockVersion = function computeBlockVersion(prev, callbac
|
||||
Chain.prototype.getInitialState = function getInitialState(callback) {
|
||||
var self = this;
|
||||
|
||||
if (this.segwitActive != null)
|
||||
return utils.nextTick(callback);
|
||||
|
||||
if (!this.tip)
|
||||
return utils.nextTick(callback);
|
||||
|
||||
@ -2268,11 +2262,8 @@ Chain.prototype.getInitialState = function getInitialState(callback) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
if (!prev) {
|
||||
self.csvActive = false;
|
||||
self.segwitActive = false;
|
||||
if (!prev)
|
||||
return callback();
|
||||
}
|
||||
|
||||
prev.getRetargetAncestors(function(err, ancestors) {
|
||||
if (err)
|
||||
@ -2282,8 +2273,7 @@ Chain.prototype.getInitialState = function getInitialState(callback) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
self.csvActive = state.hasCSV();
|
||||
self.segwitActive = state.hasWitness();
|
||||
self.state = state;
|
||||
|
||||
return callback(null, state);
|
||||
});
|
||||
|
||||
@ -691,7 +691,7 @@ Mempool.prototype.addTX = function addTX(tx, callback, force) {
|
||||
}
|
||||
|
||||
if (this.requireStandard) {
|
||||
if (!this.chain.csvActive && tx.version >= 2) {
|
||||
if (!this.chain.state.hasCSV() && tx.version >= 2) {
|
||||
return callback(new VerifyError(tx,
|
||||
'nonstandard',
|
||||
'premature-version2-tx',
|
||||
@ -699,7 +699,7 @@ Mempool.prototype.addTX = function addTX(tx, callback, force) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.chain.segwitActive && !this.prematureWitness) {
|
||||
if (!this.chain.state.hasWitness() && !this.prematureWitness) {
|
||||
if (tx.hasWitness()) {
|
||||
return callback(new VerifyError(tx,
|
||||
'nonstandard',
|
||||
@ -971,7 +971,7 @@ Mempool.prototype.verify = function verify(entry, callback) {
|
||||
var ret = {};
|
||||
var fee, modFee, now, size, rejectFee, minRelayFee, minRate;
|
||||
|
||||
if (this.chain.segwitActive)
|
||||
if (this.chain.state.hasWitness())
|
||||
mandatory |= constants.flags.VERIFY_WITNESS;
|
||||
|
||||
this.checkLocks(tx, lockFlags, function(err, result) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user