Check that tx_relay is initialized before access

This commit is contained in:
Suhas Daftuar 2019-03-08 15:48:41 -05:00
parent c4aa2ba822
commit e75c39cd42
3 changed files with 138 additions and 121 deletions

View File

@ -499,9 +499,11 @@ void CNode::copyStats(CNodeStats &stats)
X(nServices); X(nServices);
X(addr); X(addr);
X(addrBind); X(addrBind);
{ if (m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_filter); LOCK(m_tx_relay->cs_filter);
stats.fRelayTxes = m_tx_relay->fRelayTxes; stats.fRelayTxes = m_tx_relay->fRelayTxes;
} else {
stats.fRelayTxes = false;
} }
X(nLastSend); X(nLastSend);
X(nLastRecv); X(nLastRecv);
@ -528,9 +530,11 @@ void CNode::copyStats(CNodeStats &stats)
} }
X(m_legacyWhitelisted); X(m_legacyWhitelisted);
X(m_permissionFlags); X(m_permissionFlags);
{ if (m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_feeFilter); LOCK(m_tx_relay->cs_feeFilter);
stats.minFeeFilter = m_tx_relay->minFeeFilter; stats.minFeeFilter = m_tx_relay->minFeeFilter;
} else {
stats.minFeeFilter = 0;
} }
// It is common for nodes with good ping times to suddenly become lagged, // It is common for nodes with good ping times to suddenly become lagged,
@ -818,11 +822,17 @@ bool CConnman::AttemptToEvictConnection()
continue; continue;
if (node->fDisconnect) if (node->fDisconnect)
continue; continue;
bool peer_relay_txes = false;
bool peer_filter_not_null = false;
if (node->m_tx_relay != nullptr) {
LOCK(node->m_tx_relay->cs_filter); LOCK(node->m_tx_relay->cs_filter);
peer_relay_txes = node->m_tx_relay->fRelayTxes;
peer_filter_not_null = node->m_tx_relay->pfilter != nullptr;
}
NodeEvictionCandidate candidate = {node->GetId(), node->nTimeConnected, node->nMinPingUsecTime, NodeEvictionCandidate candidate = {node->GetId(), node->nTimeConnected, node->nMinPingUsecTime,
node->nLastBlockTime, node->nLastTXTime, node->nLastBlockTime, node->nLastTXTime,
HasAllDesirableServiceFlags(node->nServices), HasAllDesirableServiceFlags(node->nServices),
node->m_tx_relay->fRelayTxes, node->m_tx_relay->pfilter != nullptr, node->addr, node->nKeyedNetGroup, peer_relay_txes, peer_filter_not_null, node->addr, node->nKeyedNetGroup,
node->m_prefer_evict}; node->m_prefer_evict};
vEvictionCandidates.push_back(candidate); vEvictionCandidates.push_back(candidate);
} }

View File

@ -848,7 +848,7 @@ public:
void AddInventoryKnown(const CInv& inv) void AddInventoryKnown(const CInv& inv)
{ {
{ if (m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_tx_inventory); LOCK(m_tx_relay->cs_tx_inventory);
m_tx_relay->filterInventoryKnown.insert(inv.hash); m_tx_relay->filterInventoryKnown.insert(inv.hash);
} }
@ -856,7 +856,7 @@ public:
void PushInventory(const CInv& inv) void PushInventory(const CInv& inv)
{ {
if (inv.type == MSG_TX) { if (inv.type == MSG_TX && m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_tx_inventory); LOCK(m_tx_relay->cs_tx_inventory);
if (!m_tx_relay->filterInventoryKnown.contains(inv.hash)) { if (!m_tx_relay->filterInventoryKnown.contains(inv.hash)) {
m_tx_relay->setInventoryTxToSend.insert(inv.hash); m_tx_relay->setInventoryTxToSend.insert(inv.hash);

View File

@ -1448,7 +1448,7 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
{ {
bool sendMerkleBlock = false; bool sendMerkleBlock = false;
CMerkleBlock merkleBlock; CMerkleBlock merkleBlock;
{ if (pfrom->m_tx_relay != nullptr) {
LOCK(pfrom->m_tx_relay->cs_filter); LOCK(pfrom->m_tx_relay->cs_filter);
if (pfrom->m_tx_relay->pfilter) { if (pfrom->m_tx_relay->pfilter) {
sendMerkleBlock = true; sendMerkleBlock = true;
@ -1512,7 +1512,7 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin(); std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin();
std::vector<CInv> vNotFound; std::vector<CInv> vNotFound;
const CNetMsgMaker msgMaker(pfrom->GetSendVersion()); const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
{ if (pfrom->m_tx_relay != nullptr) {
LOCK(cs_main); LOCK(cs_main);
while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) { while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) {
@ -1995,7 +1995,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// set nodes not capable of serving the complete blockchain history as "limited nodes" // set nodes not capable of serving the complete blockchain history as "limited nodes"
pfrom->m_limited_node = (!(nServices & NODE_NETWORK) && (nServices & NODE_NETWORK_LIMITED)); pfrom->m_limited_node = (!(nServices & NODE_NETWORK) && (nServices & NODE_NETWORK_LIMITED));
{ if (pfrom->m_tx_relay != nullptr) {
LOCK(pfrom->m_tx_relay->cs_filter); LOCK(pfrom->m_tx_relay->cs_filter);
pfrom->m_tx_relay->fRelayTxes = fRelay; // set to true after we get the first filter* message pfrom->m_tx_relay->fRelayTxes = fRelay; // set to true after we get the first filter* message
} }
@ -3030,8 +3030,10 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
return true; return true;
} }
if (pfrom->m_tx_relay != nullptr) {
LOCK(pfrom->m_tx_relay->cs_tx_inventory); LOCK(pfrom->m_tx_relay->cs_tx_inventory);
pfrom->m_tx_relay->fSendMempool = true; pfrom->m_tx_relay->fSendMempool = true;
}
return true; return true;
} }
@ -3122,7 +3124,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
LOCK(cs_main); LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100); Misbehaving(pfrom->GetId(), 100);
} }
else else if (pfrom->m_tx_relay != nullptr)
{ {
LOCK(pfrom->m_tx_relay->cs_filter); LOCK(pfrom->m_tx_relay->cs_filter);
pfrom->m_tx_relay->pfilter.reset(new CBloomFilter(filter)); pfrom->m_tx_relay->pfilter.reset(new CBloomFilter(filter));
@ -3141,7 +3143,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
bool bad = false; bool bad = false;
if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) { if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) {
bad = true; bad = true;
} else { } else if (pfrom->m_tx_relay != nullptr) {
LOCK(pfrom->m_tx_relay->cs_filter); LOCK(pfrom->m_tx_relay->cs_filter);
if (pfrom->m_tx_relay->pfilter) { if (pfrom->m_tx_relay->pfilter) {
pfrom->m_tx_relay->pfilter->insert(vData); pfrom->m_tx_relay->pfilter->insert(vData);
@ -3157,6 +3159,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
} }
if (strCommand == NetMsgType::FILTERCLEAR) { if (strCommand == NetMsgType::FILTERCLEAR) {
if (pfrom->m_tx_relay == nullptr) {
return true;
}
LOCK(pfrom->m_tx_relay->cs_filter); LOCK(pfrom->m_tx_relay->cs_filter);
if (pfrom->GetLocalServices() & NODE_BLOOM) { if (pfrom->GetLocalServices() & NODE_BLOOM) {
pfrom->m_tx_relay->pfilter.reset(new CBloomFilter()); pfrom->m_tx_relay->pfilter.reset(new CBloomFilter());
@ -3169,7 +3174,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
CAmount newFeeFilter = 0; CAmount newFeeFilter = 0;
vRecv >> newFeeFilter; vRecv >> newFeeFilter;
if (MoneyRange(newFeeFilter)) { if (MoneyRange(newFeeFilter)) {
{ if (pfrom->m_tx_relay != nullptr) {
LOCK(pfrom->m_tx_relay->cs_feeFilter); LOCK(pfrom->m_tx_relay->cs_feeFilter);
pfrom->m_tx_relay->minFeeFilter = newFeeFilter; pfrom->m_tx_relay->minFeeFilter = newFeeFilter;
} }
@ -3791,6 +3796,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
} }
pto->vInventoryBlockToSend.clear(); pto->vInventoryBlockToSend.clear();
if (pto->m_tx_relay != nullptr) {
LOCK(pto->m_tx_relay->cs_tx_inventory); LOCK(pto->m_tx_relay->cs_tx_inventory);
// Check whether periodic sends should happen // Check whether periodic sends should happen
bool fSendTrickle = pto->HasPermission(PF_NOBAN); bool fSendTrickle = pto->HasPermission(PF_NOBAN);
@ -3909,6 +3915,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
} }
} }
} }
}
if (!vInv.empty()) if (!vInv.empty())
connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv)); connman->PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
@ -4066,7 +4073,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
// Message: feefilter // Message: feefilter
// //
// We don't want white listed peers to filter txs to us if we have -whitelistforcerelay // We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
if (pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) && if (pto->m_tx_relay != nullptr && pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
!pto->HasPermission(PF_FORCERELAY)) { !pto->HasPermission(PF_FORCERELAY)) {
CAmount currentFilter = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK(); CAmount currentFilter = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
int64_t timeNow = GetTimeMicros(); int64_t timeNow = GetTimeMicros();