-
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
Reduce duplicate peer traffic for ledger data #5126
Conversation
* Also log as warning when the state lowers
c357abb
to
9e5487c
Compare
09c4156
to
c69b443
Compare
* Allow a retry after 30s in case of peer or network congestion. * Addresses RIPD-1870 * (Changes levelization. That is not desirable, and will need to be fixed.)
* Allow a retry after 15s in case of peer or network congestion. * Collate duplicate TMGetLedger requests: * The requestCookie is ignored when computing the hash, thus increasing the chances of detecting duplicate messages. * With duplicate messages, keep track of the different requestCookies (or lack of cookie). When work is finally done for a given request, send the response to all the peers that are waiting on the request, sending a separate message for each requestCookie. * Addresses RIPD-1871
* Addresses RIPD-1869 --------- Co-authored-by: Valentin Balaschenko <13349202+vlntb@users.noreply.github.com> Co-authored-by: Ed Hennis <ed@ripple.com>
* When work is done for a given TMGetLedger request, send the response to all the peers that are waiting on the request, sending one message per peer, including all the cookies and a "directResponse" flag indicating the data is intended for the sender, too.
c69b443
to
e490e57
Compare
include/xrpl/basics/CanProcess.h
Outdated
insert() | ||
{ | ||
std::unique_lock<Mutex> lock_(mtx_); | ||
bool exists = collection_.contains(item_); |
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 would avoid extra lookup
auto [_, inserted] = collection_.insert(item_);
return inserted;
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. Fixed.
* Avoid an unnecessary lookup in CanProcess
* upstream/develop: Set version to 2.3.0-b4 feat(SQLite): allow configurable database pragma values (5135) refactor: re-order PRAGMA statements (5140) fix(book_changes): add "validated" field and reduce RPC latency (5096) chore: fix typos in comments (5094) Set version to 2.2.3 Update SQLite3 max_page_count to match current defaults (5114)
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.
Only minor comments. Happy to approve once addressed.
src/xrpld/overlay/detail/PeerImp.cpp
Outdated
return ledger; | ||
} | ||
|
||
JLOG(p_journal_.trace()) |
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.
[nit]: Should this be a warn
instead of trace
? Not having a peer to relay the request may indicate some configuration or environment issues.
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.
Not necessarily, though. It could mean that the node has already sent the request to all it's peers. Also not that the original message is trace
.
But there's something odd here. It looks like this code block was somehow duplicated! I must have messed up resolving a conflict when I rebased from master
to develop
. I've removed the duplicate.
src/xrpld/overlay/detail/PeerImp.cpp
Outdated
@@ -2936,7 +3078,9 @@ getPeerWithLedger( | |||
void | |||
PeerImp::sendLedgerBase( | |||
std::shared_ptr<Ledger const> const& ledger, | |||
protocol::TMLedgerData& ledgerData) | |||
protocol::TMLedgerData& ledgerData, | |||
std::map<std::shared_ptr<Peer>, std::set<std::optional<uint64_t>>> const& |
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.
std::map<std::shared_ptr<Peer>, std::set<std::optional<uint64_t>>>
is mentioned in four places. It would be more readable to define an alias:
using PeerCookieMap = std::map<std::shared_ptr<Peer>, std::set<std::optional<uint64_t>>>;
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 suggestion! Fixed.
* Add unit tests for to_short_string(base_uint * Remove duplicated code * Use type aliases for cookie maps
* That's what I get for rushing to push
* upstream/develop: Set version to 2.4.0-b3 Set version to 2.3.1 Update conan in the "nix" CI jobs Add RPC "simulate" to execute a dry run of a transaction (5069) Set version to 2.3.1-rc1 Reduce the peer charges for well-behaved peers:
* upstream/develop: Add deep freeze feature (XLS-77d) (5187)
* upstream/develop: Amendment `fixFrozenLPTokenTransfer` (5227) Improve git commit hash lookup (5225)
* upstream/develop: Updates Conan dependencies (5256)
* upstream/develop: fix: Do not allow creating Permissioned Domains if credentials are not enabled (5275) fix: issues in `simulate` RPC (5265)
* upstream/develop: fix: Amendment to add transaction flag checking functionality for Credentials (5250) fix: Omit superfluous setCurrentThreadName call in GRPCServer.cpp (5280)
src/xrpld/app/ledger/InboundLedger.h
Outdated
case CONSENSUS: | ||
return "CONSENSUS"; | ||
default: | ||
assert(false); |
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.
please replace with UNREACHABLE
and a nice & short description why (see CONTRIBUTING.md
, section " Contracts and instrumentation" for naming guideline)
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.
please replace with
UNREACHABLE
and a nice & short description why (seeCONTRIBUTING.md
, section " Contracts and instrumentation" for naming guideline)
Done.
{ | ||
// Done. Something else (probably consensus) built the ledger | ||
// locally while waiting for data (or possibly before requesting) | ||
assert(isDone()); |
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.
please replace with XRPL_ASSERT
and a short description why; see CONTRIBUTING.md
for contracts and instrumentation naming guidelines
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.
please replace with
XRPL_ASSERT
and a short description why; seeCONTRIBUTING.md
for contracts and instrumentation naming guidelines
Done
src/xrpld/app/misc/HashRouter.cpp
Outdated
|
||
for (auto const peerID : s.peekPeerSet()) | ||
{ | ||
if (!callback(peerID)) |
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.
How fast are these callbacks - we are running them over a loop inside critical section. Might need to think of an alternative solution, to avoid hogging the mutex_
. Not a major issue, because as indicated in first sentence - I do not know if these callbacks are fast or slow (or we don't know ?)
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.
The callbacks are very fast, but now I don't remember why I wanted to do this under lock.
PeerImp.cpp line 3528
std::set<HashRouter::PeerShortID> peers;
app_.getHashRouter().forEachPeer(
mHash, [&](HashRouter::PeerShortID const& peerID) {
// callback is called under lock, so finish as fast as
// possible.
peers.insert(peerID);
return true;
});
Maybe I wanted avoid making a copy of the std::set
? But this is effectively making a copy of the set anyway, so that's dumb. I'd guess I originally wrote it with the loop contents inside the callback, but decided that was too slow, and didn't think before just copying.
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.
There are 10 assert
added here, can you please turn them to XRPL_ASSERT
, following naming guideline in CONTRIBUTING.md
?
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.
Only minor remarks related to use of assert
, once fixed feel free to merge
Note to self: add unit tests for PeerImp.cpp
in a future PR
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.
Actually I realized I added a comment re. use of a loop and callback inside critical section. A sufficient explanation why this is safe might be sufficient to address this comment, but for now this is not approved.
* upstream/develop: chore: Rename missing-commits job, and combine nix job files (5268) docs: Add a summary of the git commit message rules (5283)
* upstream/develop: fix: Replace charge() by fee_.update() in OnMessage functions (5269) docs: ensure build_type and CMAKE_BUILD_TYPE match (5274) chore: Fix small typos in protocol files (5279)
Commit message:
|
- Convert a bunch of old asserts to XRPL_ASSERT - Change HashRouter::forEachPeer to getPeers, which just returns the set
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.
Thank you @ximinez , this is just to confirm that you have covered all the feedback I had for this PR, and I particularly like how you changed forEachPeer
into getPeers
and also paid attention to contract names. Nice !
High Level Overview of Change
Several changes to help reduce message traffic and improve logging and visibility.
TMGetLedger
andTMLedgerData
messages, reducing the overhead of processing those messages.TMLedgerData
message, which allows multiple identical requests to be replied to with one message.These changes are organized into several commits which are organized logically separating each functional operation. They can be merged as-is, or squashed.
Context of Change
Analysis of the issue that led to #5115 identified heavy
TMGetLedger
request andTMLedgerData
response traffic between nodes leading up to the syncing incidents. It was later determined that those messages were more a symptom of the problem, and not the root cause. However, leading up to identification of the root cause, these changes were being implemented to cut down on those messages, detect duplicates, etc. That reduction in unnecessary traffic is still valuable, so it's being included here.Type of Change
API Impact
None.
Test Plan
Future Tasks
I am still working on a follow-up to #4764 that makes use of these changes and other improvements to reduce the number of requests initiated by a given node in the first place.