chain: use separate state caches for separate deployments.

This commit is contained in:
Christopher Jeffrey 2016-07-24 23:09:22 -07:00
parent d68d79841a
commit cc6018a94e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -99,6 +99,15 @@ utils.inherits(Chain, AsyncObject);
Chain.prototype._init = function _init() {
var self = this;
var i, keys, id;
// Setup state caches.
keys = Object.keys(this.network.deployments);
for (i = 0; i < keys.length; i++) {
id = keys[i];
this.stateCache[id] = {};
}
this.locker.on('purge', function(total, size) {
self.logger.warning('Warning: %dmb of pending objects. Purging.', utils.mb(size));
@ -2135,6 +2144,7 @@ Chain.prototype.getState = function getState(prev, id, callback) {
var period = this.network.minerWindow;
var threshold = this.network.activationThreshold;
var deployment = this.network.deployments[id];
var stateCache = this.stateCache[id];
var timeStart, timeTimeout, compute, height;
if (!deployment)
@ -2174,8 +2184,8 @@ Chain.prototype.getState = function getState(prev, id, callback) {
if (!entry)
return walkForward(constants.thresholdStates.DEFINED);
if (self.stateCache[entry.hash] != null)
return walkForward(self.stateCache[entry.hash]);
if (stateCache[entry.hash] != null)
return walkForward(stateCache[entry.hash]);
return entry.getMedianTimeAsync(function(err, medianTime) {
if (err)
@ -2207,16 +2217,16 @@ Chain.prototype.getState = function getState(prev, id, callback) {
return callback(err);
if (medianTime >= timeTimeout) {
self.stateCache[entry.hash] = constants.thresholdStates.FAILED;
stateCache[entry.hash] = constants.thresholdStates.FAILED;
return walkForward(constants.thresholdStates.FAILED);
}
if (medianTime >= timeStart) {
self.stateCache[entry.hash] = constants.thresholdStates.STARTED;
stateCache[entry.hash] = constants.thresholdStates.STARTED;
return walkForward(constants.thresholdStates.STARTED);
}
self.stateCache[entry.hash] = state;
stateCache[entry.hash] = state;
return walkForward(state);
});
case constants.thresholdStates.STARTED:
@ -2225,7 +2235,7 @@ Chain.prototype.getState = function getState(prev, id, callback) {
return callback(err);
if (medianTime >= timeTimeout) {
self.stateCache[entry.hash] = constants.thresholdStates.FAILED;
stateCache[entry.hash] = constants.thresholdStates.FAILED;
return walkForward(constants.thresholdStates.FAILED);
}
@ -2253,20 +2263,20 @@ Chain.prototype.getState = function getState(prev, id, callback) {
return callback(err);
if (count >= threshold) {
self.stateCache[entry.hash] = constants.thresholdStates.LOCKED_IN;
stateCache[entry.hash] = constants.thresholdStates.LOCKED_IN;
return walkForward(constants.thresholdStates.LOCKED_IN);
}
self.stateCache[entry.hash] = state;
stateCache[entry.hash] = state;
return walkForward(state);
}
});
case constants.thresholdStates.LOCKED_IN:
self.stateCache[entry.hash] = constants.thresholdStates.ACTIVE;
stateCache[entry.hash] = constants.thresholdStates.ACTIVE;
return walkForward(constants.thresholdStates.ACTIVE);
case constants.thresholdStates.FAILED:
case constants.thresholdStates.ACTIVE:
self.stateCache[entry.hash] = state;
stateCache[entry.hash] = state;
return walkForward(state);
}