Skip to content

LW-13062 Stake pool service #1944

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

Merged
merged 3 commits into from
Jul 24, 2025
Merged

LW-13062 Stake pool service #1944

merged 3 commits into from
Jul 24, 2025

Conversation

iccicci
Copy link
Contributor

@iccicci iccicci commented Jul 8, 2025

Checklist

  • JIRA - LW-13062
  • Proper tests implemented
  • Screenshots added.

Proposed solution

  • Implemented client side stake pools services which fetches partial stake pools from BF bulk stake pools API and caches them for 1 day.
  • Implemented client side StakePoolProvider.
  • Refactored useQueryStakePools custom hook to take advantage of the new performances: removed the use of the paginator.

Testing

Manual testing

@lace-bot
Copy link
Collaborator

lace-bot commented Jul 8, 2025

Allure Report

allure-report-publisher generated test report!

processReports: ✅ test report for 4ee15b34

passed failed skipped flaky total result
Total 33 0 4 0 37

@iccicci iccicci requested a review from a team as a code owner July 8, 2025 15:08
@iccicci iccicci force-pushed the feat/LW-13062-stake-pool-service branch 2 times, most recently from 33e0e54 to f7009b8 Compare July 9, 2025 09:47
return data;
};

const asyncFetchData = () => (fetchingData ? undefined : fetchData().catch(console.error));
Copy link
Member

@DominikGuzei DominikGuzei Jul 10, 2025

Choose a reason for hiding this comment

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

Please elaborate on why asyncFetchData is required 🙏 it seems like it's about not re-fetching while fetching is already in process? If so, the check for fetchingData could maybe be moved to fetchData itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0359a41 should solve this

Copy link
Member

Choose a reason for hiding this comment

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

If we want to fire and forget an async function we could just call it without await 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it is called without await, sorry, but I can't get the point.

Copy link
Member

@DominikGuzei DominikGuzei Jul 14, 2025

Choose a reason for hiding this comment

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

@iccicci my point is that we don't need a separate function to do that …

  • the check for fetchingData could be moved into fetchData itself (so it never fetches twice)
  • the error logging could be moved into fetchData itself (by catch) and if we want to store it we could return it as Promise.reject(reason)

To me, the current interaction and dependency between fetchData and asyncFetchData is confusing. I'm in favor of defensive programming where fetchData (itself) ensures consistent results no matter how often or where it gets called from.

@iccicci iccicci force-pushed the feat/LW-13062-stake-pool-service branch from 11a0094 to 939a176 Compare July 14, 2025 10:17
Copy link
Member

@DominikGuzei DominikGuzei left a comment

Choose a reason for hiding this comment

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

@iccicci In general i think this kind of complexity warrants unit tests as it is hard for me to tell if the code does what it is supposed to do. Here are a few suggestions:

  • Move the inline functions within initStakePoolService (especially fetchData) outside and write exhaustive unit tests for it
  • Write at least 1-2 integration tests (happy path + error case) for the initStakePoolService to make sure the complete setup works as expected.

@iccicci
Copy link
Contributor Author

iccicci commented Jul 15, 2025

Hi @DominikGuzei , 5fae7ea adds tests which cover all the cases coming to my mind.

try {
data = await cachedData;

for (const [poolId, { lastFetchTime }] of poolDetails)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe get rid off poolDetails and use it directly from cachedData.poolDetails?
They represent the same data and keeping them in sync is error prone.

-   let poolDetails: StakePoolCachedData['poolDetails'] = new Map();
.....
-      for (const [poolId, { lastFetchTime }] of poolDetails)
+      for (const [poolId, { lastFetchTime }] of data.poolDetails)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cachedData and poolDetails are actually two distinct sets of data:

  • the first one stores all the global data and it is entirely refreshed by fetchData;
  • the second stores details for those stake pools which are queried by id, the details the bulk API do not provides; each entry has its own expiration date.

Probably the confusion comes from the fact I added poolDetails to cachedData with the purpose to save all the data with a single storage key. Probably it would be better to store the two distinct data with two distinct storage keys, this should help the reader understanding they are distinct and should reduce the confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another source of confusion is I decided to have two caches each with its own expiry.
After meeting with @mirceahasegan we agreed what follows; since there is not so much benefit from the separated expiration of details, for the sake of simplicity, better to have a single cache expiration: when it expires, details will be erased as well.

Copy link
Contributor

@mirceahasegan mirceahasegan left a comment

Choose a reason for hiding this comment

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

Excellent work @iccicci 🦾

@iccicci iccicci force-pushed the feat/LW-13062-stake-pool-service branch from e926e5f to 6a531cf Compare July 18, 2025 09:57
Copy link
Member

@DominikGuzei DominikGuzei 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 adding exhaustive unit tests and code improvements @iccicci 🎉
There is only one doubt left on my side: there is currently no way for the user of the service api to know if the data is coming from cache or if its the latest "real" data … this might not be critical but i don't have a full overview of the v1 staking environment to make a judgement on this.

Copy link
Contributor

@przemyslaw-wlodek przemyslaw-wlodek left a comment

Choose a reason for hiding this comment

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

Great work @iccicci ! 🚀

@iccicci iccicci force-pushed the feat/LW-13062-stake-pool-service branch from 6a531cf to 4ee15b3 Compare July 22, 2025 16:07
Copy link

@iccicci iccicci merged commit cb57d75 into main Jul 24, 2025
27 checks passed
@iccicci iccicci deleted the feat/LW-13062-stake-pool-service branch July 24, 2025 13:15
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.

5 participants