Conversation
Codecov Report
@@ Coverage Diff @@
## master #5537 +/- ##
=========================================
Coverage ? 62.14%
=========================================
Files ? 347
Lines ? 28965
Branches ? 3281
=========================================
Hits ? 18000
Misses ? 9787
Partials ? 1178 |
cbb2735 to
8740d15
Compare
|
@chfast @halfalicious I think this is ready for review. It's based on #5542 and should be rebased when it's merged. Also I need to add a CHANGELOG item here, but maybe we merge this after 1.6.0 release? |
|
The failed tests might just be unreliable, see #5544 |
|
Rebased. |
libp2p/ENR.cpp
Outdated
| #include "ENR.h" | ||
| #include <libdevcore/SHA3.h> | ||
|
|
||
| static std::string const c_keyID = "id"; |
There was a problem hiding this comment.
I don't think it is great to have global dynamically constructed objects.
There was a problem hiding this comment.
Because of run-time initialization cost? Is it better to have dynamic allocation each time this code is run? (string is probably short-string-optimized, but vector isn't)
There was a problem hiding this comment.
Yes, to avoid dynamic initialization during startup.
This can land, but I'm leaving it to consider changes.
Co-Authored-By: gumb0 <andrei@ethereum.org>
libp2p/ENR.cpp
Outdated
| constexpr char c_keyTCP[] = "tcp"; | ||
| constexpr char c_keyUDP[] = "udp"; | ||
| constexpr char c_IDV4[] = "v4"; | ||
| constexpr size_t c_ENRMaxSize = 300; |
There was a problem hiding this comment.
Would be nice to call out that this is in bytes (preferably by renaming the variable)
|
I noticed you created the tests using Gtest...is the goal to switch everything over to Gtest eventually? |
halfalicious
left a comment
There was a problem hiding this comment.
Didn't get a chance to look at the test code yet but if they all pass then they are presumably okay.
libp2p/ENR.cpp
Outdated
|
|
||
| // read key-values into vector first, to check the order | ||
| std::vector<std::pair<std::string const, bytes>> keyValues; | ||
| for (size_t i = 2; i < _rlp.itemCount(); i+= 2) |
There was a problem hiding this comment.
Technically the loop termination check should be i < _rlp.itemCount() - 1 (since you're increasing i by 2 on each loop iteration)
There was a problem hiding this comment.
count - 1 looks dangerous for unsigned type (well in this case it shouldn't underflow though)
Also _rlp[i + 1] in the body loop should throw for out of bounds and not lead to UB.
There was a problem hiding this comment.
I think _rlp[i + 1] would only throw if it happened to point to protected memory (unless you have something like full page heap enabled) and I think the chances of this are low.
There was a problem hiding this comment.
I think you confuse it with arrays/vectors.
Actually I was not right - RLP::operator[] will not throw but return empty RLP for out of bounds - I forget this all the time. So in this case it will end up with key => "" if last value is absent, which is not ideal, but it's not an UB, I think I'll merge it like this for now.
There was a problem hiding this comment.
I've added some comments to RLP::operator[] which is not very straight-forward a791c5b
libp2p/ENR.cpp
Outdated
| } | ||
|
|
||
| ENR::ENR(uint64_t _seq, std::map<std::string, bytes> const& _keyValues, SignFunction _signFunction) | ||
| : m_seq(_seq), m_map(_keyValues), m_signature(_signFunction(dev::ref(content()))) |
| m_capabilityHost(createCapabilityHost(*this)) | ||
| { | ||
| cnetnote << "Id: " << id(); | ||
| cnetnote << "ENR: " << m_enr; |
There was a problem hiding this comment.
In the interest of consistency should we call enr() here? (since we call id() rather than m_alias.pub())
Yes, all unit tests. |
halfalicious
left a comment
There was a problem hiding this comment.
Approved, only small issue is the loop iteration but I don't think that's a blocker
https://eips.ethereum.org/EIPS/eip-778
This creates ENR record for the host at program start, filling values based on
--public-ipand--listenCLI parameters.For example
aleth --public-ip 13.74.189.147 --listen 30303creates ENR like(sequence number is always 0 now, updating ENR will be added in later PRs)
At program exit ENR is serialized into
network.rlpfile and restored at the next program start.cc @fjl