Browse Source

Hopefully fix rare coredump #89

We now create a new lock for vRelayNodes, which becomes a global instead of
function level variable. This should prevent the rare case when pnode = NULL.
Also, to be even safer, we now check if pnode is NULL and if it is, we log
that we are ignoring it and go to the next iteration of the loop.
relaytx
Duke Leto 2 years ago
parent
commit
4318bff7c7
  1. 15
      src/net.cpp
  2. 3
      src/net.h

15
src/net.cpp

@ -118,6 +118,9 @@ extern void StartShutdown();
vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
vector<CNode*> vRelayNodes;
CCriticalSection cs_vRelayNodes;
map<CInv, CDataStream> mapRelay;
deque<pair<int64_t, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;
@ -2110,9 +2113,11 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss)
mapRelay.insert(std::make_pair(inv, ss));
vRelayExpiration.push_back(std::make_pair(GetTime() + 15 * 60, inv));
}
LOCK(cs_vNodes);
auto vRelayNodes = vNodes;
LOCK2(cs_vNodes, cs_vRelayNodes);
// make a copy of our full node list so we can choose a subset to relay to
vRelayNodes = vNodes;
// We always round down, except when we have only 1 connection
auto newSize = (vNodes.size() / 2) == 0 ? 1 : (vNodes.size() / 2);
@ -2120,11 +2125,17 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss)
random_shuffle( vRelayNodes.begin(), vRelayNodes.end(), GetRandInt );
vRelayNodes.resize(newSize);
// We do not log this to debug.log because it leaks metadata about how many
// peers this node had at a certain timestamp
fprintf(stderr, "%s: Relaying to %lu of %lu peers\n", __func__, newSize, vNodes.size() );
// Only relay to randomly chosen 50% of peers
BOOST_FOREACH(CNode* pnode, vRelayNodes)
{
if(!pnode) {
LogPrintf("%s: invalid relay node found, ignoring\n", __func__);
continue;
}
if(!pnode->fRelayTxes)
continue;
LOCK(pnode->cs_filter);

3
src/net.h

@ -179,6 +179,9 @@ extern int nMaxConnections;
extern std::vector<CNode*> vNodes;
extern CCriticalSection cs_vNodes;
extern std::vector<CNode*> vRelayNodes;
extern CCriticalSection cs_vRelayNodes;
extern std::map<CInv, CDataStream> mapRelay;
extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
extern CCriticalSection cs_mapRelay;

Loading…
Cancel
Save