Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge: make some headers submissions free #4102

Merged
merged 60 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bc26ff5
move bridge extensions to a separate folder
svyatonik Apr 12, 2024
812d474
added FreeHeadersInterval to pallet-bridge-grandpa configuration
svyatonik Mar 12, 2024
b45fde5
added is_free_execution_expected parameter to the submit_finality_pro…
svyatonik Mar 12, 2024
1161805
move grandpa call result check from RefundTransactionExtensionAdapter…
svyatonik Mar 13, 2024
148d9b3
added RefundBridgedMessages to refund and bump priority of standalone…
svyatonik Mar 13, 2024
3cfd666
check_obsolete_submit_finality_proof may now boost transaction priori…
svyatonik Mar 13, 2024
38c558b
added CheckAndBoostBridgeGrandpaTransactions that checks whether brid…
svyatonik Mar 13, 2024
ad8edb5
relayer may be slashed to explicit account
svyatonik Mar 13, 2024
791ea6a
slash registered relayer if it has submitted failed GRANDPA transaction
svyatonik Mar 13, 2024
b90615a
allow accepting some parachain headers for free
svyatonik Mar 13, 2024
df1928f
added FreeParachainUpdateForFreeRelayHeader
svyatonik Mar 13, 2024
6d852d4
fix benchmarks compilation
svyatonik Mar 15, 2024
3209053
added WeightInfoExt for pallet-bridge-grandpa to include extra wight …
svyatonik Mar 15, 2024
3f95fb0
also refund for submitting initial parachain head
svyatonik Mar 20, 2024
84c9757
make FreeHeadersRemaining an Option => we know that when we are outsi…
svyatonik Mar 20, 2024
a3831e2
add more traces to pallets
svyatonik Mar 20, 2024
1a6baf9
check for reorgs in signed ext for parachains module
svyatonik Mar 20, 2024
3922d6a
fix benchmarks compilation
svyatonik Mar 20, 2024
666aad2
free interval instead of fixed free headers
svyatonik Mar 22, 2024
efeba93
fixed trace
svyatonik Mar 22, 2024
85a5a40
CannotAcceptMoreFreeHeaders -> FreeHeadersLimitExceded
svyatonik Mar 22, 2024
0c87d48
additional_call_result_check -> check_call_result_ex
svyatonik Mar 22, 2024
c3f0bc5
is_granda_call_succeeded -> is_grandpa_call_successful
svyatonik Mar 22, 2024
8e710d2
move tx priority boost from check_obsolete_submit_finality_proof to e…
svyatonik Mar 22, 2024
3ca9d7e
lost changes
svyatonik Mar 22, 2024
7f1375b
dec counter when importing new para header
svyatonik Mar 22, 2024
5772858
cherry pick https://github.com/paritytech/parity-bridges-common/pull/…
svyatonik Apr 12, 2024
61c7ff5
added grandpa_and_parachain_pallets_share_free_headers_counter test
svyatonik Mar 25, 2024
e0817e9
with free intervals (instead of fixed free headers) we need to check …
svyatonik Mar 25, 2024
380fe97
fix test name
svyatonik Mar 25, 2024
779bf9d
added CheckAndBoostBridgeParachainsTransactions to boost parachain tr…
svyatonik Mar 25, 2024
19fb766
check parachain id in CheckAndBoostBridgeParachainsTransactions
svyatonik Mar 25, 2024
7a89e16
use submit_parachain_head_call_ex in tests
svyatonik Mar 25, 2024
b984204
removed commented code
svyatonik Mar 25, 2024
d4533e2
changed condition for consistency
svyatonik Mar 25, 2024
3c9acee
include overweight from runtime signed extensions into submit_paracha…
svyatonik Mar 25, 2024
75b4bc0
fixed comment
svyatonik Mar 25, 2024
1effc3d
removed obsolete code comment
svyatonik Mar 25, 2024
3a7e5aa
added important comment + test
svyatonik Mar 25, 2024
d1eaba0
fix no-std compile
svyatonik Mar 25, 2024
50a44ee
again fix lost change
svyatonik Mar 25, 2024
346cb7c
fix for mandatory + interval check in ext
svyatonik Mar 25, 2024
aea38c0
apply review suggestions
svyatonik Apr 11, 2024
0b1fc99
Update modules/grandpa/src/lib.rs
svyatonik Apr 11, 2024
66d1d96
remove unused getter
svyatonik Apr 12, 2024
561e663
Merge branch 'master' into sv-refund-non-mandatory-headers-fee-polkad…
svyatonik Apr 15, 2024
bea7677
fixed TODOs and added some more tests
svyatonik Apr 15, 2024
c049082
apply new extensions and configurations to bridge-hub-rococo-runtime …
svyatonik Apr 15, 2024
cbf08d0
added tooling to compute `PriorityBoostPerRelayHeader` and `PriorityB…
svyatonik Apr 15, 2024
7aba809
fixed tests in BH runtimes
svyatonik Apr 15, 2024
21962bd
port FinalityApi::free_headers_interval from https://github.com/parit…
svyatonik Apr 16, 2024
aa89040
adapted 0001-asset-transfer test for new fee scheme
svyatonik Apr 16, 2024
51e51d7
fix `bridge-runtime-common` compilation after recent refactoring
svyatonik Apr 16, 2024
f07eddb
added prdoc
svyatonik Apr 16, 2024
c5471c9
fixed messages pallet benchmarks
svyatonik Apr 16, 2024
775ea7b
temporary commented bridges+zombienet tests, because they'll need a n…
svyatonik Apr 16, 2024
9886447
apply suggestion from https://github.com/paritytech/parity-bridges-co…
svyatonik Apr 23, 2024
18e15fb
added comment
svyatonik Apr 23, 2024
cad5d31
Merge branch 'master' into sv-refund-non-mandatory-headers-fee-polkad…
svyatonik Apr 23, 2024
cde347f
added free_relay_extrinsic_works tests to ensure that we submit final…
svyatonik Apr 24, 2024
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
4 changes: 2 additions & 2 deletions bridges/chains/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ frame_support::parameter_types! {

/// Transaction fee that is paid at the Rococo BridgeHub for delivering single inbound message.
/// (initially was calculated by test `BridgeHubRococo::can_calculate_fee_for_complex_message_delivery_transaction` + `33%`)
pub const BridgeHubRococoBaseDeliveryFeeInRocs: u128 = 5_651_581_649;
pub const BridgeHubRococoBaseDeliveryFeeInRocs: u128 = 314_037_860;

/// Transaction fee that is paid at the Rococo BridgeHub for delivering single outbound message confirmation.
/// (initially was calculated by test `BridgeHubRococo::can_calculate_fee_for_complex_message_confirmation_transaction` + `33%`)
pub const BridgeHubRococoBaseConfirmationFeeInRocs: u128 = 5_380_901_781;
pub const BridgeHubRococoBaseConfirmationFeeInRocs: u128 = 57_414_813;
Comment on lines -106 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10x-15x reduction ❤️

}
8 changes: 4 additions & 4 deletions bridges/chains/chain-bridge-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ frame_support::parameter_types! {
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 17_756_830_000;

/// Transaction fee that is paid at the Westend BridgeHub for delivering single inbound message.
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_complex_message_delivery_transaction` + `33%`)
pub const BridgeHubWestendBaseDeliveryFeeInWnds: u128 = 1_695_489_961_344;
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`)
pub const BridgeHubWestendBaseDeliveryFeeInWnds: u128 = 94_211_536_452;

/// Transaction fee that is paid at the Westend BridgeHub for delivering single outbound message confirmation.
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_complex_message_confirmation_transaction` + `33%`)
pub const BridgeHubWestendBaseConfirmationFeeInWnds: u128 = 1_618_309_961_344;
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_standalone_message_confirmation_transaction` + `33%`)
pub const BridgeHubWestendBaseConfirmationFeeInWnds: u128 = 17_224_486_452;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ fn construct_and_apply_extrinsic(
r.unwrap()
}

fn construct_and_estimate_extrinsic_fee(batch: pallet_utility::Call<Runtime>) -> Balance {
let batch_call = RuntimeCall::Utility(batch);
let batch_info = batch_call.get_dispatch_info();
let xt = construct_extrinsic(Alice, batch_call);
TransactionPayment::compute_fee(xt.encoded_size() as _, &batch_info, 0)
fn construct_and_estimate_extrinsic_fee(call: RuntimeCall) -> Balance {
let info = call.get_dispatch_info();
let xt = construct_extrinsic(Alice, call);
TransactionPayment::compute_fee(xt.encoded_size() as _, &info, 0)
}

fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime> {
Expand Down Expand Up @@ -375,23 +374,6 @@ mod bridge_hub_westend_tests {
)
}

#[test]
pub fn complex_relay_extrinsic_works() {
// for Westend
from_parachain::complex_relay_extrinsic_works::<RuntimeTestsAdapter>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
BridgeHubWestendChainId::get(),
Rococo,
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
|| (),
construct_and_apply_extrinsic,
);
}

#[test]
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
bridge_hub_test_utils::check_sane_fees_values(
Expand All @@ -414,12 +396,12 @@ mod bridge_hub_westend_tests {
}

#[test]
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
fn can_calculate_fee_for_standalone_message_delivery_transaction() {
bridge_hub_test_utils::check_sane_fees_values(
"bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs",
bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get(),
|| {
from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
from_parachain::can_calculate_fee_for_standalone_message_delivery_transaction::<
RuntimeTestsAdapter,
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
},
Expand All @@ -433,12 +415,12 @@ mod bridge_hub_westend_tests {
}

#[test]
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
fn can_calculate_fee_for_standalone_message_confirmation_transaction() {
bridge_hub_test_utils::check_sane_fees_values(
"bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs",
bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get(),
|| {
from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
from_parachain::can_calculate_fee_for_standalone_message_confirmation_transaction::<
RuntimeTestsAdapter,
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
},
Expand Down Expand Up @@ -581,28 +563,12 @@ mod bridge_hub_bulletin_tests {
}

#[test]
pub fn complex_relay_extrinsic_works() {
// for Bulletin
from_grandpa_chain::complex_relay_extrinsic_works::<RuntimeTestsAdapter>(
collator_session_keys(),
slot_durations(),
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
RococoBulletinChainId::get(),
Rococo,
XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN,
|| (),
construct_and_apply_extrinsic,
);
}

#[test]
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
pub fn can_calculate_fee_for_standalone_message_delivery_transaction() {
bridge_hub_test_utils::check_sane_fees_values(
"bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs",
bp_bridge_hub_rococo::BridgeHubRococoBaseDeliveryFeeInRocs::get(),
|| {
from_grandpa_chain::can_calculate_fee_for_complex_message_delivery_transaction::<
from_grandpa_chain::can_calculate_fee_for_standalone_message_delivery_transaction::<
RuntimeTestsAdapter,
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
},
Expand All @@ -617,12 +583,12 @@ mod bridge_hub_bulletin_tests {
}

#[test]
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
pub fn can_calculate_fee_for_standalone_message_confirmation_transaction() {
bridge_hub_test_utils::check_sane_fees_values(
"bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs",
bp_bridge_hub_rococo::BridgeHubRococoBaseConfirmationFeeInRocs::get(),
|| {
from_grandpa_chain::can_calculate_fee_for_complex_message_confirmation_transaction::<
from_grandpa_chain::can_calculate_fee_for_standalone_message_confirmation_transaction::<
RuntimeTestsAdapter,
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ fn construct_and_apply_extrinsic(
r.unwrap()
}

fn construct_and_estimate_extrinsic_fee(batch: pallet_utility::Call<Runtime>) -> Balance {
let batch_call = RuntimeCall::Utility(batch);
let batch_info = batch_call.get_dispatch_info();
let xt = construct_extrinsic(Alice, batch_call);
TransactionPayment::compute_fee(xt.encoded_size() as _, &batch_info, 0)
fn construct_and_estimate_extrinsic_fee(call: RuntimeCall) -> Balance {
let info = call.get_dispatch_info();
let xt = construct_extrinsic(Alice, call);
TransactionPayment::compute_fee(xt.encoded_size() as _, &info, 0)
}

fn collator_session_keys() -> bridge_hub_test_utils::CollatorSessionKeys<Runtime> {
Expand Down Expand Up @@ -271,22 +270,6 @@ fn relayed_incoming_message_works() {
)
}

#[test]
pub fn complex_relay_extrinsic_works() {
from_parachain::complex_relay_extrinsic_works::<RuntimeTestsAdapter>(
bkontur marked this conversation as resolved.
Show resolved Hide resolved
collator_session_keys(),
slot_durations(),
bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_PARACHAIN_ID,
bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID,
SIBLING_PARACHAIN_ID,
BridgeHubRococoChainId::get(),
Westend,
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
|| (),
construct_and_apply_extrinsic,
);
}

#[test]
pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
bridge_hub_test_utils::check_sane_fees_values(
Expand All @@ -309,12 +292,12 @@ pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() {
}

#[test]
pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
pub fn can_calculate_fee_for_standalone_message_delivery_transaction() {
bridge_hub_test_utils::check_sane_fees_values(
"bp_bridge_hub_westend::BridgeHubWestendBaseDeliveryFeeInWnds",
bp_bridge_hub_westend::BridgeHubWestendBaseDeliveryFeeInWnds::get(),
|| {
from_parachain::can_calculate_fee_for_complex_message_delivery_transaction::<
from_parachain::can_calculate_fee_for_standalone_message_delivery_transaction::<
RuntimeTestsAdapter,
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
},
Expand All @@ -328,12 +311,12 @@ pub fn can_calculate_fee_for_complex_message_delivery_transaction() {
}

#[test]
pub fn can_calculate_fee_for_complex_message_confirmation_transaction() {
pub fn can_calculate_fee_for_standalone_message_confirmation_transaction() {
bridge_hub_test_utils::check_sane_fees_values(
"bp_bridge_hub_westend::BridgeHubWestendBaseConfirmationFeeInWnds",
bp_bridge_hub_westend::BridgeHubWestendBaseConfirmationFeeInWnds::get(),
|| {
from_parachain::can_calculate_fee_for_complex_message_confirmation_transaction::<
from_parachain::can_calculate_fee_for_standalone_message_confirmation_transaction::<
RuntimeTestsAdapter,
>(collator_session_keys(), construct_and_estimate_extrinsic_fee)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,108 @@ where
compute_extrinsic_fee(batch)
})
}

/// Estimates transaction fee for default message delivery transaction from bridged GRANDPA chain.
pub fn can_calculate_fee_for_standalone_message_delivery_transaction<RuntimeHelper>(
collator_session_key: CollatorSessionKeys<RuntimeHelper::Runtime>,
compute_extrinsic_fee: fn(
<RuntimeHelper::Runtime as frame_system::Config>::RuntimeCall,
) -> u128,
) -> u128
where
RuntimeHelper: WithRemoteGrandpaChainHelper,
RuntimeCallOf<RuntimeHelper::Runtime>:
From<BridgeMessagesCall<RuntimeHelper::Runtime, RuntimeHelper::MPI>>,
UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>: ChainWithGrandpa,
<RuntimeHelper::Runtime as BridgeMessagesConfig<RuntimeHelper::MPI>>::SourceHeaderChain:
SourceHeaderChain<
MessagesProof = FromBridgedChainMessagesProof<
HashOf<MessageBridgedChain<RuntimeHelper::MB>>,
>,
>,
{
run_test::<RuntimeHelper::Runtime, _>(collator_session_key, 1000, vec![], || {
// generate bridged relay chain finality, parachain heads and message proofs,
// to be submitted by relayer to this chain.
//
// we don't care about parameter values here, apart from the XCM message size. But we
// do not need to have a large message here, because we're charging for every byte of
// the message additionally
let (_, _, message_proof) =
test_data::from_grandpa_chain::make_complex_relayer_delivery_proofs::<
RuntimeHelper::MB,
(),
>(
LaneId::default(),
vec![Instruction::<()>::ClearOrigin; 1_024].into(),
1,
[GlobalConsensus(Polkadot), Parachain(1_000)].into(),
1u32.into(),
);

let call = test_data::from_grandpa_chain::make_standalone_relayer_delivery_call::<
RuntimeHelper::Runtime,
RuntimeHelper::GPI,
RuntimeHelper::MPI,
>(
message_proof,
helpers::relayer_id_at_bridged_chain::<RuntimeHelper::Runtime, RuntimeHelper::MPI>(),
);

compute_extrinsic_fee(call)
})
}

/// Estimates transaction fee for default message confirmation transaction (batched with required
/// proofs) from bridged parachain.
pub fn can_calculate_fee_for_standalone_message_confirmation_transaction<RuntimeHelper>(
collator_session_key: CollatorSessionKeys<RuntimeHelper::Runtime>,
compute_extrinsic_fee: fn(
<RuntimeHelper::Runtime as frame_system::Config>::RuntimeCall,
) -> u128,
) -> u128
where
RuntimeHelper: WithRemoteGrandpaChainHelper,
AccountIdOf<RuntimeHelper::Runtime>: From<AccountId32>,
MessageThisChain<RuntimeHelper::MB>:
bp_runtime::Chain<AccountId = AccountIdOf<RuntimeHelper::Runtime>>,
RuntimeCallOf<RuntimeHelper::Runtime>:
From<BridgeMessagesCall<RuntimeHelper::Runtime, RuntimeHelper::MPI>>,
UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>: ChainWithGrandpa,
<RuntimeHelper::Runtime as BridgeMessagesConfig<RuntimeHelper::MPI>>::TargetHeaderChain:
TargetHeaderChain<
XcmAsPlainPayload,
AccountIdOf<RuntimeHelper::Runtime>,
MessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof<
HashOf<UnderlyingChainOf<MessageBridgedChain<RuntimeHelper::MB>>>,
>,
>,
{
run_test::<RuntimeHelper::Runtime, _>(collator_session_key, 1000, vec![], || {
// generate bridged relay chain finality, parachain heads and message proofs,
// to be submitted by relayer to this chain.
let unrewarded_relayers = UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 1,
..Default::default()
};
let (_, _, message_delivery_proof) =
test_data::from_grandpa_chain::make_complex_relayer_confirmation_proofs::<
RuntimeHelper::MB,
(),
>(
LaneId::default(),
1u32.into(),
AccountId32::from(Alice.public()).into(),
unrewarded_relayers.clone(),
);

let call = test_data::from_grandpa_chain::make_standalone_relayer_confirmation_call::<
RuntimeHelper::Runtime,
RuntimeHelper::GPI,
RuntimeHelper::MPI,
>(message_delivery_proof, unrewarded_relayers);

compute_extrinsic_fee(call)
})
}
Loading
Loading