mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 14:05:51 +00:00
Get ledger acquire work off the main thread and out of the master lock.
Prioritize ledger acquire work appripriately. This should help prevent the server from becoming overly sluggish while acquiring ledgers. Still todo: Finish all pending receive operations before sending out any data requests.
This commit is contained in:
@@ -39,6 +39,7 @@ const char* Job::toString(JobType t)
|
|||||||
case jtVALIDATION_ut: return "untrustedValidation";
|
case jtVALIDATION_ut: return "untrustedValidation";
|
||||||
case jtPROOFWORK: return "proofOfWork";
|
case jtPROOFWORK: return "proofOfWork";
|
||||||
case jtPROPOSAL_ut: return "untrustedProposal";
|
case jtPROPOSAL_ut: return "untrustedProposal";
|
||||||
|
case jtLEDGER_DATA: return "ledgerData";
|
||||||
case jtCLIENT: return "clientCommand";
|
case jtCLIENT: return "clientCommand";
|
||||||
case jtTRANSACTION: return "transaction";
|
case jtTRANSACTION: return "transaction";
|
||||||
case jtPUBLEDGER: return "publishNewLedger";
|
case jtPUBLEDGER: return "publishNewLedger";
|
||||||
|
|||||||
@@ -25,16 +25,17 @@ enum JobType
|
|||||||
jtVALIDATION_ut = 2, // A validation from an untrusted source
|
jtVALIDATION_ut = 2, // A validation from an untrusted source
|
||||||
jtPROOFWORK = 3, // A proof of work demand from another server
|
jtPROOFWORK = 3, // A proof of work demand from another server
|
||||||
jtPROPOSAL_ut = 4, // A proposal from an untrusted source
|
jtPROPOSAL_ut = 4, // A proposal from an untrusted source
|
||||||
jtCLIENT = 5, // A websocket command from the client
|
jtLEDGER_DATA = 5, // Received data for a ledger we're acquiring
|
||||||
jtTRANSACTION = 6, // A transaction received from the network
|
jtCLIENT = 6, // A websocket command from the client
|
||||||
jtPUBLEDGER = 7, // Publish a fully-accepted ledger
|
jtTRANSACTION = 7, // A transaction received from the network
|
||||||
jtWAL = 8, // Write-ahead logging
|
jtPUBLEDGER = 8, // Publish a fully-accepted ledger
|
||||||
jtVALIDATION_t = 9, // A validation from a trusted source
|
jtWAL = 9, // Write-ahead logging
|
||||||
jtWRITE = 10, // Write out hashed objects
|
jtVALIDATION_t = 10, // A validation from a trusted source
|
||||||
jtTRANSACTION_l = 11, // A local transaction
|
jtWRITE = 11, // Write out hashed objects
|
||||||
jtPROPOSAL_t = 12, // A proposal from a trusted source
|
jtTRANSACTION_l = 12, // A local transaction
|
||||||
jtADMIN = 13, // An administrative operation
|
jtPROPOSAL_t = 13, // A proposal from a trusted source
|
||||||
jtDEATH = 14, // job of death, used internally
|
jtADMIN = 14, // An administrative operation
|
||||||
|
jtDEATH = 15, // job of death, used internally
|
||||||
|
|
||||||
// special types not dispatched by the job pool
|
// special types not dispatched by the job pool
|
||||||
jtPEER = 24,
|
jtPEER = 24,
|
||||||
|
|||||||
@@ -477,6 +477,7 @@ void LedgerAcquire::trigger(Peer::ref peer)
|
|||||||
{
|
{
|
||||||
cLog(lsDEBUG) << "Done:" << (mComplete ? " complete" : "") << (mFailed ? " failed " : " ")
|
cLog(lsDEBUG) << "Done:" << (mComplete ? " complete" : "") << (mFailed ? " failed " : " ")
|
||||||
<< mLedger->getLedgerSeq();
|
<< mLedger->getLedgerSeq();
|
||||||
|
sl.unlock();
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -830,13 +831,19 @@ void LedgerAcquireMaster::dropLedger(const uint256& hash)
|
|||||||
mLedgers.erase(hash);
|
mLedgers.erase(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer::ref peer)
|
void LedgerAcquireMaster::gotLedgerData(Job&, boost::shared_ptr<ripple::TMLedgerData> packet_ptr,
|
||||||
|
boost::weak_ptr<Peer> wPeer)
|
||||||
{
|
{
|
||||||
|
ripple::TMLedgerData& packet = *packet_ptr;
|
||||||
|
Peer::pointer peer = wPeer.lock();
|
||||||
|
if (!peer)
|
||||||
|
return;
|
||||||
|
|
||||||
uint256 hash;
|
uint256 hash;
|
||||||
if (packet.ledgerhash().size() != 32)
|
if (packet.ledgerhash().size() != 32)
|
||||||
{
|
{
|
||||||
std::cerr << "Acquire error" << std::endl;
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
return SMAddNode::invalid();
|
return;
|
||||||
}
|
}
|
||||||
memcpy(hash.begin(), packet.ledgerhash().data(), 32);
|
memcpy(hash.begin(), packet.ledgerhash().data(), 32);
|
||||||
cLog(lsTRACE) << "Got data (" << packet.nodes().size() << ") for acquiring ledger: " << hash;
|
cLog(lsTRACE) << "Got data (" << packet.nodes().size() << ") for acquiring ledger: " << hash;
|
||||||
@@ -845,7 +852,8 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
|||||||
if (!ledger)
|
if (!ledger)
|
||||||
{
|
{
|
||||||
cLog(lsINFO) << "Got data for ledger we're not acquiring";
|
cLog(lsINFO) << "Got data for ledger we're not acquiring";
|
||||||
return SMAddNode();
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.type() == ripple::liBASE)
|
if (packet.type() == ripple::liBASE)
|
||||||
@@ -853,12 +861,14 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
|||||||
if (packet.nodes_size() < 1)
|
if (packet.nodes_size() < 1)
|
||||||
{
|
{
|
||||||
cLog(lsWARNING) << "Got empty base data";
|
cLog(lsWARNING) << "Got empty base data";
|
||||||
return SMAddNode::invalid();
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!ledger->takeBase(packet.nodes(0).nodedata()))
|
if (!ledger->takeBase(packet.nodes(0).nodedata()))
|
||||||
{
|
{
|
||||||
cLog(lsWARNING) << "Got invalid base data";
|
cLog(lsWARNING) << "Got invalid base data";
|
||||||
return SMAddNode::invalid();
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
SMAddNode san = SMAddNode::useful();
|
SMAddNode san = SMAddNode::useful();
|
||||||
if ((packet.nodes().size() > 1) && !ledger->takeAsRootNode(strCopy(packet.nodes(1).nodedata()), san))
|
if ((packet.nodes().size() > 1) && !ledger->takeAsRootNode(strCopy(packet.nodes(1).nodedata()), san))
|
||||||
@@ -871,7 +881,7 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
|||||||
}
|
}
|
||||||
if (!san.isInvalid())
|
if (!san.isInvalid())
|
||||||
ledger->trigger(peer);
|
ledger->trigger(peer);
|
||||||
return san;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((packet.type() == ripple::liTX_NODE) || (packet.type() == ripple::liAS_NODE))
|
if ((packet.type() == ripple::liTX_NODE) || (packet.type() == ripple::liAS_NODE))
|
||||||
@@ -882,7 +892,8 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
|||||||
if (packet.nodes().size() <= 0)
|
if (packet.nodes().size() <= 0)
|
||||||
{
|
{
|
||||||
cLog(lsINFO) << "Got response with no nodes";
|
cLog(lsINFO) << "Got response with no nodes";
|
||||||
return SMAddNode::invalid();
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < packet.nodes().size(); ++i)
|
for (int i = 0; i < packet.nodes().size(); ++i)
|
||||||
{
|
{
|
||||||
@@ -890,7 +901,8 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
|||||||
if (!node.has_nodeid() || !node.has_nodedata())
|
if (!node.has_nodeid() || !node.has_nodedata())
|
||||||
{
|
{
|
||||||
cLog(lsWARNING) << "Got bad node";
|
cLog(lsWARNING) << "Got bad node";
|
||||||
return SMAddNode::invalid();
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeIDs.push_back(SHAMapNode(node.nodeid().data(), node.nodeid().size()));
|
nodeIDs.push_back(SHAMapNode(node.nodeid().data(), node.nodeid().size()));
|
||||||
@@ -902,12 +914,12 @@ SMAddNode LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer:
|
|||||||
else
|
else
|
||||||
ledger->takeAsNode(nodeIDs, nodeData, ret);
|
ledger->takeAsNode(nodeIDs, nodeData, ret);
|
||||||
if (!ret.isInvalid())
|
if (!ret.isInvalid())
|
||||||
ledger->trigger(peer);
|
ledger->trigger(peer);
|
||||||
return ret;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cLog(lsWARNING) << "Not sure what ledger data we got";
|
cLog(lsWARNING) << "Not sure what ledger data we got";
|
||||||
return SMAddNode::invalid();
|
peer->punishPeer(LT_InvalidRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedgerAcquireMaster::sweep()
|
void LedgerAcquireMaster::sweep()
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public:
|
|||||||
LedgerAcquire::pointer find(const uint256& hash);
|
LedgerAcquire::pointer find(const uint256& hash);
|
||||||
bool hasLedger(const uint256& ledgerHash);
|
bool hasLedger(const uint256& ledgerHash);
|
||||||
void dropLedger(const uint256& ledgerHash);
|
void dropLedger(const uint256& ledgerHash);
|
||||||
SMAddNode gotLedgerData(ripple::TMLedgerData& packet, Peer::ref);
|
void gotLedgerData(Job&, boost::shared_ptr<ripple::TMLedgerData> packet, boost::weak_ptr<Peer> peer);
|
||||||
|
|
||||||
int getFetchCount(int& timeoutCount);
|
int getFetchCount(int& timeoutCount);
|
||||||
void logFailure(const uint256& h) { mRecentFailures.add(h); }
|
void logFailure(const uint256& h) { mRecentFailures.add(h); }
|
||||||
|
|||||||
@@ -590,8 +590,8 @@ void Peer::processReadBuffer()
|
|||||||
case ripple::mtLEDGER_DATA:
|
case ripple::mtLEDGER_DATA:
|
||||||
{
|
{
|
||||||
event->reName("Peer::ledgerdata");
|
event->reName("Peer::ledgerdata");
|
||||||
ripple::TMLedgerData msg;
|
boost::shared_ptr<ripple::TMLedgerData> msg = boost::make_shared<ripple::TMLedgerData>();
|
||||||
if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
|
if (msg->ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
|
||||||
recvLedger(msg);
|
recvLedger(msg);
|
||||||
else
|
else
|
||||||
cLog(lsWARNING) << "parse error: " << type;
|
cLog(lsWARNING) << "parse error: " << type;
|
||||||
@@ -1606,8 +1606,9 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
|
|||||||
sendPacket(oPacket, true);
|
sendPacket(oPacket, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::recvLedger(ripple::TMLedgerData& packet)
|
void Peer::recvLedger(const boost::shared_ptr<ripple::TMLedgerData>& packet_ptr)
|
||||||
{
|
{
|
||||||
|
ripple::TMLedgerData& packet = *packet_ptr;
|
||||||
if (packet.nodes().size() <= 0)
|
if (packet.nodes().size() <= 0)
|
||||||
{
|
{
|
||||||
cLog(lsWARNING) << "Ledger/TXset data with no nodes";
|
cLog(lsWARNING) << "Ledger/TXset data with no nodes";
|
||||||
@@ -1664,9 +1665,9 @@ void Peer::recvLedger(ripple::TMLedgerData& packet)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMAddNode san = theApp->getMasterLedgerAcquire().gotLedgerData(packet, shared_from_this());
|
theApp->getJobQueue().addJob(jtLEDGER_DATA, "gotLedgerData",
|
||||||
if (san.isInvalid())
|
boost::bind(&LedgerAcquireMaster::gotLedgerData, &theApp->getMasterLedgerAcquire(),
|
||||||
punishPeer(LT_UnwantedData);
|
_1, packet_ptr, boost::weak_ptr<Peer>(shared_from_this())));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::hasLedger(const uint256& hash) const
|
bool Peer::hasLedger(const uint256& hash) const
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ protected:
|
|||||||
void recvGetAccount(ripple::TMGetAccount& packet);
|
void recvGetAccount(ripple::TMGetAccount& packet);
|
||||||
void recvAccount(ripple::TMAccount& packet);
|
void recvAccount(ripple::TMAccount& packet);
|
||||||
void recvGetLedger(ripple::TMGetLedger& packet);
|
void recvGetLedger(ripple::TMGetLedger& packet);
|
||||||
void recvLedger(ripple::TMLedgerData& packet);
|
void recvLedger(const boost::shared_ptr<ripple::TMLedgerData>& packet);
|
||||||
void recvStatus(ripple::TMStatusChange& packet);
|
void recvStatus(ripple::TMStatusChange& packet);
|
||||||
void recvPropose(const boost::shared_ptr<ripple::TMProposeSet>& packet);
|
void recvPropose(const boost::shared_ptr<ripple::TMProposeSet>& packet);
|
||||||
void recvHaveTxSet(ripple::TMHaveTransactionSet& packet);
|
void recvHaveTxSet(ripple::TMHaveTransactionSet& packet);
|
||||||
|
|||||||
Reference in New Issue
Block a user