Simplify and optimize the processing of inbound transactions

This commit is contained in:
Nik Bougalis
2022-01-12 22:28:23 -08:00
committed by manojsdoshi
parent 3eb8aa8b80
commit 18235067af
3 changed files with 23 additions and 34 deletions

View File

@@ -71,6 +71,7 @@ public:
, m_zeroSet(m_map[uint256()]) , m_zeroSet(m_map[uint256()])
, m_gotSet(std::move(gotSet)) , m_gotSet(std::move(gotSet))
, m_peerSetBuilder(std::move(peerSetBuilder)) , m_peerSetBuilder(std::move(peerSetBuilder))
, j_(app_.journal("InboundTransactions"))
{ {
m_zeroSet.mSet = std::make_shared<SHAMap>( m_zeroSet.mSet = std::make_shared<SHAMap>(
SHAMapType::TRANSACTION, uint256(), app_.getNodeFamily()); SHAMapType::TRANSACTION, uint256(), app_.getNodeFamily());
@@ -99,9 +100,7 @@ public:
{ {
std::lock_guard sl(mLock); std::lock_guard sl(mLock);
auto it = m_map.find(hash); if (auto it = m_map.find(hash); it != m_map.end())
if (it != m_map.end())
{ {
if (acquire) if (acquire)
{ {
@@ -140,11 +139,8 @@ public:
{ {
protocol::TMLedgerData& packet = *packet_ptr; protocol::TMLedgerData& packet = *packet_ptr;
JLOG(app_.journal("InboundLedger").trace()) JLOG(j_.trace()) << "Got data (" << packet.nodes().size()
<< "Got data (" << packet.nodes().size() << ") for acquiring ledger: " << hash;
<< ") "
"for acquiring ledger: "
<< hash;
TransactionAcquire::pointer ta = getAcquire(hash); TransactionAcquire::pointer ta = getAcquire(hash);
@@ -154,8 +150,9 @@ public:
return; return;
} }
std::list<SHAMapNodeID> nodeIDs; std::vector<std::pair<SHAMapNodeID, Slice>> data;
std::list<Blob> nodeData; data.reserve(packet.nodes().size());
for (auto const& node : packet.nodes()) for (auto const& node : packet.nodes())
{ {
if (!node.has_nodeid() || !node.has_nodedata()) if (!node.has_nodeid() || !node.has_nodedata())
@@ -172,12 +169,10 @@ public:
return; return;
} }
nodeIDs.emplace_back(*id); data.emplace_back(std::make_pair(*id, makeSlice(node.nodedata())));
nodeData.emplace_back(
node.nodedata().begin(), node.nodedata().end());
} }
if (!ta->takeNodes(nodeIDs, nodeData, peer).isUseful()) if (!ta->takeNodes(data, peer).isUseful())
peer->charge(Resource::feeUnwantedData); peer->charge(Resource::feeUnwantedData);
} }
@@ -262,6 +257,8 @@ private:
std::function<void(std::shared_ptr<SHAMap> const&, bool)> m_gotSet; std::function<void(std::shared_ptr<SHAMap> const&, bool)> m_gotSet;
std::unique_ptr<PeerSetBuilder> m_peerSetBuilder; std::unique_ptr<PeerSetBuilder> m_peerSetBuilder;
beast::Journal j_;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@@ -65,7 +65,7 @@ TransactionAcquire::done()
if (failed_) if (failed_)
{ {
JLOG(journal_.warn()) << "Failed to acquire TX set " << hash_; JLOG(journal_.debug()) << "Failed to acquire TX set " << hash_;
} }
else else
{ {
@@ -176,8 +176,7 @@ TransactionAcquire::trigger(std::shared_ptr<Peer> const& peer)
SHAMapAddNode SHAMapAddNode
TransactionAcquire::takeNodes( TransactionAcquire::takeNodes(
const std::list<SHAMapNodeID>& nodeIDs, std::vector<std::pair<SHAMapNodeID, Slice>> const& data,
const std::list<Blob>& data,
std::shared_ptr<Peer> const& peer) std::shared_ptr<Peer> const& peer)
{ {
ScopedLockType sl(mtx_); ScopedLockType sl(mtx_);
@@ -196,24 +195,20 @@ TransactionAcquire::takeNodes(
try try
{ {
if (nodeIDs.empty()) if (data.empty())
return SHAMapAddNode::invalid(); return SHAMapAddNode::invalid();
std::list<SHAMapNodeID>::const_iterator nodeIDit = nodeIDs.begin();
std::list<Blob>::const_iterator nodeDatait = data.begin();
ConsensusTransSetSF sf(app_, app_.getTempNodeCache()); ConsensusTransSetSF sf(app_, app_.getTempNodeCache());
while (nodeIDit != nodeIDs.end()) for (auto const& d : data)
{ {
if (nodeIDit->isRoot()) if (d.first.isRoot())
{ {
if (mHaveRoot) if (mHaveRoot)
JLOG(journal_.debug()) JLOG(journal_.debug())
<< "Got root TXS node, already have it"; << "Got root TXS node, already have it";
else if (!mMap->addRootNode( else if (!mMap->addRootNode(
SHAMapHash{hash_}, SHAMapHash{hash_}, d.second, nullptr)
makeSlice(*nodeDatait),
nullptr)
.isGood()) .isGood())
{ {
JLOG(journal_.warn()) << "TX acquire got bad root node"; JLOG(journal_.warn()) << "TX acquire got bad root node";
@@ -221,24 +216,22 @@ TransactionAcquire::takeNodes(
else else
mHaveRoot = true; mHaveRoot = true;
} }
else if (!mMap->addKnownNode(*nodeIDit, makeSlice(*nodeDatait), &sf) else if (!mMap->addKnownNode(d.first, d.second, &sf).isGood())
.isGood())
{ {
JLOG(journal_.warn()) << "TX acquire got bad non-root node"; JLOG(journal_.warn()) << "TX acquire got bad non-root node";
return SHAMapAddNode::invalid(); return SHAMapAddNode::invalid();
} }
++nodeIDit;
++nodeDatait;
} }
trigger(peer); trigger(peer);
progress_ = true; progress_ = true;
return SHAMapAddNode::useful(); 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(); return SHAMapAddNode::invalid();
} }
} }

View File

@@ -44,8 +44,7 @@ public:
SHAMapAddNode SHAMapAddNode
takeNodes( takeNodes(
const std::list<SHAMapNodeID>& IDs, std::vector<std::pair<SHAMapNodeID, Slice>> const& data,
const std::list<Blob>& data,
std::shared_ptr<Peer> const&); std::shared_ptr<Peer> const&);
void void