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) {
|
ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||||
var undo = new BufferWriter();
|
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)
|
if (this.options.spv)
|
||||||
return utils.asyncify(callback)(null, block);
|
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++) {
|
if (!tx.isCoinbase()) {
|
||||||
input = tx.inputs[j];
|
for (j = 0; j < tx.inputs.length; j++) {
|
||||||
|
input = tx.inputs[j];
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
assert(input.coin);
|
||||||
break;
|
|
||||||
|
|
||||||
assert(input.coin);
|
if (this.options.indexAddress) {
|
||||||
|
address = input.getHash();
|
||||||
if (this.options.indexAddress) {
|
if (address) {
|
||||||
address = input.getHash();
|
prev = input.prevout;
|
||||||
if (address) {
|
this.del(layout.C(address, prev.hash, prev.index));
|
||||||
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++) {
|
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();
|
view = view.toArray();
|
||||||
|
|
||||||
for (i = 0; i < view.length; i++) {
|
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)
|
if (undo.written > 0)
|
||||||
this.put(layout.u(block.hash()), undo.render());
|
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) {
|
ChainDB.prototype.disconnectBlock = function disconnectBlock(block, callback) {
|
||||||
var self = this;
|
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)
|
if (this.options.spv)
|
||||||
return utils.asyncify(callback)(null, block);
|
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++) {
|
if (!tx.isCoinbase()) {
|
||||||
input = tx.inputs[j];
|
for (j = 0; j < tx.inputs.length; j++) {
|
||||||
|
input = tx.inputs[j];
|
||||||
|
|
||||||
if (tx.isCoinbase())
|
assert(input.coin);
|
||||||
break;
|
|
||||||
|
|
||||||
assert(input.coin);
|
if (self.options.indexAddress) {
|
||||||
|
address = input.getHash();
|
||||||
if (self.options.indexAddress) {
|
if (address) {
|
||||||
address = input.getHash();
|
prev = input.prevout;
|
||||||
if (address) {
|
self.put(layout.C(address, prev.hash, prev.index), DUMMY);
|
||||||
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
|
// 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();
|
view = view.toArray();
|
||||||
|
|
||||||
for (i = 0; i < view.length; i++) {
|
for (i = 0; i < view.length; i++) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user