Skip to content

Instantly share code, notes, and snippets.

@jamesob
Created August 15, 2019 15:34
Show Gist options
  • Save jamesob/9ef1305e1af4d403c669eb79b2466307 to your computer and use it in GitHub Desktop.
Save jamesob/9ef1305e1af4d403c669eb79b2466307 to your computer and use it in GitHub Desktop.
diff ~/.ackr/15759.sdaftuar.p2p_add_2_outbound_bloc/4.aff2a19/base.diff ~/.ackr/15759.sdaftuar.p2p_add_2_outbound_bloc/5.6962113/base.diff
2c2
< index f9723196b0..716350d853 100644
---
> index 25c964205a..338c271b40 100644
5c5
< @@ -1777,7 +1777,8 @@ bool AppInitMain(InitInterfaces& interfaces)
---
> @@ -1753,7 +1753,8 @@ bool AppInitMain(InitInterfaces& interfaces)
16c16
< index 3c6f5a05f3..9d788a6bca 100644
---
> index 0464a6e9ea..c03ac2edbb 100644
19c19
< @@ -348,7 +348,7 @@ static CAddress GetBindAddress(SOCKET sock)
---
> @@ -352,7 +352,7 @@ static CAddress GetBindAddress(SOCKET sock)
28c28
< @@ -438,7 +438,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
---
> @@ -442,7 +442,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
37c37
< @@ -497,9 +497,9 @@ void CNode::copyStats(CNodeStats &stats)
---
> @@ -499,9 +499,9 @@ void CNode::copyStats(CNodeStats &stats)
50,51c50
< @@ -525,9 +525,9 @@ void CNode::copyStats(CNodeStats &stats)
< X(nRecvBytes);
---
> @@ -528,9 +528,9 @@ void CNode::copyStats(CNodeStats &stats)
53c52,53
< X(fWhitelisted);
---
> X(m_legacyWhitelisted);
> X(m_permissionFlags);
63c63
< @@ -815,11 +815,17 @@ bool CConnman::AttemptToEvictConnection()
---
> @@ -818,11 +818,17 @@ bool CConnman::AttemptToEvictConnection()
83c83
< @@ -892,7 +898,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
---
> @@ -895,7 +901,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
92c92
< @@ -1651,7 +1657,7 @@ int CConnman::GetExtraOutboundCount()
---
> @@ -1656,7 +1662,7 @@ int CConnman::GetExtraOutboundCount()
101c101,102
< @@ -1712,6 +1718,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
---
> @@ -1716,7 +1722,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
> CAddress addrConnect;
104c105,106
< int nOutbound = 0;
---
> - int nOutbound = 0;
> + int nOutboundFullRelay = 0;
109c111,112
< @@ -1724,6 +1731,9 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
---
> @@ -1728,7 +1735,11 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
> // also have the added issue that they're attacker controlled and could be used
112c115
< nOutbound++;
---
> - nOutbound++;
114a118,119
> + } else if (!pnode->fFeeler) {
> + nOutboundFullRelay++;
119c124
< @@ -1742,7 +1752,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
---
> @@ -1747,7 +1758,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
124c129
< + if (nOutbound >= m_max_outbound_full_relay + m_max_outbound_blocks_only && !GetTryNewOutboundPeer()) {
---
> + if (nOutboundFullRelay >= m_max_outbound_full_relay && nOutboundBlocksOnly >= m_max_outbound_blocks_only && !GetTryNewOutboundPeer()) {
128c133
< @@ -1816,7 +1826,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
---
> @@ -1821,7 +1832,14 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
133c138,145
< + OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, fFeeler, false, nOutboundBlocksOnly < m_max_outbound_blocks_only);
---
> + // Open this connection as blocks-only if we're already at our
> + // full-relay capacity, but not yet at our blocks-only peer limit.
> + // (It should not be possible for fFeeler to be set if we're not
> + // also at our blocks-only peer limit, but check against that as
> + // well for sanity.)
> + bool blocks_only = nOutboundBlocksOnly < m_max_outbound_blocks_only && !fFeeler && nOutboundFullRelay >= m_max_outbound_full_relay;
> +
> + OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, fFeeler, false, blocks_only);
137c149
< @@ -1903,7 +1913,7 @@ void CConnman::ThreadOpenAddedConnections()
---
> @@ -1908,7 +1926,7 @@ void CConnman::ThreadOpenAddedConnections()
146c158
< @@ -1922,7 +1932,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
---
> @@ -1927,7 +1945,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
155c167
< @@ -2224,7 +2234,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
---
> @@ -2230,7 +2248,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
164c176
< @@ -2302,7 +2312,7 @@ void CConnman::Interrupt()
---
> @@ -2308,7 +2326,7 @@ void CConnman::Interrupt()
173c185
< @@ -2612,14 +2622,17 @@ int CConnman::GetBestHeight() const
---
> @@ -2618,14 +2636,17 @@ int CConnman::GetBestHeight() const
193c205
< @@ -2628,8 +2641,9 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
---
> @@ -2634,8 +2655,9 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
206c218
< index 37aaf1a63b..38be50866a 100644
---
> index 75c05c9cb5..dd29c71f83 100644
209c221
< @@ -55,10 +55,12 @@ static const unsigned int MAX_ADDR_TO_SEND = 1000;
---
> @@ -56,10 +56,12 @@ static const unsigned int MAX_ADDR_TO_SEND = 1000;
224c236
< @@ -125,7 +127,8 @@ public:
---
> @@ -126,7 +128,8 @@ public:
234c246
< @@ -148,10 +151,12 @@ public:
---
> @@ -150,10 +153,12 @@ public:
248c260
< @@ -190,7 +195,7 @@ public:
---
> @@ -192,7 +197,7 @@ public:
257c269
< @@ -246,7 +251,7 @@ public:
---
> @@ -248,7 +253,7 @@ public:
266c278
< @@ -346,7 +351,7 @@ private:
---
> @@ -350,7 +355,7 @@ private:
272c284
< bool IsWhitelistedRange(const CNetAddr &addr);
---
> void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const;
275c287
< @@ -405,9 +410,11 @@ private:
---
> @@ -409,9 +414,11 @@ private:
288c300
< @@ -433,7 +440,7 @@ private:
---
> @@ -437,7 +444,7 @@ private:
297c309
< @@ -668,15 +675,8 @@ public:
---
> @@ -676,15 +683,8 @@ public:
313c325
< @@ -695,28 +695,51 @@ public:
---
> @@ -703,28 +703,51 @@ public:
377c389
< @@ -733,15 +756,10 @@ public:
---
> @@ -741,15 +764,10 @@ public:
394c406
< @@ -833,20 +851,21 @@ public:
---
> @@ -842,20 +860,21 @@ public:
424c436
< index 3d0a9b192d..2860e8b233 100644
---
> index 3db460d444..d21d98a653 100644
427c439
< @@ -422,7 +422,7 @@ static void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime)
---
> @@ -425,7 +425,7 @@ static void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime)
436c448
< @@ -743,11 +743,11 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
---
> @@ -756,11 +756,11 @@ void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
442c454
< +// Returns true for outbound transaction-relay peers, excluding manual
---
> +// Returns true for outbound full-relay peers, excluding manual
451c463
< @@ -1316,7 +1316,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connma
---
> @@ -1329,7 +1329,7 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connma
460c472
< @@ -1435,11 +1435,11 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
---
> @@ -1448,11 +1448,11 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
476c488
< @@ -1499,7 +1499,7 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
---
> @@ -1512,7 +1512,12 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
480a493,497
> +
> + // Note that if we receive a getdata for a MSG_TX or MSG_WITNESS_TX from a
> + // blocks-only outbound peer, we will stop processing further getdata
> + // messages from this peer (likely resulting in our peer eventually
> + // disconnecting us).
485c502
< @@ -1519,11 +1519,11 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
---
> @@ -1532,11 +1537,11 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
499c516
< @@ -1970,9 +1970,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -1995,9 +2000,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
512c529
< @@ -1991,7 +1991,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -2016,7 +2021,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
521c538,553
< @@ -2106,6 +2106,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -2088,9 +2093,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
> // Mark this node as currently connected, so we update its timestamp later.
> LOCK(cs_main);
> State(pfrom->GetId())->fCurrentlyConnected = true;
> - LogPrintf("New outbound peer connected: version: %d, blocks=%d, peer=%d%s\n",
> - pfrom->nVersion.load(), pfrom->nStartingHeight, pfrom->GetId(),
> - (fLogIPs ? strprintf(", peeraddr=%s", pfrom->addr.ToString()) : ""));
> + LogPrintf("New outbound peer connected: version: %d, blocks=%d, blocks-only=%s, feeler=%s, peer=%d%s\n",
> + pfrom->nVersion.load(), pfrom->nStartingHeight,
> + pfrom->m_tx_relay == nullptr ? "true" : "false",
> + pfrom->fFeeler ? "true" : "false",
> + pfrom->GetId(), (fLogIPs ? strprintf(", peeraddr=%s", pfrom->addr.ToString()) : ""));
> }
>
> if (pfrom->nVersion >= SENDHEADERS_VERSION) {
> @@ -2131,6 +2138,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
531c563
< @@ -2964,6 +2967,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -2989,6 +2999,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
542c574
< @@ -2999,8 +3006,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -3030,8 +3044,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
555c587
< @@ -3091,12 +3100,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -3122,12 +3138,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
573c605
< @@ -3110,10 +3119,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -3141,10 +3157,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
588c620
< @@ -3126,11 +3135,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -3157,11 +3173,14 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
606c638
< @@ -3138,9 +3150,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
---
> @@ -3169,9 +3188,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
619c651
< @@ -3524,7 +3536,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
---
> @@ -3575,7 +3594,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
628c660
< @@ -3532,7 +3544,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
---
> @@ -3583,7 +3602,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
637c669
< @@ -3740,120 +3752,123 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
---
> @@ -3791,120 +3810,123 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
642c674
< - bool fSendTrickle = pto->fWhitelisted;
---
> - bool fSendTrickle = pto->HasPermission(PF_NOBAN);
653c685
< + bool fSendTrickle = pto->fWhitelisted;
---
> + bool fSendTrickle = pto->HasPermission(PF_NOBAN);
818c850
< + }
---
> }
826c858
< }
---
> + }
861c893
< @@ -3987,27 +4002,27 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
---
> @@ -4065,27 +4087,27 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
867c899
< !(pto->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY))) {
---
> !pto->HasPermission(PF_FORCERELAY)) {
898c930
< index d47f395c15..687a860c4c 100644
---
> index a50d6854f8..b0a613372f 100644
901c933
< @@ -149,17 +149,17 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
---
> @@ -151,17 +151,17 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
922c954
< @@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
---
> @@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
931c963
< @@ -201,10 +201,10 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
---
> @@ -203,10 +203,10 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment