refactor prune.
This commit is contained in:
parent
a484d290d2
commit
1c1c34e6a4
@ -476,12 +476,7 @@ ChainDB.prototype.save = function save(entry, block, connect, callback) {
|
||||
this.saveBlock(block, batch, true, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
self._pruneBlock(block, batch, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return batch.write(callback);
|
||||
});
|
||||
return batch.write(callback);
|
||||
});
|
||||
};
|
||||
|
||||
@ -790,8 +785,6 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
||||
}
|
||||
|
||||
this._ensureBlock(block, function(err, block) {
|
||||
var height;
|
||||
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
@ -849,7 +842,11 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
||||
|
||||
self.emit('add block', block);
|
||||
|
||||
return callback(null, block);
|
||||
self._pruneBlock(block, batch, function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return callback(null, block);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -1540,8 +1537,7 @@ ChainDB.prototype.isSpentTX = function isSpentTX(hash, callback) {
|
||||
};
|
||||
|
||||
ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
||||
var futureHeight;
|
||||
var i, j, tx, input;
|
||||
var futureHeight, i, j, key, tx, input;
|
||||
|
||||
if (this.options.spv)
|
||||
return callback();
|
||||
@ -1560,24 +1556,17 @@ ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
||||
for (i = 0; i < block.txs.length; i++) {
|
||||
tx = block.txs[i];
|
||||
|
||||
if (tx.isCoinbase())
|
||||
break;
|
||||
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
key = input.prevout.hash + '/' + input.prevout.index;
|
||||
|
||||
if (tx.isCoinbase())
|
||||
break;
|
||||
|
||||
assert(input.coin);
|
||||
|
||||
batch.put('u/x/'
|
||||
+ input.prevout.hash
|
||||
+ '/' + input.prevout.index,
|
||||
input.coin.toRaw());
|
||||
|
||||
batch.put('u/q/'
|
||||
+ futureHeight
|
||||
+ '/' + input.prevout.hash
|
||||
+ '/' + input.prevout.index,
|
||||
DUMMY);
|
||||
batch.put('u/x/' + key, input.coin.toRaw());
|
||||
batch.put('u/q/' + futureHeight + '/' + key, DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user