mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-04 11:15:56 +00:00
Only forward to p2p nodes that are in sync
This commit is contained in:
@@ -43,7 +43,7 @@ class NetworkValidatedLedgers
|
||||
|
||||
mutable std::mutex m_;
|
||||
|
||||
std::condition_variable cv_;
|
||||
mutable std::condition_variable cv_;
|
||||
|
||||
bool stopping_ = false;
|
||||
|
||||
@@ -64,13 +64,23 @@ public:
|
||||
/// @return sequence of most recently validated ledger. empty optional if
|
||||
/// the datastructure has been stopped
|
||||
std::optional<uint32_t>
|
||||
getMostRecent()
|
||||
getMostRecent() const
|
||||
{
|
||||
std::unique_lock lck(m_);
|
||||
cv_.wait(lck, [this]() { return max_ || stopping_; });
|
||||
return max_;
|
||||
}
|
||||
|
||||
/// Get most recently validated sequence.
|
||||
/// @return sequence of most recently validated ledger, or empty optional
|
||||
/// if no ledgers are known to have been validated.
|
||||
std::optional<uint32_t>
|
||||
tryGetMostRecent() const
|
||||
{
|
||||
std::unique_lock lk(m_);
|
||||
return max_;
|
||||
}
|
||||
|
||||
/// Waits for the sequence to be validated by the network
|
||||
/// @param sequence to wait for
|
||||
/// @return true if sequence was validated, false otherwise
|
||||
|
||||
@@ -760,13 +760,24 @@ ETLLoadBalancer::forwardToP2p(RPC::JsonContext& context) const
|
||||
srand((unsigned)time(0));
|
||||
auto sourceIdx = rand() % sources_.size();
|
||||
auto numAttempts = 0;
|
||||
|
||||
auto mostRecent = etl_.getNetworkValidatedLedgers().tryGetMostRecent();
|
||||
while (numAttempts < sources_.size())
|
||||
{
|
||||
res = sources_[sourceIdx]->forwardToP2p(context);
|
||||
if (!res.isMember("forwarded") || res["forwarded"] != true)
|
||||
{
|
||||
auto increment = [&]() {
|
||||
sourceIdx = (sourceIdx + 1) % sources_.size();
|
||||
++numAttempts;
|
||||
};
|
||||
auto& src = sources_[sourceIdx];
|
||||
if (mostRecent && !src->hasLedger(*mostRecent))
|
||||
{
|
||||
increment();
|
||||
continue;
|
||||
}
|
||||
res = src->forwardToP2p(context);
|
||||
if (!res.isMember("forwarded") || res["forwarded"] != true)
|
||||
{
|
||||
increment();
|
||||
continue;
|
||||
}
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user