3

I guess I have to make use of the utility.batch call but I am not sure how to pass the different anonymous proxy TXs in the batch call. I am also not sure of the use of the variable index in the anonymous call. Maybe it is there to distinguish the different anonymous proxy transactions?

1 Answer 1

7

The reason for the index in the anonymous call in pallet-proxy is exactly for the purposes of disambiguating multiple anonymous proxies in a single transaction.

It's because of the way that the proxies module deterministically generates account IDs for proxies: https://github.com/paritytech/substrate/blob/f98ef8abfc54bb7801b21be899e63f5058350e14/frame/proxy/src/lib.rs#L648-L664

    pub fn anonymous_account(
        who: &T::AccountId,
        proxy_type: &T::ProxyType,
        index: u16,
        maybe_when: Option<(T::BlockNumber, u32)>,
    ) -> T::AccountId {
        let (height, ext_index) = maybe_when.unwrap_or_else(|| {
            (
                system::Pallet::<T>::block_number(),
                system::Pallet::<T>::extrinsic_index().unwrap_or_default(),
            )
        });
        let entropy = (b"modlpy/proxy____", who, height, ext_index, proxy_type, index)
            .using_encoded(blake2_256);
        Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
            .expect("infinite length input; no invalid inputs for type; qed")
    }

As you can see, it takes the block height and current extrinsic index within the block as inputs. If this isn't within a batch call, then there's no need for disambiguation. However, if multiple calls to anonymous_account occur within the same extrinsic, they need a disambiguating input to the account ID generation function.

https://github.com/paritytech/substrate/blob/f98ef8abfc54bb7801b21be899e63f5058350e14/frame/proxy/src/lib.rs#L317

        pub fn anonymous(
            origin: OriginFor<T>,
            proxy_type: T::ProxyType,
            delay: T::BlockNumber,
            index: u16,
        ) -> DispatchResult {
            let who = ensure_signed(origin)?;

            let anonymous = Self::anonymous_account(&who, &proxy_type, index, None);

        // .. remainder omitted
        }

This is why fn anonymous accepts an index the user can use to avoid collisions in a batch.

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.