Fixing Config endpoint and adding preferred peers#196
Conversation
| config_json["min_confirmations"] = config.GetMinimumConfirmations(); | ||
|
|
||
| return request.BuildResult(config_json); | ||
| result["Ok"] = config_json; |
There was a problem hiding this comment.
Why this? The "Ok" response is completely redundant, and goes against the jsonrpc 2.0 spec. I'm aware that the rust repo does that, but it's completely wrong to do so.
There was a problem hiding this comment.
true, you're correct 👍🏽
src/Server/Main.cpp
Outdated
| { | ||
| pConfig = Config::Load(config_path, environment); | ||
| if(config_path.has_value()){ | ||
| pConfig->SetConfigPath(config_path.value()); |
There was a problem hiding this comment.
It's technically breaking the pattern by including config path in the config itself, since it's not actually part of the config. If you're going to though, you should at least move the calls to these setters into Config::Load, so other consumers get it for free. Also, this allows you to avoid duplicating the path calculation logic on lines 72-73
There was a problem hiding this comment.
could src\Core\Global.cpp be a better place? let's not break the pattern.
There was a problem hiding this comment.
Yep, 2 options come to mind:
- Store it as a new field in global with a getter/setter
- Wrap ConfigPtr with a new class (ConfigFile? LoadedConfig?) that has 2 fields: path & values(the ConfigPtr). Then store that in global instead of the ConfigPtr.
src/Core/Config.cpp
Outdated
| uint8_t Config::GetMinSyncPeers() const noexcept { return m_pImpl->m_nodeConfig.GetP2P().GetMinSyncPeers(); } | ||
|
|
||
| const std::vector<std::string>& Config::GetPreferredPeers() const noexcept { return m_pImpl->m_nodeConfig.GetP2P().GetPreferredPeers(); } | ||
| const std::vector<std::string>& Config::GetAlloweddPeers() const noexcept { return m_pImpl->m_nodeConfig.GetP2P().GetAllowedPeers(); } |
There was a problem hiding this comment.
I'm a fan of double D's, but not at the end of the word 'allowed'
src/Core/Config/P2PConfig.h
Outdated
| Json::Value peers = p2pJSON.get(ConfigProps::P2P::PREFERRED_PEERS, Json::Value(Json::nullValue)); | ||
| for (auto& peer : peers) { | ||
| m_peferredPeers.push_back(peer.asString()); | ||
| } |
|
While testing, I'm constantly getting this error from the peers:
I would appreciate suggestions on how to properly debug that. |
src/P2P/Seed/Seeder.cpp
Outdated
| )); | ||
|
|
||
| if(Global::GetConfig().GetBlockedPeers().size() > 0 && | ||
| Global::GetConfig().IsPeerBlocked(pSocket->GetIPAddress().GetAddress().to_string())) |
There was a problem hiding this comment.
No need to check size first
src/P2P/Seed/Seeder.cpp
Outdated
| return; | ||
| } | ||
|
|
||
| if(Global::GetConfig().GetAlloweddPeers().size() > 0 && |
There was a problem hiding this comment.
IsPeerAllowed should do the empty check
DavidBurkett
left a comment
There was a problem hiding this comment.
Couple small comments, but other than that, looks good
I'll message you on TG tmrw |
src/Core/Config.cpp
Outdated
| return false; | ||
| } | ||
|
|
||
| bool Config::IsPeerPreferred (const std::string peer) { |
There was a problem hiding this comment.
std::string => std::string&
nit: Unnecessary space between IsPeerPreferred and (
There was a problem hiding this comment.
Better yet, take in a const IPAddress& instead, and store IPAddresss when parsing the config.
src/Core/Config.cpp
Outdated
| } | ||
|
|
||
| bool Config::IsPeerPreferred (const std::string peer) { | ||
| std::vector<std::string> vec = m_pImpl->m_nodeConfig.GetP2P().GetPreferredPeers(); |
There was a problem hiding this comment.
You need to store this variable as a const std::vector<std::string>& , or else this will be doing an expensive copy on every single usage.
Also, since you're always treating preferred peers as a set, you should be storing it as one (actually, a std::unordered_set, which tends to have an even faster lookup time)
src/P2P/Seed/Seeder.cpp
Outdated
|
|
||
| const std::string& ipAddressStr = ipAddress.GetAddress().to_string(); | ||
|
|
||
| if(Global::GetConfig().IsPeerBlocked(ipAddressStr)) { |
There was a problem hiding this comment.
nit: C++ devs nearly always include a space between if and (. I would recommend sticking with that formatting standard.
src/P2P/Seed/Seeder.cpp
Outdated
|
|
||
| if(Global::GetConfig().IsPeerBlocked(pSocket->GetIPAddress().GetAddress().to_string())) { | ||
| LOG_TRACE_F("peer is blocked: {}", pPeer); | ||
| const std::string& ipAddressStr = pSocket->GetIPAddress().GetAddress().to_string(); |
There was a problem hiding this comment.
to_string() returns a std::string not a const std::string&, so you shouldn't store it as a reference (I'm surrprised there's no compiler warning). If you follow my suggestion to change the IsPeerXXX functions to take in a const IPAddress& instead, then you can just store pSocket->GetIPAddress() instead, which does return a const reference.
|
File used to test this PR: |
478b25d to
9f0f930
Compare
0862e86 to
de66615
Compare
de66615 to
9f0f930
Compare
|
@DavidBurkett would you mind to do a final review to this PR. I don't I will add nothing else to this PR. I've been testing on Windows, Linux and MacOS. 128kb as buffet size for downloading the TxHashSet file ( ) seems to be reasonably to me due the amount of slow peers, but I'm not fully convinced yet. |
- Setting BUFFER_SIZE = 128 * 1024 for TxHashSetPipe - Checking if tor binary is present to avoid logging unnecessarily.
Findings: Socket (P2P) instability while syncing