-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
Implement standard keymanager API - review #3880
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
@@ -80,7 +76,7 @@ export class KeymanagerApi implements Api { | |||
message?: string; | |||
}[]; | |||
}> { | |||
const interchange = (slashingProtectionStr as unknown) as Interchange; | |||
const interchange = JSON.parse(slashingProtectionStr) as Interchange; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dadepo do you know why JSON.parse() was not necessary if slashingProtectionStr
is supposed to be a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because the arguments to the function is passed in as an http body and fastify parses it already, so by the time our code calls finds the relevant handler here it is already an object hence no need to use JSON.parse within the function.
I also think the types safety of the function is weaker as it is decoupled from the calling logic in here so at runtime, it is an object that is passed in, which is then attempted to be parsed into JSON
My guess is that If it were a query path or params, then the parsing will be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So can you add a nice long comment explaining this above my change and do conditional parsing?
const interchange: Interchange = typeof slashingProtectionStr === "string" ? JSON.parse(slashingProtectionStr) : slashingProtectionStr;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment but I feel that the conditional parsing is not necessary since the endpoint is going to be called with the payload within the body of the request.
Also the snippet you shared won't work. What will work will require changing the type for slashingProtectionStr: SlashingProtectionData | Record<string, unknown>
and then have the conditional parsing as follows:
const interchange = typeof slashingProtectionStr === "string"
? (JSON.parse(slashingProtectionStr) as Interchange)
: ((slashingProtectionStr as unknown) as Interchange);
Which I think is a bit too much since payload will always come within the body
Codecov Report
@@ Coverage Diff @@
## master #3880 +/- ##
==========================================
- Coverage 36.25% 34.96% -1.29%
==========================================
Files 328 328
Lines 9142 10683 +1541
Branches 1438 1790 +352
==========================================
+ Hits 3314 3735 +421
- Misses 5682 6795 +1113
- Partials 146 153 +7 |
@dadepo Please if you can fix the test I broken and approve if it looks good then 🙏 |
Tests are now passing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meta-Approve ✔️ @dadepo it's my PR so you or someone else has to approve
Motivation
Post-merge review of #3522
Description
Fixes some potential issues: