fix: Fix regressions in server_definitions - #7008
Conversation
There was a problem hiding this comment.
This constructor is only used by sfGeneric and sfInvalid
There was a problem hiding this comment.
Pull request overview
This PR aims to restore expected server_definitions output behavior by making the FIELDS section deterministic and removing a duplicate sfGeneric entry that was introduced in #5590.
Changes:
- Remove the manual
Genericinsertion and prevent duplicates between manually-added fields and registeredSFields. - Make
FIELDSordering deterministic by iterating over a sorted view ofSField::getKnownCodeToField(). - Update
server_definitionsunit tests to reflect the new ordering and add a duplicate-name check.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/xrpld/rpc/handlers/server_info/ServerDefinitions.cpp | Switches FIELDS generation to a deterministic, sorted iteration and filters out manually-added field names to avoid duplicates. |
| src/test/rpc/ServerDefinitions_test.cpp | Updates assertions for the new FIELDS ordering and adds a no-duplicates check. |
| src/libxrpl/protocol/SField.cpp | Adjusts default signing-field behavior for the (fieldCode, name) SField constructor (affecting sfGeneric / sfInvalid). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| auto const field = result[jss::result][jss::FIELDS][6u]; | ||
| BEAST_EXPECT(field[0u].asString() == "LedgerEntryType"); | ||
| BEAST_EXPECT(field[1][jss::isSerialized].asBool() == true); | ||
| BEAST_EXPECT(field[1][jss::isSigningField].asBool() == true); | ||
| BEAST_EXPECT(field[1][jss::isVLEncoded].asBool() == false); |
There was a problem hiding this comment.
The assertion that FIELDS[6] is LedgerEntryType is brittle: adding any new SField with a smaller sort key will shift indices even if ordering is still correct. Consider locating the field by name (and then asserting its properties) and/or asserting the ordering property directly instead of relying on a hard-coded index.
There was a problem hiding this comment.
That's done on purpose. Everything below it is hard-coded.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #7008 +/- ##
=========================================
- Coverage 82.1% 82.1% -0.0%
=========================================
Files 1010 1010
Lines 76033 76024 -9
Branches 7379 7373 -6
=========================================
- Hits 62426 62392 -34
- Misses 13607 13632 +25
🚀 New features to boost your workflow:
|
godexsoft
left a comment
There was a problem hiding this comment.
Looks alright to me. Please address copilot's concerns 👍
ximinez
left a comment
There was a problem hiding this comment.
I am not super-familiar with ServerDefinitions, but the changes look right, aside from the couple of comments below.
| , fieldMeta(sMD_Never) | ||
| , fieldNum(++num) | ||
| , signingField(IsSigning::yes) | ||
| , signingField(IsSigning::no) |
There was a problem hiding this comment.
This has been yes for 11 years (and true before that). I'm not entirely clear on why it needs to change. Could you explain what's going on?
There was a problem hiding this comment.
sfGeneric also used to be labeled as IsSigning::no in the definitions.json output, so one of those is wrong then.
This constructor is only used for these two SFields, to clarify:
SField const sfInvalid(access, -1, "");
SField const sfGeneric(access, 0, "Generic");
There was a problem hiding this comment.
sfGenericalso used to be labeled asIsSigning::noin thedefinitions.jsonoutput, so one of those is wrong then.This constructor is only used for these two SFields, to clarify:
That makes sense.
However, it looks like the only reason sfGeneric was listed as non-signing is because it had been hard-coded. https://github.com/XRPLF/rippled/pull/7008/changes#diff-c9864c2527cd17eeac088af7a96edca5f1347208dc6b77a4317e3427cc2dca36L158-L160. This PR removes that hard-coding.
My concern is that even though these fields are only used as placeholders, and never intentionally used in transaction data, they may be ignored if they ever found their way into transaction data. E.g. through a bug, or perhaps a malicious injection into serialized data / protocol messages.
Please feel free to disagree, but I think the way forward here is to
- revert the change
SField.cppback toIsSigning::Yes, - and then in
ServerDefinitions.cppeither- Put the hard-coded "Generic" back, and skip over it when found in the loop (
if (field->fieldName.empty() || field->fieldName == "Generic") continue;, - OR put an override in the assignment.
innerObj[jss::isSigningField] = field->fieldName == "Generic" ? false : field->shouldInclude(false);
- Put the hard-coded "Generic" back, and skip over it when found in the loop (
There was a problem hiding this comment.
We can skip step 2 if you're okay with labeling sfGeneric as isSigningField: true since it seems that that's more accurate.
There was a problem hiding this comment.
We can skip step 2 if you're okay with labeling
sfGenericasisSigningField: truesince it seems that that's more accurate.
Yeah, I'm very happy with that! I didn't realize that was an acceptable outcome. 😀
There was a problem hiding this comment.
I just assumed what was there before was the desired answer, based on this conversation that's not the case :)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
|
We recently merged a refactor to One-time setupIf you don't already have clang-tidy working in your env, on macOS: brew install llvm@21
# Follow brew's hint to put $(brew --prefix llvm@21)/bin on PATH so run-clang-tidy is found.Workflow on your branch (before merging develop)1. Grab the new git remote -v # should show 'upstream' among others; if not:
# git remote set-url upstream git@github.com:XRPLF/rippled.git
git fetch upstream
git checkout upstream/develop -- .clang-tidy2. Reconfigure conan/cmake so 3. Apply renames for the files modified in your PR: git diff --name-only $(git merge-base HEAD upstream/develop) HEAD \
| grep -E '\.(cpp|h|hpp|ipp)$' \
| xargs run-clang-tidy -p build -fix -allow-no-checks
# or -p .build, or whatever your build dir is called4. Build + test, then commit as a single dedicated commit: cmake --build build -j8
git commit -am "refactor: Align identifier naming with develop"5. Now merge develop: git merge upstream/developExtraRun clang-tidy once more after the merge to catch any stragglers introduced from develop's side: run-clang-tidy -p build -fix -allow-no-checks src tests
# or -p .build, or whatever your build dir is called |
|
All conflicts have been resolved. Assigned reviewers can now start or resume their review. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/xrpld/rpc/handlers/server_info/ServerDefinitions.cpp:246
- After removing the hard-coded "Generic" entry, the remaining "Generic" row will now be generated from
kSF_GENERIC(which hasfieldType == STI_UNKNOWN). With the current predicate(type < 10000 && name != "hash" && name != "index"), that makesGeneric.isSerializedevaluate totrue, which differs from the previous explicitisSerialized=falsesemantics for Generic and is likely misleading for an STI_UNKNOWN placeholder field. Consider excludingSTI_UNKNOWN(and/orfield->fieldCodeMem <= 0/!field->isUseful()) from theisSerializedpredicate, or reintroduce a dedicated exception entry for Generic and skip it in the loop to preserve the intended output contract.
// whether the field is included in serialization
innerObj[jss::isSerialized] =
(type < 10000 && field->fieldName != "hash" &&
field->fieldName !=
"index"); // hash, index, TRANSACTION, LEDGER_ENTRY, VALIDATION, METADATA
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
server_definitionsserver_definitions
High Level Overview of Change
This PR fixes regressions in the output of
server_definitions, namely:FIELDSarray was not sorted by field valuesfGenericwas listed twice in theFIELDSarrayContext of Change
These regressions were missed in #5590, caught by @pdp2121.
API Impact
Only fixes, no API format change