0

I have had two contracts (A, B), where contract a calls a function on contract b, when contract a is deployed. This works fine up to a certain point where I receive a contracts.ContractTrapped error (Usually after calling this function around 300-400 times)

When I redeploy contract B, with a new contractAddress, when I Initialize contract A with the new contractAddress, It obviously does work.

Also when I call the function that is called by contract A on contract B set_end_date I get the same contracts.contractTrapped error. So it is definitely an issue with contract B

That said I can read everything from contract B so it is not in the tombstone state!

This is the function being called on Contract B

     #[ink(message)]
    pub fn set_end_date(&mut self, end_date: u64) -> Result<()> {
        let caller = self.env().caller();
        self.end_date.insert(caller, end_date);
        Ok(())
    }

I really suspect this is an issue perhaps with the amount of storage a given key can have on the contracts pallet, but was curious if anyone else has had this issue and can point me in the right direction!

Follow up

I ran a loop to see when this issue starts happening and it happens at the 408th time the function on contract b (set_end_date) is being called. I strongly suspect that this is an issue for how much storage a mapping can contain on the contracts pallet, will keep you posted!

3
  • are you calling the function with different caller every time? Or what is the type of the end_date field?
    – kriko727
    Feb 23 at 9:31
  • @kriko727, I am not individually calling the set_end_date, rather I am deploying a smart contract, which in its constructor calls the set_end_date function. So the caller of the set_end_date is the deployed contract! That said I have after the fact also called it with various different accounts and this issue persists! the end_date field is as follows: end_date: BTreeMap<AccountId, u64>, Simply a mapping of an address to a timestamp!
    – BRNHINLT
    Feb 23 at 12:05
  • okay, so you deploy a contract, the contract calls B::set_end_date right? And you deploy 408 contracts, is that correct?
    – kriko727
    Feb 23 at 15:54

2 Answers 2

1

It is indeed an issue with the storage, as the BTreeMap is a Packed struct, therefore being contained within one cell (see doc: https://use.ink/datastructures/mapping)

1
  • Thanks Kriko, It was indeed this, made my week!
    – BRNHINLT
    Feb 27 at 13:28
-1

Contract Trapped During Exucution error while cross-contract calling issue occur because I guess you haven't instantiated contract which you are calling. I have produced this error why contracts.ContractTrapped issue occurs and also solve it. you can view this code example here and you can also docs of this contract here

4
  • Thanks for the response! but I don't think this is the case, I am correctly calling the contract B when contract A is being deployed. I actually just ran some tests on how many times contract a calls the function b before there is an error, and it happens on the 408th time the function is called. I will leave a more in depth follow up above!
    – BRNHINLT
    Feb 22 at 15:26
  • if possible can you please send code link?
    – Ganesh11
    Feb 22 at 15:34
  • Thank you guys, But the issue was me using BTreeMap!
    – BRNHINLT
    Feb 27 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.