Skip to content

Commit

Permalink
Merge pull request #1955 from MonsieurNicolas/overlayMemory
Browse files Browse the repository at this point in the history
better use of floodmap (lower memory footprint)

Reviewed-by: graydon
  • Loading branch information
latobarita authored Feb 11, 2019
2 parents f0e7da9 + c5f4ce2 commit 54504c7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/asio
Submodule asio updated 1039 files
2 changes: 2 additions & 0 deletions src/herder/Herder.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Herder
// for some reason this envelope was discarded - either is was invalid,
// used unsane qset or was coming from node that is not in quorum
ENVELOPE_STATUS_DISCARDED,
// envelope was skipped as it's from this validator
ENVELOPE_STATUS_SKIPPED_SELF,
// envelope data is currently being fetched
ENVELOPE_STATUS_FETCHING,
// current call to recvSCPEnvelope() was the first when the envelope
Expand Down
12 changes: 6 additions & 6 deletions src/herder/HerderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,6 @@ HerderImpl::recvSCPEnvelope(SCPEnvelope const& envelope)
<< " i:" << envelope.statement.slotIndex
<< " a:" << mApp.getStateHuman();

if (envelope.statement.nodeID == getSCP().getLocalNode()->getNodeID())
{
CLOG(DEBUG, "Herder") << "recvSCPEnvelope: skipping own message";
return Herder::ENVELOPE_STATUS_DISCARDED;
}

mSCPMetrics.mEnvelopeReceive.Mark();

uint32_t minLedgerSeq = getCurrentLedgerSeq();
Expand Down Expand Up @@ -416,6 +410,12 @@ HerderImpl::recvSCPEnvelope(SCPEnvelope const& envelope)
return Herder::ENVELOPE_STATUS_DISCARDED;
}

if (envelope.statement.nodeID == getSCP().getLocalNode()->getNodeID())
{
CLOG(DEBUG, "Herder") << "recvSCPEnvelope: skipping own message";
return Herder::ENVELOPE_STATUS_SKIPPED_SELF;
}

auto status = mPendingEnvelopes.recvSCPEnvelope(envelope);
if (status == Herder::ENVELOPE_STATUS_READY)
{
Expand Down
20 changes: 14 additions & 6 deletions src/overlay/Floodgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Floodgate::FloodRecord::FloodRecord(StellarMessage const& msg, uint32_t ledger,
: mLedgerSeq(ledger), mMessage(msg)
{
if (peer)
mPeersTold.insert(peer);
mPeersTold.insert(peer->toString());
}

Floodgate::Floodgate(Application& app)
Expand Down Expand Up @@ -71,7 +71,7 @@ Floodgate::addRecord(StellarMessage const& msg, Peer::pointer peer)
}
else
{
result->second->mPeersTold.insert(peer);
result->second->mPeersTold.insert(peer->toString());
return false;
}
}
Expand All @@ -96,19 +96,19 @@ Floodgate::broadcast(StellarMessage const& msg, bool force)
mFloodMapSize.set_count(mFloodMap.size());
}
// send it to people that haven't sent it to us
std::set<Peer::pointer>& peersTold = result->second->mPeersTold;
auto& peersTold = result->second->mPeersTold;

// make a copy, in case peers gets modified
auto peers = mApp.getOverlayManager().getAuthenticatedPeers();

for (auto peer : peers)
{
assert(peer.second->isAuthenticated());
if (peersTold.find(peer.second) == peersTold.end())
if (peersTold.find(peer.second->toString()) == peersTold.end())
{
mSendFromBroadcast.Mark();
peer.second->sendMessage(msg);
peersTold.insert(peer.second);
peersTold.insert(peer.second->toString());
}
}
CLOG(TRACE, "Overlay") << "broadcast " << hexAbbrev(index) << " told "
Expand All @@ -122,7 +122,15 @@ Floodgate::getPeersKnows(Hash const& h)
auto record = mFloodMap.find(h);
if (record != mFloodMap.end())
{
res = record->second->mPeersTold;
auto& ids = record->second->mPeersTold;
auto const& peers = mApp.getOverlayManager().getAuthenticatedPeers();
for (auto& p : peers)
{
if (ids.find(p.second->toString()) != ids.end())
{
res.insert(p.second);
}
}
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/overlay/Floodgate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Floodgate

uint32_t mLedgerSeq;
StellarMessage mMessage;
std::set<Peer::pointer> mPeersTold;
std::set<std::string> mPeersTold;

FloodRecord(StellarMessage const& msg, uint32_t ledger,
Peer::pointer peer);
Expand Down
12 changes: 6 additions & 6 deletions src/overlay/Peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,6 @@ Peer::recvSCPMessage(StellarMessage const& msg)
<< "recvSCPMessage node: "
<< mApp.getConfig().toShortString(msg.envelope().statement.nodeID);

mApp.getOverlayManager().recvFloodedMsg(msg, shared_from_this());

auto type = msg.envelope().statement.pledges.type();
auto t = (type == SCP_ST_PREPARE
? mRecvSCPPrepareTimer.TimeScope()
Expand All @@ -778,7 +776,11 @@ Peer::recvSCPMessage(StellarMessage const& msg)
? mRecvSCPExternalizeTimer.TimeScope()
: (mRecvSCPNominateTimer.TimeScope()))));

mApp.getHerder().recvSCPEnvelope(envelope);
auto res = mApp.getHerder().recvSCPEnvelope(envelope);
if (res != Herder::ENVELOPE_STATUS_DISCARDED)
{
mApp.getOverlayManager().recvFloodedMsg(msg, shared_from_this());
}
}

void
Expand Down Expand Up @@ -1018,10 +1020,8 @@ Peer::recvAuth(StellarMessage const& msg)
return;
}

// send SCP State
// remove when all known peers implements the next line
mApp.getHerder().sendSCPStateToPeer(0, self);
// ask for SCP state if not synced
// this requests data for slots lcl+1 ... latest consensus (if possible)
sendGetScpState(mApp.getLedgerManager().getLastClosedLedgerNum() + 1);
}

Expand Down

0 comments on commit 54504c7

Please sign in to comment.