Skip to content

Commit

Permalink
fix: checkFilter()
Browse files Browse the repository at this point in the history
  • Loading branch information
manavdesai27 committed Jul 8, 2023
1 parent 4832f54 commit fdc3f91
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
12 changes: 3 additions & 9 deletions lib/net/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ class Pool extends EventEmitter {
this.filterSyncing = true;
const cFHeaderHeight = await this.chain.getCFHeaderHeight();
const startHeight = cFHeaderHeight
? cFHeaderHeight : 1;
? cFHeaderHeight + 1 : 1;
const chainHeight = await this.chain.height;
const stopHeight = chainHeight > 2000 ? 2000 : chainHeight;
const stopHash = await this.chain.getHash(stopHeight);
Expand All @@ -769,7 +769,7 @@ class Pool extends EventEmitter {
this.filterSyncing = true;
const cFilterHeight = await this.chain.getCFilterHeight();
const startHeight = cFilterHeight
? cFilterHeight : 1;
? cFilterHeight + 1 : 1;
const chainHeight = await this.chain.height;
const stopHeight = chainHeight > 1000 ? 1000 : chainHeight;
const stopHash = await this.chain.getHash(stopHeight);
Expand Down Expand Up @@ -1761,10 +1761,7 @@ class Pool extends EventEmitter {
return;

if (this.neutrino) {
const locator = await this.chain.getLocator();
this.sendLocator(locator, peer);
if (!this.syncing)
this.startFilterHeadersSync();
this.startSync();
return;
}

Expand Down Expand Up @@ -3668,9 +3665,6 @@ class Pool extends EventEmitter {
*/

getBlock(peer, hashes) {
if (this.options.neutrino)
return;

if (!this.opened)
return;

Expand Down
6 changes: 2 additions & 4 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,8 @@ class WalletDB extends EventEmitter {
}

async checkFilter (blockHash, filter) {
// script pub keys
this.filterHeight = this.filterHeight + 1;
const gcsKey = blockHash.reverse().slice(0, 16);
const gcsKey = blockHash.slice(0, 16);

const piter = this.db.iterator({
gte: layout.p.min(),
Expand All @@ -590,10 +589,9 @@ class WalletDB extends EventEmitter {

await piter.each(async (key) => {
const [data] = layout.p.decode(key);
// address fromHash toScript
if (data.length === 20) {
const script = Script.fromPubkeyhash(data);
const match = filter.match(gcsKey, script);
const match = filter.match(gcsKey, script.raw);
if (match) {
await this.client.getBlockFromNode(blockHash, filter);
return;
Expand Down
8 changes: 2 additions & 6 deletions test/wallet-neutrino-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const fwAddresses = [];
const nwAddresses = [];

async function mineBlock(tx, address) {
console.log('address', address);
const job = await miner.createJob();

if (!tx)
Expand Down Expand Up @@ -83,7 +82,6 @@ describe('wallet-neutrino', function() {
for (let i = 0; i < 10; i++) {
const key = await wallet1.createReceive(0);
const address = key.getAddress().toString(node1.network.type);
// console.log(address);
fwAddresses.push(address);
miner.addAddress(address);
}
Expand Down Expand Up @@ -148,11 +146,9 @@ describe('wallet-neutrino', function() {
const basicFilter = new BasicFilter();
const gcs = basicFilter.fromNBytes(filter.filter);
const key = hash.slice(0, 16);
const address = Address.fromString(fwAddresses[i], node2.network.type);
const address = Address.fromString(fwAddresses[i], node1.network.type);
const script = Script.fromAddress(address);
// console.log(address.hash);
console.log(script.toRaw());
// assert(gcs.match(key, script.));
assert(gcs.match(key, script.raw));
}
});
});

0 comments on commit fdc3f91

Please sign in to comment.