async work.
This commit is contained in:
parent
cefeaf779b
commit
3a63da5735
@ -695,15 +695,9 @@ Chain.prototype._addEntry = function _addEntry(entry, block, callback) {
|
||||
};
|
||||
|
||||
Chain.prototype.resetHeight = function resetHeight(height) {
|
||||
var self = this;
|
||||
var i, existing;
|
||||
|
||||
assert(height <= count - 1);
|
||||
assert(this.tip);
|
||||
|
||||
this._clearPending();
|
||||
|
||||
if (height === count - 1)
|
||||
if (height === this.db.getSize() - 1)
|
||||
return;
|
||||
|
||||
this.db.resetHeightSync(height);
|
||||
@ -721,10 +715,6 @@ Chain.prototype.resetHeight = function resetHeight(height) {
|
||||
Chain.prototype.resetHeightAsync = function resetHeightAsync(height, callback) {
|
||||
var self = this;
|
||||
var lock = this.lock;
|
||||
var i;
|
||||
|
||||
assert(height <= count - 1);
|
||||
assert(this.tip);
|
||||
|
||||
this.lock = true;
|
||||
|
||||
@ -734,7 +724,7 @@ Chain.prototype.resetHeightAsync = function resetHeightAsync(height, callback) {
|
||||
callback(err, result);
|
||||
}
|
||||
|
||||
if (height === count - 1)
|
||||
if (height === this.db.getSize() - 1)
|
||||
return utils.nextTick(done);
|
||||
|
||||
this.db.resetHeightAsync(height, function(err) {
|
||||
@ -1708,7 +1698,7 @@ Chain.prototype.getLocatorAsync = function getLocatorAsync(start, callback) {
|
||||
i = i - step;
|
||||
if (i <= 0) {
|
||||
if (i + step !== 0)
|
||||
hashes.push(0);
|
||||
hashes.push(network.genesis.hash);
|
||||
break;
|
||||
}
|
||||
if (hashes.length >= 10)
|
||||
@ -1739,6 +1729,8 @@ Chain.prototype.getLocatorAsync = function getLocatorAsync(start, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
// Chain.prototype.getLocatorAsync = wrap(Chain.prototype.getLocatorAsync);
|
||||
|
||||
Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
||||
var self = this;
|
||||
var root;
|
||||
|
||||
@ -272,6 +272,43 @@ Pool.prototype.loadHeaders = function loadHeaders(peer, top, stop) {
|
||||
});
|
||||
};
|
||||
|
||||
Pool.prototype.loadBlocks = function loadBlocks(peer, top, stop) {
|
||||
var self = this;
|
||||
this.chain._onFlush(function() {
|
||||
self.chain.getLocatorAsync(top, function(err, locator) {
|
||||
if (err)
|
||||
throw err;
|
||||
peer.loadBlocks(locator, stop);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Pool.prototype.loadOrphan = function loadOrphan(peer, top, orphan) {
|
||||
var self = this;
|
||||
assert(orphan);
|
||||
this.chain._onFlush(function() {
|
||||
self.chain.getLocatorAsync(top, function(err, locator) {
|
||||
if (err)
|
||||
throw err;
|
||||
peer.loadBlocks(
|
||||
locator,
|
||||
self.chain.getOrphanRoot(orphan)
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Pool.prototype.loadHeaders = function loadHeaders(peer, top, stop) {
|
||||
var self = this;
|
||||
this.chain._onFlush(function() {
|
||||
self.chain.getLocatorAsync(top, function(err, locator) {
|
||||
if (err)
|
||||
throw err;
|
||||
peer.loadHeaders(locator, stop);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Pool.prototype.startServer = function startServer() {
|
||||
var self = this;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user