rpc: optimize getchaintips.

This commit is contained in:
Christopher Jeffrey 2016-08-09 21:12:53 -07:00
parent 20a8d23c76
commit 242fbd0a59
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -956,7 +956,7 @@ RPC.prototype.getchaintips = function getchaintips(args, callback) {
tips.push(self.chain.tip);
utils.forEachSerial(tips, function(entry, next) {
self.chain.findFork(entry, self.chain.tip, function(err, fork) {
self._findFork(entry, function(err, fork) {
if (err)
return next(err);
@ -984,6 +984,20 @@ RPC.prototype.getchaintips = function getchaintips(args, callback) {
});
};
RPC.prototype._findFork = function _findFork(entry, callback) {
(function next(err, entry) {
entry.isMainChain(function(err, main) {
if (err)
return callback(err);
if (main)
return callback(null, entry);
entry.getPrevious(next);
});
})(null, entry);
};
RPC.prototype.getdifficulty = function getdifficulty(args, callback) {
if (args.help || args.length !== 0)
return callback(new RPCError('getdifficulty'));