Skip to content

Commit

Permalink
Simplify and optimize the processing of inbound transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
nbougalis authored and manojsdoshi committed Mar 30, 2022
1 parent 3eb8aa8 commit 1823506
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
25 changes: 11 additions & 14 deletions src/ripple/app/ledger/impl/InboundTransactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class InboundTransactionsImp : public InboundTransactions
, m_zeroSet(m_map[uint256()])
, m_gotSet(std::move(gotSet))
, m_peerSetBuilder(std::move(peerSetBuilder))
, j_(app_.journal("InboundTransactions"))
{
m_zeroSet.mSet = std::make_shared<SHAMap>(
SHAMapType::TRANSACTION, uint256(), app_.getNodeFamily());
Expand Down Expand Up @@ -99,9 +100,7 @@ class InboundTransactionsImp : public InboundTransactions
{
std::lock_guard sl(mLock);

auto it = m_map.find(hash);

if (it != m_map.end())
if (auto it = m_map.find(hash); it != m_map.end())
{
if (acquire)
{
Expand Down Expand Up @@ -140,11 +139,8 @@ class InboundTransactionsImp : public InboundTransactions
{
protocol::TMLedgerData& packet = *packet_ptr;

JLOG(app_.journal("InboundLedger").trace())
<< "Got data (" << packet.nodes().size()
<< ") "
"for acquiring ledger: "
<< hash;
JLOG(j_.trace()) << "Got data (" << packet.nodes().size()
<< ") for acquiring ledger: " << hash;

TransactionAcquire::pointer ta = getAcquire(hash);

Expand All @@ -154,8 +150,9 @@ class InboundTransactionsImp : public InboundTransactions
return;
}

std::list<SHAMapNodeID> nodeIDs;
std::list<Blob> nodeData;
std::vector<std::pair<SHAMapNodeID, Slice>> data;
data.reserve(packet.nodes().size());

for (auto const& node : packet.nodes())
{
if (!node.has_nodeid() || !node.has_nodedata())
Expand All @@ -172,12 +169,10 @@ class InboundTransactionsImp : public InboundTransactions
return;
}

nodeIDs.emplace_back(*id);
nodeData.emplace_back(
node.nodedata().begin(), node.nodedata().end());
data.emplace_back(std::make_pair(*id, makeSlice(node.nodedata())));
}

if (!ta->takeNodes(nodeIDs, nodeData, peer).isUseful())
if (!ta->takeNodes(data, peer).isUseful())
peer->charge(Resource::feeUnwantedData);
}

Expand Down Expand Up @@ -262,6 +257,8 @@ class InboundTransactionsImp : public InboundTransactions
std::function<void(std::shared_ptr<SHAMap> const&, bool)> m_gotSet;

std::unique_ptr<PeerSetBuilder> m_peerSetBuilder;

beast::Journal j_;
};

//------------------------------------------------------------------------------
Expand Down
29 changes: 11 additions & 18 deletions src/ripple/app/ledger/impl/TransactionAcquire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TransactionAcquire::done()

if (failed_)
{
JLOG(journal_.warn()) << "Failed to acquire TX set " << hash_;
JLOG(journal_.debug()) << "Failed to acquire TX set " << hash_;
}
else
{
Expand Down Expand Up @@ -176,8 +176,7 @@ TransactionAcquire::trigger(std::shared_ptr<Peer> const& peer)

SHAMapAddNode
TransactionAcquire::takeNodes(
const std::list<SHAMapNodeID>& nodeIDs,
const std::list<Blob>& data,
std::vector<std::pair<SHAMapNodeID, Slice>> const& data,
std::shared_ptr<Peer> const& peer)
{
ScopedLockType sl(mtx_);
Expand All @@ -196,49 +195,43 @@ TransactionAcquire::takeNodes(

try
{
if (nodeIDs.empty())
if (data.empty())
return SHAMapAddNode::invalid();

std::list<SHAMapNodeID>::const_iterator nodeIDit = nodeIDs.begin();
std::list<Blob>::const_iterator nodeDatait = data.begin();
ConsensusTransSetSF sf(app_, app_.getTempNodeCache());

while (nodeIDit != nodeIDs.end())
for (auto const& d : data)
{
if (nodeIDit->isRoot())
if (d.first.isRoot())
{
if (mHaveRoot)
JLOG(journal_.debug())
<< "Got root TXS node, already have it";
else if (!mMap->addRootNode(
SHAMapHash{hash_},
makeSlice(*nodeDatait),
nullptr)
SHAMapHash{hash_}, d.second, nullptr)
.isGood())
{
JLOG(journal_.warn()) << "TX acquire got bad root node";
}
else
mHaveRoot = true;
}
else if (!mMap->addKnownNode(*nodeIDit, makeSlice(*nodeDatait), &sf)
.isGood())
else if (!mMap->addKnownNode(d.first, d.second, &sf).isGood())
{
JLOG(journal_.warn()) << "TX acquire got bad non-root node";
return SHAMapAddNode::invalid();
}

++nodeIDit;
++nodeDatait;
}

trigger(peer);
progress_ = true;
return SHAMapAddNode::useful();
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(journal_.error()) << "Peer sends us junky transaction node data";
JLOG(journal_.error())
<< "Peer " << peer->id()
<< " sent us junky transaction node data: " << ex.what();
return SHAMapAddNode::invalid();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/app/ledger/impl/TransactionAcquire.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class TransactionAcquire final

SHAMapAddNode
takeNodes(
const std::list<SHAMapNodeID>& IDs,
const std::list<Blob>& data,
std::vector<std::pair<SHAMapNodeID, Slice>> const& data,
std::shared_ptr<Peer> const&);

void
Expand Down

0 comments on commit 1823506

Please sign in to comment.