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

Add derive.assets.all #4509

Closed
wants to merge 8 commits into from
Closed

Add derive.assets.all #4509

wants to merge 8 commits into from

Conversation

MiZiet
Copy link

@MiZiet MiZiet commented Jan 27, 2022

No description provided.

Comment on lines +50 to +52
const initialBlockHash = api.rpc.chain.subscribeNewHeads()
.pipe(take(1))
.pipe((val) => val.pipe(map(({ hash }) => hash)));
Copy link
Member

Choose a reason for hiding this comment

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

rpc.chain.getHeader returns the latest, no sub.

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean changing to:
const initBlockHash = api.rpc.chain.getHeader().pipe(val => val.pipe(map(({ hash }) => hash)))?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed. api.rpc.chain.getHeader().pipe(map(({ hash }) => hash))

@MiZiet
Copy link
Author

MiZiet commented Jan 31, 2022

By the way we've plugged this into useAssets hook in our app, it seems to work as expected.
Here's the setup that we use for local relay chain and parachain testing, where the problem with observing metadata changes occured

@MiZiet MiZiet marked this pull request as ready for review January 31, 2022 16:03
Comment on lines +77 to +82
switchMap((blockHash: Hash) =>
combineLatest([
api.query.assets.asset.entriesAt(blockHash),
api.query.assets.metadata.entriesAt(blockHash)
])
)
Copy link
Member

@jacogr jacogr Feb 3, 2022

Choose a reason for hiding this comment

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

This is a very, very heavy operation. Basically you refresh everything no matter what has changed on which id. The events actually have the ids of those changed, so should pin-point to those and only update those.

(crowdloans is an example of this - it tries to not get everything each time something has changed, rather it only refreshes based on the events received. As the state grows, this approach would just become slower and slower...)

For the initial load, 100% - we need all, on subsequent changes, this is the hammer approach and exceptionally ineffective and adding a lot of load.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood. Though still not sure how to solve it. Reason we use entriesAt is initially that multi did not get the updates from latest (non-finalized) block (polkadot-js/apps#6874 (comment)). As there is no entriesAt(blockHash, keys), I understand we need to load all, and then update state based on data from events (asset and metadata changes)?

Copy link
Member

Choose a reason for hiding this comment

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

So if we can get a minimal reproducable sample with API code, can actually log that on Substrate. (There could obviously be an issue with the apps UI implementation itself)

Copy link
Member

@jacogr jacogr Feb 11, 2022

Choose a reason for hiding this comment

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

Take a look at this issue, which is also parachain-related - /~https://github.com/paritytech/substrate/issues/10743

Would love a sample on a single connection where -

(a) event is available
(b) query for that item is not updated

I honestly cannot replicate this (relating to assets) on a stand-alone node.

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

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

As commented - we need a scalpel, not a hammer :)

@jacogr
Copy link
Member

jacogr commented Jul 26, 2022

Closing as-is. (However, this may not be an issue anymore in the apps UI, I know it had some significant changes on asset handling a while ago, which could have benefited here)

@jacogr jacogr closed this Jul 26, 2022
@jacogr jacogr deleted the mz-add-assets-all-to-derive branch July 26, 2022 06:47
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants