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

multi-test: cleaner use of transactions #349

Closed
ethanfrey opened this issue Jul 26, 2021 · 2 comments · Fixed by #357
Closed

multi-test: cleaner use of transactions #349

ethanfrey opened this issue Jul 26, 2021 · 2 comments · Fixed by #357

Comments

@ethanfrey
Copy link
Member

We use StorageTransaction::new(), a number of places to give us:

  1. ability to revert/commit changes written to a cache
  2. read-only access to an underlying snapshot and write access to a cache, which is needed for wasm execution (at least)

This is also called a number of places. I would simplify this by calling it primarily one place: Router.execute, which works like the "ante handler" transaction wrapper from the SDK. This also means any sub messages from WasmKeeper (which call into that) also are automatically transaction wrapped.

We can provide a helper method to make it cleaner. Something like:

as_transaction(&mut base_storage, |write_cache: &mut Storage, read_snapshot: &Storage| -> Result<T, String> {
});

It would wrap the base, return a cache and a read-only reference to base to the closure. Only on Ok, it will commit the cache to base, and it will return the Result from the closure to the caller.

@maurolacy
Copy link
Contributor

Taking a look at this now.

@ethanfrey
Copy link
Member Author

I finished this. You can gladly review #357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants