11// Copyright (c) 2009-2019 The Bitcoin Core developers
2- // Copyright (c) 2014-2019 The DigiByte Core developers
2+ // Copyright (c) 2014-2021 The DigiByte Core developers
33// Distributed under the MIT software license, see the accompanying
44// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
@@ -27,6 +27,9 @@ extern void EraseOrphansFor(NodeId peer);
2727extern unsigned int LimitOrphanTxSize (unsigned int nMaxOrphans);
2828extern void Misbehaving (NodeId nodeid, int howmuch, const std::string& message=" " );
2929
30+ // Arbitrary Timeout Value to trigger a disconnect.
31+ #define CONNECTION_TIMEOUT_MS 20000
32+
3033struct COrphanTx {
3134 CTransactionRef tx;
3235 NodeId fromPeer;
@@ -60,7 +63,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
6063
6164 // Mock an outbound peer
6265 CAddress addr1 (ip (0xa0b0c001 ), NODE_NONE);
63- CNode dummyNode1 (id++, ServiceFlags (NODE_NETWORK|NODE_WITNESS), 0 , INVALID_SOCKET, addr1, 0 , 0 , CAddress (), " " , /* fInboundIn=*/ false );
66+ CNode dummyNode1 (id++, ServiceFlags (NODE_NETWORK|NODE_WITNESS|NODE_GETUTXO ), 0 , INVALID_SOCKET, addr1, 0 , 0 , CAddress (), " " , /* fInboundIn=*/ false );
6467 dummyNode1.SetSendVersion (PROTOCOL_VERSION);
6568
6669 peerLogic->InitializeNode (&dummyNode1);
@@ -87,7 +90,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
8790
8891 int64_t nStartTime = GetTime ();
8992 // Wait 21 minutes
90- SetMockTime (nStartTime+21 *60 );
93+ SetMockTime (nStartTime+21 *60 ); // Overrides future calls to GetTime()
9194 {
9295 LOCK2 (cs_main, dummyNode1.cs_sendProcessing );
9396 peerLogic->SendMessages (&dummyNode1); // should result in getheaders
@@ -97,13 +100,13 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
97100 BOOST_CHECK (dummyNode1.vSendMsg .size () > 0 );
98101 }
99102 // Wait 3 more minutes
100- SetMockTime (nStartTime+24 *60 );
103+ SetMockTime (nStartTime+24 *60 ); // Overrides future calls to GetTime()
101104 {
102105 LOCK2 (cs_main, dummyNode1.cs_sendProcessing );
103106 peerLogic->SendMessages (&dummyNode1); // should result in disconnect
104107 }
105108 BOOST_CHECK (dummyNode1.fDisconnect == true );
106- SetMockTime (0 );
109+ SetMockTime (0 ); // Overrides future calls to GetTime()
107110
108111 bool dummy;
109112 peerLogic->FinalizeNode (dummyNode1.GetId (), dummy);
@@ -112,7 +115,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
112115static void AddRandomOutboundPeer (std::vector<CNode *> &vNodes, PeerLogicValidation &peerLogic)
113116{
114117 CAddress addr (ip (GetRandInt (0xffffffff )), NODE_NONE);
115- vNodes.emplace_back (new CNode (id++, ServiceFlags (NODE_NETWORK|NODE_WITNESS), 0 , INVALID_SOCKET, addr, 0 , 0 , CAddress (), " " , /* fInboundIn=*/ false ));
118+ vNodes.emplace_back (new CNode (id++, ServiceFlags (NODE_NETWORK|NODE_WITNESS|NODE_GETUTXO ), 0 , INVALID_SOCKET, addr, 0 , 0 , CAddress (), " " , /* fInboundIn=*/ false ));
116119 CNode &node = *vNodes.back ();
117120 node.SetSendVersion (PROTOCOL_VERSION);
118121
@@ -147,7 +150,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
147150 BOOST_CHECK (node->fDisconnect == false );
148151 }
149152
150- SetMockTime (GetTime () + 3 *consensusParams. nPowTargetSpacing + 1 );
153+ SetMockTime (GetTime () + CONNECTION_TIMEOUT_MS); // Overrides future calls to GetTime()
151154
152155 // Now tip should definitely be stale, and we should look for an extra
153156 // outbound peer
@@ -214,7 +217,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
214217 BOOST_CHECK (!connman->IsBanned (ip (0xa0b0c001 |0x0000ff00 ))); // Different IP, not banned
215218
216219 CAddress addr2 (ip (0xa0b0c002 ), NODE_NONE);
217- CNode dummyNode2 (id++, NODE_NETWORK, 0 , INVALID_SOCKET, addr2, 1 , 1 , CAddress (), " " , true );
220+ CNode dummyNode2 (id++, ServiceFlags ( NODE_NETWORK|NODE_GETUTXO) , 0 , INVALID_SOCKET, addr2, 1 , 1 , CAddress (), " " , true );
218221 dummyNode2.SetSendVersion (PROTOCOL_VERSION);
219222 peerLogic->InitializeNode (&dummyNode2);
220223 dummyNode2.nVersion = 1 ;
@@ -250,7 +253,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
250253 connman->ClearBanned ();
251254 gArgs .ForceSetArg (" -banscore" , " 111" ); // because 11 is my favorite number
252255 CAddress addr1 (ip (0xa0b0c001 ), NODE_NONE);
253- CNode dummyNode1 (id++, NODE_NETWORK, 0 , INVALID_SOCKET, addr1, 3 , 1 , CAddress (), " " , true );
256+ CNode dummyNode1 (id++, ServiceFlags ( NODE_NETWORK|NODE_GETUTXO) , 0 , INVALID_SOCKET, addr1, 3 , 1 , CAddress (), " " , true );
254257 dummyNode1.SetSendVersion (PROTOCOL_VERSION);
255258 peerLogic->InitializeNode (&dummyNode1);
256259 dummyNode1.nVersion = 1 ;
@@ -312,10 +315,10 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
312315 }
313316 BOOST_CHECK (connman->IsBanned (addr));
314317
315- SetMockTime (nStartTime+60 *60 );
318+ SetMockTime (nStartTime+60 *60 ); // Overrides future calls to GetTime()
316319 BOOST_CHECK (connman->IsBanned (addr));
317320
318- SetMockTime (nStartTime+60 *60 *24 +1 );
321+ SetMockTime (nStartTime+60 *60 *24 +1 ); // Overrides future calls to GetTime()
319322 BOOST_CHECK (!connman->IsBanned (addr));
320323
321324 bool dummy;
0 commit comments