Trait bp_messages::target_chain::MessageDispatch
source · pub trait MessageDispatch {
type DispatchPayload: Decode;
type DispatchLevelResult: Clone + Debug + Eq;
type LaneId: Encode;
// Required methods
fn is_active(lane: Self::LaneId) -> bool;
fn dispatch_weight(
message: &mut DispatchMessage<Self::DispatchPayload, Self::LaneId>,
) -> Weight;
fn dispatch(
message: DispatchMessage<Self::DispatchPayload, Self::LaneId>,
) -> MessageDispatchResult<Self::DispatchLevelResult>;
}
Expand description
Called when inbound message is received.
Required Associated Types§
sourcetype DispatchPayload: Decode
type DispatchPayload: Decode
Decoded message payload type. Valid message may contain invalid payload. In this case
message is delivered, but dispatch fails. Therefore, two separate types of payload
(opaque MessagePayload
used in delivery and this DispatchPayload
used in dispatch).
sourcetype DispatchLevelResult: Clone + Debug + Eq
type DispatchLevelResult: Clone + Debug + Eq
Fine-grained result of single message dispatch (for better diagnostic purposes)
Required Methods§
sourcefn is_active(lane: Self::LaneId) -> bool
fn is_active(lane: Self::LaneId) -> bool
Returns true
if dispatcher is ready to accept additional messages. The false
should
be treated as a hint by both dispatcher and its consumers - i.e. dispatcher shall not
simply drop messages if it returns false
. The consumer may still call the dispatch
if dispatcher has returned false
.
We check it in the messages delivery transaction prologue. So if it becomes false
after some portion of messages is already dispatched, it doesn’t fail the whole transaction.
sourcefn dispatch_weight(
message: &mut DispatchMessage<Self::DispatchPayload, Self::LaneId>,
) -> Weight
fn dispatch_weight( message: &mut DispatchMessage<Self::DispatchPayload, Self::LaneId>, ) -> Weight
Estimate dispatch weight.
This function must return correct upper bound of dispatch weight. The return value
of this function is expected to match return value of the corresponding
From<Chain>InboundLaneApi::message_details().dispatch_weight
call.
sourcefn dispatch(
message: DispatchMessage<Self::DispatchPayload, Self::LaneId>,
) -> MessageDispatchResult<Self::DispatchLevelResult>
fn dispatch( message: DispatchMessage<Self::DispatchPayload, Self::LaneId>, ) -> MessageDispatchResult<Self::DispatchLevelResult>
Called when inbound message is received.
It is up to the implementers of this trait to determine whether the message is invalid (i.e. improperly encoded, has too large weight, …) or not.