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

Software Design: Introduce nonce caching #318

Open
haerdib opened this issue Nov 14, 2022 · 4 comments
Open

Software Design: Introduce nonce caching #318

haerdib opened this issue Nov 14, 2022 · 4 comments
Labels
F6-optimization This should optimize the performance F8-newfeature Introduces a new feature Q9-needsdesign

Comments

@haerdib
Copy link
Contributor

haerdib commented Nov 14, 2022

Currently, every compose_extrinsic! call, calls the substrate storage. There's already a workaround for this by using ccompose_extrinsic_offline!, but it sure would be nice, to have a nonce cache that caches the nonce, and updates it with a storage request in case of a failure (e.g. mark it as dirty or something).

Complexity: When to revert nonce? What about future?

@haerdib haerdib added F6-optimization This should optimize the performance F8-newfeature Introduces a new feature Q5-involved Will take some time to fix this labels Nov 14, 2022
@haerdib haerdib added Q9-needsdesign and removed Q5-involved Will take some time to fix this labels Mar 21, 2023
@Niederb
Copy link
Contributor

Niederb commented Apr 20, 2023

Maybe in a first version we can introduce a NonceProvider trait that abstracts over getting the nonce and provide two simple implementations:

  • LocalNonceProvider: Fetches the nonce only once and increases it automatically, but does not implement additional logic (fetching nonce again on error, ...). This one could also be useful for no_std where I don't have an Api instance.
  • OnlineNonceProvider: The approach currently used that always fetches the nonce from the node

This will already be some work to think about how the trait should look, how to configure this and how to pass the NonceProvider around. We could then implement fancier nonce caching later on.

@haerdib
Copy link
Contributor Author

haerdib commented Apr 20, 2023

I agree in general, but before doing all this work, we should probably make sure that a local nonce cache does make sense. At least theoretically. E.g. find out if such a cache could ever be robust enough to be applied in the field. What do you think?

@Niederb
Copy link
Contributor

Niederb commented Apr 20, 2023

Yes, I agree and I think even this "simple" approach is more involved that it seems at first glance.

@haerdib
Copy link
Contributor Author

haerdib commented Apr 20, 2023

Yes. I was just thinking about the separation of creating and sending extriniscs. The creation is done without the api, while the sending is done with it. For a cache, those two elements would need to be combined somehow. Otherwise, the cache could never be reverted / updated in case something goes wrong during sending.

@masapr masapr changed the title Introduce nonce caching Software Design: Introduce nonce caching Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F6-optimization This should optimize the performance F8-newfeature Introduces a new feature Q9-needsdesign
Projects
None yet
Development

No branches or pull requests

2 participants