multiversx / mx-chain-go

⚡ The official implementation of the MultiversX blockchain protocol, written in golang.

Home Page:https://multiversx.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Async call gets wrong mapping in callback (different shards)

zekdigital opened this issue · comments

Hello,

Given first contract named router on Shard0:

#![no_std]
#![feature(generic_associated_types)]

elrond_wasm::imports!();

#[elrond_wasm::contract]
pub trait Router {
    #[init]
    fn init(&self) { }

    #[endpoint(router)]
    fn router(
        &self,
        arg1: u8
    ) -> u8 {
        return 3 + arg1;
    }
}

and given second contract named main on Shard1:

#![no_std]
#![feature(generic_associated_types)]

elrond_wasm::imports!();

mod routing {
    elrond_wasm::imports!();

    #[elrond_wasm::proxy]
    pub trait RoutingContract {
        #[endpoint(router)]
        fn router(
            &self,
            arg1: u8
        ) -> u8;
    }
}

#[elrond_wasm::contract]
pub trait Main {
    #[proxy]
    fn contract_proxy(&self, sc_address: ManagedAddress) -> routing::Proxy<Self::Api>;

    #[init]
    fn init(
        &self, 
        router: ManagedAddress
    ) {
        self.routerAddr().set(&router);
    }

    #[endpoint(test)]
    fn test(&self) {
        self.contract_proxy(self.routerAddr().get())
            .router(8)
            .async_call()
            .with_callback(self.callbacks().my_callback())
            .call_and_exit();
    }

    #[callback]
    fn my_callback(
        &self,
        #[call_result] result: ManagedAsyncCallResult<u8>
    ) {
        match result {
            ManagedAsyncCallResult::Ok(value) => {
                sc_panic!("success {:x}", value);
            },
            ManagedAsyncCallResult::Err(err) => {
                sc_panic!("error {:x}", err.err_msg);
            }
        }
    }   

    /* Router address */
    #[storage_mapper("routerAddr")]
    fn routerAddr(&self) -> SingleValueMapper<ManagedAddress>;
}

The problem is that everytime i run the test transaction, i get mapped on error with err_msg the actual response.

This is the actual transaction i've made, you can see the panic is an error with 11 encoded as hex.

Anyone has any idea?

Executing details
Environment: devnet (but also reproductible on mainnet)
WASM Version: 0.31.1

I think WASM 0.32.0 is not yet out on mainnet or devnet. Have you tried using version 0.31.1?

yes still happens

Hello!
Thank you for reporting this. The fix is currently under development and a PR will be opened next week.