paritytech / parity-bridges-common

Collection of Useful Bridge Building Tools 🏗️
GNU General Public License v3.0
270 stars 129 forks source link

Make pallets XCM compatible + less configuration overhead #2457

Open svyatonik opened 2 years ago

svyatonik commented 2 years ago

We've removed a lot of code (#1638) because the architecture has been changed significantly. And now we have some options to make pallets configuration easier. That's a task for the future (after initial deployment), but I'm gonna leave some ideas here:

Things to do after refactoring:

svyatonik commented 1 year ago

Also see this comment: https://github.com/paritytech/parity-bridges-common/pull/1657#discussion_r1042998528

svyatonik commented 1 year ago

Future pallet_bridge_messages::Config (may be changed):

    #[pallet::config]
    pub trait Config<I: 'static = ()>: frame_system::Config {
        // General types

        /// The overarching event type.
        type RuntimeEvent: From<Event<Self, I>>
            + IsType<<Self as frame_system::Config>::RuntimeEvent>;
        /// Benchmarks results from runtime we're plugged into.
        type WeightInfo: WeightInfoExt;

        /// This chain type.
        type ThisChain: ChainWithMessages;
        /// Bridged chain type.
        type BridgedChain: ChainWithMessages;
        /// Bridged chain headers provider.
        type BridgedHeaderChain: HeaderChain<Self::BridgedChain>;

        /// Get all active outbound lanes that the message pallet is serving.
        type ActiveOutboundLanes: Get<&'static [LaneId]>;

        /// Payload type of outbound messages. This payload is dispatched on the bridged chain.
        type OutboundPayload: Parameter + Size;
        /// Payload type of inbound messages. This payload is dispatched on this chain.
        type InboundPayload: Decode;

        /// Handler for relayer payments that happen during message delivery transaction.
        type DeliveryPayments: DeliveryPayments<Self::AccountId>;
        /// Handler for relayer payments that happen during message delivery confirmation
        /// transaction.
        type DeliveryConfirmationPayments: DeliveryConfirmationPayments<Self::AccountId>;

        /// Message dispatch handler.
        type MessageDispatch: MessageDispatch<DispatchPayload = Self::InboundPayload>;
    }
}
svyatonik commented 1 year ago

The main part of this issue is fixed. I've decided to leave OutboundPayload + InboundPayload + MessageDispatch abstractions because at some point we may (?) start accepting messages, which are sent to bridge hub itself => we'll probably need to decode the encoded XCM BridgeMessage at bridge hub.

Regarding the first point (merging ChainId, LaneId and XCM locations) - let's think of that in context of paritytech/parity-bridges-common#2451. I'm not sure right now what's the best way to implement that

svyatonik commented 1 year ago

Working on paritytech/parity-bridges-common#2213, I think the best way would be to: 1) to avoid referencing XCM primitives from basic bridge pallets. Right now it'll be complicated, because we'll have a temptation to use some stuff from Cumulus, but we can't. So let's not use XCM stuff directly from the basic bridge pallets; 2) instead, let's add some abstractions to those pallets: 2.1) let's remove LaneId([u8; 4]) and make code generic over lane key. We'll use ordered (MultiLocation, MultiLocation) for that. See details in the paritytech/parity-bridges-common#2213 2.2) let's try to get rid of ChainId and either make code generic over this type. We'll use XCM NetworkId for that. Alternative may be using (don't know how, though) the Vec<u8> as chain ID.