-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
packages/staking/src/features/BrowsePools/hooks/useQueryStakePools.tsx
Outdated
Show resolved
Hide resolved
Allure Report
processReports: ✅ test report for 4ee15b34
|
33e0e54
to
f7009b8
Compare
return data; | ||
}; | ||
|
||
const asyncFetchData = () => (fetchingData ? undefined : fetchData().catch(console.error)); |
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.
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?
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.
Ok.
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.
0359a41 should solve this
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.
If we want to fire and forget an async function we could just call it without await
🤔
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.
Indeed it is called without await
, sorry, but I can't get the point.
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.
@iccicci my point is that we don't need a separate function to do that …
- the check for
fetchingData
could be moved intofetchData
itself (so it never fetches twice) - the error logging could be moved into
fetchData
itself (bycatch
) and if we want to store it we could return it asPromise.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.
11a0094
to
939a176
Compare
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.
@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
(especiallyfetchData
) 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.
Hi @DominikGuzei , 5fae7ea adds tests which cover all the cases coming to my mind. |
packages/staking/src/features/BrowsePools/hooks/useQueryStakePools.tsx
Outdated
Show resolved
Hide resolved
try { | ||
data = await cachedData; | ||
|
||
for (const [poolId, { lastFetchTime }] of poolDetails) |
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.
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)
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.
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.
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.
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.
packages/cardano/src/wallet/lib/__tests__/stakePoolService.test.ts
Outdated
Show resolved
Hide resolved
packages/staking/src/features/BrowsePools/hooks/useQueryStakePools.tsx
Outdated
Show resolved
Hide resolved
packages/staking/src/features/BrowsePools/hooks/useQueryStakePools.tsx
Outdated
Show resolved
Hide resolved
packages/staking/src/features/BrowsePools/hooks/useQueryStakePools.tsx
Outdated
Show resolved
Hide resolved
packages/cardano/src/wallet/lib/__tests__/stakePoolService.test.ts
Outdated
Show resolved
Hide resolved
packages/cardano/src/wallet/lib/__tests__/stakePoolService.test.ts
Outdated
Show resolved
Hide resolved
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.
Excellent work @iccicci 🦾
e926e5f
to
6a531cf
Compare
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.
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.
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.
Great work @iccicci ! 🚀
6a531cf
to
4ee15b3
Compare
|
Checklist
Proposed solution
StakePoolProvider
.useQueryStakePools
custom hook to take advantage of the new performances: removed the use of the paginator.Testing
Manual testing