Conversation
d81b758 to
a8c1ff3
Compare
|
I think I finally finished this. Sometimes it felt like brute forcing to get the levels of caching working and I am sure it could use cleanup. Happy for a review, even if only stylistic changes. |
|
Okay, with #328 I fixed how we handle attributes to make it compatible with the events as returned with the SDK. And simplified/corrected how we handle SubMsg/reply. I feel better about the functionality, but still think I need to organize the code better... especially all those traits I added to unify *Router and *Cache |
| id: msg.id, | ||
| result: ContractResult::Ok(SubMsgExecutionResponse { | ||
| events: r.events, | ||
| data: r.data, |
There was a problem hiding this comment.
For the better reply test, maybe it is possible to wrap the data with Protobuf wrappers depends on the message type (bank & wasm::execute, wasm::instantiate)
message MsgInstantiateContractResponse {
// Address is the bech32 address of the new contract instance.
string address = 1;
// Data contains base64-encoded bytes to returned from the contract
bytes data = 2;
}Then, we can properly test Protobuf decoding part at reply like
let res: MsgInstantiateContractResponse =
Message::parse_from_bytes(msg.result.unwrap().data.unwrap().as_slice()).map_err(|_| {
StdError::parse_err("MsgInstantiateContractResponse", "failed to parse data")
})?;There was a problem hiding this comment.
Nice catch. I did something in init_response, but that was the old (pre-protobuf) version. Thanks for pointing this out.
maurolacy
left a comment
There was a problem hiding this comment.
Partial review of wasm.rs. lgtm.
Will continue reviewing later, as I have some errands to do now.
| } | ||
| } | ||
|
|
||
| pub fn cache(&self) -> WasmCache<C> { |
There was a problem hiding this comment.
I started reviewing this file, and this is a little above my head at this point, but:
I guess we need a multi-level (contract state) cache, to separate "server" contracts state from "client" contracts states. This, to mimic the transactional nature of the different contracts in the SDK.
Impressive piece of work, by the way.
There was a problem hiding this comment.
Before this PR we had a one-level cache in App.execute_multi. That is, all the messages are run together in a cache, and any error will cause the state changes to rollback. They will only be committed to the "real" storage if all return a success.
With submessages, each submessage will need it's own cache. They can write state and then fail, and then reply could catch the error and turn it to a success. That would mean the "parent contract" writes should be committed but the submessage writes not. These semanatics are described here: https://github.com/CosmWasm/cosmwasm/blob/main/SEMANTICS.md#submessages
This leads to the need of an arbitrarily multi-level caching technique. I feel my approach in this PR is a bit brute force and could probably use a bigger refactor to only use one Storage (rather than multiple HashMaps), and unify a lot on the caching in the end, but that would be much more work than needed to get a 0.7.0 release out. This package really should get some more refactors when we have capacity.
Closes #259
replyto contract wrapper contructor