Page MenuHomePhabricator

D8781.diff
No OneTemporary

D8781.diff

diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp
--- a/src/avalanche/test/processor_tests.cpp
+++ b/src/avalanche/test/processor_tests.cpp
@@ -81,8 +81,8 @@
m_connman = connman.get();
m_node.connman = std::move(connman);
m_node.peer_logic = std::make_unique<PeerLogicValidation>(
- m_connman, m_node.banman.get(), *m_node.scheduler, *m_node.chainman,
- *m_node.mempool);
+ *m_connman, m_node.banman.get(), *m_node.scheduler,
+ *m_node.chainman, *m_node.mempool);
m_node.chain = interfaces::MakeChain(m_node, config.GetChainParams());
// Get the processor ready.
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -2267,7 +2267,7 @@
ChainstateManager &chainman = *Assert(node.chainman);
node.peer_logic.reset(
- new PeerLogicValidation(node.connman.get(), node.banman.get(),
+ new PeerLogicValidation(*node.connman, node.banman.get(),
*node.scheduler, chainman, *node.mempool));
RegisterValidationInterface(node.peer_logic.get());
diff --git a/src/net_processing.h b/src/net_processing.h
--- a/src/net_processing.h
+++ b/src/net_processing.h
@@ -36,7 +36,7 @@
class PeerLogicValidation final : public CValidationInterface,
public NetEventsInterface {
private:
- CConnman *const connman;
+ CConnman &m_connman;
BanMan *const m_banman;
ChainstateManager &m_chainman;
CTxMemPool &m_mempool;
@@ -44,7 +44,7 @@
bool CheckIfBanned(CNode &pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
public:
- PeerLogicValidation(CConnman *connman, BanMan *banman,
+ PeerLogicValidation(CConnman &connman, BanMan *banman,
CScheduler &scheduler, ChainstateManager &chainman,
CTxMemPool &pool);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -957,7 +957,7 @@
pnode->IsManualConn()));
}
if (!pnode->IsInboundConn()) {
- PushNodeVersion(config, *pnode, *connman, GetTime());
+ PushNodeVersion(config, *pnode, m_connman, GetTime());
}
}
@@ -1347,11 +1347,11 @@
STALE_RELAY_AGE_LIMIT);
}
-PeerLogicValidation::PeerLogicValidation(CConnman *connmanIn, BanMan *banman,
+PeerLogicValidation::PeerLogicValidation(CConnman &connman, BanMan *banman,
CScheduler &scheduler,
ChainstateManager &chainman,
CTxMemPool &pool)
- : connman(connmanIn), m_banman(banman), m_chainman(chainman),
+ : m_connman(connman), m_banman(banman), m_chainman(chainman),
m_mempool(pool), m_stale_tip_check_time(0) {
// Initialize global variables that cannot be constructed at startup.
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
@@ -1485,8 +1485,8 @@
most_recent_compact_block = pcmpctblock;
}
- connman->ForEachNode([this, &pcmpctblock, pindex, &msgMaker,
- &hashBlock](CNode *pnode) {
+ m_connman.ForEachNode([this, &pcmpctblock, pindex, &msgMaker,
+ &hashBlock](CNode *pnode) {
AssertLockHeld(cs_main);
// TODO: Avoid the repeated-serialization here
@@ -1502,7 +1502,7 @@
LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n",
"PeerLogicValidation::NewPoWValidBlock",
hashBlock.ToString(), pnode->GetId());
- connman->PushMessage(
+ m_connman.PushMessage(
pnode, msgMaker.Make(NetMsgType::CMPCTBLOCK, *pcmpctblock));
state.pindexBestHeaderSent = pindex;
}
@@ -1517,7 +1517,7 @@
const CBlockIndex *pindexFork,
bool fInitialDownload) {
const int nNewHeight = pindexNew->nHeight;
- connman->SetBestHeight(nNewHeight);
+ m_connman.SetBestHeight(nNewHeight);
SetServiceFlagsIBDCache(!fInitialDownload);
if (!fInitialDownload) {
@@ -1536,7 +1536,7 @@
}
// Relay inventory, but don't relay old inventory during initial block
// download.
- connman->ForEachNode([nNewHeight, &vHashes](CNode *pnode) {
+ m_connman.ForEachNode([nNewHeight, &vHashes](CNode *pnode) {
if (nNewHeight > (pnode->nStartingHeight != -1
? pnode->nStartingHeight - 2000
: 0)) {
@@ -1545,7 +1545,7 @@
}
}
});
- connman->WakeMessageHandler();
+ m_connman.WakeMessageHandler();
}
}
@@ -1578,7 +1578,7 @@
!::ChainstateActive().IsInitialBlockDownload() &&
mapBlocksInFlight.count(hash) == mapBlocksInFlight.size()) {
if (it != mapBlockSource.end()) {
- MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first, *connman);
+ MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first, m_connman);
}
}
@@ -4260,7 +4260,7 @@
if (m_banman) {
m_banman->Discourage(pnode.addr);
}
- connman->DisconnectNode(pnode.addr);
+ m_connman.DisconnectNode(pnode.addr);
}
return true;
}
@@ -4280,12 +4280,12 @@
bool fMoreWork = false;
if (!pfrom->vRecvGetData.empty()) {
- ProcessGetData(config, *pfrom, *connman, m_mempool, interruptMsgProc);
+ ProcessGetData(config, *pfrom, m_connman, m_mempool, interruptMsgProc);
}
if (!pfrom->orphan_work_set.empty()) {
LOCK2(cs_main, g_cs_orphans);
- ProcessOrphanTx(config, *connman, m_mempool, pfrom->orphan_work_set);
+ ProcessOrphanTx(config, m_connman, m_mempool, pfrom->orphan_work_set);
}
if (pfrom->fDisconnect) {
@@ -4317,7 +4317,7 @@
pfrom->vProcessMsg.begin());
pfrom->nProcessQueueSize -= msgs.front().m_raw_message_size;
pfrom->fPauseRecv =
- pfrom->nProcessQueueSize > connman->GetReceiveFloodSize();
+ pfrom->nProcessQueueSize > m_connman.GetReceiveFloodSize();
fMoreWork = !pfrom->vProcessMsg.empty();
}
CNetMessage &msg(msgs.front());
@@ -4334,7 +4334,7 @@
if (m_banman) {
m_banman->Discourage(pfrom->addr);
}
- connman->DisconnectNode(pfrom->addr);
+ m_connman.DisconnectNode(pfrom->addr);
pfrom->fDisconnect = true;
return false;
@@ -4360,13 +4360,13 @@
if (m_banman) {
m_banman->Discourage(pfrom->addr);
}
- connman->DisconnectNode(pfrom->addr);
+ m_connman.DisconnectNode(pfrom->addr);
return fMoreWork;
}
try {
ProcessMessage(config, *pfrom, msg_type, vRecv, msg.m_time, m_mempool,
- m_chainman, *connman, m_banman, interruptMsgProc);
+ m_chainman, m_connman, m_banman, interruptMsgProc);
if (interruptMsgProc) {
return false;
}
@@ -4453,7 +4453,7 @@
: "<none>",
state.m_chain_sync.m_work_header->GetBlockHash()
.ToString());
- connman->PushMessage(
+ m_connman.PushMessage(
&pto,
msgMaker.Make(NetMsgType::GETHEADERS,
::ChainActive().GetLocator(
@@ -4477,7 +4477,7 @@
void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds) {
// Check whether we have too many outbound peers
- int extra_peers = connman->GetExtraOutboundCount();
+ int extra_peers = m_connman.GetExtraOutboundCount();
if (extra_peers <= 0) {
return;
}
@@ -4488,7 +4488,7 @@
NodeId worst_peer = -1;
int64_t oldest_block_announcement = std::numeric_limits<int64_t>::max();
- connman->ForEachNode([&](CNode *pnode) {
+ m_connman.ForEachNode([&](CNode *pnode) {
AssertLockHeld(cs_main);
// Ignore non-outbound peers, or nodes marked for disconnect already
@@ -4521,7 +4521,7 @@
return;
}
- bool disconnected = connman->ForNode(worst_peer, [&](CNode *pnode) {
+ bool disconnected = m_connman.ForNode(worst_peer, [&](CNode *pnode) {
AssertLockHeld(cs_main);
// Only disconnect a peer that has been connected to us for some
@@ -4553,7 +4553,7 @@
// stale tip. Don't try any more extra peers until we next detect a
// stale tip, to limit the load we put on the network from these extra
// connections.
- connman->SetTryNewOutboundPeer(false);
+ m_connman.SetTryNewOutboundPeer(false);
}
}
@@ -4561,10 +4561,6 @@
const Consensus::Params &consensusParams) {
LOCK(cs_main);
- if (connman == nullptr) {
- return;
- }
-
int64_t time_in_seconds = GetTime();
EvictExtraOutboundPeers(time_in_seconds);
@@ -4575,14 +4571,14 @@
// Check whether our tip is stale, and if so, allow using an extra outbound
// peer.
- if (!fImporting && !fReindex && connman->GetNetworkActive() &&
- connman->GetUseAddrmanOutgoing() && TipMayBeStale(consensusParams)) {
+ if (!fImporting && !fReindex && m_connman.GetNetworkActive() &&
+ m_connman.GetUseAddrmanOutgoing() && TipMayBeStale(consensusParams)) {
LogPrintf("Potential stale tip detected, will try using extra outbound "
"peer (last tip update: %d seconds ago)\n",
time_in_seconds - g_last_tip_update);
- connman->SetTryNewOutboundPeer(true);
- } else if (connman->GetTryNewOutboundPeer()) {
- connman->SetTryNewOutboundPeer(false);
+ m_connman.SetTryNewOutboundPeer(true);
+ } else if (m_connman.GetTryNewOutboundPeer()) {
+ m_connman.SetTryNewOutboundPeer(false);
}
m_stale_tip_check_time = time_in_seconds + STALE_CHECK_INTERVAL;
}
@@ -4640,12 +4636,12 @@
pto->nPingUsecStart = GetTimeMicros();
if (pto->nVersion > BIP0031_VERSION) {
pto->nPingNonceSent = nonce;
- connman->PushMessage(pto, msgMaker.Make(NetMsgType::PING, nonce));
+ m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::PING, nonce));
} else {
// Peer is too old to support ping command with nonce, pong will
// never arrive.
pto->nPingNonceSent = 0;
- connman->PushMessage(pto, msgMaker.Make(NetMsgType::PING));
+ m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::PING));
}
}
@@ -4686,7 +4682,7 @@
vAddr.push_back(addr);
// receiver rejects addr messages larger than 1000
if (vAddr.size() >= 1000) {
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::ADDR, vAddr));
vAddr.clear();
}
@@ -4694,7 +4690,7 @@
}
pto->vAddrToSend.clear();
if (!vAddr.empty()) {
- connman->PushMessage(pto, msgMaker.Make(NetMsgType::ADDR, vAddr));
+ m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::ADDR, vAddr));
}
// we only send the big addr message once
@@ -4743,7 +4739,7 @@
LogPrint(BCLog::NET,
"initial getheaders (%d) to peer=%d (startheight:%d)\n",
pindexStart->nHeight, pto->GetId(), pto->nStartingHeight);
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::GETHEADERS,
::ChainActive().GetLocator(pindexStart),
uint256()));
@@ -4836,7 +4832,7 @@
if (most_recent_block_hash == pBestIndex->GetBlockHash()) {
CBlockHeaderAndShortTxIDs cmpctblock(
*most_recent_block);
- connman->PushMessage(
+ m_connman.PushMessage(
pto,
msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK,
cmpctblock));
@@ -4849,7 +4845,7 @@
ReadBlockFromDisk(block, pBestIndex, consensusParams);
assert(ret);
CBlockHeaderAndShortTxIDs cmpctblock(block);
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK,
cmpctblock));
}
@@ -4867,7 +4863,7 @@
__func__, vHeaders.front().GetHash().ToString(),
pto->GetId());
}
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::HEADERS, vHeaders));
state.pindexBestHeaderSent = pBestIndex;
} else {
@@ -4919,7 +4915,8 @@
for (const BlockHash &hash : pto->vInventoryBlockToSend) {
vInv.push_back(CInv(MSG_BLOCK, hash));
if (vInv.size() == MAX_INV_SZ) {
- connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
+ m_connman.PushMessage(pto,
+ msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
}
}
@@ -4933,7 +4930,7 @@
fSendTrickle = true;
if (pto->IsInboundConn()) {
pto->m_tx_relay->nNextInvSend = std::chrono::microseconds{
- connman->PoissonNextSendInbound(
+ m_connman.PoissonNextSendInbound(
nNow, INVENTORY_BROADCAST_INTERVAL)};
} else {
// Skip delay for outbound peers, as there is less
@@ -4980,7 +4977,7 @@
pto->m_tx_relay->filterInventoryKnown.insert(txid);
vInv.push_back(inv);
if (vInv.size() == MAX_INV_SZ) {
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
}
@@ -5069,7 +5066,7 @@
}
}
if (vInv.size() == MAX_INV_SZ) {
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::INV, vInv));
vInv.clear();
}
@@ -5079,7 +5076,7 @@
}
}
if (!vInv.empty()) {
- connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
+ m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
}
// Detect whether we're stalling
@@ -5242,7 +5239,7 @@
pto->GetId());
vGetData.push_back(inv);
if (vGetData.size() >= MAX_GETDATA_SZ) {
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
vGetData.clear();
}
@@ -5265,7 +5262,8 @@
}
if (!vGetData.empty()) {
- connman->PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
+ m_connman.PushMessage(pto,
+ msgMaker.Make(NetMsgType::GETDATA, vGetData));
}
//
@@ -5291,7 +5289,7 @@
filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK());
if (filterToSend != pto->m_tx_relay->lastSentFeeFilter) {
- connman->PushMessage(
+ m_connman.PushMessage(
pto, msgMaker.Make(NetMsgType::FEEFILTER, filterToSend));
pto->m_tx_relay->lastSentFeeFilter = filterToSend;
}
diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp
--- a/src/test/denialofservice_tests.cpp
+++ b/src/test/denialofservice_tests.cpp
@@ -79,7 +79,7 @@
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337);
auto peerLogic = std::make_unique<PeerLogicValidation>(
- connman.get(), nullptr, *m_node.scheduler, *m_node.chainman,
+ *connman, nullptr, *m_node.scheduler, *m_node.chainman,
*m_node.mempool);
// Mock an outbound peer
@@ -163,7 +163,7 @@
auto connman = std::make_unique<CConnmanTest>(config, 0x1337, 0x1337);
auto peerLogic = std::make_unique<PeerLogicValidation>(
- connman.get(), nullptr, *m_node.scheduler, *m_node.chainman,
+ *connman, nullptr, *m_node.scheduler, *m_node.chainman,
*m_node.mempool);
const Consensus::Params &consensusParams =
@@ -243,7 +243,7 @@
DEFAULT_MISBEHAVING_BANTIME);
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337);
auto peerLogic = std::make_unique<PeerLogicValidation>(
- connman.get(), banman.get(), *m_node.scheduler, *m_node.chainman,
+ *connman, banman.get(), *m_node.scheduler, *m_node.chainman,
*m_node.mempool);
banman->ClearBanned();
@@ -315,7 +315,7 @@
DEFAULT_MISBEHAVING_BANTIME);
auto connman = std::make_unique<CConnman>(config, 0x1337, 0x1337);
auto peerLogic = std::make_unique<PeerLogicValidation>(
- connman.get(), banman.get(), *m_node.scheduler, *m_node.chainman,
+ *connman, banman.get(), *m_node.scheduler, *m_node.chainman,
*m_node.mempool);
banman->ClearBanned();
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -205,7 +205,7 @@
// Deterministic randomness for tests.
m_node.connman = std::make_unique<CConnman>(config, 0x1337, 0x1337);
m_node.peer_logic = std::make_unique<PeerLogicValidation>(
- m_node.connman.get(), m_node.banman.get(), *m_node.scheduler,
+ *m_node.connman, m_node.banman.get(), *m_node.scheduler,
*m_node.chainman, *m_node.mempool);
{
CConnman::Options options;

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 11:38 (6 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187649
Default Alt Text
D8781.diff (18 KB)

Event Timeline