Skip to content

Commit

Permalink
fix: Update Handler::Condition enum values XRPLF#3417 (XRPLF#4239)
Browse files Browse the repository at this point in the history
- Use powers of two to clearly indicate the bitmask
- Replace bitmask with explicit if-conditions to better indicate predicates

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

Implement the simplified condition evaluation
removes the complex bitwise and(&) operator
Implement the second proposed solution in Nik Bougalis's comment - Software does not distinguish between different Conditions (Version: 1.5) XRPLF#3417 (comment)
I have tested this code change by performing RPC calls with the commands server_info, server_state, peers and validation_info. These commands worked as expected.
  • Loading branch information
ckeshava committed Sep 25, 2023
1 parent 5bad308 commit 1d4a9c3
Showing 1 changed file with 7 additions and 9 deletions.
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,
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))
{
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

0 comments on commit 1d4a9c3

Please sign in to comment.