minor improvements.
This commit is contained in:
parent
2037060c35
commit
33f7b38433
@ -105,6 +105,9 @@ Chain.prototype._init = function _init() {
|
|||||||
if (!self.synced && self.height < self.network.block.slowHeight)
|
if (!self.synced && self.height < self.network.block.slowHeight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (self.options.spv)
|
||||||
|
return;
|
||||||
|
|
||||||
bcoin.debug('Block %s (%d) added to chain.',
|
bcoin.debug('Block %s (%d) added to chain.',
|
||||||
utils.revHex(entry.hash), entry.height);
|
utils.revHex(entry.hash), entry.height);
|
||||||
});
|
});
|
||||||
@ -285,6 +288,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
var buf, height, stream;
|
var buf, height, stream;
|
||||||
var request = require('./http/request');
|
var request = require('./http/request');
|
||||||
var locker = new bcoin.locker();
|
var locker = new bcoin.locker();
|
||||||
|
var flushed = 0;
|
||||||
|
|
||||||
if (!this.options.preload)
|
if (!this.options.preload)
|
||||||
return callback();
|
return callback();
|
||||||
@ -295,7 +299,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
if (this.network.type !== 'main')
|
if (this.network.type !== 'main')
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
bcoin.debug('Loading %s', url);
|
bcoin.debug('Loading %s.', url);
|
||||||
|
|
||||||
function parseHeader(buf) {
|
function parseHeader(buf) {
|
||||||
var headers = bcoin.protocol.parser.parseBlockHeaders(buf);
|
var headers = bcoin.protocol.parser.parseBlockHeaders(buf);
|
||||||
@ -315,6 +319,9 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((++flushed % 50000) === 0)
|
||||||
|
utils.print('Flushed %d headers to DB.', flushed);
|
||||||
|
|
||||||
if (locker.jobs.length === 0 && save.ended)
|
if (locker.jobs.length === 0 && save.ended)
|
||||||
return callback();
|
return callback();
|
||||||
|
|
||||||
@ -334,10 +341,16 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
stream.on('response', function(res) {
|
stream.on('response', function(res) {
|
||||||
|
var height = +res.headers['content-length'] / 80 | 0;
|
||||||
if (res.statusCode >= 400) {
|
if (res.statusCode >= 400) {
|
||||||
stream.destroy();
|
stream.destroy();
|
||||||
return callback(new Error('Bad response code: ' + res.statusCode));
|
return callback(new Error('Bad response code: ' + res.statusCode));
|
||||||
}
|
}
|
||||||
|
if (chainHeight > height - 30000) {
|
||||||
|
bcoin.debug('Preload height is %d. Skipping.', height);
|
||||||
|
stream.destroy();
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('error', function(err) {
|
stream.on('error', function(err) {
|
||||||
@ -365,9 +378,6 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
buf.size += data.length;
|
buf.size += data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blocks.length === 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < blocks.length; i++) {
|
for (i = 0; i < blocks.length; i++) {
|
||||||
data = blocks[i];
|
data = blocks[i];
|
||||||
|
|
||||||
@ -405,9 +415,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
// Create a chain entry.
|
// Create a chain entry.
|
||||||
entry = new bcoin.chainentry(self, data, lastEntry);
|
entry = new bcoin.chainentry(self, data, lastEntry);
|
||||||
|
|
||||||
if (entry.height <= chainHeight)
|
if (entry.height > chainHeight)
|
||||||
self.db.addCache(entry);
|
|
||||||
else
|
|
||||||
save(entry);
|
save(entry);
|
||||||
|
|
||||||
if ((height + 1) % 50000 === 0)
|
if ((height + 1) % 50000 === 0)
|
||||||
|
|||||||
@ -1283,6 +1283,8 @@ Pool.prototype._removePeer = function _removePeer(peer) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.watch = function watch(data, enc) {
|
Pool.prototype.watch = function watch(data, enc) {
|
||||||
|
if (!this.options.spv)
|
||||||
|
return;
|
||||||
this.spvFilter.add(data, enc);
|
this.spvFilter.add(data, enc);
|
||||||
this.updateWatch();
|
this.updateWatch();
|
||||||
};
|
};
|
||||||
@ -1292,6 +1294,8 @@ Pool.prototype.watch = function watch(data, enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.unwatch = function unwatch() {
|
Pool.prototype.unwatch = function unwatch() {
|
||||||
|
if (!this.options.spv)
|
||||||
|
return;
|
||||||
this.spvFilter.reset();
|
this.spvFilter.reset();
|
||||||
this.updateWatch();
|
this.updateWatch();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -160,21 +160,6 @@ SPVNode.prototype._init = function _init() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
|
||||||
var i;
|
|
||||||
self.walletdb.getUnconfirmed(function(err, txs) {
|
|
||||||
if (err)
|
|
||||||
return next(err);
|
|
||||||
|
|
||||||
if (txs.length > 0)
|
|
||||||
bcoin.debug('Rebroadcasting %d transactions.', txs.length);
|
|
||||||
|
|
||||||
for (i = 0; i < txs.length; i++)
|
|
||||||
self.pool.broadcast(txs[i]);
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(next) {
|
function(next) {
|
||||||
var i;
|
var i;
|
||||||
self.walletdb.getAddresses(function(err, hashes) {
|
self.walletdb.getAddresses(function(err, hashes) {
|
||||||
@ -190,6 +175,21 @@ SPVNode.prototype._init = function _init() {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
function(next) {
|
||||||
|
var i;
|
||||||
|
self.walletdb.getUnconfirmed(function(err, txs) {
|
||||||
|
if (err)
|
||||||
|
return next(err);
|
||||||
|
|
||||||
|
if (txs.length > 0)
|
||||||
|
bcoin.debug('Rebroadcasting %d transactions.', txs.length);
|
||||||
|
|
||||||
|
for (i = 0; i < txs.length; i++)
|
||||||
|
self.pool.broadcast(txs[i]);
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
if (!self.chain.options.preload)
|
if (!self.chain.options.preload)
|
||||||
return next();
|
return next();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user