Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

srml-contract: ext_rent_allowance caching #2793

Closed
pepyakin opened this issue Jun 5, 2019 · 2 comments
Closed

srml-contract: ext_rent_allowance caching #2793

pepyakin opened this issue Jun 5, 2019 · 2 comments
Labels
J0-enhancement An additional feature request.

Comments

@pepyakin
Copy link
Contributor

pepyakin commented Jun 5, 2019

For now, ext_rent_allowance requires a DB access. However, the rent allowance value is stored along with the other data essential for execution of a contract meaning that we already loaded rent_allowance when we execute a contract.

We should check if it is possible to cache this value in memory.

@pepyakin pepyakin added the J0-enhancement An additional feature request. label Jun 5, 2019
@jimpo
Copy link
Contributor

jimpo commented Aug 1, 2019

I've thought about this quite a bit and can't come up with a clean way to do it that makes it seem worthwhile.

For newly instantiated contracts, access to rent_allowance is already fast as it is stored in memory in an OverlayDb and requires no DB access. So it only might be slow for pre-existing contracts. If a pre-existing contract is called, before execution begins we load the account from storage in order to check its rent payment. Thus we do have the contract info, including it's rent allowance prior to the execution of the extrinsic in memory and can theoretically cache it somehow to avoid another DB access during ext_rent_allowance.

The problem is that we can't cache the ContractInfo on the OverlayDb, as it may be out of date. Specifically, if a contract A with initial rent allowance X is called, sets its rent allowance to Y, then calls B which calls A again, then the stored ContractInfo of A will still show the rent allowance as X as the changes have not been committed yet. So either we need to cache the contract info of A on the DirectAccountDb, the bottom-most AccountDb in the stack underneath all of the OverlayDbs, or update the contract info with the changes from all OverlayDbs. Both of these are possible, but kind of gross and complicated.

I'm just not sure it's worth it, given that there's no good reason for a contract to ever call ext_rent_allowance more than once per execution (since it can just store the result). Thoughts?

@pepyakin
Copy link
Contributor Author

Superseded by #6439

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request.
Projects
Status: No status
Development

No branches or pull requests

2 participants