scanning: more bloom filter things.

This commit is contained in:
Christopher Jeffrey 2016-10-24 19:16:10 -07:00
parent c9b84252af
commit c9b038d4e0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 36 additions and 28 deletions

View File

@ -1108,7 +1108,6 @@ ChainDB.prototype.scan = co(function* scan(start, filter, iter) {
var total = 0;
var i, j, entry, hashes;
var hash, tx, txs, block;
var input, prevout, found;
if (start == null)
start = this.network.genesis.hash;
@ -1127,7 +1126,7 @@ ChainDB.prototype.scan = co(function* scan(start, filter, iter) {
throw new Error('Cannot rescan an alternate chain.');
while (entry) {
block = yield this.getBlock(entry.hash);
block = yield this.getFullBlock(entry.hash);
txs = [];
total++;
@ -1145,30 +1144,12 @@ ChainDB.prototype.scan = co(function* scan(start, filter, iter) {
for (i = 0; i < block.txs.length; i++) {
tx = block.txs[i];
found = false;
if (!tx.isCoinbase()) {
for (j = 0; j < tx.inputs.length; j++) {
input = tx.inputs[j];
prevout = input.prevout;
if (filter.test(prevout.hash, 'hex')) {
txs.push(tx);
found = true;
break;
}
}
if (found)
continue;
}
hashes = tx.getOutputHashes();
hashes = tx.getHashes();
for (j = 0; j < hashes.length; j++) {
hash = hashes[j];
if (filter.test(hash)) {
txs.push(tx);
filter.add(tx.hash());
break;
}
}

View File

@ -1561,7 +1561,30 @@ ClientSocket.prototype.testBlock = function testBlock(block) {
};
ClientSocket.prototype.testFilter = function testFilter(tx) {
var i, hashes, hash, input, prevout;
if (this.chain.db.options.spv)
return this.testFilterSPV(tx);
return this.testFilterFull(tx);
};
ClientSocket.prototype.testFilterFull = function testFilterFull(tx) {
var i, hashes, hash;
if (!this.filter)
return false;
hashes = tx.getHashes();
for (i = 0; i < hashes.length; i++) {
hash = hashes[i];
if (this.filter.test(hash))
return true;
}
return false;
};
ClientSocket.prototype.testFilterSPV = function testFilterSPV(tx) {
var i, hash, input, prevout, output, outpoint;
if (!this.filter)
return false;
@ -1570,17 +1593,21 @@ ClientSocket.prototype.testFilter = function testFilter(tx) {
for (i = 0; i < tx.inputs.length; i++) {
input = tx.inputs[i];
prevout = input.prevout;
if (this.filter.test(prevout.hash, 'hex'))
if (this.filter.test(prevout.toRaw()))
return true;
}
}
hashes = tx.getOutputHashes();
for (i = 0; i < tx.outputs.length; i++) {
output = tx.outputs[i];
hash = output.getHash();
if (!hash)
continue;
for (i = 0; i < hashes.length; i++) {
hash = hashes[i];
if (this.filter.test(hash)) {
this.filter.add(tx.hash());
outpoint = Outpoint.fromTX(tx, i);
this.filter.add(outpoint.toRaw());
return true;
}
}

View File

@ -230,7 +230,7 @@ Pool.prototype._initOptions = function _initOptions() {
}
if (this.options.spv)
this.spvFilter = Bloom.fromRate(10000, 0.001, constants.bloom.NONE);
this.spvFilter = Bloom.fromRate(10000, 0.001, constants.bloom.ALL);
if (!this.options.mempool)
this.txFilter = new Bloom.Rolling(50000, 0.000001);