Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Outputs ENR text representation in admin.nodeInfo RPC #5701

Merged
merged 5 commits into from
Aug 5, 2019

Conversation

twinstar26
Copy link
Contributor

Fixes #5622
Old PR #5697

@twinstar26
Copy link
Contributor Author

@gumb0 based on reviews in old PR #5697

Everything seems to be working fine. Also can you double check changes in libdevcore/Base64.cpp.
If everything is fine I will go on to create a unit test as suggested.

Copy link
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just several minor stylistic changes needed.

Also, could you please in a separate commit (can be this same PR) convert all tabs to spaces in the file Base64.cpp?

And yes, a unit test would be appreciated.

@@ -46,13 +46,8 @@ static inline byte find_base64_char_index(byte c)
else return 1 + find_base64_char_index('/');
}

string dev::toBase64(bytesConstRef _in)
string toBase64Encoding(bytesConstRef _in, char const* base64_chars, bool _pad)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string toBase64Encoding(bytesConstRef _in, char const* base64_chars, bool _pad)
string toBase64Encoding(bytesConstRef _in, char const* _base64_chars, bool _pad)

"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
bool _pad = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool _pad = true;
bool const pad = true;

"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789-_";
bool _pad = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool _pad = false;
bool const pad = false;

ret += '=';
}

return ret;
}

string dev::toBase64(bytesConstRef _in)
{
static const char base64_chars[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static const char base64_chars[] =
static char const base64_chars[] =


string dev::toBase64URLSafe(bytesConstRef _in)
{
static const char base64_chars[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static const char base64_chars[] =
static char const base64_chars[] =

libp2p/ENR.cpp Outdated
std::string ENR::textEncoding() const
{
RLPStream s;
this->streamRLP(s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this->streamRLP(s);
streamRLP(s);

libp2p/ENR.cpp Outdated
{
RLPStream s;
this->streamRLP(s);
return toBase64URLSafe(std::string(s.out().begin(), s.out().end()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like

Suggested change
return toBase64URLSafe(std::string(s.out().begin(), s.out().end()));
return toBase64URLSafe(ref(s.out()));

should work

libp2p/Host.h Outdated
p2p::NodeInfo nodeInfo() const { return NodeInfo(id(), (networkConfig().publicIPAddress.empty() ? m_tcpPublic.address().to_string() : networkConfig().publicIPAddress), m_tcpPublic.port(), m_clientVersion); }
p2p::NodeInfo nodeInfo() const
{
auto e = enr();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto e = enr();
auto const e = enr();

Copy link
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, one more thing: you need to add a prefix enr: in function ENR::textEncoding()
See the spec https://github.com/ethereum/EIPs/blob/master/EIPS/eip-778.md#text-encoding

@gumb0
Copy link
Member

gumb0 commented Jul 29, 2019

For unit test add a check that enr.textEncoding() is enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8 to this test

TEST(enr, parse)

(this is a test vector from EIP spec)

@codecov-io
Copy link

codecov-io commented Jul 29, 2019

Codecov Report

Merging #5701 into master will decrease coverage by <.01%.
The diff coverage is 84.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5701      +/-   ##
==========================================
- Coverage   63.05%   63.05%   -0.01%     
==========================================
  Files         353      351       -2     
  Lines       30110    30015      -95     
  Branches     3378     3362      -16     
==========================================
- Hits        18987    18926      -61     
+ Misses       9894     9880      -14     
+ Partials     1229     1209      -20

@twinstar26
Copy link
Contributor Author

Ah, one more thing: you need to add a prefix enr: in function ENR::textEncoding()
See the spec https://github.com/ethereum/EIPs/blob/master/EIPS/eip-778.md#text-encoding

@gumb0
Thanks for the reviews!
So I was thinking of string concat of "enr:" and enrtext since ENR::textEncoding() returns string.

@twinstar26
Copy link
Contributor Author

twinstar26 commented Jul 31, 2019

For unit test add a check that enr.textEncoding() is enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8 to this test

TEST(enr, parse)

(this is a test vector from EIP spec)

@gumb0
So after this do I have to create a unit-test explicitly and if so what is that (output of which function) I have to test.

@gumb0
Copy link
Member

gumb0 commented Jul 31, 2019

So I was thinking of string concat of "enr:" and enrtext since ENR::textEncoding() returns string.

Yes, just return "enr:" + toBase64URLSafe(...) from textEncoding()

So after this do I have to create a unit-test explicitly and if so what is that (output of which function) I have to test.

Let's add just this one check

EXPECT_EQ(enr.textEncoding(), "enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8")

to the end of the test I linked, I think that would be enough for this PR.

@gumb0
Copy link
Member

gumb0 commented Jul 31, 2019

Also please add an item to CHANGELOG.md

@twinstar26
Copy link
Contributor Author

@gumb0
This is merge ready. Please check and if not so please suggest changes.

gumb0
gumb0 previously approved these changes Aug 2, 2019
Copy link
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, please fix just one last minor naming issue and changelog, then it's ready

}

return ret;
static char const _base64_chars[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static char const _base64_chars[] =
static char const c_base64_chars[] =


string dev::toBase64URLSafe(bytesConstRef _in)
{
static char const _base64_chars[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static char const _base64_chars[] =
static char const c_base64_chars[] =

CHANGELOG.md Outdated
@@ -15,6 +15,7 @@
- Added: [#5634](https://github.com/ethereum/aleth/pull/5634) Bootnodes for Rinkeby and Goerli.
- Added: [#5640](https://github.com/ethereum/aleth/pull/5640) Istanbul support: EIP-1702 Generalized Account Versioning Scheme.
- Added: [#5690](https://github.com/ethereum/aleth/issues/5690) Istanbul support: EIP-2028 transaction data gas cost reduction.
- Added: [#5622](https://github.com/ethereum/aleth/issues/5622) Outputs ENR text representation in admin.nodeInfo RPC.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link this to this PR instead of an issue

@gumb0 gumb0 self-requested a review August 2, 2019 16:03
@gumb0 gumb0 dismissed their stale review August 2, 2019 16:04

minor fixes left

@chfast
Copy link
Member

chfast commented Aug 5, 2019

Merge?

@gumb0 gumb0 merged commit 88e6896 into ethereum:master Aug 5, 2019
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output ENR text representation in admin.nodeInfo RPC
4 participants