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
+6 -1
View File
@@ -15,7 +15,7 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
use bp_runtime::Chain as ChainBase;
use frame_support::Parameter;
use frame_support::{weights::WeightToFeePolynomial, Parameter};
use jsonrpsee_ws_client::{DeserializeOwned, Serialize};
use num_traits::{Bounded, CheckedSub, SaturatingAdd, Zero};
use sp_core::{storage::StorageKey, Pair};
@@ -77,12 +77,17 @@ pub trait Chain: ChainBase + Clone {
+ SaturatingAdd
+ Zero
+ std::convert::TryFrom<sp_core::U256>;
/// Type that is used by the chain, to convert from weight to fee.
type WeightToFee: WeightToFeePolynomial<Balance = Self::Balance>;
}
/// Balance type used by the chain
pub type BalanceOf<C> = <C as Chain>::Balance;
/// Index type used by the chain
pub type IndexOf<C> = <C as Chain>::Index;
/// Weight-to-Fee type used by the chain
pub type WeightToFeeOf<C> = <C as Chain>::WeightToFee;
/// Substrate-based chain with `frame_system::Config::AccountData` set to
/// the `pallet_balances::AccountData<Balance>`.
+13 -12
View File
@@ -310,23 +310,24 @@ impl<C: Chain> Client<C> {
}
/// Estimate fee that will be spent on given extrinsic.
pub async fn estimate_extrinsic_fee(&self, transaction: Bytes) -> Result<C::Balance> {
pub async fn estimate_extrinsic_fee(&self, transaction: Bytes) -> Result<InclusionFee<C::Balance>> {
self.jsonrpsee_execute(move |client| async move {
let fee_details = Substrate::<C>::payment_query_fee_details(&*client, transaction, None).await?;
let inclusion_fee = fee_details
.inclusion_fee
.map(|inclusion_fee| {
InclusionFee {
base_fee: C::Balance::try_from(inclusion_fee.base_fee.into_u256())
.unwrap_or_else(|_| C::Balance::max_value()),
len_fee: C::Balance::try_from(inclusion_fee.len_fee.into_u256())
.unwrap_or_else(|_| C::Balance::max_value()),
adjusted_weight_fee: C::Balance::try_from(inclusion_fee.adjusted_weight_fee.into_u256())
.unwrap_or_else(|_| C::Balance::max_value()),
}
.inclusion_fee()
.map(|inclusion_fee| InclusionFee {
base_fee: C::Balance::try_from(inclusion_fee.base_fee.into_u256())
.unwrap_or_else(|_| C::Balance::max_value()),
len_fee: C::Balance::try_from(inclusion_fee.len_fee.into_u256())
.unwrap_or_else(|_| C::Balance::max_value()),
adjusted_weight_fee: C::Balance::try_from(inclusion_fee.adjusted_weight_fee.into_u256())
.unwrap_or_else(|_| C::Balance::max_value()),
})
.unwrap_or_else(Zero::zero);
.unwrap_or_else(|| InclusionFee {
base_fee: Zero::zero(),
len_fee: Zero::zero(),
adjusted_weight_fee: Zero::zero(),
});
Ok(inclusion_fee)
})
.await
@@ -194,6 +194,7 @@ mod tests {
sp_runtime::generic::SignedBlock<sp_runtime::generic::Block<Self::Header, sp_runtime::OpaqueExtrinsic>>;
type Call = ();
type Balance = u32;
type WeightToFee = frame_support::weights::IdentityFee<u32>;
}
impl ChainWithBalances for TestChain {
+3 -1
View File
@@ -31,7 +31,9 @@ pub mod metrics;
use std::time::Duration;
pub use crate::chain::{BalanceOf, BlockWithJustification, Chain, ChainWithBalances, IndexOf, TransactionSignScheme};
pub use crate::chain::{
BalanceOf, BlockWithJustification, Chain, ChainWithBalances, IndexOf, TransactionSignScheme, WeightToFeeOf,
};
pub use crate::client::{Client, JustificationsSubscription, OpaqueGrandpaAuthoritiesSet};
pub use crate::error::{Error, Result};
pub use crate::sync_header::SyncHeader;