Skip to content

multi-test: cleaner use of transactions #349

@ethanfrey

Description

@ethanfrey

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions