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

Fix: Resolve Type Warnings for ConfigService.get() #3350

Merged

Conversation

belloibrahv
Copy link
Contributor

@belloibrahv belloibrahv commented Dec 21, 2024

Description:
TL;DR; Enhancing Type Inference, Config Consistency, and Establishing a Single Source of Truth in ConfigService

This PR significantly improves type inference in ConfigService.get(), ensuring more reliable and explicit type resolution across configurations.

It also updates the entire codebase to adhere to a single source of truth for configuration management, enhancing consistency, reliability, and maintainability.

Key improvements include:

  • Strengthened type inference in ConfigService.get(), introducing explicit TypeScript types and interfaces that precisely map config keys to their expected types, reducing manual casting and type mismatches.
  • Unified configuration values across the codebase, ensuring all components rely on a single, authoritative source of truth.
  • Updated default values for all global configs to align with configurations.md, enhancing correctness and consistency.
  • Replaced hardcoded constants with corresponding config values, reducing redundancy and improving maintainability.
  • Alphabetized configuration tables in configurations.md, ensuring proper documentation and organization.

These enhancements improve type safety, reliability, and maintainability, making the configuration system more robust and easier to manage across the entire codebase.


Related issue(s):
Fixes #3142


Checklist:

  • Documented: Added/updated relevant code comments and documentation.
  • Tested: Verified changes with updated and new unit tests to ensure correctness.

@belloibrahv belloibrahv changed the title fix: resolve type warnings for ConfigService.get() Fix: Resolve Type Warnings for ConfigService.get() Dec 21, 2024
@belloibrahv
Copy link
Contributor Author

@Nana-EC @ebadiere @quiet-node I've submitted a PR addressing issue #3142 to resolve type warnings for ConfigService.get(). It ensures type consistency across test cases by refining type usage and adding/removing the necessary casting. Let me know if further changes are needed. Thank you for reviewing!

Copy link
Collaborator

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution.

@quiet-node quiet-node added this to the 0.64.0 milestone Dec 23, 2024
@quiet-node quiet-node added the internal For changes that affect the project's internal workings but not its outward-facing functionality. label Dec 23, 2024
@belloibrahv belloibrahv requested review from a team as code owners December 25, 2024 07:55
@belloibrahv belloibrahv force-pushed the 3142-fix-configservice-get-type-warnings branch from 27253f5 to 7f440e4 Compare December 25, 2024 08:54
@belloibrahv
Copy link
Contributor Author

@Nana-EC @acuarica @quiet-node, Could you please review my updates and let me know if further adjustments are needed?

Copy link
Contributor

@acuarica acuarica left a comment

Choose a reason for hiding this comment

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

Hi @belloibrahv, thanks for taking the time to send this, it's looking good. Left a couple of suggestions we can continue iterating on to improve the config.

@acuarica
Copy link
Contributor

Also @belloibrahv please take a look at #3350 (comment).

@quiet-node
Copy link
Member

@belloibrahv belloibrahv force-pushed the 3142-fix-configservice-get-type-warnings branch from 7f440e4 to c7e6a08 Compare December 26, 2024 23:23
@belloibrahv
Copy link
Contributor Author

@quiet-node @acuarica @Nana-EC @shemnon , thank you for the suggestion. I've implemented the following changes based on your feedback:

  1. Updated ConfigService.get to accept name: ConfigKey, removing the need for as ConfigKey assertions.
  2. Added a missing configuration entry for SERVER_HOST in _CONFIG.
  3. Adjusted test cases to align with the updated method definition.

Let me know if there's anything else you'd like me to address!

@belloibrahv
Copy link
Contributor Author

Also @belloibrahv please take a look at #3350 (comment).

@acuarica, Thank you for the suggestion! I think adding a getString (or similar methods like getNumber, getBoolean) in ConfigService could significantly simplify casting and improve developer experience. It could also centralize type handling and reduce repetitive casting logic.

Would you suggest we implement these methods for this task or address it as a follow-up? Also, should these methods throw errors for mismatched types, or return defaults like null? Happy to explore this further and incorporate it if needed!

@Nana-EC
Copy link
Collaborator

Nana-EC commented Dec 27, 2024

Also @belloibrahv please take a look at #3350 (comment).

@acuarica, Thank you for the suggestion! I think adding a getString (or similar methods like getNumber, getBoolean) in ConfigService could significantly simplify casting and improve developer experience. It could also centralize type handling and reduce repetitive casting logic.

Would you suggest we implement these methods for this task or address it as a follow-up? Also, should these methods throw errors for mismatched types, or return defaults like null? Happy to explore this further and incorporate it if needed!

Let's do it in a separate PR after this.

Also appreciate the patience.
The team is on holiday for the Christmas season so things are a bit slow.

@belloibrahv
Copy link
Contributor Author

Hi @quiet-node, @acuarica, @Nana-EC, @shemnon, Hope you all had a wonderful holiday! When you have a moment, please review and provide feedback on the requested changes to the PR. Thank you for your understanding!

Copy link
Contributor

@acuarica acuarica left a comment

Choose a reason for hiding this comment

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

Hi @belloibrahv, hope you had a wonderful holiday too! It's looking good, left some comments.

We appreciate your patience on this. Next week the full team will be back from holidays, so you'll get more reviews.

packages/config-service/src/services/index.ts Outdated Show resolved Hide resolved
packages/relay/tests/lib/eth/eth-config.ts Outdated Show resolved Hide resolved
packages/relay/tests/lib/ethGetBlockBy.spec.ts Outdated Show resolved Hide resolved
tools/brownie-example/LICENSE Outdated Show resolved Hide resolved
@belloibrahv
Copy link
Contributor Author

Great job @quiet-node 🚀

@quiet-node quiet-node requested a review from acuarica February 4, 2025 18:37
acuarica
acuarica previously approved these changes Feb 4, 2025
Copy link
Contributor

@acuarica acuarica left a comment

Choose a reason for hiding this comment

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

Thanks @belloibrahv and @quiet-node for putting the effort to get this done. Great stuff!

natanasow
natanasow previously approved these changes Feb 5, 2025
Copy link
Collaborator

@natanasow natanasow left a comment

Choose a reason for hiding this comment

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

Fantastic work!

@belloibrahv
Copy link
Contributor Author

@quiet-node @acuarica @natanasow @Nana-EC 🚀 🚀🚀 Thank You all

acuarica
acuarica previously approved these changes Feb 5, 2025
@quiet-node quiet-node dismissed stale reviews from acuarica and natanasow via dd09502 February 5, 2025 19:02
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 82.27848% with 14 lines in your changes missing coverage. Please review.

Project coverage is 53.61%. Comparing base (58ab012) to head (dd09502).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
packages/config-service/src/services/index.ts 62.50% 1 Missing and 2 partials ⚠️
...s/config-service/src/services/validationService.ts 33.33% 2 Missing ⚠️
packages/relay/src/lib/poller.ts 0.00% 2 Missing ⚠️
packages/relay/src/lib/subscriptionController.ts 66.66% 2 Missing ⚠️
packages/relay/src/lib/clients/mirrorNodeClient.ts 94.11% 0 Missing and 1 partial ⚠️
packages/relay/src/lib/eth.ts 80.00% 1 Missing ⚠️
packages/relay/src/lib/relay.ts 50.00% 0 Missing and 1 partial ⚠️
.../lib/services/ethService/ethCommonService/index.ts 0.00% 1 Missing ⚠️
packages/relay/src/lib/web3.ts 0.00% 1 Missing ⚠️

❌ Your project check has failed because the head coverage (53.61%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (58ab012) and HEAD (dd09502). Click for more details.

HEAD has 34 uploads less than BASE
Flag BASE (58ab012) HEAD (dd09502)
config-service 2 0
relay 2 0
server 2 0
ws-server 2 0
34 8
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3350       +/-   ##
===========================================
- Coverage   85.58%   53.61%   -31.98%     
===========================================
  Files          69       65        -4     
  Lines        4753     4525      -228     
  Branches     1059      979       -80     
===========================================
- Hits         4068     2426     -1642     
- Misses        393     1700     +1307     
- Partials      292      399      +107     
Flag Coverage Δ
config-service ?
relay ?
server ?
ws-server ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ckages/config-service/src/services/globalConfig.ts 100.00% <100.00%> (ø)
...kages/relay/src/lib/clients/cache/localLRUCache.ts 25.37% <ø> (-67.49%) ⬇️
packages/relay/src/lib/clients/cache/redisCache.ts 48.14% <100.00%> (-39.13%) ⬇️
packages/relay/src/lib/clients/sdkClient.ts 54.31% <100.00%> (-16.08%) ⬇️
...ay/src/lib/config/hbarSpendingPlanConfigService.ts 25.86% <100.00%> (-66.38%) ⬇️
packages/relay/src/lib/constants.ts 100.00% <ø> (+5.17%) ⬆️
packages/relay/src/lib/net.ts 66.66% <100.00%> (-33.34%) ⬇️
packages/relay/src/lib/precheck.ts 48.64% <100.00%> (-40.45%) ⬇️
...elay/src/lib/services/cacheService/cacheService.ts 26.66% <ø> (-65.93%) ⬇️
.../relay/src/lib/services/hapiService/hapiService.ts 72.36% <100.00%> (-22.37%) ⬇️
... and 13 more

... and 31 files with indirect coverage changes

Signed-off-by: Logan Nguyen <[email protected]>

Revert "fix(ci): fixed ci test with fallback log level"

This reverts commit 9af4396.

Reapply "fix(ci): fixed ci test with fallback log level"

This reverts commit bd81c5729ffa7e4e20cf07cccbec718aff61af9b.

Revert "fix(ci): fixed ci test with fallback log level"

This reverts commit 981cad0a66a4e487d6e396dfcc0fa1123f19296f.

Reapply "fix(ci): fixed ci test with fallback log level"

This reverts commit 87eb44fd5fcd09156210cd431d7a0d00e9f8e720.
@quiet-node quiet-node force-pushed the 3142-fix-configservice-get-type-warnings branch from fa189dd to 67a8e75 Compare February 5, 2025 19:40
Copy link

sonarqubecloud bot commented Feb 5, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
4.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@quiet-node quiet-node self-assigned this Feb 6, 2025
@quiet-node quiet-node merged commit 237b452 into hashgraph:main Feb 6, 2025
50 of 51 checks passed
@quiet-node
Copy link
Member

Thanks, team, for the great responses and feedback!

Congrats on the merge, @belloibrahv! Appreciate your effort and patience—looking forward to more of your contributions in the future!

@belloibrahv
Copy link
Contributor Author

Thank You all for helping out, I look forward to working and collaborating on more work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal For changes that affect the project's internal workings but not its outward-facing functionality.
Projects
None yet
6 participants