-
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
Improve transaction relay logic #4985
base: develop
Are you sure you want to change the base?
Changes from 54 commits
c3805a7
36dddfa
99a63a0
e048a41
3c0dbeb
88c0074
029d64c
a1218af
f67f346
3863b01
8b43ea8
23636d1
7096d0a
643ca1a
f0170d3
8742e3b
e6f2597
0f71e1c
31a18f8
58a5797
05e4164
ff27e9e
5d1ab36
43d8ab1
c7e08bc
3054f5a
c9eed68
3ac1a8a
0940acd
00e1945
77138fc
c2f600c
29dbd50
3d741e1
fb0e201
f982d93
284399b
03f9d0f
31e982a
0641f77
01bd73b
f3e3199
b056f25
0bbb61a
b008dbc
022142f
be52629
12af9f1
c1866d1
79fb1cc
b5624fe
a35aab0
9595d8c
eeb1277
91d0867
3c5e9cf
2ca015e
65303b3
e5233f2
8f48d64
d5ba2c6
dcc3ca5
d3a9522
9082414
96f9219
c94bf7d
9fe23dc
e96745f
1cd33b8
158c285
5b09745
e8c0d7b
76dd4e1
47da138
93b9a6d
0855726
1fed810
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
|
||
#include <xrpld/app/misc/HashRouter.h> | ||
|
||
#include <xrpld/core/Config.h> | ||
|
||
namespace ripple { | ||
|
||
auto | ||
|
@@ -33,7 +35,7 @@ HashRouter::emplace(uint256 const& key) -> std::pair<Entry&, bool> | |
} | ||
|
||
// See if any supressions need to be expired | ||
expire(suppressionMap_, holdTime_); | ||
expire(suppressionMap_, setup_.holdTime); | ||
|
||
return std::make_pair( | ||
std::ref(suppressionMap_.emplace(key, Entry()).first->second), true); | ||
|
@@ -122,10 +124,45 @@ HashRouter::shouldRelay(uint256 const& key) | |
|
||
auto& s = emplace(key).first; | ||
|
||
if (!s.shouldRelay(suppressionMap_.clock().now(), holdTime_)) | ||
if (!s.shouldRelay(suppressionMap_.clock().now(), setup_.relayTime)) | ||
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. Can we have a comment here why 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.
The parameter in |
||
return {}; | ||
|
||
return s.releasePeerSet(); | ||
} | ||
|
||
HashRouter::Setup | ||
setup_HashRouter(Config const& config) | ||
{ | ||
using namespace std::chrono; | ||
|
||
HashRouter::Setup setup; | ||
auto const& section = config.section("hashrouter"); | ||
|
||
std::int32_t tmp; | ||
|
||
if (set(tmp, "hold_time", section)) | ||
{ | ||
if (tmp < 8) | ||
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. The error message below says something different; is this meant to be 8 or 12 ? Also, given this is a free function, it should be easy to add to unit tests, including test that an exception is thrown. 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.
This looks like a copy/paste error. Unfortunately, I don't remember which direction. LOL. |
||
Throw<std::runtime_error>( | ||
"HashRouter hold time must be at least 12 seconds (the " | ||
"approximate validation time for three ledgers)."); | ||
setup.holdTime = seconds(tmp); | ||
} | ||
if (set(tmp, "relay_time", section)) | ||
{ | ||
if (tmp < 8) | ||
Throw<std::runtime_error>( | ||
"HashRouter relay time must be at least 8 seconds (the " | ||
"approximate validation time for two ledgers)."); | ||
setup.relayTime = seconds(tmp); | ||
} | ||
if (setup.relayTime > setup.holdTime) | ||
{ | ||
Throw<std::runtime_error>( | ||
"HashRouter relay time must be less than or equal to hold time"); | ||
} | ||
|
||
return setup; | ||
} | ||
|
||
} // namespace ripple |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ namespace ripple { | |
// TODO convert these macros to int constants or an enum | ||
#define SF_BAD 0x02 // Temporarily bad | ||
#define SF_SAVED 0x04 | ||
#define SF_HELD 0x08 // Held by LedgerMaster after potential processing failure | ||
#define SF_TRUSTED 0x10 // comes from trusted source | ||
|
||
// Private flags, used internally in apply.cpp. | ||
|
@@ -44,6 +45,8 @@ namespace ripple { | |
#define SF_PRIVATE5 0x1000 | ||
#define SF_PRIVATE6 0x2000 | ||
|
||
class Config; | ||
|
||
/** Routing table for objects identified by hash. | ||
|
||
This table keeps track of which hashes have been received by which peers. | ||
|
@@ -56,6 +59,27 @@ class HashRouter | |
// The type here *MUST* match the type of Peer::id_t | ||
using PeerShortID = std::uint32_t; | ||
|
||
/** Structure used to customize @ref HashRouter behavior. | ||
* | ||
* Even though these items are configurable, don't change them unless there | ||
* is a good reason, and network-wide coordination to do it. | ||
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. This is confusing. On the one hand, this comment and the code implies that we should best rely on hardcoded values, on the other it is read from configuration, but the new configuration values are not documented in Perhaps it would be better to 1. remove I do not insist this is better but it will be probably easier to understand what's going on : better cohesion re. parsing configuration and populating this structure, immutable data members, documented config in Alternatively (perhaps even better), keep the default values here, give up on reading this from configuration and remove 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. This is a pretty common pattern throughout This isn't the only undocumented configuration feature in Based on your feedback, I did update this comment to reflect
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. Thank you, that works |
||
*/ | ||
struct Setup | ||
{ | ||
/// Default constructor | ||
explicit Setup() = default; | ||
|
||
using seconds = std::chrono::seconds; | ||
|
||
/** Expiration time for a hash entry | ||
*/ | ||
seconds holdTime{300}; | ||
|
||
/** Amount of time required before a relayed item will be relayed again. | ||
*/ | ||
seconds relayTime{30}; | ||
}; | ||
|
||
private: | ||
/** An entry in the routing table. | ||
*/ | ||
|
@@ -135,16 +159,8 @@ class HashRouter | |
}; | ||
|
||
public: | ||
static inline std::chrono::seconds | ||
getDefaultHoldTime() | ||
{ | ||
using namespace std::chrono; | ||
|
||
return 300s; | ||
} | ||
|
||
HashRouter(Stopwatch& clock, std::chrono::seconds entryHoldTimeInSeconds) | ||
: suppressionMap_(clock), holdTime_(entryHoldTimeInSeconds) | ||
HashRouter(Setup const& setup, Stopwatch& clock) | ||
: setup_(setup), suppressionMap_(clock) | ||
{ | ||
} | ||
|
||
|
@@ -195,11 +211,11 @@ class HashRouter | |
Effects: | ||
|
||
If the item should be relayed, this function will not | ||
return `true` again until the hold time has expired. | ||
return a seated optional again until the relay time has expired. | ||
The internal set of peers will also be reset. | ||
|
||
@return A `std::optional` set of peers which do not need to be | ||
relayed to. If the result is uninitialized, the item should | ||
relayed to. If the result is unseated, the item should | ||
_not_ be relayed. | ||
*/ | ||
std::optional<std::set<PeerShortID>> | ||
|
@@ -220,9 +236,13 @@ class HashRouter | |
hardened_hash<strong_hash>> | ||
suppressionMap_; | ||
|
||
std::chrono::seconds const holdTime_; | ||
// Configurable parameters | ||
Setup const setup_; | ||
}; | ||
|
||
HashRouter::Setup | ||
setup_HashRouter(Config const&); | ||
|
||
} // namespace ripple | ||
|
||
#endif |
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 add to this file