3

As far as I know, contract calls are expensive because the called contract code must be loaded.

  1. What if I make 2 cross-contract calls in one function to the same smart contract? Is the contract code loaded two times?
  2. What if I make 2 cross-contract calls in one function to the two different smart contracts that share the same code_hash? For example, I call two different PSP22s.

1 Answer 1

2

The only really expensive part is loading the contract code because its size usually dominates every other storage access.

The costs of loading a contract code consists of two parts:

  1. Pulling the contract from storage into the runtime
  2. Delivering the contract code the the validator over the internet (only applies if pallet-contracts is deployed on a parachain).

Please note that the costs for 1 are theoretically reduced if you use the same code from the same pallet-contracts::call and the costs for 2 even when doing it within the same block.

However, we do not account for that right now. Due to the dynamic nature of weight tracking in pallet-contracts as opposed to simple pallets it would require additional work to make that happen: We would need to track which codes were accessed and then reduce the costs if they are loaded a second time. It is possible but it is just not happening right now.

Since we currently have no way to account for the costs of 2 we simulate it with ContractAccessWeight. We could reduce these costs if it happens in the same pallet-contracts:call in the same way as mentioned above. Tracking it per block is not in the cards right now.

2
  • " It is possible but it is just not happening right now." So basically in both case 1 & 2, 2 wasm blob are loaded from storage + delivered to network ? It was sure for 2. as a call to 300 flipper with same code hash increase the PoV size a lot but was not sure for 1. case
    – P.Ossun
    Aug 17, 2022 at 13:01
  • 1
    No. In case 1: Loaded from cache. In case 2: Only included once in the PoV. However, we don't track this and hence the costs are still incurred even though the work does not occur. Aug 17, 2022 at 13:31

Your Answer

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

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