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

Change enum values to be powers of two (fix #3417) #4239

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/ripple/rpc/impl/Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace RPC {
enum Condition {
NO_CONDITION = 0,
NEEDS_NETWORK_CONNECTION = 1,
NEEDS_CURRENT_LEDGER = 2 + NEEDS_NETWORK_CONNECTION,
NEEDS_CLOSED_LEDGER = 4 + NEEDS_NETWORK_CONNECTION,
NEEDS_CURRENT_LEDGER = 1 << 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is NEEDS_NETWORK_CONNECTION not required anymore?

NEEDS_CLOSED_LEDGER = 1 << 2,
};

struct Handler
Expand Down Expand Up @@ -94,20 +94,18 @@ conditionMet(Condition condition_required, T& context)
}

if (context.app.getOPs().isAmendmentBlocked() &&
(condition_required & NEEDS_CURRENT_LEDGER ||
condition_required & NEEDS_CLOSED_LEDGER))
(condition_required != NO_CONDITION))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the same test as before. Is the change on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, I agree that the conditions have changed. I made this change approximately one year ago, so I am spacing out on the details. Let me think/check and get back to you

Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on the old values, I think the conditions are equivalent. Between NEEDS_CURRENT_LEDGER and NEEDS_CLOSED_LEDGER, having any of the three low bits set in condition_required would result in the expression evaluating to true, so that covers all of the != NO_CONDITION conditions. So functionally, they are equivalent.

Now whether that was the intent is a different question.

It turns out there are only two operations which have NEEDS_NETWORK_CONNECTION: ledger_cleaner and tx. I think it's fine to disallow both of them if the server is amendment blocked.

{
return rpcAMENDMENT_BLOCKED;
}

if (context.app.getOPs().isUNLBlocked() &&
(condition_required & NEEDS_CURRENT_LEDGER ||
condition_required & NEEDS_CLOSED_LEDGER))
(condition_required != NO_CONDITION))
{
return rpcEXPIRED_VALIDATOR_LIST;
}

if ((condition_required & NEEDS_NETWORK_CONNECTION) &&
if ((condition_required != NO_CONDITION) &&
(context.netOps.getOperatingMode() < OperatingMode::SYNCING))
{
JLOG(context.j.info()) << "Insufficient network mode for RPC: "
Expand All @@ -119,7 +117,7 @@ conditionMet(Condition condition_required, T& context)
}

if (!context.app.config().standalone() &&
condition_required & NEEDS_CURRENT_LEDGER)
condition_required != NO_CONDITION)
{
if (context.ledgerMaster.getValidatedLedgerAge() >
Tuning::maxValidatedLedgerAge)
Expand All @@ -143,7 +141,7 @@ conditionMet(Condition condition_required, T& context)
}
}

if ((condition_required & NEEDS_CLOSED_LEDGER) &&
if ((condition_required != NO_CONDITION) &&
!context.ledgerMaster.getClosedLedger())
{
if (context.apiVersion == 1)
Expand Down