Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network tests & updates #692

Merged
merged 17 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/net/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const assert = require('bsert');
const EventEmitter = require('events');
const {Lock} = require('bmutex');
const IP = require('binet');
const dns = require('bdns');
const tcp = require('btcp');
const UPNP = require('bupnp');
const socks = require('bsocks');
Expand Down Expand Up @@ -85,6 +84,7 @@ class Pool extends EventEmitter {
this.pendingFilter = null;
this.refillTimer = null;
this.discoverTimer = null;
this.connectedGroups = new Set();

this.checkpoints = false;
this.headerChain = new List();
Expand Down Expand Up @@ -663,6 +663,7 @@ class Pool extends EventEmitter {
this.logger.info('Adding loader peer (%s).', peer.hostname());

this.peers.add(peer);
this.connectedGroups.add(addr.getGroup());

this.setLoader(peer);
}
Expand Down Expand Up @@ -3367,6 +3368,7 @@ class Pool extends EventEmitter {

if (!entry)
break;

const addr = entry.addr;

if (this.peers.has(addr.hostname))
Expand All @@ -3390,6 +3392,10 @@ class Pool extends EventEmitter {
if (this.options.brontideOnly && !addr.hasKey())
continue;

// Don't connect to outbound peers in the same group.
if (this.connectedGroups.has(addr.getGroup()))
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we allow this with some low probability? or is it always bad

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm.. Maybe last 2 tries ? pc80 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like Bitcoin Core really doesnt allow this at all:

https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp#L2114-L2117

So I defer to you, just not sure given the limited size of the handshake network if this is actually beneficial.


if (i < pc30 && now - entry.lastAttempt < 600)
continue;

Expand Down Expand Up @@ -3428,6 +3434,7 @@ class Pool extends EventEmitter {
const peer = this.createOutbound(addr);

this.peers.add(peer);
this.connectedGroups.add(addr.getGroup());

this.emit('peer', peer);
}
Expand Down Expand Up @@ -3482,6 +3489,9 @@ class Pool extends EventEmitter {
removePeer(peer) {
this.peers.remove(peer);

if (peer.outbound)
this.connectedGroups.delete(peer.address.getGroup());

for (const hash of peer.blockMap.keys())
this.resolveBlock(peer, hash);

Expand Down
9 changes: 9 additions & 0 deletions test/net-netaddress-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

/* Parts of this software are based on bitcoin/bitcoin:
* Copyright (c) 2009-2019, The Bitcoin Core Developers (MIT License).
* Copyright (c) 2009-2019, The Bitcoin Developers (MIT License).
* https://github.com/bitcoin/bitcoin
*
* Resources:
* https://github.com/bitcoin/bitcoin/blob/46fc4d1a24c88e797d6080336e3828e45e39c3fd/src/test/netbase_tests.cpp
*/

const assert = require('bsert');
const NetAddress = require('../lib/net/netaddress');
const Network = require('../lib/protocol/network');
Expand Down