1

Can two pallets have exactly same event name and event parameters. If yes then is there a way to distinguish the event came from which pallet in golang.

1

1 Answer 1

4

Yes, event name is superficial. What actually matters is how the pallet event is encoded into bytes.

Pallet events are encoded such that the first byte represents the pallet index, and the second byte represents the event index. Pallet index is determined by the ordering or explicit numbering in the construct_runtime! macro, and event index is determined by the ordering in the Event enum.

Here is a minimal example:

frame_support::construct_runtime!(
    pub enum Test where
        Block = Block,
        NodeBlock = Block,
        UncheckedExtrinsic = UncheckedExtrinsic,
    {
        System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
        Pallet1: pallet_example::<Instance1>,
        Pallet2: pallet_example::<Instance2>,
    }
);

You can see in this example, we are actually using the exact same pallet twice in our runtime via pallet instancing. Thus, these two pallet instances will have all of the exact same events, parameters, and even functions.

The way we distinguish these two, is that we also prepend the encoded bytes with the pallet index first.

So the second event (index 1) of Pallet1 will be encoded as 0x0101, whereas the same event in Pallet2 will be encoded as 0x0201.

The same can be said for extrinsics, errors, and other "aggregated" types.

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.