Skip to content

Commit

Permalink
fix: Update Handler::Condition enum values #3417
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
  • Loading branch information
Chenna Keshava B S authored and ckeshava committed Jun 26, 2023
1 parent beb0904 commit 248e2f0
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 248e2f0

Please sign in to comment.