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

Calculate numFeatures automatically #5324

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Conversation

ximinez
Copy link
Collaborator

@ximinez ximinez commented Feb 27, 2025

High Level Overview of Change

Finally, we are free from the tyranny of needing to update numFeatures in Feature.h!

This PR, if merged, will take advantage of the XRPL_FEATURE and XRPL_FIX macros, and add a new XRPL_RETIRE to automatically set numFeatures so it can be used elsewhere.

I want to call this PR "Trivial", but the macros are just fiddly enough that I'd rather have two eyes on it.

Context of Change

Requiring manual updates of numFeatures is an annoying manual process that is easily forgotten, and leads to frequent merge conflicts.

Type of Change

  • Refactor (non-breaking change that only restructures code)

Before / After

If relevant, use this section for an English description of the change at a technical level.
If this change affects an API, examples should be included here.

For performance-impacting changes, please provide these details:

  1. Is this a new feature, bug fix, or improvement to existing functionality?
  2. What behavior/functionality does the change impact?
  3. In what processing can the impact be measured? Be as specific as possible - e.g. RPC client call, payment transaction that involves LOB, AMM, caching, DB operations, etc.
  4. Does this change affect concurrent processing - e.g. does it involve acquiring locks, multi-threaded processing, or async processing?
    -->

Test Plan

As long as rippled builds and is able to start, this change is good.

Future Tasks

It would be cool to take advantage of features.macro inside of the FeatureCollections ctor so that the object can be const after construction. Each feature could be a public member variable of FeatureCollections, and the global variables can simply be a reference to the corresponding members.

@ximinez ximinez added this to the 2.5.0 (2025) milestone Feb 27, 2025
- Update documentation
@ximinez ximinez force-pushed the ximinez/numFeatures branch from 412f6c3 to 16d1e3a Compare February 27, 2025 00:43
@ximinez ximinez changed the title Make numFeatures automatic Calculate numFeatures automatically Feb 27, 2025
Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.1%. Comparing base (0a1ca06) to head (9429bf4).
Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5324     +/-   ##
=========================================
- Coverage     78.2%   78.1%   -0.1%     
=========================================
  Files          790     790             
  Lines        67741   67908    +167     
  Branches      8178    8229     +51     
=========================================
+ Hits         52969   53023     +54     
- Misses       14771   14885    +114     
+ Partials         1       0      -1     
Files with missing lines Coverage Δ
include/xrpl/protocol/Feature.h 100.0% <ø> (ø)
src/libxrpl/protocol/Feature.cpp 94.8% <ø> (ø)

... and 18 files with indirect coverage changes

Impacted file tree graph

@@ -80,7 +80,27 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 88;
static constexpr std::size_t numFeatures = 0
Copy link
Collaborator

@Bronek Bronek Feb 27, 2025

Choose a reason for hiding this comment

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

This is so simple, it's brilliant, but I would prefer to further improve readability, by:

  • moving all the preprocessor (except #include obviously) outside of 0 ... ; block, i.e. one part immediately before and one part immediately after.
  • put the 0 ... ; block in parentheses
  • squint your eyes a little and see how close this resembles something like
constexpr numFeatures = (
  0 
#  define ... + 1
#  define ... + 1
#  define ... + 1
#  include ...
);

Copy link
Collaborator

Choose a reason for hiding this comment

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

... or actually, because 0 + + 1 is valid and identical to 0 + 1, do this

constexpr numFeatures = (
  0 +
#include ...
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • moving all the preprocessor (except #include obviously) outside of 0 ... ; block, i.e. one part immediately before and one part immediately after.

This is a great suggestion! I made this change, and added the parenthesis, and the +.

Do you want to re-review?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is so simple, it's brilliant

BTW, thank you!

@vvysokikh1
Copy link
Collaborator

I was interested in looking into existing solutions like this and stumbled on https://www.boost.org/doc/libs/1_87_0/libs/preprocessor/doc/ref/counter.html

I tried to integrate it into XRPL_FEATURE/FIX macros, but seems like passing #include into the macro is no easy fit. Maybe if we have an easy solution to this problem we could use this boost counter

@Bronek
Copy link
Collaborator

Bronek commented Feb 27, 2025

I was interested in looking into existing solutions like this and stumbled on https://www.boost.org/doc/libs/1_87_0/libs/preprocessor/doc/ref/counter.html

I tried to integrate it into XRPL_FEATURE/FIX macros, but seems like passing #include into the macro is no easy fit. Maybe if we have an easy solution to this problem we could use this boost counter

I think what @ximinez proposed here is better because it's easier to understand.

Copy link
Collaborator

@Bronek Bronek left a comment

Choose a reason for hiding this comment

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

I do not feel strongly about proposed changes in Feature.h - if you think they are making things worse, feel free to merge as-is.

@ximinez ximinez added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Feb 28, 2025
* SUPPORTED, change the macro parameter in features.macro to Supported::yes.
*
* 4) When the feature is ready to be ENABLED, change the macro parameter in
* features.macro parameter to `VoteBehavior::DefaultYes`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that the section below explicitly says that newly supported amendments are NOT DefaultYes (which is indeed the policy), would it make sense to remove this point ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed and reworded.

@Bronek Bronek removed the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Feb 28, 2025
- Reword some of the instructions to better reflect current behaviors.
@ximinez ximinez force-pushed the ximinez/numFeatures branch from d6f8855 to 0fc28f1 Compare February 28, 2025 20:51
@ximinez ximinez requested a review from Bronek February 28, 2025 20:51
Fix typo found by @mvadari

Co-authored-by: Mayukha Vadari <[email protected]>
* a `VoteBehavior::DefaultNo` indefinitely so that external governance can
* make the decision on when to activate it. High priority bug fixes can be
* an exception to this rule. In such cases, change the macro parameter in
* features.macro to `VoteBehavior::DefaultYes`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps add something like ... and ensure that the fix has been clearly communicated to the community, using the appropriate channels. . Or even swap the order i.e. ensure the communication in the first place, then change the macro parameter.

I know this goes implied, but we must assume that not everyone reading this comment will grasp the significance of clear communication in this case.

static constexpr std::size_t numFeatures =
(0 +
#include <xrpl/protocol/detail/features.macro>
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

love this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants