The AI Works community logo The Blockchain Works community logo The Functional Works community logo The Golang Works community logo The Java Works community logo The JavaScript Works community logo The Python Works community logo The Remote Works community logo The WorksHub company logo

We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies.

We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies. Less

We use cookies and other tracking technologies... More

Login or register
to publish this job!

Login or register
to save this job!

Login or register
to save interesting jobs!

Login or register
to get access to all your job applications!

Login or register to start contributing with an article!

Login or register
to see more jobs from this company!

Login or register
to boost this post!

Show some love to the author of this blog by giving their post some rocket fuel 🚀.

Login or register to search for your ideal job!

Login or register to start working on this issue!

Login or register
to save articles!

Login to see the application

Engineers who find a new job through AI Works average a 15% increase in salary 🚀

You will be redirected back to this page right after signin

StorageTransaction doesn't need mutable reference until commit

Issue closed
Pull requests: 0
Contributors: 1
Level: Intermediate
  • Rust
Issue closed
Pull requests: 0
Contributors: 1
Level: Intermediate
  • Rust

On GitHub

Library for building cosmos-compatible wasm smart contracts
More info >

Issue posted by: 
ethanfrey's avatar

Ethan Frey

Description

Needed for #98 / #101

Right now StorageTransaction holds a &mut Storage for the entire lifetime, although it only needs &ReadonlyStorage until the final commit(). https://github.com/confio/cosmwasm/blob/master/src/storage.rs#L5-L12

This is fine, but for query implementations we will want to hold multiple references to the pre-message snapshot. If StorageTransaction took &Storage, it would work the same until commit(), and in the meantime, we can pass multiple &ReadonlyStorage of the pre-message snapshot to other contracts to perform queries. The change to commit would be something like:

impl StorageTransaction {
    pub fn prepare(self) -> Commit { /* ... */ }
}

struct Commit {
  rep_log: Vec<Op>,
}

impl Commit() {
    pub fn commit(self, store: &mut Storage) {
      // this would behave as current commit.
    }
}

Usage would be something like this:

let mut subtx = StorageTransaction::new(&store);
subtx.set(b"foo", b"bar");
subtx.prepare().commit(&mut store)

Or maybe this if the borrow checker requires:

let mut subtx = StorageTransaction::new(&store);
subtx.set(b"foo", b"bar");
let ops = subtx.prepare()  // this will release the `&store`
ops.commit(&mut store)

    Use Open Source to hire or get hired

    On GitHub

    Library for building cosmos-compatible wasm smart contracts
    More info >

    Issue posted by: 
    ethanfrey's avatar

    Ethan Frey

    Use Open Source to hire or get hired

    StorageTransaction doesn't need mutable reference until commit
    View on GitHub