-
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 peer message traffic for ledger data #5126
Open
ximinez
wants to merge
19
commits into
XRPLF:develop
Choose a base branch
from
ximinez:pr/getledger
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f0cf1fd
Log the caller / reason for server state changes:
ximinez 756cad9
Class "CanProcess" to keep track of processing of distinct items
ximinez 8a17f16
Drop duplicate outgoing TMGetLedger messages per peer:
ximinez 226cb56
Drop duplicate incoming TMGetLedger messages per peer:
ximinez d5ec2d3
Drop duplicate incoming TMLedgerData messages:
vlntb ecfa396
Collapse multiple outgoing TMLedgerData messages with cookies into one
ximinez e490e57
Improve logging related to ledger acquisition
ximinez 30eee9b
Review feedback from @Bronek:
ximinez 978fecd
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez b8b7b31
[FOLD] Review feedback from @vlntb:
ximinez 43b6e3e
[FOLD] Fix typo in unit test:
ximinez 813ef05
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez 89f5a67
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez d7e2d70
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez 29de22e
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez e250086
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez da4a30c
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez eee8184
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez 85dcf70
Merge remote-tracking branch 'upstream/develop' into pr/getledger
ximinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of rippled: https://github.com/ripple/rippled | ||
Copyright (c) 2024 Ripple Labs Inc. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#ifndef RIPPLE_BASICS_CANPROCESS_H_INCLUDED | ||
#define RIPPLE_BASICS_CANPROCESS_H_INCLUDED | ||
|
||
/** RAII class to check if an Item is already being processed on another thread, | ||
* as indicated by it's presence in a Collection. | ||
* | ||
* If the Item is not in the Collection, it will be added under lock in the | ||
* ctor, and removed under lock in the dtor. The object will be considered | ||
* "usable" and evaluate to `true`. | ||
* | ||
* If the Item is in the Collection, no changes will be made to the collection, | ||
* and the CanProcess object will be considered "unusable". | ||
* | ||
* It's up to the caller to decide what "usable" and "unusable" mean. (e.g. | ||
* Process or skip a block of code, or set a flag.) | ||
* | ||
* The current use is to avoid lock contention that would be involved in | ||
* processing something associated with the Item. | ||
* | ||
* Examples: | ||
* | ||
* void IncomingLedgers::acquireAsync(LedgerHash const& hash, ...) | ||
* { | ||
* if (CanProcess check{acquiresMutex_, pendingAcquires_, hash}) | ||
* { | ||
* acquire(hash, ...); | ||
* } | ||
* } | ||
* | ||
* bool | ||
* NetworkOPsImp::recvValidation( | ||
* std::shared_ptr<STValidation> const& val, | ||
* std::string const& source) | ||
* { | ||
* CanProcess check( | ||
* validationsMutex_, pendingValidations_, val->getLedgerHash()); | ||
* BypassAccept bypassAccept = | ||
* check.canProcess() ? BypassAccept::no : BypassAccept::yes; | ||
* handleNewValidation(app_, val, source, bypassAccept, m_journal); | ||
* } | ||
* | ||
*/ | ||
template <class Mutex, class Collection, class Item> | ||
class CanProcess | ||
{ | ||
public: | ||
CanProcess(Mutex& mtx, Collection& collection, Item const& item) | ||
: mtx_(mtx), collection_(collection), item_(item), canProcess_(insert()) | ||
{ | ||
} | ||
|
||
~CanProcess() | ||
{ | ||
if (canProcess_) | ||
{ | ||
std::unique_lock<Mutex> lock_(mtx_); | ||
collection_.erase(item_); | ||
} | ||
} | ||
|
||
bool | ||
canProcess() const | ||
{ | ||
return canProcess_; | ||
} | ||
|
||
operator bool() const | ||
{ | ||
return canProcess_; | ||
} | ||
|
||
private: | ||
bool | ||
insert() | ||
{ | ||
std::unique_lock<Mutex> lock_(mtx_); | ||
auto const [_, inserted] = collection_.insert(item_); | ||
return inserted; | ||
} | ||
|
||
Mutex& mtx_; | ||
Collection& collection_; | ||
Item const item_; | ||
bool const canProcess_; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]: Adding checks for the to_short_string in the base_unit_test next to existing to_string cases would be good.
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 wouldn't call that a nit. Missing test coverage is pretty significant. Thanks for catching it. Fixed.