-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Software does not distinguish between different Conditions (Version: 1.5) #3417
Comments
For anyone scratching their head because git blame says I wrote this code, I actually just moved it from a different file. Prior to commit |
D'oh... this code is ancient (probably around 6 years old) and it does have the bug you describe, which is incredibly subtle. I suspect the intention was to communicate that, e.g. In the meantime, your proposed solution is correct: replace the Alternatively, we can change the enum values to be just powers of two, and change:
to this:
I think that this is minimal and probably less brittle. |
Hey I want to work on these isssue |
@Coderayush13 or anyone else: please feel free to work on this issue. Comment here with any questions you have. |
- Use powers of two to clearly indicate the bitmask - Replace bitmask with explicit if-conditions to better indicate predicates
* upstream/develop: ci: cancel overridden workflows (4597) fix: Update Handler::Condition enum values XRPLF#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 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.
- 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.
- 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.
I discovered some code that just doesn't smell right. I don't know the intended behavior, but I suspect the intent is different than what is actually happening.
The code that checks whether the condition that is required for a given RPC is met does not actually consider what condition is required. All of the conditions except
NO_CONDITION
are treated exactly the same. All of the following lines (in the same function) evaluate to the exact same value (false ifrequired_condition
isNO_CONDITION
and true otherwise).https://github.com/ripple/rippled/blob/3d86b49dae8173344b39deb75e53170a9b6c5284/src/ripple/rpc/impl/Handler.h#L80
https://github.com/ripple/rippled/blob/3d86b49dae8173344b39deb75e53170a9b6c5284/src/ripple/rpc/impl/Handler.h#L90
https://github.com/ripple/rippled/blob/3d86b49dae8173344b39deb75e53170a9b6c5284/src/ripple/rpc/impl/Handler.h#L91
https://github.com/ripple/rippled/blob/3d86b49dae8173344b39deb75e53170a9b6c5284/src/ripple/rpc/impl/Handler.h#L97
https://github.com/ripple/rippled/blob/3d86b49dae8173344b39deb75e53170a9b6c5284/src/ripple/rpc/impl/Handler.h#L117
The reason these lines all evaluate to the exact same value is because of the way these conditions are defined: all except
NO_CONDITION
have the least significant bit set to 1. So, when we bitwise and any two conditions together, the result is false if either areNO_CONDITION
and true otherwise. I don't think this was the intended behavior of the code, since all of these lines could be replaced withcondition_required != NO_CONDITION
. Maybe someone who understands the intention of this piece of code can chime in here.The text was updated successfully, but these errors were encountered: