optimize.
This commit is contained in:
parent
6081998516
commit
1e962a5594
@ -305,12 +305,12 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function save(entry) {
|
function save(entry, header) {
|
||||||
var unlock = locker.lock(save, [entry]);
|
var unlock = locker.lock(save, [entry]);
|
||||||
if (!unlock)
|
if (!unlock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
self.db.save(entry, null, null, true, function(err) {
|
self.db.save(entry, header, null, true, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
stream.destroy();
|
stream.destroy();
|
||||||
locker.destroy();
|
locker.destroy();
|
||||||
@ -414,7 +414,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
entry = new bcoin.chainentry(self, data, lastEntry);
|
entry = new bcoin.chainentry(self, data, lastEntry);
|
||||||
|
|
||||||
if (entry.height > chainHeight)
|
if (entry.height > chainHeight)
|
||||||
save(entry);
|
save(entry, block);
|
||||||
|
|
||||||
if ((height + 1) % 50000 === 0)
|
if ((height + 1) % 50000 === 0)
|
||||||
bcoin.debug('Received %d headers from electrum.org.', height + 1);
|
bcoin.debug('Received %d headers from electrum.org.', height + 1);
|
||||||
|
|||||||
@ -555,17 +555,10 @@ ChainDB.prototype.get = function get(hash, callback) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
|
ChainDB.prototype.save = function save(entry, block, view, connect, callback) {
|
||||||
var batch, hash, height;
|
var batch = this.db.batch();
|
||||||
|
var hash = block.hash();
|
||||||
|
var height = new Buffer(4);
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
|
||||||
|
|
||||||
assert(entry.height >= 0);
|
|
||||||
|
|
||||||
batch = this.db.batch();
|
|
||||||
|
|
||||||
hash = new Buffer(entry.hash, 'hex');
|
|
||||||
|
|
||||||
height = new Buffer(4);
|
|
||||||
height.writeUInt32LE(height, 0, true);
|
height.writeUInt32LE(height, 0, true);
|
||||||
|
|
||||||
batch.put(layout.h(entry.hash), height);
|
batch.put(layout.h(entry.hash), height);
|
||||||
@ -625,7 +618,7 @@ ChainDB.prototype.getTip = function getTip(callback) {
|
|||||||
|
|
||||||
ChainDB.prototype.connect = function connect(entry, block, view, callback) {
|
ChainDB.prototype.connect = function connect(entry, block, view, callback) {
|
||||||
var batch = this.db.batch();
|
var batch = this.db.batch();
|
||||||
var hash = new Buffer(entry.hash, 'hex');
|
var hash = block.hash();
|
||||||
|
|
||||||
batch.put(layout.n(entry.prevBlock), hash);
|
batch.put(layout.n(entry.prevBlock), hash);
|
||||||
batch.put(layout.H(entry.height), hash);
|
batch.put(layout.H(entry.height), hash);
|
||||||
@ -656,9 +649,7 @@ ChainDB.prototype.connect = function connect(entry, block, view, callback) {
|
|||||||
|
|
||||||
ChainDB.prototype.disconnect = function disconnect(entry, callback) {
|
ChainDB.prototype.disconnect = function disconnect(entry, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var batch;
|
var batch = this.db.batch();
|
||||||
|
|
||||||
batch = this.db.batch();
|
|
||||||
|
|
||||||
batch.del(layout.n(entry.prevBlock));
|
batch.del(layout.n(entry.prevBlock));
|
||||||
batch.del(layout.H(entry.height));
|
batch.del(layout.H(entry.height));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user