I am writing a chain-extension that is a 1 to 1 map of a pallet. Based on this:
[...] charging the appropriate amount of weight. In order to do so benchmarks must be written and the charge_weight function must be called before carrying out any action that causes the consumption of the chargeable weight.
I wonder if you should charge weight before any call to the pallet:
let base_weight = <T as pallet_dapps_staking::Config>::WeightInfo::bond_and_stake(); env.charge_weight(base_weight)?; let call_result = pallet_dapps_staking::Pallet::<T>::bond_and_stake( RawOrigin::Signed(caller).into(), contract, value, );
Or if the weight will be charged in the pallet call anyway (and the above code might charge the weight two times).
Also as chain-extension exposes a
call function that can dispatch different pallet calls, how to ensure proper weight is handled to not excess max block weight ? basically the equivalent of
#[pallet::weight(T::WeightInfo::extrinsic())] for pallets.