Fix delivery transaction estimation used by rational relayer (#1109)

* fix delivery transaction estimation in greedy relayer

* fixed typo

* improve logging

* improve logging

* fmt

* fix compilation

* fmt

* Update relays/lib-substrate-relay/src/messages_target.rs

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

* review

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2021-09-06 12:04:33 +03:00
committed by Bastian Köcher
parent 2101ed9cc5
commit 03a54df398
35 changed files with 391 additions and 71 deletions
@@ -7,13 +7,17 @@ edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
smallvec = "1.6"
# Bridge Dependencies
bp-messages = { path = "../messages", default-features = false }
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
bp-runtime = { path = "../runtime", default-features = false }
# Substrate Based Dependencies
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" , default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -23,6 +27,7 @@ std = [
"bp-messages/std",
"bp-polkadot-core/std",
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-std/std",
]
@@ -21,6 +21,7 @@
#![allow(clippy::unnecessary_mut_passed)]
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
use frame_support::weights::{WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial};
use sp_std::prelude::*;
pub use bp_polkadot_core::*;
@@ -28,6 +29,24 @@ pub use bp_polkadot_core::*;
/// Kusama Chain
pub type Kusama = PolkadotLike;
// NOTE: This needs to be kept up to date with the Kusama runtime found in the Polkadot repo.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
const CENTS: Balance = 1_000_000_000_000 / 30_000;
// in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
smallvec::smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::from_rational(p % q, q),
coeff_integer: p / q,
}]
}
}
// We use this to get the account on Kusama (target) which is derived from Polkadot's (source)
// account.
pub fn derive_account_from_polkadot_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId {