-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Network id validation stream and forwarding #4921
base: develop
Are you sure you want to change the base?
Conversation
…to validate network_id is present in validation and ledger streams
@intelliot this one is ready for review |
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.
Hi 👋 I've been looking at this code for a few weeks but still learning and this is my first code review on it. Hopefully you find the comments useful!
auto const view = m_ledgerMaster.getCurrentLedger(); | ||
|
||
if (view->rules().enabled(featureNetworkIDValidation) && | ||
val->getNetworkID() != static_cast<Json::UInt>(*networkID)) |
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.
This code is probably wrong. The cast is unnecessary and confusing but (if my understanding is correct) the call val->getNetworkID()
which calls getFieldU32
which calls STObject::getFieldByValue
will throw
an exception if the sfNetworkID
field is not present in the received validation.
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.
This is my first attempted commit to rippled and still trying to pick up C, so also learning lots as I go here. That being said will, test and validate this and possibly also add a test case to prove that we get the desired result here.
return setup_.networkID; | ||
if (auto const netid = setup_.networkID) | ||
return netid; | ||
return 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.
Previously this code could return std::nullopt
but now it will return an std::optional
with a value of 0
which (if I understand the code correctly) is the ID of the mainnet. That makes no sense and seems very wrong. Why even have the optional return?
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.
This is by design, we always want to default to mainnet if something goes wrong looking up the network ID.
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 that this will result in a change of the behavior and I am not sure it is correct. The code previously could return std::nullopt
and now won't and maybe some parts of the code relied on that? This change should be signed off by someone with better understanding of the codebase than me before you put the change in and admins of servers shoudl be informed.
std::uint32_t | ||
STValidation::getNetworkID() const | ||
{ | ||
return getFieldU32(sfNetworkID); |
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 you should return optional here. Something like:
std::optional<std::uint32_t>
STValidation::getNetworkID() const
{
if (!isFieldPresent(sfNetworkID))
return std::nullopt;
return getFieldU32(sfNetworkID);
}
There may be a way to do this more efficiently using the weird ~sfNetworkID
syntax but I'm still learning code.
High Level Overview of Change
Context of Change
Rework of #4869 and add the feature request by @intelliot in #4783
Type of Change
API Impact