Skip to content
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

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

shortthefomo
Copy link

@shortthefomo shortthefomo commented Feb 19, 2024

High Level Overview of Change

  • append the network id to the ledger and validation stream.
  • featureNetworkIDValidation which also stops forwarding validations to peers to stop cross network talk.

Context of Change

Rework of #4869 and add the feature request by @intelliot in #4783

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)

API Impact

  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@shortthefomo shortthefomo changed the title Network id validators Network id validation stream and forwarding Feb 19, 2024
@shortthefomo
Copy link
Author

@intelliot this one is ready for review

Copy link

@exunda exunda left a 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))
Copy link

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.

Copy link
Author

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;
Copy link

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?

Copy link
Author

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.

Copy link

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);
Copy link

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.

@intelliot intelliot added this to the 2.3.0 (August 2024) milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 Needs review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants