Fees, weights, message delivery and dispatch (#339)

* introduce BridgedHeaderChain trait

* LaneMessageVerifier + tests

* fixed tests

* do not expose intenal functions

* cargo fmt --all + fix no_std compilation

* ByWeightDispatcher

* process queued messages from message-lane::on_initialize

* scheduled_messages_are_processed_from_on_initialize

* flush

* deal with fees + weights

* drop heavy messages on dispatch

* cargo fmt

* clippy

* fix comment

* Update primitives/message-lane/src/source_chain.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* removed messages_processed

* Update primitives/message-lane/src/source_chain.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Update modules/message-lane/src/lib.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* remove queueing from message-lane

* also remove queueing from RPCs

* remove by-weight traces

* dispatch fee

* receiving -> delivery

* receival -> delivery

* remove extra line

* Update primitives/message-lane/src/source_chain.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* cargo fmt --all

* clippy

* let dispatch_weight to be larger than actual_dispatch_weight

* post-merge fix

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2020-09-25 22:22:44 +03:00
committed by Bastian Köcher
parent 44beb30836
commit 3cd8937b38
13 changed files with 799 additions and 141 deletions
@@ -16,12 +16,16 @@
//! Everything about incoming messages receival.
use bp_message_lane::{InboundLaneData, LaneId, Message, MessageKey, MessageNonce, OnMessageReceived};
use bp_message_lane::{
target_chain::MessageDispatch, InboundLaneData, LaneId, Message, MessageData, MessageKey, MessageNonce,
};
/// Inbound lane storage.
pub trait InboundLaneStorage {
/// Message payload.
type Payload;
/// Delivery and dispatch fee type on source chain.
type MessageFee;
/// Lane id.
fn id(&self) -> LaneId;
@@ -43,10 +47,10 @@ impl<S: InboundLaneStorage> InboundLane<S> {
}
/// Receive new message.
pub fn receive_message<P: OnMessageReceived<S::Payload>>(
pub fn receive_message<P: MessageDispatch<S::Payload, S::MessageFee>>(
&mut self,
nonce: MessageNonce,
payload: S::Payload,
message_data: MessageData<S::Payload, S::MessageFee>,
) -> bool {
let mut data = self.storage.data();
let is_correct_message = nonce == data.latest_received_nonce + 1;
@@ -57,12 +61,12 @@ impl<S: InboundLaneStorage> InboundLane<S> {
data.latest_received_nonce = nonce;
self.storage.set_data(data);
P::on_message_received(Message {
P::dispatch(Message {
key: MessageKey {
lane_id: self.storage.id(),
nonce,
},
payload,
data: message_data,
});
true
@@ -74,14 +78,14 @@ mod tests {
use super::*;
use crate::{
inbound_lane,
mock::{run_test, TestRuntime, REGULAR_PAYLOAD, TEST_LANE_ID},
mock::{message_data, run_test, TestMessageDispatch, TestRuntime, REGULAR_PAYLOAD, TEST_LANE_ID},
};
#[test]
fn fails_to_receive_message_with_incorrect_nonce() {
run_test(|| {
let mut lane = inbound_lane::<TestRuntime, _>(TEST_LANE_ID);
assert!(!lane.receive_message::<()>(10, REGULAR_PAYLOAD));
assert!(!lane.receive_message::<TestMessageDispatch>(10, message_data(REGULAR_PAYLOAD)));
assert_eq!(lane.storage.data().latest_received_nonce, 0);
});
}
@@ -90,7 +94,7 @@ mod tests {
fn correct_message_is_processed_instantly() {
run_test(|| {
let mut lane = inbound_lane::<TestRuntime, _>(TEST_LANE_ID);
assert!(lane.receive_message::<()>(1, REGULAR_PAYLOAD));
assert!(lane.receive_message::<TestMessageDispatch>(1, message_data(REGULAR_PAYLOAD)));
assert_eq!(lane.storage.data().latest_received_nonce, 1);
});
}