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

Identical calls executing instantiation of a sub contract fail if made from a message call, succeed from another constructor #740

Closed
vminkov opened this issue Mar 19, 2021 · 9 comments

Comments

@vminkov
Copy link

vminkov commented Mar 19, 2021

Using ink! 3.0.0-rc3 , it always results in ContractTrapped when trying to instantiate a contract (like the delegator example) from an #[ink(message)] call. The same exact code succeeds when attempted to instantiate from a constructor.
Different salt is used every time, increased block size and weight - it still says ContractTrapped with no details for the error.

I am attaching a repo that reproduces the case with Mocha (polkadot.js) test cases.

https://github.com/vminkov/ink-substrate-issue

vminkov added a commit to vminkov/ink-substrate-issue that referenced this issue Mar 19, 2021
@vminkov
Copy link
Author

vminkov commented Mar 24, 2021

found the problem, deploy() needs to be payable

@vminkov vminkov closed this as completed Mar 24, 2021
@forgetso
Copy link
Contributor

forgetso commented Sep 15, 2021

function_name() needs to be payable

This should be the error message instead of ContractTrapped!

For those finding this, add the payable decorator to your function.

        #[ink(message)]
        #[ink(payable)]
        pub fn function_name(&mut self) {

@cmichi
Copy link
Collaborator

cmichi commented Sep 23, 2021

@forgetso I looked into this issue and payable is not actually required. If you have some sample contract I could look into why the contract fails. In general I would recommend running your node with --tmp --dev -lerror,runtime::contracts=debug. This way you would e.g. see output like panicked at 'failed at instantiating the new sub contract: CodeNotFound' on the console for the ink! message (no output is currently shown for constructors).

@vminkov I got your ink-substrate-issue contract to work with the latest ink! rc5 an initial endowment of 10000. Maybe the issue was fixed in ink! in the meantime?

@forgetso
Copy link
Contributor

forgetso commented Oct 29, 2021

Thanks for investigating @cmichi. I'm running into this issue again and I'm using the contracts node with substrate-contracts-node --dev --tmp --unsafe-ws-external --rpc-cors all --ws-port=9944 -lerror,runtime::contracts=debug but I don't get anything printed at all. The ink! function I'm calling has lines like ink_env::debug_println!("{:?}", caller);. Any thoughts on why nothing appears in the terminal?

I've actually created an issue for this in the contracts node repo: paritytech/substrate-contracts-node#13

@forgetso
Copy link
Contributor

Hi @cmichi , I've found a reproducible example of ContractTrapped appearing when payable is not added as a decorator.

If you take this repos contract: https://github.com/prosopo-io/protocol/blob/master/contracts/lib.rs

And remove the payable function from this function:

        // Stake and activate the provider's service
        #[ink(message)]
        #[ink(payable)]
        pub fn provider_stake(&mut self) -> Result<(), ProsopoError> {

You get ContractTrapped. Add it back in and it works fine.

Reproducing this requires a fair amount of cloning repos and setup. The instructions are included in the readme here.

rustup --version
rustup 1.24.3 (ce5817a94 2021-05-31)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.56.1 (59eed8a2a 2021-11-01)`

@xgreenx
Copy link
Collaborator

xgreenx commented Nov 18, 2021

@forgetso This function requires the user to send the native token to it. If you send tokens to function without payable decorate, you will get contract trapped(or in case of debug mode you will see an error PaidUnpayableMessage about the reason for the trap). So it is expected=)

image

@forgetso
Copy link
Contributor

Ok, well that's good to know. I'm still building in release mode due to the contract size. I will change my node so that I can deploy the full size contract and get these more helpful messages!

@xgreenx
Copy link
Collaborator

xgreenx commented Nov 18, 2021

Ok, well that's good to know. I'm still building in release mode due to the contract size. I will change my node so that I can deploy the full size contract and get these more helpful messages!

I suggest you comment empty functions and start to use ink_storage::lazy::Mapping instead of InkHashMap=)

@forgetso
Copy link
Contributor

I thought Mapping was still a work in progress. Nice to hear it's available. Thanks for all the tips!

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

No branches or pull requests

4 participants