-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only forward to p2p nodes that are in sync #4028
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,13 +760,24 @@ ETLLoadBalancer::forwardToP2p(RPC::JsonContext& context) const | |
srand((unsigned)time(0)); | ||
auto sourceIdx = rand() % sources_.size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't fix this right now, but I think there's a better way to get a uniform int distribution post C++11: https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution This may not be a critical place for it, but we should still model good coding practices. That's a good change to make some time in the future. |
||
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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to read
max_
withm_
locked. Otherwise you can get a tornoptional
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should probably be
const
(as shouldgetMostRecent()
which is probably why this method is not).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make these methods
const
,std::condition_variable cv_
has to be mademutable
. I'll make that change too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch