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) {
|
this.saveBlock(block, batch, true, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
return batch.write(callback);
|
||||||
self._pruneBlock(block, batch, function(err) {
|
|
||||||
if (err)
|
|
||||||
return callback(err);
|
|
||||||
return batch.write(callback);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -790,8 +785,6 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._ensureBlock(block, function(err, block) {
|
this._ensureBlock(block, function(err, block) {
|
||||||
var height;
|
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
@ -849,7 +842,11 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
|||||||
|
|
||||||
self.emit('add block', block);
|
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) {
|
ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
||||||
var futureHeight;
|
var futureHeight, i, j, key, tx, input;
|
||||||
var i, j, tx, input;
|
|
||||||
|
|
||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
return callback();
|
return callback();
|
||||||
@ -1560,24 +1556,17 @@ ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
|||||||
for (i = 0; i < block.txs.length; i++) {
|
for (i = 0; i < block.txs.length; i++) {
|
||||||
tx = block.txs[i];
|
tx = block.txs[i];
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
|
||||||
break;
|
|
||||||
|
|
||||||
for (j = 0; j < tx.inputs.length; j++) {
|
for (j = 0; j < tx.inputs.length; j++) {
|
||||||
input = tx.inputs[j];
|
input = tx.inputs[j];
|
||||||
|
key = input.prevout.hash + '/' + input.prevout.index;
|
||||||
|
|
||||||
|
if (tx.isCoinbase())
|
||||||
|
break;
|
||||||
|
|
||||||
assert(input.coin);
|
assert(input.coin);
|
||||||
|
|
||||||
batch.put('u/x/'
|
batch.put('u/x/' + key, input.coin.toRaw());
|
||||||
+ input.prevout.hash
|
batch.put('u/q/' + futureHeight + '/' + key, DUMMY);
|
||||||
+ '/' + input.prevout.index,
|
|
||||||
input.coin.toRaw());
|
|
||||||
|
|
||||||
batch.put('u/q/'
|
|
||||||
+ futureHeight
|
|
||||||
+ '/' + input.prevout.hash
|
|
||||||
+ '/' + input.prevout.index,
|
|
||||||
DUMMY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user