-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Submessage reply can overwrite caller response #502
Conversation
Codecov Report
@@ Coverage Diff @@
## master #502 +/- ##
==========================================
+ Coverage 58.45% 58.62% +0.17%
==========================================
Files 41 42 +1
Lines 4460 4474 +14
==========================================
+ Hits 2607 2623 +16
+ Misses 1636 1635 -1
+ Partials 217 216 -1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
My one question is whether the reply
interface that actually goes over FFI to a wasm contract properly distinguished between nil
and []byte("")
. I will look more into that.
origRspData []byte, | ||
) ([]byte, error) { | ||
result := origRspData | ||
switch rsp, err := h.md.DispatchSubmessages(ctx, contractAddr, ibcPort, submessages); { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactor of types and adding a feature in one PR make it hard to see what you did. I will verify what I see.
This is https://github.com/CosmWasm/wasmd/pull/502/files#diff-4e16010ab332946722b789b22962fb5a0814d529cd8de443b925d20ccd13705fL772-L780 but now handling the rsp != nil
case. Note: do we need to differentiate between nil
and []byte{}
here? I guess so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After researching wasmvm
, I came to the conclusion this all works perfectly fine with the existing Go-Rust interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ja, I realized later that it may not be easy to review this as it is displayed as new content. Apologies for this. Tests were not refactored though.
Note: do we need to differentiate between nil and []byte{} here
If we consider empty []bye
a valid response from a contract then we need to be able to overwrite this by the reply. The nil
result is considered an opt out to overwrite the response.
After researching wasmvm, I came to the conclusion this all works perfectly fine with the existing Go-Rust interface
👏
I checked the handling of We parse raw Rust-encoded response into a data, gasUsed, err := api.Reply(vm.cache, checksum, envBin, replyBin, &gasMeter, store, &goapi, &querier, gasLimit, vm.printDebug)
if err != nil {
return nil, gasUsed, err
}
var resp types.ContractResult
err = json.Unmarshal(data, &resp) This type defines // ContractResult is the raw response from the instantiate/execute/migrate calls.
// This is mirrors Rust's ContractResult<Response>.
type ContractResult struct {
Ok *Response `json:"ok,omitempty"`
Err string `json:"error,omitempty"`
}
// Response defines the return value on a successful instantiate/execute/migrate.
// This is the counterpart of [Response](https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta1/packages/std/src/results/response.rs#L73-L88)
type Response struct {
// Submessages are like Messages, but they guarantee a reply to the calling contract
// after their execution, and return both success and error rather than auto-failing on error
Submessages []SubMsg `json:"submessages"`
// Messages comes directly from the contract and is it's request for action
Messages []CosmosMsg `json:"messages"`
// base64-encoded bytes to return as ABCI.Data field
Data []byte `json:"data"`
// attributes for a log event to return over abci interface
Attributes []EventAttribute `json:"attributes"`
} |
Thank you for this detailed review feedback. Especially for the time you took to look into the wasmvm response data de/serialization. Very happy that it makes sense 😄 |
Resolves #495
Although there a good tests for submessages that work with wasm contracts I found it very hard to to test the reply workflow without mocks. As a result I extracted:
MessageDispatcher
to handle the message/submessage flowDefaultWasmVMContractResponseHandler
to coordinate the dispatching order and result overwrite. This may become a nice extension pointNot related to the task but "refactored as needed" : rename of
WASMVMQueryHandler