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

DO NOT MERGE: Demo new approach to error handling in ibc receive #20

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ethanfrey
Copy link
Contributor

This is not meant to merge, but as a demo for discussion on CosmWasm/wasmd#1220

Copy link
Contributor Author

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few annotations to understand the approach

/// we look for a the proper reflect contract to relay to and send the message
/// We cannot return any meaningful response value as we do not know the response value
/// of execution. We just return ok if we dispatched, error if we failed to dispatch
/// This is a demo of a new way to handle both error ack and abort in a CosmWasm contract
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start here reading the general flow we are modelling

msg: IbcPacketReceiveMsg,
) -> Result<IbcReceiveResponse, ContractError> {
// Any error in this initial checks should abort the whole IBC transaction
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do inline only actions that can abort the tx (don't capture in x/wasm)

let sub = SubMsg::reply_always(
WasmMsg::Execute {
contract_addr: env.contract.address.into_string(),
msg: to_binary(&ExecuteMsg::ProcessIbc {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call self to actually do the logic

ContractError::OnlySelfCall
);

match packet {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines moved from old ibc_packet_receive

@@ -199,20 +216,79 @@ pub fn reply_init_callback(deps: DepsMut, reply: Reply) -> Result<Response, Cont
Ok(Response::new())
}

/// This takes the submessage and encodes the proper ack field
pub fn reply_process_ibc(_deps: DepsMut, reply: Reply) -> Result<Response, ContractError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is where we handle the self-dispatch, both error and success cases.

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

Successfully merging this pull request may close these issues.

1 participant