Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #87 from btc1/2017_node_segwit2x
Browse files Browse the repository at this point in the history
Advertise NODE_SEGWIT2X service flag + peer seeking.
  • Loading branch information
jgarzik authored Jul 21, 2017
2 parents 5e19bce + e6b8cde commit bd9dd47
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion qa/rpc-tests/p2p-compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def run_test(self):
connections = []
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], self.test_node))
connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1],
self.segwit_node, services=NODE_NETWORK|NODE_WITNESS))
self.segwit_node, services=NODE_NETWORK|NODE_WITNESS|NODE_SEGWIT2X))
connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1],
self.old_node, services=NODE_NETWORK))
self.test_node.add_connection(connections[0])
Expand Down
6 changes: 3 additions & 3 deletions qa/rpc-tests/p2p-segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,16 +1954,16 @@ def test_non_standard_witness(self):

def run_test(self):
# Setup the p2p connections and start up the network thread.
self.test_node = TestNode() # sets NODE_WITNESS|NODE_NETWORK
self.test_node = TestNode() # sets NODE_WITNESS|NODE_NETWORK|NODE_SEGWIT2X
self.old_node = TestNode() # only NODE_NETWORK
self.std_node = TestNode() # for testing node1 (fRequireStandard=true)

self.p2p_connections = [self.test_node, self.old_node]

self.connections = []
self.connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], self.test_node, services=NODE_NETWORK|NODE_WITNESS))
self.connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], self.test_node, services=NODE_NETWORK|NODE_WITNESS|NODE_SEGWIT2X))
self.connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], self.old_node, services=NODE_NETWORK))
self.connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], self.std_node, services=NODE_NETWORK|NODE_WITNESS))
self.connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], self.std_node, services=NODE_NETWORK|NODE_WITNESS|NODE_SEGWIT2X))
self.test_node.add_connection(self.connections[0])
self.old_node.add_connection(self.connections[1])
self.std_node.add_connection(self.connections[2])
Expand Down
1 change: 1 addition & 0 deletions qa/rpc-tests/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
NODE_GETUTXO = (1 << 1)
NODE_BLOOM = (1 << 2)
NODE_WITNESS = (1 << 3)
NODE_SEGWIT2X = (1 << 7)

# Keep our own socket map for asyncore, so that we can track disconnects
# ourselves (to workaround an issue with closing an asyncore socket when
Expand Down
11 changes: 11 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false;
static const bool DEFAULT_DISABLE_SAFEMODE = false;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
static const bool DEFAULT_PREFPEERING = true;

std::unique_ptr<CConnman> g_connman;
std::unique_ptr<PeerLogicValidation> peerLogic;
Expand Down Expand Up @@ -475,6 +476,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-bytespersigop", strprintf(_("Equivalent bytes per sigop in transactions for relay and mining (default: %u)"), DEFAULT_BYTES_PER_SIGOP));
strUsage += HelpMessageOpt("-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %u)"), DEFAULT_ACCEPT_DATACARRIER));
strUsage += HelpMessageOpt("-datacarriersize", strprintf(_("Maximum size of data in data carrier transactions we relay and mine (default: %u)"), MAX_OP_RETURN_RELAY));
strUsage += HelpMessageOpt("-prefpeering", strprintf(_("Preferential peering with segwit2x (and segwit) nodes (default: %u)"), DEFAULT_PREFPEERING));
strUsage += HelpMessageOpt("-mempoolreplacement", strprintf(_("Enable transaction replacement in the memory pool (default: %u)"), DEFAULT_ENABLE_REPLACEMENT));

strUsage += HelpMessageGroup(_("Block creation options:"));
Expand Down Expand Up @@ -1048,6 +1050,15 @@ bool AppInitParameterInteraction()
fAcceptDatacarrier = GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes);

// Advertise as segwit2x node
nLocalServices = ServiceFlags(nLocalServices | NODE_SEGWIT2X);

// Prefer peers with compatible rulesets
if (GetBoolArg("-prefpeering", DEFAULT_PREFPEERING)) {
nRelevantServices = ServiceFlags(nRelevantServices | NODE_SEGWIT2X);
nRelevantServices = ServiceFlags(nRelevantServices | NODE_WITNESS); // TBR
}

// Option to startup with mocktime set (used for regression testing):
SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op

Expand Down
3 changes: 3 additions & 0 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ enum ServiceFlags : uint64_t {
// If this is turned off then the node will not service nor make xthin requests
NODE_XTHIN = (1 << 4),

// NODE_SEGWIT2X supports segwit2x
NODE_SEGWIT2X = (1 << 7),

// Bits 24-31 are reserved for temporary experiments. Just pick a bit that
// isn't getting used, or one not being used much, and notify the
// bitcoin-development mailing list. Remember that service bits are just
Expand Down
3 changes: 3 additions & 0 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,9 @@ QString formatServicesStr(quint64 mask)
case NODE_WITNESS:
strList.append("WITNESS");
break;
case NODE_SEGWIT2X:
strList.append("SEGWIT2X");
break;
case NODE_XTHIN:
strList.append("XTHIN");
break;
Expand Down

0 comments on commit bd9dd47

Please sign in to comment.