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

Refactor account utxos #1184

Closed
wants to merge 2 commits into from
Closed

Conversation

DavidTranDucVL
Copy link
Contributor

Resolves issues #1181

@DavidTranDucVL DavidTranDucVL added the needs review PR waiting to be reviewed label Oct 20, 2021
@DavidTranDucVL DavidTranDucVL requested a review from refi93 October 20, 2021 04:52
@DavidTranDucVL DavidTranDucVL self-assigned this Oct 20, 2021
@mlenik mlenik temporarily deployed to adalite-refactor-accoun-xsfjud October 20, 2021 04:52 Inactive
Copy link
Collaborator

@refi93 refi93 left a comment

Choose a reason for hiding this comment

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

see comments

@refi93 refi93 removed the needs review PR waiting to be reviewed label Oct 22, 2021
@DavidTranDucVL DavidTranDucVL force-pushed the refactor-account-utxos branch 2 times, most recently from f8bd892 to 8a36cb3 Compare October 25, 2021 13:28
@DavidTranDucVL DavidTranDucVL requested a review from refi93 October 25, 2021 14:14
@DavidTranDucVL DavidTranDucVL added the needs review PR waiting to be reviewed label Oct 25, 2021
@refi93 refi93 closed this Oct 27, 2021
@refi93 refi93 reopened this Oct 27, 2021
@mlenik mlenik temporarily deployed to adalite-refactor-accoun-3yqri0 October 27, 2021 06:03 Inactive
@DavidTranDucVL DavidTranDucVL temporarily deployed to adalite-refactor-accoun-3yqri0 October 27, 2021 06:08 Inactive
const accountXpubs = await getAccountXpubs()
const stakingXpub = await getStakingXpub(cryptoProvider, accountIndex)
const stakingAddress = await myAddresses.getStakingAddress()
const {baseAddressBalance, nonStakingBalance, balance, tokenBalance} = await getBalance()
const utxos = await getUtxos()
const shelleyAccountInfo = await getStakingInfo(validStakepoolDataProvider)
Copy link
Collaborator

Choose a reason for hiding this comment

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

these network calls (getStakingInfo, getStakingHistory, ...) within fetchAccountInfo should probably be prefixed "fetch" as well for the sake of consistency, and if they are not exported, I'd prefix them with an underscore for the sake of clarity given we don't have this implemented as TS classes to capture that with private methods

// must be called before using other methods of the account object
async function loadCurrentState(validStakepoolDataProvider: StakepoolDataProvider) {
const [accountInfo, newUtxos] = await Promise.all([
_fetchAccountInfo(validStakepoolDataProvider),
Copy link
Collaborator

@refi93 refi93 Oct 27, 2021

Choose a reason for hiding this comment

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

I'd put here a clarifying comment on why we want to keep account info and utxos in sync (to prevent the transaction history/balnce shown from being behind the app's set of utxos, which could lead to multiple transactions going through if the set of utxos was updated meanwhile.)

Also, I just realized that this logic doesn't strictly ensure that utxos are at most as old as the rest of the account info, even if we awaited the utxos before the account info, because the _fetchUtxos() call is actually coupled and depends on the same cached source of data as account info does - the transaction history call is used both for address discovery and address info retrieval :/ Moreover, if loadCurrentState() was called too frequently, more often than our current cache timeout of 5 seconds, the utxos can actually get ahead of the transaction history if they happen to be updated during that time.

I can see this problem being solved by refactoring our isSomeAddressUsed call in the blockchain explorer to use our backend call to check whether addresses are used, instead of transaction history and cache that one, as that's actually the call we use repeatedly in other depending calls. getTransactionHistory as a bonus would no longer have to chunk the requests by the gap limit as it would no longer be coupled with account discovery (though at the cost of few more calls to filter used addresses, but these are pretty lightweight anyway). These non-trivial dependencies between the calls/caching would deserve also some comment explaining them as I can see that being pretty confusing - either here or in blockchain explorer

Then the fetching of utxos ahead of the account info would actually give us the guarantees we want.

It's a bit tedious refactor, but I think it's for the better and I'd propose doing it before merging this PR

Copy link
Collaborator

@refi93 refi93 Oct 27, 2021

Choose a reason for hiding this comment

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

ok not really, still the caching behind getAddressInfos call (needed e.g. for getBalance()) can cause it to get behind the utxos, this call should probably have a way to invalidate the address infos cache to prevent that from happening

Copy link
Collaborator

@refi93 refi93 Oct 27, 2021

Choose a reason for hiding this comment

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

finally, we may relax the requirement of transaction history having to be younger than the utxos and at least make sure to have the balance shown in sync with the utxos and leave the scenarios described above as an edge-case which if happens by any chance, user still sees balance in sync with the utxos, feel free to think of other solutions/tradeoffs

@refi93 refi93 added needs work on hold and removed needs review PR waiting to be reviewed on hold labels Oct 27, 2021
@refi93 refi93 added the on hold label Dec 20, 2022
@refi93 refi93 closed this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants