@@ -81,9 +81,6 @@ void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="");
81
81
82
82
// Internal stuff
83
83
namespace {
84
- /* * Enable BIP61 (sending reject messages) */
85
- bool g_enable_bip61 = DEFAULT_ENABLE_BIP61;
86
-
87
84
/* * Number of nodes with fSyncStarted. */
88
85
int nSyncStarted = 0 ;
89
86
@@ -834,8 +831,8 @@ static bool BlockRequestAllowed(const CBlockIndex* pindex, const Consensus::Para
834
831
(GetBlockProofEquivalentTime (*pindexBestHeader, *pindex, *pindexBestHeader, consensusParams) < STALE_RELAY_AGE_LIMIT);
835
832
}
836
833
837
- PeerLogicValidation::PeerLogicValidation (CConnman* connmanIn, CScheduler &scheduler) : connman(connmanIn), m_stale_tip_check_time( 0 ) {
838
- g_enable_bip61 = gArgs . GetBoolArg ( " -enablebip61 " , DEFAULT_ENABLE_BIP61);
834
+ PeerLogicValidation::PeerLogicValidation (CConnman* connmanIn, CScheduler &scheduler, bool enable_bip61)
835
+ : connman(connmanIn), m_stale_tip_check_time( 0 ), m_enable_bip61(enable_bip61) {
839
836
840
837
// Initialize global variables that cannot be constructed at startup.
841
838
recentRejects.reset (new CRollingBloomFilter (120000 , 0.000001 ));
@@ -1564,7 +1561,7 @@ bool static ProcessHeadersMessage(CNode *pfrom, CConnman *connman, const std::ve
1564
1561
return true ;
1565
1562
}
1566
1563
1567
- bool static ProcessMessage (CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman* connman, const std::atomic<bool >& interruptMsgProc)
1564
+ bool static ProcessMessage (CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman* connman, const std::atomic<bool >& interruptMsgProc, bool enable_bip61 )
1568
1565
{
1569
1566
LogPrint (BCLog::NET, " received: %s (%u bytes) peer=%d\n " , SanitizeString (strCommand), vRecv.size (), pfrom->GetId ());
1570
1567
if (gArgs .IsArgSet (" -dropmessagestest" ) && GetRand (gArgs .GetArg (" -dropmessagestest" , 0 )) == 0 )
@@ -1618,7 +1615,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1618
1615
// Each connection can only send one version message
1619
1616
if (pfrom->nVersion != 0 )
1620
1617
{
1621
- if (g_enable_bip61 ) {
1618
+ if (enable_bip61 ) {
1622
1619
connman->PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_DUPLICATE, std::string (" Duplicate version message" )));
1623
1620
}
1624
1621
LOCK (cs_main);
@@ -1649,7 +1646,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1649
1646
if (!pfrom->fInbound && !pfrom->fFeeler && !pfrom->m_manual_connection && !HasAllDesirableServiceFlags (nServices))
1650
1647
{
1651
1648
LogPrint (BCLog::NET, " peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n " , pfrom->GetId (), nServices, GetDesirableServiceFlags (nServices));
1652
- if (g_enable_bip61 ) {
1649
+ if (enable_bip61 ) {
1653
1650
connman->PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_NONSTANDARD,
1654
1651
strprintf (" Expected to offer services %08x" , GetDesirableServiceFlags (nServices))));
1655
1652
}
@@ -1672,7 +1669,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
1672
1669
{
1673
1670
// disconnect from peers older than this proto version
1674
1671
LogPrint (BCLog::NET, " peer=%d using obsolete version %i; disconnecting\n " , pfrom->GetId (), nVersion);
1675
- if (g_enable_bip61 ) {
1672
+ if (enable_bip61 ) {
1676
1673
connman->PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
1677
1674
strprintf (" Version must be %d or greater" , MIN_PEER_PROTO_VERSION)));
1678
1675
}
@@ -2373,7 +2370,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2373
2370
LogPrint (BCLog::MEMPOOLREJ, " %s from peer=%d was not accepted: %s\n " , tx.GetHash ().ToString (),
2374
2371
pfrom->GetId (),
2375
2372
FormatStateMessage (state));
2376
- if (g_enable_bip61 && state.GetRejectCode () > 0 && state.GetRejectCode () < REJECT_INTERNAL) { // Never send AcceptToMemoryPool's internal codes over P2P
2373
+ if (enable_bip61 && state.GetRejectCode () > 0 && state.GetRejectCode () < REJECT_INTERNAL) { // Never send AcceptToMemoryPool's internal codes over P2P
2377
2374
connman->PushMessage (pfrom, msgMaker.Make (NetMsgType::REJECT, strCommand, (unsigned char )state.GetRejectCode (),
2378
2375
state.GetRejectReason ().substr (0 , MAX_REJECT_MESSAGE_LENGTH), inv.hash ));
2379
2376
}
@@ -2558,7 +2555,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2558
2555
} // cs_main
2559
2556
2560
2557
if (fProcessBLOCKTXN )
2561
- return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, interruptMsgProc);
2558
+ return ProcessMessage (pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, interruptMsgProc, enable_bip61 );
2562
2559
2563
2560
if (fRevertToHeaderProcessing ) {
2564
2561
// Headers received from HB compact block peers are permitted to be
@@ -2944,12 +2941,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
2944
2941
return true ;
2945
2942
}
2946
2943
2947
- static bool SendRejectsAndCheckIfBanned (CNode* pnode, CConnman* connman)
2944
+ static bool SendRejectsAndCheckIfBanned (CNode* pnode, CConnman* connman, bool enable_bip61 )
2948
2945
{
2949
2946
AssertLockHeld (cs_main);
2950
2947
CNodeState &state = *State (pnode->GetId ());
2951
2948
2952
- if (g_enable_bip61 ) {
2949
+ if (enable_bip61 ) {
2953
2950
for (const CBlockReject& reject : state.rejects ) {
2954
2951
connman->PushMessage (pnode, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, std::string (NetMsgType::BLOCK), reject.chRejectCode , reject.strRejectReason , reject.hashBlock ));
2955
2952
}
@@ -3051,15 +3048,15 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
3051
3048
bool fRet = false ;
3052
3049
try
3053
3050
{
3054
- fRet = ProcessMessage (pfrom, strCommand, vRecv, msg.nTime , chainparams, connman, interruptMsgProc);
3051
+ fRet = ProcessMessage (pfrom, strCommand, vRecv, msg.nTime , chainparams, connman, interruptMsgProc, m_enable_bip61 );
3055
3052
if (interruptMsgProc)
3056
3053
return false ;
3057
3054
if (!pfrom->vRecvGetData .empty ())
3058
3055
fMoreWork = true ;
3059
3056
}
3060
3057
catch (const std::ios_base::failure& e)
3061
3058
{
3062
- if (g_enable_bip61 ) {
3059
+ if (m_enable_bip61 ) {
3063
3060
connman->PushMessage (pfrom, CNetMsgMaker (INIT_PROTO_VERSION).Make (NetMsgType::REJECT, strCommand, REJECT_MALFORMED, std::string (" error parsing message" )));
3064
3061
}
3065
3062
if (strstr (e.what (), " end of data" ))
@@ -3093,7 +3090,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
3093
3090
}
3094
3091
3095
3092
LOCK (cs_main);
3096
- SendRejectsAndCheckIfBanned (pfrom, connman);
3093
+ SendRejectsAndCheckIfBanned (pfrom, connman, m_enable_bip61 );
3097
3094
3098
3095
return fMoreWork ;
3099
3096
}
@@ -3291,7 +3288,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
3291
3288
if (!lockMain)
3292
3289
return true ;
3293
3290
3294
- if (SendRejectsAndCheckIfBanned (pto, connman))
3291
+ if (SendRejectsAndCheckIfBanned (pto, connman, m_enable_bip61 ))
3295
3292
return true ;
3296
3293
CNodeState &state = *State (pto->GetId ());
3297
3294
0 commit comments