-
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
Update Base58 codec and remove Bitcoin support: #3575
Conversation
Use C++17 constant expressions to calculate the inverse alphabet map at compile time instead of at runtime. Remove support for encoding & decoding tokens using the Bitcoin alphabet.
src/ripple/protocol/impl/tokens.cpp
Outdated
@@ -30,13 +30,22 @@ | |||
|
|||
namespace ripple { | |||
|
|||
static char rippleAlphabet[] = | |||
static constexpr char const* const xrplAlphabetForward = |
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.
static constexpr char const* const xrplAlphabetForward = | |
static constexpr char const* const rippleAlphabetForward = |
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.
Also in other places...
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.
Can you explain what you mean here? I am not understanding. You think it should use ripple? But the name 'ripple' is belong to the company and not the software.
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.
The software is called rippled
, the company is called "Ripple Labs" and it just holds the copyright for the name "Ripple" (the project named "Ripple" is much older than that). Heck, even that folder is src/ripple/...
. Previous code used rippleAlphabet
, changing it to xrplAlphabet
just puts the ISO-4217 shorthand of a cryptocurrency in the name for no good reason.
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.
Aha
Yes I understand you now and I prefer the name ripple also but the company is using that now because it is not RL any more and so to continue use of ripple for naming seems causes a lot of confusion.
Maybe the company can answer on what this should be because the name get used again elsewhere.
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.
The company is actually still called "Ripple Labs Inc", it just uses the name "Ripple" in its branding. See for example https://ripple.com/terms-of-use/ ("These Terms of Use (“Terms”) apply to your access to, and use of, the websites of Ripple Labs Inc. and its subsidiaries and affiliated companies (“Ripple,” “we” or “us”), including www.ripple.com (collectively, the “Site”)."), in their privacy policy you also see the full company name (something you should maybe be aware of, if you are impersonating their CEO... ;-) ).
I guess someone working there will eventually review and resolve this.
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 think we all like the name 'ripple' for this wonderful, collaborative project and feel an attachment to it. And if it were up to me I'd have kept it for the project and this could stay rippleAlphabet
. But, feelings aside, there's reality. And, as has been pointed out, the naming can cause confusion.
So, since I work "there", let me play Solomon and split the proverbial baby so that we can all move forward: how about simply calling these variables alphabet
and reverseAlphabet
and avoiding this whole situation?
Rationale: your car doesn't use "FordNuts" or "FordBolts". It just uses "nuts" and "bolts".
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 changed variable names to 'alphabetForward' and 'alphabetReverse' as you have asked
Maybe Ripple can see the problem the name 'Xrp Ledger' has and can allow the name 'ripple' to be used again in future?
"json", | ||
"account_currencies", | ||
boost::lexical_cast<std::string>(params))[jss::result]; | ||
BEAST_EXPECT(result[jss::error] == "actBitcoin"); |
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.
Probably the actBitcoin
Error can be removed too then.
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.
Good spotting! Yes, I think removing rpcACT_BITCOIN
from ErrorCodes.h and ErrorCodes.cpp is a good idea. If you do this, please include a comment that value 34
is unused in ErrorCodes.h. Thanks.
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.
Looks good to me. The only thing that needs to be done that I can see is to amend the second commit message to begin with [FOLD] so that we remember to squash these two commits prior to merge.
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.
Nicely done! I really like the constexpr
calculation for alphabetReverse
. I left some comments for minor improvements, none of which are mandatory.
I also think @HowardHinnant's request that any commits addressing review comments be marked with [FOLD]
is a very good idea. The person that puts together a beta may not have been in on the review, so they don't automatically know which commits should be squashed and which should not.
Thanks.
{ | ||
std::string const ret = decodeBase58(s, inv); | ||
assert(size != 0); |
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.
The assert
is a nice addition. However, since the assert
is only effective in a debug build I'd prefer replacing the assert
with:
if (size == 0)
return {};
If you like including the assert
it could go inside the conditional. Then you'd have the assert
and still have safety in a release build.
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.
That would change output of functoin I think and didn't wnat to change behaviour that but having the assert makes sense to me. I can do this if the change is not the problem.
// Lay the data out as | ||
// <type><token><checksum> | ||
buf[0] = safe_cast<std::underlying_type_t<TokenType>>(type); | ||
if (size) |
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.
If you return on size == 0
at the top of the function then you can remove this check for if (size)
.
static constexpr std::array<int, 256> const alphabetReverse = []() constexpr | ||
{ | ||
std::array<int, 256> map{}; | ||
|
||
//------------------------------------------------------------------------------ | ||
for (auto& m : map) | ||
m = -1; | ||
|
||
for (int i = 0, j = 0; alphabetForward[i] != 0; ++i) | ||
map[static_cast<unsigned char>(alphabetForward[i])] = j++; | ||
|
||
return map; | ||
} |
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.
Very nicely done! Thanks.
"json", | ||
"account_currencies", | ||
boost::lexical_cast<std::string>(params))[jss::result]; | ||
BEAST_EXPECT(result[jss::error] == "actBitcoin"); |
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.
Good spotting! Yes, I think removing rpcACT_BITCOIN
from ErrorCodes.h and ErrorCodes.cpp is a good idea. If you do this, please include a comment that value 34
is unused in ErrorCodes.h. Thanks.
@@ -30,13 +30,22 @@ | |||
|
|||
namespace ripple { | |||
|
|||
static char rippleAlphabet[] = | |||
static constexpr char const* const alphabetForward = |
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.
Not something I feel strongly about, but the const
that follows *
is redundant since alphabetForward
is constexpr
. So, if you want, you can omit the second const
.
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.
OK that looks good
"rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"; | ||
|
||
static char bitcoinAlphabet[] = | ||
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
static constexpr std::array<int, 256> const alphabetReverse = []() constexpr |
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.
Another point I don't feel strongly about, but the trailing constexpr
is unnecessary. As of C++17 any lambda that can be constexpr
automatically is. To quote from cppreference:
constexpr: explicitly specifies that the function call operator is a constexpr function. When this specifier is not present, the function call operator will be constexpr anyway, if it happens to satisfy all constexpr function requirements
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.
Yes i didn't know that change! Very nice.
Added the fold message and responded to review comments. ccan you reopen please? |
I don't think we can reopen because you deleted your branch and now GitHub is confused. Please feel free to open a new PR for this! Thanks. |
Use C++17 constant expressions to calculate the inverse
alphabet map at compile time instead of at runtime.
Remove support for encoding & decoding tokens using the
Bitcoin alphabet.