Use real weights to compute message delivery and dispatch fee (#598)

* message fee formula

* update GetDelvieryConfirmationTransactionFee

* include cost of transactions (i.e. not only dispatch cost) in delivery_and_dispatch_fee

* endow relayers fund account

* include db ops weight in max tx weight estimation

* (in bytes)

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
This commit is contained in:
Svyatoslav Nikolsky
2021-01-21 12:35:04 +03:00
committed by Bastian Köcher
parent fd7f2a45d8
commit 0f56f18778
16 changed files with 263 additions and 50 deletions
+5 -2
View File
@@ -326,16 +326,19 @@ decl_module! {
// finally, save message in outbound storage and emit event
let mut lane = outbound_lane::<T, I>(lane_id);
let encoded_payload = payload.encode();
let encoded_payload_len = encoded_payload.len();
let nonce = lane.send_message(MessageData {
payload: payload.encode(),
payload: encoded_payload,
fee: delivery_and_dispatch_fee,
});
lane.prune_messages(T::MaxMessagesToPruneAtOnce::get());
frame_support::debug::trace!(
"Accepted message {} to lane {:?}",
"Accepted message {} to lane {:?}. Message size: {:?}",
nonce,
lane_id,
encoded_payload_len,
);
Self::deposit_event(RawEvent::MessageAccepted(lane_id, nonce));
@@ -22,7 +22,10 @@ use bp_message_lane::MessageNonce;
use frame_support::weights::Weight;
/// Ensure that weights from `WeightInfoExt` implementation are looking correct.
pub fn ensure_weights_are_correct<W: WeightInfoExt>() {
pub fn ensure_weights_are_correct<W: WeightInfoExt>(
expected_max_single_message_delivery_tx_weight: Weight,
expected_max_messages_delivery_tx_weight: Weight,
) {
assert_ne!(W::send_message_overhead(), 0);
assert_ne!(W::send_message_size_overhead(0), 0);
@@ -30,9 +33,33 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>() {
assert_ne!(W::receive_messages_proof_messages_overhead(1), 0);
assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), 0);
let actual_max_single_message_delivery_tx_weight = W::receive_messages_proof_overhead()
.checked_add(W::receive_messages_proof_messages_overhead(1))
.expect("weights are too large")
.checked_add(W::receive_messages_proof_outbound_lane_state_overhead())
.expect("weights are too large");
assert!(
actual_max_single_message_delivery_tx_weight <= expected_max_single_message_delivery_tx_weight,
"Single message delivery transaction weight {} is larger than expected weight {}",
actual_max_single_message_delivery_tx_weight,
expected_max_single_message_delivery_tx_weight,
);
assert_ne!(W::receive_messages_delivery_proof_overhead(), 0);
assert_ne!(W::receive_messages_delivery_proof_messages_overhead(1), 0);
assert_ne!(W::receive_messages_delivery_proof_relayers_overhead(1), 0);
let actual_max_messages_delivery_tx_weight = W::receive_messages_delivery_proof_overhead()
.checked_add(W::receive_messages_delivery_proof_messages_overhead(1))
.expect("weights are too large")
.checked_add(W::receive_messages_delivery_proof_relayers_overhead(1))
.expect("weights are too large");
assert!(
actual_max_messages_delivery_tx_weight <= expected_max_messages_delivery_tx_weight,
"Messages delivery confirmation transaction weight {} is larger than expected weight {}",
actual_max_messages_delivery_tx_weight,
expected_max_messages_delivery_tx_weight,
);
}
/// Extended weight info.