From a07d6f939b4593feb0eb778a8813ff822d3c5dc2 Mon Sep 17 00:00:00 2001 From: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com> Date: Thu, 29 Jun 2023 09:12:15 -0700 Subject: [PATCH] fix: Update Handler::Condition enum values #3417 (#4239) - 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 #3417) #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) #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. --- src/ripple/rpc/impl/Handler.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/ripple/rpc/impl/Handler.h b/src/ripple/rpc/impl/Handler.h index 73f2232d5..e2188ef51 100644 --- a/src/ripple/rpc/impl/Handler.h +++ b/src/ripple/rpc/impl/Handler.h @@ -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 @@ -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: " @@ -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) @@ -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)