Skip to content

Commit

Permalink
Merge d4e2b6b into dfa0741
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Jul 3, 2022
2 parents dfa0741 + d4e2b6b commit 4819bea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
3 changes: 0 additions & 3 deletions lib/net/peer.js
Expand Up @@ -1083,9 +1083,6 @@ class Peer extends EventEmitter {
return;

switch (packet.type) {
case packetTypes.MEMPOOL:
this.request(packetTypes.INV, timeout);
break;
case packetTypes.GETBLOCKS:
if (!this.options.isFull())
this.request(packetTypes.INV, timeout);
Expand Down
5 changes: 5 additions & 0 deletions lib/net/pool.js
Expand Up @@ -783,6 +783,11 @@ class Pool extends EventEmitter {
if (!force && peer.syncing)
continue;

if (force) {
peer.lastTip = consensus.ZERO_HASH;
peer.lastStop = consensus.ZERO_HASH;
}

this.sendLocator(locator, peer);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/protocol/networks.js
Expand Up @@ -591,7 +591,7 @@ main.selfConnect = false;
* @const {Boolean}
*/

main.requestMempool = false;
main.requestMempool = true;

/**
* DNSSEC ownership prefix.
Expand Down Expand Up @@ -749,7 +749,7 @@ testnet.identityKey = null;

testnet.selfConnect = false;

testnet.requestMempool = false;
testnet.requestMempool = true;

testnet.claimPrefix = 'hns-testnet:';

Expand Down Expand Up @@ -1042,7 +1042,7 @@ simnet.identityKey = Buffer.from(

simnet.selfConnect = true;

simnet.requestMempool = false;
simnet.requestMempool = true;

simnet.claimPrefix = 'hns-simnet:';

Expand Down
33 changes: 18 additions & 15 deletions test/net-spv-test.js
Expand Up @@ -11,6 +11,7 @@ const NameState = require('../lib/covenants/namestate');
const {Resource} = require('../lib/dns/resource');
const {types: packetTypes} = require('../lib/net/packets');
const {types: urkelTypes} = require('urkel').Proof;
const {forValue} = require('./util/common');

const network = Network.get('regtest');
const {
Expand Down Expand Up @@ -95,14 +96,8 @@ describe('SPV', function() {

it('should generate blocks', async () => {
addr = await wallet.receiveAddress(0);
const waiter = new Promise((res, rej) => {
spv.on('connect', (entry) => {
if (entry.height === 10)
res();
});
});
await mineBlocks(10);
await waiter;
await forValue(spv.chain, 'height', 10);
assert.strictEqual(full.chain.height, spv.chain.height);
});

Expand Down Expand Up @@ -209,18 +204,26 @@ describe('SPV', function() {
const proofType = await waiter1;
assert.strictEqual(proofType, urkelTypes.TYPE_EXISTS);

// Restore
const waiter2 = new Promise((res, rej) => {
spv.on('connect', (entry) => {
if (entry.height === full.chain.height)
res();
});
});
await spv.chain.removeInvalid(entry.hash);
await waiter2;
await forValue(spv.chain, 'height', full.chain.height);
assert.strictEqual(full.chain.height, spv.chain.height);
});

it('should resync multiple times', async () => {
const resetHeight = 1;
const fullNodeHeight = full.chain.height;

// Rescan once
await spv.chain.reset(resetHeight);
await forValue(spv.chain, 'height', fullNodeHeight);
assert(spv.chain.height === fullNodeHeight);

// Rescan again
await spv.chain.reset(resetHeight);
await forValue(spv.chain, 'height', fullNodeHeight);
assert(spv.chain.height === fullNodeHeight);
});

it('should request name data with unknown tree root', async () => {
// SPV node teleports to a parallel dimension
await mineSPVFork(100, full.chain.tip);
Expand Down

0 comments on commit 4819bea

Please sign in to comment.