Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6cd5775
Add `AtLeast32BitUnsigned` for MessageLance::SourceChainBalance (#1207)
fewensa Nov 11, 2021
877e8d0
Fix UI deployment. (#1211)
tomusdrw Nov 15, 2021
9bc071d
Remove unused PoA<>Substrate bridge (#1210)
acatangiu Nov 15, 2021
39140d0
Remove unused `relays/headers` (#1216)
acatangiu Nov 16, 2021
d1541e7
remove abandoned exchange relay (#1217)
svyatonik Nov 17, 2021
6b5cf2b
Unify metric names (#1209)
svyatonik Nov 22, 2021
bd2f8bf
Add CODEOWNERS file (#1219)
sergejparity Nov 22, 2021
ffef6f8
fixed set_operational in GRANDPA pallet (#1226)
svyatonik Nov 24, 2021
98eb9ee
Add mut support (#1232)
fewensa Nov 30, 2021
d94b62b
update dependencies (#1229)
Nov 30, 2021
816ddd2
Integrate BEEFY with Rialto & Millau runtimes (#1227)
acatangiu Nov 30, 2021
cd771f1
Fix storage parameter name computation (#1238)
svyatonik Dec 1, 2021
04d4d1c
Enable Beefy debug logs in test deployment (#1237)
acatangiu Dec 1, 2021
e860fec
Enable offchain indexing for Rialto/Millau nodes (#1239)
tomusdrw Dec 3, 2021
7bf76f1
Update Rococo/Wococo version + prepare relay for Rococo<>Wococo bridg…
svyatonik Dec 3, 2021
f927775
Refactor finality relay helpers (#1220)
svyatonik Dec 3, 2021
c07bba9
Expose prometheus BEEFY metrics and add them to grafana dashboard (#1…
acatangiu Dec 3, 2021
52232d8
Fix transactions mortality (#1196)
svyatonik Dec 6, 2021
a15b4fa
post-merge build fix (#1243)
svyatonik Dec 6, 2021
fed5437
Refactor message relay helpers (#1234)
svyatonik Dec 6, 2021
4fc8a29
Use same endowed accounts set on dev/local chains (#1244)
svyatonik Dec 7, 2021
9ead06a
runtimes: fix call_size() test (#1245)
acatangiu Dec 8, 2021
80c9429
Bump relay version to 1.0.0 (#1249)
tomusdrw Dec 13, 2021
3bc7435
Add missing RPC APIs to rialto parachain node (#1250)
svyatonik Dec 14, 2021
65e51b5
decrease startup sleep to 5s for relays and to 120s for generators + …
svyatonik Dec 14, 2021
4009d97
pin bridges-ci image (#1256)
svyatonik Dec 16, 2021
edfcb74
Change submit transaction spec_version and transaction_version query …
fewensa Dec 16, 2021
4f98840
remporary use pinned bridges-ci image in Dockerfile (#1258)
svyatonik Dec 17, 2021
467ca5e
move storage keys computation to primitivs (#1254)
svyatonik Dec 17, 2021
50ffb5d
override conversion rate in estimate-message-fee RPC (#1189)
svyatonik Dec 17, 2021
82c08c5
read latest_generated_nonce directly from storage (#1260)
svyatonik Dec 21, 2021
9f4b34a
bump rococo version (#1263)
svyatonik Dec 22, 2021
572206f
Merge branch 'master' into polkadot-staging-update
svyatonik Dec 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
override conversion rate in estimate-message-fee RPC (#1189)
  • Loading branch information
svyatonik authored Dec 17, 2021
commit 50ffb5dd08d662d811e42f6a7cfd9cfb1a7f7de7
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
ApplyExtrinsicResult, FixedPointNumber, FixedU128, MultiSignature, MultiSigner, Perquintill,
};
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -744,10 +744,12 @@ impl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
_lane_id: bp_messages::LaneId,
payload: ToRialtoMessagePayload,
rialto_to_this_conversion_rate: Option<FixedU128>,
) -> Option<Balance> {
estimate_message_dispatch_and_delivery_fee::<WithRialtoMessageBridge>(
&payload,
WithRialtoMessageBridge::RELAYER_FEE_PERCENT,
rialto_to_this_conversion_rate,
).ok()
}

Expand Down
13 changes: 8 additions & 5 deletions bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ impl MessageBridge for WithRialtoMessageBridge {
type ThisChain = Millau;
type BridgedChain = Rialto;

fn bridged_balance_to_this_balance(bridged_balance: bp_rialto::Balance) -> bp_millau::Balance {
bp_millau::Balance::try_from(
RialtoToMillauConversionRate::get().saturating_mul_int(bridged_balance),
)
.unwrap_or(bp_millau::Balance::MAX)
fn bridged_balance_to_this_balance(
bridged_balance: bp_rialto::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)
}
}

Expand Down
4 changes: 3 additions & 1 deletion bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, Block as BlockT, Keccak256, NumberFor, OpaqueKeys},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
ApplyExtrinsicResult, FixedPointNumber, FixedU128, MultiSignature, MultiSigner, Perquintill,
};
use sp_std::{collections::btree_map::BTreeMap, prelude::*};
#[cfg(feature = "std")]
Expand Down Expand Up @@ -892,10 +892,12 @@ impl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
_lane_id: bp_messages::LaneId,
payload: ToMillauMessagePayload,
millau_to_this_conversion_rate: Option<FixedU128>,
) -> Option<Balance> {
estimate_message_dispatch_and_delivery_fee::<WithMillauMessageBridge>(
&payload,
WithMillauMessageBridge::RELAYER_FEE_PERCENT,
millau_to_this_conversion_rate,
).ok()
}

Expand Down
13 changes: 8 additions & 5 deletions bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ impl MessageBridge for WithMillauMessageBridge {
type ThisChain = Rialto;
type BridgedChain = Millau;

fn bridged_balance_to_this_balance(bridged_balance: bp_millau::Balance) -> bp_rialto::Balance {
bp_rialto::Balance::try_from(
MillauToRialtoConversionRate::get().saturating_mul_int(bridged_balance),
)
.unwrap_or(bp_rialto::Balance::MAX)
fn bridged_balance_to_this_balance(
bridged_balance: bp_millau::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)
}
}

Expand Down
46 changes: 40 additions & 6 deletions bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub trait MessageBridge {
/// Convert Bridged chain balance into This chain balance.
fn bridged_balance_to_this_balance(
bridged_balance: BalanceOf<BridgedChain<Self>>,
bridged_to_this_conversion_rate_override: Option<FixedU128>,
) -> BalanceOf<ThisChain<Self>>;
}

Expand Down Expand Up @@ -316,8 +317,11 @@ pub mod source {
pallet_bridge_dispatch::verify_message_origin(submitter, payload)
.map_err(|_| BAD_ORIGIN)?;

let minimal_fee_in_this_tokens =
estimate_message_dispatch_and_delivery_fee::<B>(payload, B::RELAYER_FEE_PERCENT)?;
let minimal_fee_in_this_tokens = estimate_message_dispatch_and_delivery_fee::<B>(
payload,
B::RELAYER_FEE_PERCENT,
None,
)?;

// compare with actual fee paid
if *delivery_and_dispatch_fee < minimal_fee_in_this_tokens {
Expand Down Expand Up @@ -371,6 +375,7 @@ pub mod source {
pub fn estimate_message_dispatch_and_delivery_fee<B: MessageBridge>(
payload: &FromThisChainMessagePayload<B>,
relayer_fee_percent: u32,
bridged_to_this_conversion_rate: Option<FixedU128>,
) -> Result<BalanceOf<ThisChain<B>>, &'static str> {
// the fee (in Bridged tokens) of all transactions that are made on the Bridged chain
//
Expand All @@ -391,8 +396,11 @@ pub mod source {
ThisChain::<B>::transaction_payment(confirmation_transaction);

// minimal fee (in This tokens) is a sum of all required fees
let minimal_fee = B::bridged_balance_to_this_balance(delivery_transaction_fee)
.checked_add(&confirmation_transaction_fee);
let minimal_fee = B::bridged_balance_to_this_balance(
delivery_transaction_fee,
bridged_to_this_conversion_rate,
)
.checked_add(&confirmation_transaction_fee);

// before returning, add extra fee that is paid to the relayer (relayer interest)
minimal_fee
Expand Down Expand Up @@ -798,8 +806,12 @@ mod tests {

fn bridged_balance_to_this_balance(
bridged_balance: BridgedChainBalance,
bridged_to_this_conversion_rate_override: Option<FixedU128>,
) -> 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)
}
}

Expand All @@ -817,7 +829,10 @@ mod tests {
type ThisChain = BridgedChain;
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!()
}
}
Expand Down Expand Up @@ -1095,6 +1110,7 @@ mod tests {
source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
&payload,
OnThisChainBridge::RELAYER_FEE_PERCENT,
None,
),
Ok(ThisChainBalance(EXPECTED_MINIMAL_FEE)),
);
Expand All @@ -1106,6 +1122,7 @@ mod tests {
source::estimate_message_dispatch_and_delivery_fee::<OnThisChainBridge>(
&payload_with_pay_on_target,
OnThisChainBridge::RELAYER_FEE_PERCENT,
None,
)
.expect(
"estimate_message_dispatch_and_delivery_fee failed for pay-at-target-chain message",
Expand Down Expand Up @@ -1572,4 +1589,21 @@ mod tests {
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);
}
}
2 changes: 2 additions & 0 deletions primitives/chain-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bp-runtime = { path = "../runtime", 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-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-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

Expand All @@ -30,6 +31,7 @@ std = [
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"sp-version/std",
]
2 changes: 2 additions & 0 deletions primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}
use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use sp_runtime::FixedU128;
use sp_std::prelude::*;
use sp_version::RuntimeVersion;

Expand Down Expand Up @@ -141,6 +142,7 @@ sp_api::decl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
lane_id: LaneId,
payload: OutboundPayload,
kusama_to_this_conversion_rate: Option<FixedU128>,
) -> Option<OutboundMessageFee>;
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
Expand Down
3 changes: 2 additions & 1 deletion primitives/chain-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use scale_info::TypeInfo;
use sp_core::Hasher as HasherT;
use sp_runtime::{
traits::{Convert, IdentifyAccount, Verify},
MultiSignature, MultiSigner, Perbill,
FixedU128, MultiSignature, MultiSigner, Perbill,
};
use sp_std::prelude::*;
use sp_trie::{trie_types::Layout, TrieConfiguration};
Expand Down Expand Up @@ -319,6 +319,7 @@ sp_api::decl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
lane_id: LaneId,
payload: OutboundPayload,
millau_to_this_conversion_rate: Option<FixedU128>,
) -> Option<OutboundMessageFee>;
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
Expand Down
2 changes: 2 additions & 0 deletions primitives/chain-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bp-runtime = { path = "../runtime", 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-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-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

Expand All @@ -30,6 +31,7 @@ std = [
"bp-runtime/std",
"frame-support/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"sp-version/std",
]
2 changes: 2 additions & 0 deletions primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}
use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use sp_runtime::FixedU128;
use sp_std::prelude::*;
use sp_version::RuntimeVersion;

Expand Down Expand Up @@ -141,6 +142,7 @@ sp_api::decl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
lane_id: LaneId,
payload: OutboundPayload,
polkadot_to_this_conversion_rate: Option<FixedU128>,
) -> Option<OutboundMessageFee>;
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
Expand Down
3 changes: 2 additions & 1 deletion primitives/chain-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use frame_system::limits;
use sp_core::Hasher as HasherT;
use sp_runtime::{
traits::{BlakeTwo256, Convert, IdentifyAccount, Verify},
MultiSignature, MultiSigner, Perbill,
FixedU128, MultiSignature, MultiSigner, Perbill,
};
use sp_std::prelude::*;

Expand Down Expand Up @@ -291,6 +291,7 @@ sp_api::decl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
lane_id: LaneId,
payload: OutboundPayload,
rialto_to_this_conversion_rate: Option<FixedU128>,
) -> Option<OutboundMessageFee>;
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
Expand Down
2 changes: 2 additions & 0 deletions primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}
use frame_support::weights::{
Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
};
use sp_runtime::FixedU128;
use sp_std::prelude::*;
use sp_version::RuntimeVersion;

Expand Down Expand Up @@ -142,6 +143,7 @@ sp_api::decl_runtime_apis! {
fn estimate_message_delivery_and_dispatch_fee(
lane_id: LaneId,
payload: OutboundPayload,
rococo_to_this_conversion_rate: Option<FixedU128>,
) -> Option<OutboundMessageFee>;
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
Expand Down
2 changes: 0 additions & 2 deletions primitives/chain-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ smallvec = "1.7"
# Bridge Dependencies

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-runtime = { path = "../runtime", default-features = false }

Expand All @@ -30,7 +29,6 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master
default = ["std"]
std = [
"bp-header-chain/std",
"bp-messages/std",
"bp-polkadot-core/std",
"bp-runtime/std",
"frame-support/std",
Expand Down
Loading