chaindb: optimize.
This commit is contained in:
parent
3a43a9aefa
commit
b55068f30d
@ -994,7 +994,8 @@ ChainDB.prototype.removeBlock = function removeBlock(hash, callback) {
|
||||
|
||||
ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||
var undo = new BufferWriter();
|
||||
var i, j, tx, input, output, prev, hashes, address, hash, coins, raw;
|
||||
var i, j, tx, input, output, prev;
|
||||
var hashes, address, hash, coins, raw;
|
||||
|
||||
if (this.options.spv)
|
||||
return utils.asyncify(callback)(null, block);
|
||||
@ -1022,25 +1023,26 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
if (!tx.isCoinbase()) {
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
|
||||
if (tx.isCoinbase())
|
||||
break;
|
||||
assert(input.coin);
|
||||
|
||||
assert(input.coin);
|
||||
|
||||
if (this.options.indexAddress) {
|
||||
address = input.getHash();
|
||||
if (address) {
|
||||
prev = input.prevout;
|
||||
this.del(layout.C(address, prev.hash, prev.index));
|
||||
if (this.options.indexAddress) {
|
||||
address = input.getHash();
|
||||
if (address) {
|
||||
prev = input.prevout;
|
||||
this.del(layout.C(address, prev.hash, prev.index));
|
||||
}
|
||||
}
|
||||
|
||||
// Add coin to set of undo
|
||||
// coins for the block.
|
||||
input.coin.toRaw(undo);
|
||||
|
||||
this.pending.spend(input.coin);
|
||||
}
|
||||
|
||||
input.coin.toRaw(undo);
|
||||
|
||||
this.pending.spend(input.coin);
|
||||
}
|
||||
|
||||
for (j = 0; j < tx.outputs.length; j++) {
|
||||
@ -1059,6 +1061,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// Commit new coin state.
|
||||
view = view.toArray();
|
||||
|
||||
for (i = 0; i < view.length; i++) {
|
||||
@ -1073,6 +1076,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// Write undo coins (if there are any).
|
||||
if (undo.written > 0)
|
||||
this.put(layout.u(block.hash()), undo.render());
|
||||
|
||||
@ -1091,7 +1095,8 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||
|
||||
ChainDB.prototype.disconnectBlock = function disconnectBlock(block, callback) {
|
||||
var self = this;
|
||||
var i, j, tx, input, output, prev, hashes, address, hash, coins, raw;
|
||||
var i, j, tx, input, output, prev;
|
||||
var hashes, address, hash, coins, raw;
|
||||
|
||||
if (this.options.spv)
|
||||
return utils.asyncify(callback)(null, block);
|
||||
@ -1117,23 +1122,22 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
if (!tx.isCoinbase()) {
|
||||
for (j = 0; j < tx.inputs.length; j++) {
|
||||
input = tx.inputs[j];
|
||||
|
||||
if (tx.isCoinbase())
|
||||
break;
|
||||
assert(input.coin);
|
||||
|
||||
assert(input.coin);
|
||||
|
||||
if (self.options.indexAddress) {
|
||||
address = input.getHash();
|
||||
if (address) {
|
||||
prev = input.prevout;
|
||||
self.put(layout.C(address, prev.hash, prev.index), DUMMY);
|
||||
if (self.options.indexAddress) {
|
||||
address = input.getHash();
|
||||
if (address) {
|
||||
prev = input.prevout;
|
||||
self.put(layout.C(address, prev.hash, prev.index), DUMMY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.pending.add(input.coin);
|
||||
self.pending.add(input.coin);
|
||||
}
|
||||
}
|
||||
|
||||
// Add all of the coins we are about to
|
||||
@ -1160,6 +1164,7 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
// Commit new coin state.
|
||||
view = view.toArray();
|
||||
|
||||
for (i = 0; i < view.length; i++) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user