mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +00:00
override conversion rate in estimate-message-fee RPC (#1189)
This commit is contained in:
committed by
Bastian Köcher
parent
22b1e456ab
commit
741484214e
@@ -52,7 +52,7 @@ use sp_runtime::{
|
|||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
|
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
|
||||||
transaction_validity::{TransactionSource, TransactionValidity},
|
transaction_validity::{TransactionSource, TransactionValidity},
|
||||||
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
|
ApplyExtrinsicResult, FixedPointNumber, FixedU128, MultiSignature, MultiSigner, Perquintill,
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -744,10 +744,12 @@ impl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
_lane_id: bp_messages::LaneId,
|
_lane_id: bp_messages::LaneId,
|
||||||
payload: ToRialtoMessagePayload,
|
payload: ToRialtoMessagePayload,
|
||||||
|
rialto_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<Balance> {
|
) -> Option<Balance> {
|
||||||
estimate_message_dispatch_and_delivery_fee::<WithRialtoMessageBridge>(
|
estimate_message_dispatch_and_delivery_fee::<WithRialtoMessageBridge>(
|
||||||
&payload,
|
&payload,
|
||||||
WithRialtoMessageBridge::RELAYER_FEE_PERCENT,
|
WithRialtoMessageBridge::RELAYER_FEE_PERCENT,
|
||||||
|
rialto_to_this_conversion_rate,
|
||||||
).ok()
|
).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,10 +91,13 @@ impl MessageBridge for WithRialtoMessageBridge {
|
|||||||
type ThisChain = Millau;
|
type ThisChain = Millau;
|
||||||
type BridgedChain = Rialto;
|
type BridgedChain = Rialto;
|
||||||
|
|
||||||
fn bridged_balance_to_this_balance(bridged_balance: bp_rialto::Balance) -> bp_millau::Balance {
|
fn bridged_balance_to_this_balance(
|
||||||
bp_millau::Balance::try_from(
|
bridged_balance: bp_rialto::Balance,
|
||||||
RialtoToMillauConversionRate::get().saturating_mul_int(bridged_balance),
|
bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||||
)
|
) -> bp_millau::Balance {
|
||||||
|
let conversion_rate = bridged_to_this_conversion_rate_override
|
||||||
|
.unwrap_or_else(|| RialtoToMillauConversionRate::get());
|
||||||
|
bp_millau::Balance::try_from(conversion_rate.saturating_mul_int(bridged_balance))
|
||||||
.unwrap_or(bp_millau::Balance::MAX)
|
.unwrap_or(bp_millau::Balance::MAX)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ use sp_runtime::{
|
|||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
traits::{AccountIdLookup, Block as BlockT, Keccak256, NumberFor, OpaqueKeys},
|
traits::{AccountIdLookup, Block as BlockT, Keccak256, NumberFor, OpaqueKeys},
|
||||||
transaction_validity::{TransactionSource, TransactionValidity},
|
transaction_validity::{TransactionSource, TransactionValidity},
|
||||||
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
|
ApplyExtrinsicResult, FixedPointNumber, FixedU128, MultiSignature, MultiSigner, Perquintill,
|
||||||
};
|
};
|
||||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -892,10 +892,12 @@ impl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
_lane_id: bp_messages::LaneId,
|
_lane_id: bp_messages::LaneId,
|
||||||
payload: ToMillauMessagePayload,
|
payload: ToMillauMessagePayload,
|
||||||
|
millau_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<Balance> {
|
) -> Option<Balance> {
|
||||||
estimate_message_dispatch_and_delivery_fee::<WithMillauMessageBridge>(
|
estimate_message_dispatch_and_delivery_fee::<WithMillauMessageBridge>(
|
||||||
&payload,
|
&payload,
|
||||||
WithMillauMessageBridge::RELAYER_FEE_PERCENT,
|
WithMillauMessageBridge::RELAYER_FEE_PERCENT,
|
||||||
|
millau_to_this_conversion_rate,
|
||||||
).ok()
|
).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,10 +91,13 @@ impl MessageBridge for WithMillauMessageBridge {
|
|||||||
type ThisChain = Rialto;
|
type ThisChain = Rialto;
|
||||||
type BridgedChain = Millau;
|
type BridgedChain = Millau;
|
||||||
|
|
||||||
fn bridged_balance_to_this_balance(bridged_balance: bp_millau::Balance) -> bp_rialto::Balance {
|
fn bridged_balance_to_this_balance(
|
||||||
bp_rialto::Balance::try_from(
|
bridged_balance: bp_millau::Balance,
|
||||||
MillauToRialtoConversionRate::get().saturating_mul_int(bridged_balance),
|
bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||||
)
|
) -> bp_rialto::Balance {
|
||||||
|
let conversion_rate = bridged_to_this_conversion_rate_override
|
||||||
|
.unwrap_or_else(|| MillauToRialtoConversionRate::get());
|
||||||
|
bp_rialto::Balance::try_from(conversion_rate.saturating_mul_int(bridged_balance))
|
||||||
.unwrap_or(bp_rialto::Balance::MAX)
|
.unwrap_or(bp_rialto::Balance::MAX)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ pub trait MessageBridge {
|
|||||||
/// Convert Bridged chain balance into This chain balance.
|
/// Convert Bridged chain balance into This chain balance.
|
||||||
fn bridged_balance_to_this_balance(
|
fn bridged_balance_to_this_balance(
|
||||||
bridged_balance: BalanceOf<BridgedChain<Self>>,
|
bridged_balance: BalanceOf<BridgedChain<Self>>,
|
||||||
|
bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||||
) -> BalanceOf<ThisChain<Self>>;
|
) -> BalanceOf<ThisChain<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,8 +317,11 @@ pub mod source {
|
|||||||
pallet_bridge_dispatch::verify_message_origin(submitter, payload)
|
pallet_bridge_dispatch::verify_message_origin(submitter, payload)
|
||||||
.map_err(|_| BAD_ORIGIN)?;
|
.map_err(|_| BAD_ORIGIN)?;
|
||||||
|
|
||||||
let minimal_fee_in_this_tokens =
|
let minimal_fee_in_this_tokens = estimate_message_dispatch_and_delivery_fee::<B>(
|
||||||
estimate_message_dispatch_and_delivery_fee::<B>(payload, B::RELAYER_FEE_PERCENT)?;
|
payload,
|
||||||
|
B::RELAYER_FEE_PERCENT,
|
||||||
|
None,
|
||||||
|
)?;
|
||||||
|
|
||||||
// compare with actual fee paid
|
// compare with actual fee paid
|
||||||
if *delivery_and_dispatch_fee < minimal_fee_in_this_tokens {
|
if *delivery_and_dispatch_fee < minimal_fee_in_this_tokens {
|
||||||
@@ -371,6 +375,7 @@ pub mod source {
|
|||||||
pub fn estimate_message_dispatch_and_delivery_fee<B: MessageBridge>(
|
pub fn estimate_message_dispatch_and_delivery_fee<B: MessageBridge>(
|
||||||
payload: &FromThisChainMessagePayload<B>,
|
payload: &FromThisChainMessagePayload<B>,
|
||||||
relayer_fee_percent: u32,
|
relayer_fee_percent: u32,
|
||||||
|
bridged_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Result<BalanceOf<ThisChain<B>>, &'static str> {
|
) -> Result<BalanceOf<ThisChain<B>>, &'static str> {
|
||||||
// the fee (in Bridged tokens) of all transactions that are made on the Bridged chain
|
// the fee (in Bridged tokens) of all transactions that are made on the Bridged chain
|
||||||
//
|
//
|
||||||
@@ -391,7 +396,10 @@ pub mod source {
|
|||||||
ThisChain::<B>::transaction_payment(confirmation_transaction);
|
ThisChain::<B>::transaction_payment(confirmation_transaction);
|
||||||
|
|
||||||
// minimal fee (in This tokens) is a sum of all required fees
|
// minimal fee (in This tokens) is a sum of all required fees
|
||||||
let minimal_fee = B::bridged_balance_to_this_balance(delivery_transaction_fee)
|
let minimal_fee = B::bridged_balance_to_this_balance(
|
||||||
|
delivery_transaction_fee,
|
||||||
|
bridged_to_this_conversion_rate,
|
||||||
|
)
|
||||||
.checked_add(&confirmation_transaction_fee);
|
.checked_add(&confirmation_transaction_fee);
|
||||||
|
|
||||||
// before returning, add extra fee that is paid to the relayer (relayer interest)
|
// before returning, add extra fee that is paid to the relayer (relayer interest)
|
||||||
@@ -798,8 +806,12 @@ mod tests {
|
|||||||
|
|
||||||
fn bridged_balance_to_this_balance(
|
fn bridged_balance_to_this_balance(
|
||||||
bridged_balance: BridgedChainBalance,
|
bridged_balance: BridgedChainBalance,
|
||||||
|
bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||||
) -> ThisChainBalance {
|
) -> ThisChainBalance {
|
||||||
ThisChainBalance(bridged_balance.0 * BRIDGED_CHAIN_TO_THIS_CHAIN_BALANCE_RATE as u32)
|
let conversion_rate = bridged_to_this_conversion_rate_override
|
||||||
|
.map(|r| r.to_float() as u32)
|
||||||
|
.unwrap_or(BRIDGED_CHAIN_TO_THIS_CHAIN_BALANCE_RATE);
|
||||||
|
ThisChainBalance(bridged_balance.0 * conversion_rate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,7 +829,10 @@ mod tests {
|
|||||||
type ThisChain = BridgedChain;
|
type ThisChain = BridgedChain;
|
||||||
type BridgedChain = ThisChain;
|
type BridgedChain = ThisChain;
|
||||||
|
|
||||||
fn bridged_balance_to_this_balance(_this_balance: ThisChainBalance) -> BridgedChainBalance {
|
fn bridged_balance_to_this_balance(
|
||||||
|
_this_balance: ThisChainBalance,
|
||||||
|
_bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||||
|
) -> BridgedChainBalance {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1095,6 +1110,7 @@ mod tests {
|
|||||||
source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
|
source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
|
||||||
&payload,
|
&payload,
|
||||||
OnThisChainBridge::RELAYER_FEE_PERCENT,
|
OnThisChainBridge::RELAYER_FEE_PERCENT,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
Ok(ThisChainBalance(EXPECTED_MINIMAL_FEE)),
|
Ok(ThisChainBalance(EXPECTED_MINIMAL_FEE)),
|
||||||
);
|
);
|
||||||
@@ -1106,6 +1122,7 @@ mod tests {
|
|||||||
source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
|
source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
|
||||||
&payload_with_pay_on_target,
|
&payload_with_pay_on_target,
|
||||||
OnThisChainBridge::RELAYER_FEE_PERCENT,
|
OnThisChainBridge::RELAYER_FEE_PERCENT,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.expect(
|
.expect(
|
||||||
"estimate_message_dispatch_and_delivery_fee failed for pay-at-target-chain message",
|
"estimate_message_dispatch_and_delivery_fee failed for pay-at-target-chain message",
|
||||||
@@ -1572,4 +1589,21 @@ mod tests {
|
|||||||
100 + 50 * 10 + 777,
|
100 + 50 * 10 + 777,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn conversion_rate_override_works() {
|
||||||
|
let payload = regular_outbound_message_payload();
|
||||||
|
let regular_fee = source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
|
||||||
|
&payload,
|
||||||
|
OnThisChainBridge::RELAYER_FEE_PERCENT,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
let overrided_fee = source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
|
||||||
|
&payload,
|
||||||
|
OnThisChainBridge::RELAYER_FEE_PERCENT,
|
||||||
|
Some(FixedU128::from_float((BRIDGED_CHAIN_TO_THIS_CHAIN_BALANCE_RATE * 2) as f64)),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(regular_fee < overrided_fee);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ bp-runtime = { path = "../runtime", default-features = false }
|
|||||||
|
|
||||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
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-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ std = [
|
|||||||
"bp-runtime/std",
|
"bp-runtime/std",
|
||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
"sp-api/std",
|
"sp-api/std",
|
||||||
|
"sp-runtime/std",
|
||||||
"sp-std/std",
|
"sp-std/std",
|
||||||
"sp-version/std",
|
"sp-version/std",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}
|
|||||||
use frame_support::weights::{
|
use frame_support::weights::{
|
||||||
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
||||||
};
|
};
|
||||||
|
use sp_runtime::FixedU128;
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use sp_version::RuntimeVersion;
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ sp_api::decl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: OutboundPayload,
|
payload: OutboundPayload,
|
||||||
|
kusama_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<OutboundMessageFee>;
|
) -> Option<OutboundMessageFee>;
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
||||||
/// messages in given inclusive range.
|
/// messages in given inclusive range.
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use scale_info::TypeInfo;
|
|||||||
use sp_core::Hasher as HasherT;
|
use sp_core::Hasher as HasherT;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{Convert, IdentifyAccount, Verify},
|
traits::{Convert, IdentifyAccount, Verify},
|
||||||
MultiSignature, MultiSigner, Perbill,
|
FixedU128, MultiSignature, MultiSigner, Perbill,
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use sp_trie::{trie_types::Layout, TrieConfiguration};
|
use sp_trie::{trie_types::Layout, TrieConfiguration};
|
||||||
@@ -319,6 +319,7 @@ sp_api::decl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: OutboundPayload,
|
payload: OutboundPayload,
|
||||||
|
millau_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<OutboundMessageFee>;
|
) -> Option<OutboundMessageFee>;
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
||||||
/// messages in given inclusive range.
|
/// messages in given inclusive range.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ bp-runtime = { path = "../runtime", default-features = false }
|
|||||||
|
|
||||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
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-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
|
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ std = [
|
|||||||
"bp-runtime/std",
|
"bp-runtime/std",
|
||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
"sp-api/std",
|
"sp-api/std",
|
||||||
|
"sp-runtime/std",
|
||||||
"sp-std/std",
|
"sp-std/std",
|
||||||
"sp-version/std",
|
"sp-version/std",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}
|
|||||||
use frame_support::weights::{
|
use frame_support::weights::{
|
||||||
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
||||||
};
|
};
|
||||||
|
use sp_runtime::FixedU128;
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use sp_version::RuntimeVersion;
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ sp_api::decl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: OutboundPayload,
|
payload: OutboundPayload,
|
||||||
|
polkadot_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<OutboundMessageFee>;
|
) -> Option<OutboundMessageFee>;
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
||||||
/// messages in given inclusive range.
|
/// messages in given inclusive range.
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use frame_system::limits;
|
|||||||
use sp_core::Hasher as HasherT;
|
use sp_core::Hasher as HasherT;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{BlakeTwo256, Convert, IdentifyAccount, Verify},
|
traits::{BlakeTwo256, Convert, IdentifyAccount, Verify},
|
||||||
MultiSignature, MultiSigner, Perbill,
|
FixedU128, MultiSignature, MultiSigner, Perbill,
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
|
|
||||||
@@ -291,6 +291,7 @@ sp_api::decl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: OutboundPayload,
|
payload: OutboundPayload,
|
||||||
|
rialto_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<OutboundMessageFee>;
|
) -> Option<OutboundMessageFee>;
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
||||||
/// messages in given inclusive range.
|
/// messages in given inclusive range.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}
|
|||||||
use frame_support::weights::{
|
use frame_support::weights::{
|
||||||
Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
||||||
};
|
};
|
||||||
|
use sp_runtime::FixedU128;
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
use sp_version::RuntimeVersion;
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
@@ -142,6 +143,7 @@ sp_api::decl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: OutboundPayload,
|
payload: OutboundPayload,
|
||||||
|
rococo_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<OutboundMessageFee>;
|
) -> Option<OutboundMessageFee>;
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
||||||
/// messages in given inclusive range.
|
/// messages in given inclusive range.
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ smallvec = "1.7"
|
|||||||
# Bridge Dependencies
|
# Bridge Dependencies
|
||||||
|
|
||||||
bp-header-chain = { path = "../header-chain", default-features = false }
|
bp-header-chain = { path = "../header-chain", default-features = false }
|
||||||
bp-messages = { path = "../messages", default-features = false }
|
|
||||||
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
|
bp-polkadot-core = { path = "../polkadot-core", default-features = false }
|
||||||
bp-runtime = { path = "../runtime", default-features = false }
|
bp-runtime = { path = "../runtime", default-features = false }
|
||||||
|
|
||||||
@@ -30,7 +29,6 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master
|
|||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = [
|
std = [
|
||||||
"bp-header-chain/std",
|
"bp-header-chain/std",
|
||||||
"bp-messages/std",
|
|
||||||
"bp-polkadot-core/std",
|
"bp-polkadot-core/std",
|
||||||
"bp-runtime/std",
|
"bp-runtime/std",
|
||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
|
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
|
||||||
#![allow(clippy::unnecessary_mut_passed)]
|
#![allow(clippy::unnecessary_mut_passed)]
|
||||||
|
|
||||||
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
|
|
||||||
use frame_support::weights::{
|
use frame_support::weights::{
|
||||||
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
|
||||||
};
|
};
|
||||||
@@ -130,51 +129,4 @@ sp_api::decl_runtime_apis! {
|
|||||||
/// Returns number and hash of the best finalized header known to the bridge module.
|
/// Returns number and hash of the best finalized header known to the bridge module.
|
||||||
fn best_finalized() -> (BlockNumber, Hash);
|
fn best_finalized() -> (BlockNumber, Hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Outbound message lane API for messages that are sent to Westend chain.
|
|
||||||
///
|
|
||||||
/// This API is implemented by runtimes that are sending messages to Westend chain, not the
|
|
||||||
/// Westend runtime itself.
|
|
||||||
pub trait ToWestendOutboundLaneApi<OutboundMessageFee: Parameter, OutboundPayload: Parameter> {
|
|
||||||
/// Estimate message delivery and dispatch fee that needs to be paid by the sender on
|
|
||||||
/// this chain.
|
|
||||||
///
|
|
||||||
/// Returns `None` if message is too expensive to be sent to Westend from this chain.
|
|
||||||
///
|
|
||||||
/// Please keep in mind that this method returns the lowest message fee required for message
|
|
||||||
/// to be accepted to the lane. It may be good idea to pay a bit over this price to account
|
|
||||||
/// future exchange rate changes and guarantee that relayer would deliver your message
|
|
||||||
/// to the target chain.
|
|
||||||
fn estimate_message_delivery_and_dispatch_fee(
|
|
||||||
lane_id: LaneId,
|
|
||||||
payload: OutboundPayload,
|
|
||||||
) -> Option<OutboundMessageFee>;
|
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
|
||||||
/// messages in given inclusive range.
|
|
||||||
///
|
|
||||||
/// If some (or all) messages are missing from the storage, they'll also will
|
|
||||||
/// be missing from the resulting vector. The vector is ordered by the nonce.
|
|
||||||
fn message_details(
|
|
||||||
lane: LaneId,
|
|
||||||
begin: MessageNonce,
|
|
||||||
end: MessageNonce,
|
|
||||||
) -> Vec<MessageDetails<OutboundMessageFee>>;
|
|
||||||
/// Returns nonce of the latest message, received by bridged chain.
|
|
||||||
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
|
|
||||||
/// Returns nonce of the latest message, generated by given lane.
|
|
||||||
fn latest_generated_nonce(lane: LaneId) -> MessageNonce;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Inbound message lane API for messages sent by Westend chain.
|
|
||||||
///
|
|
||||||
/// This API is implemented by runtimes that are receiving messages from Westend chain, not the
|
|
||||||
/// Westend runtime itself.
|
|
||||||
pub trait FromWestendInboundLaneApi {
|
|
||||||
/// Returns nonce of the latest message, received by given lane.
|
|
||||||
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
|
|
||||||
/// Nonce of the latest message that has been confirmed to the bridged chain.
|
|
||||||
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
|
|
||||||
/// State of the unrewarded relayers set at given lane.
|
|
||||||
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#![allow(clippy::unnecessary_mut_passed)]
|
#![allow(clippy::unnecessary_mut_passed)]
|
||||||
|
|
||||||
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
|
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
|
||||||
|
use sp_runtime::FixedU128;
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
|
|
||||||
pub use bp_polkadot_core::*;
|
pub use bp_polkadot_core::*;
|
||||||
@@ -95,6 +96,7 @@ sp_api::decl_runtime_apis! {
|
|||||||
fn estimate_message_delivery_and_dispatch_fee(
|
fn estimate_message_delivery_and_dispatch_fee(
|
||||||
lane_id: LaneId,
|
lane_id: LaneId,
|
||||||
payload: OutboundPayload,
|
payload: OutboundPayload,
|
||||||
|
wococo_to_this_conversion_rate: Option<FixedU128>,
|
||||||
) -> Option<OutboundMessageFee>;
|
) -> Option<OutboundMessageFee>;
|
||||||
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
|
||||||
/// messages in given inclusive range.
|
/// messages in given inclusive range.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use crate::{
|
|||||||
use bp_runtime::BalanceOf;
|
use bp_runtime::BalanceOf;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use relay_substrate_client::Chain;
|
use relay_substrate_client::Chain;
|
||||||
|
use sp_runtime::FixedU128;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use strum::VariantNames;
|
use strum::VariantNames;
|
||||||
|
|
||||||
@@ -72,8 +73,13 @@ pub(crate) async fn estimate_message_delivery_and_dispatch_fee<Fee: Decode, C: C
|
|||||||
lane: bp_messages::LaneId,
|
lane: bp_messages::LaneId,
|
||||||
payload: P,
|
payload: P,
|
||||||
) -> anyhow::Result<Fee> {
|
) -> anyhow::Result<Fee> {
|
||||||
|
let conversion_rate_override: Option<FixedU128> = None;
|
||||||
let encoded_response = client
|
let encoded_response = client
|
||||||
.state_call(estimate_fee_method.into(), (lane, payload).encode().into(), None)
|
.state_call(
|
||||||
|
estimate_fee_method.into(),
|
||||||
|
(lane, payload, conversion_rate_override).encode().into(),
|
||||||
|
None,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let decoded_response: Option<Fee> = Decode::decode(&mut &encoded_response.0[..])
|
let decoded_response: Option<Fee> = Decode::decode(&mut &encoded_response.0[..])
|
||||||
.map_err(relay_substrate_client::Error::ResponseParseFailed)?;
|
.map_err(relay_substrate_client::Error::ResponseParseFailed)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user