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

Dynamic fees implementation that reports bridge queues state to the sending chain (backup option) #2233

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"modules/parachains",
"modules/relayers",
"modules/shift-session-manager",
"modules/xcm-bridge-hub-router",
"primitives/beefy",
"primitives/chain-bridge-hub-cumulus",
"primitives/chain-bridge-hub-kusama",
Expand All @@ -37,6 +38,7 @@ members = [
"primitives/relayers",
"primitives/runtime",
"primitives/test-utils",
"primitives/xcm-bridge-hub-router",
"relays/bin-substrate",
"relays/client-bridge-hub-kusama",
"relays/client-bridge-hub-polkadot",
Expand Down
2 changes: 2 additions & 0 deletions bin/runtime-common/src/messages_call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ mod tests {
state: LaneState::Opened,
relayers: Default::default(),
last_confirmed_nonce: 10,
dispatcher_state: Default::default(),
},
);
}
Expand Down Expand Up @@ -496,6 +497,7 @@ mod tests {
oldest_unpruned_nonce: 0,
latest_received_nonce: 10,
latest_generated_nonce: 10,
bridged_dispatcher_state: None,
},
);
}
Expand Down
10 changes: 7 additions & 3 deletions bin/runtime-common/src/messages_xcm_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

use bp_messages::{
source_chain::MessagesBridge,
target_chain::{DispatchMessage, MessageDispatch},
LaneId,
target_chain::{DispatchMessage, MessageDispatch, MessageDispatchResult},
DispatcherState, LaneId,
};
use bp_runtime::{messages::MessageDispatchResult, Chain};
use bp_runtime::Chain;
use codec::{Decode, Encode};
use frame_support::{dispatch::Weight, CloneNoBound, EqNoBound, PartialEqNoBound};
use pallet_bridge_messages::WeightInfoExt as MessagesPalletWeights;
Expand Down Expand Up @@ -124,6 +124,10 @@ impl<BlobDispatcher: DispatchBlob, Weights: MessagesPalletWeights> MessageDispat
};
MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result }
}

fn state() -> DispatcherState {
unimplemented!("TODO")
}
}

/// [`XcmBlobHauler`] is responsible for sending messages to the bridge "point-to-point link" from
Expand Down
5 changes: 5 additions & 0 deletions modules/messages/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ mod tests {
oldest_unpruned_nonce: 1,
latest_received_nonce: 1,
latest_generated_nonce: 1,
bridged_dispatcher_state: None,
}),
encode_all_messages,
|d| {
Expand Down Expand Up @@ -434,6 +435,7 @@ mod tests {
oldest_unpruned_nonce: 1,
latest_received_nonce: 1,
latest_generated_nonce: 1,
bridged_dispatcher_state: None,
}),
encode_all_messages,
encode_lane_data,
Expand All @@ -449,6 +451,7 @@ mod tests {
oldest_unpruned_nonce: 1,
latest_received_nonce: 1,
latest_generated_nonce: 1,
bridged_dispatcher_state: None,
}),
messages: Vec::new(),
},
Expand All @@ -468,6 +471,7 @@ mod tests {
oldest_unpruned_nonce: 1,
latest_received_nonce: 1,
latest_generated_nonce: 1,
bridged_dispatcher_state: None,
}),
encode_all_messages,
encode_lane_data,
Expand All @@ -483,6 +487,7 @@ mod tests {
oldest_unpruned_nonce: 1,
latest_received_nonce: 1,
latest_generated_nonce: 1,
bridged_dispatcher_state: None,
}),
messages: vec![Message {
key: MessageKey { lane_id: test_lane_id(), nonce: 1 },
Expand Down
15 changes: 9 additions & 6 deletions modules/messages/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ use bp_messages::{
source_chain::{DeliveryConfirmationPayments, FromBridgedChainMessagesDeliveryProof},
target_chain::{
DeliveryPayments, DispatchMessage, DispatchMessageData, FromBridgedChainMessagesProof,
MessageDispatch,
MessageDispatch, MessageDispatchResult,
},
ChainWithMessages, DeliveredMessages, InboundLaneData, LaneId, LaneState, Message, MessageKey,
MessageNonce, MessagePayload, OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState,
};
use bp_runtime::{
messages::MessageDispatchResult, Chain, ChainId, Size, UnverifiedStorageProofParams,
ChainWithMessages, DeliveredMessages, DispatcherState, InboundLaneData, LaneId, LaneState,
Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData, UnrewardedRelayer,
UnrewardedRelayersState,
};
use bp_runtime::{Chain, ChainId, Size, UnverifiedStorageProofParams};
use codec::{Decode, Encode};
use frame_support::{
parameter_types,
Expand Down Expand Up @@ -405,6 +404,10 @@ impl MessageDispatch for TestMessageDispatch {
Err(_) => dispatch_result(0),
}
}

fn state() -> DispatcherState {
DispatcherState::default()
}
}

/// Return test lane message with given nonce and payload.
Expand Down
23 changes: 17 additions & 6 deletions modules/messages/src/tests/pallet_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use crate::{
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof, BridgeMessagesCall, ChainWithMessages,
DeliveredMessages, InboundLaneData, InboundMessageDetails, LaneId, LaneState, MessageKey,
MessageNonce, MessagesOperatingMode, OutboundLaneData, OutboundMessageDetails,
DeliveredMessages, DispatcherState, InboundLaneData, InboundMessageDetails, LaneId, LaneState,
MessageKey, MessageNonce, MessagesOperatingMode, OutboundLaneData, OutboundMessageDetails,
UnrewardedRelayer, UnrewardedRelayersState, VerificationError,
};
use bp_runtime::{BasicOperatingMode, PreComputedSize, Size};
Expand Down Expand Up @@ -88,6 +88,7 @@ fn receive_messages_delivery_proof() {
messages: DeliveredMessages::new(1),
}]
.into(),
dispatcher_state: DispatcherState::default(),
},
),
UnrewardedRelayersState {
Expand Down Expand Up @@ -144,6 +145,7 @@ fn pallet_rejects_transactions_if_halted() {
state: LaneState::Opened,
last_confirmed_nonce: 1,
relayers: vec![unrewarded_relayer(1, 1, TEST_RELAYER_A)].into(),
dispatcher_state: DispatcherState::default(),
},
);
assert_noop!(
Expand Down Expand Up @@ -193,6 +195,7 @@ fn pallet_rejects_new_messages_in_rejecting_outbound_messages_operating_mode() {
state: LaneState::Opened,
last_confirmed_nonce: 1,
relayers: vec![unrewarded_relayer(1, 1, TEST_RELAYER_A)].into(),
dispatcher_state: DispatcherState::default(),
},
),
UnrewardedRelayersState {
Expand Down Expand Up @@ -273,6 +276,7 @@ fn receive_messages_proof_updates_confirmed_message_nonce() {
unrewarded_relayer(10, 10, TEST_RELAYER_B),
]
.into(),
dispatcher_state: DispatcherState::default(),
},
);
assert_eq!(
Expand Down Expand Up @@ -307,6 +311,7 @@ fn receive_messages_proof_updates_confirmed_message_nonce() {
unrewarded_relayer(11, 11, TEST_RELAYER_A)
]
.into(),
dispatcher_state: DispatcherState::default(),
},
);
assert_eq!(
Expand Down Expand Up @@ -736,6 +741,7 @@ fn proof_size_refund_from_receive_messages_proof_works() {
]
.into(),
last_confirmed_nonce: 0,
dispatcher_state: DispatcherState::default(),
}),
);
let post_dispatch_weight = Pallet::<TestRuntime>::receive_messages_proof(
Expand Down Expand Up @@ -765,6 +771,7 @@ fn proof_size_refund_from_receive_messages_proof_works() {
]
.into(),
last_confirmed_nonce: 0,
dispatcher_state: DispatcherState::default(),
}),
);
let post_dispatch_weight = Pallet::<TestRuntime>::receive_messages_proof(
Expand Down Expand Up @@ -794,17 +801,18 @@ fn receive_messages_delivery_proof_rejects_proof_if_trying_to_confirm_more_messa
send_regular_message();

// 1) InboundLaneData declares that the `last_confirmed_nonce` is 1;
// 2) InboundLaneData has no entries => `InboundLaneData::last_delivered_nonce()`
// returns `last_confirmed_nonce`;
// 2) InboundLaneData has no entries => `InboundLaneData::last_delivered_nonce()` returns
// `last_confirmed_nonce`;
// 3) it means that we're going to confirm delivery of messages 1..=1;
// 4) so the number of declared messages (see `UnrewardedRelayersState`) is `0` and
// numer of actually confirmed messages is `1`.
// 4) so the number of declared messages (see `UnrewardedRelayersState`) is `0` and numer of
// actually confirmed messages is `1`.
let proof = prepare_messages_delivery_proof(
test_lane_id(),
InboundLaneData {
state: LaneState::Opened,
last_confirmed_nonce: 1,
relayers: Default::default(),
dispatcher_state: DispatcherState::default(),
},
);
assert_noop!(
Expand Down Expand Up @@ -875,6 +883,7 @@ fn test_bridge_messages_call_is_correctly_defined() {
messages: DeliveredMessages::new(1),
}]
.into(),
dispatcher_state: DispatcherState::default(),
},
);
let unrewarded_relayer_state = UnrewardedRelayersState {
Expand Down Expand Up @@ -943,6 +952,7 @@ fn inbound_storage_extra_proof_size_bytes_works() {
state: LaneState::Opened,
relayers: vec![relayer_entry(); relayer_entries].into(),
last_confirmed_nonce: 0,
dispatcher_state: DispatcherState::default(),
},
_phantom: Default::default(),
}
Expand Down Expand Up @@ -1031,6 +1041,7 @@ fn receive_messages_delivery_proof_fails_if_outbound_lane_is_unknown() {
messages: DeliveredMessages::new(1),
}]
.into(),
dispatcher_state: DispatcherState::default(),
},
)
};
Expand Down
47 changes: 47 additions & 0 deletions modules/xcm-bridge-hub-router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "pallet-xcm-bridge-hub-router"
description = "Module that supports dynamic bridges over sibling/child bridge hub."
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
scale-info = { version = "2.8.0", default-features = false, features = ["bit-vec", "derive", "serde"] }

# Bridge dependencies

bp-messages = { path = "../../primitives/messages", default-features = false }
bp-xcm-bridge-hub-router = { path = "../../primitives/xcm-bridge-hub-router", default-features = false }

# Substrate Dependencies

frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { 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 }

# Polkadot Dependencies

xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }

[features]
default = ["std"]
std = [
"bp-messages/std",
"bp-xcm-bridge-hub-router/std",
"codec/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
"xcm-builder/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
Loading