Skip to content

Commit

Permalink
Add Derived Account Origins to Dispatcher (paritytech#519)
Browse files Browse the repository at this point in the history
* Update some docs

* Add derived account origin

* Add tests for derived origin

* Do a little bit of cleanup

* Change Origin type to use AccountIds instead of Public keys

* Update (most) tests to use new Origin types

* Remove redundant test

* Update `runtime-common` tests to use new Origin types

* Remove unused import

* Fix documentation around origin verification

* Update config types to use AccountIds in runtime

* Update Origin type used in message relay

* Use correct type when verifying message origin

* Make CallOrigin docs more consistent

* Use AccountIds instead of Public keys in Runtime types

* Introduce trait for converting AccountIds

* Bring back standalone function for deriving account IDs

* Remove AccountIdConverter configuration trait

* Remove old bridge_account_id derivation function

* Handle target ID decoding errors more gracefully

* Update message-lane to use new AccountId derivation

* Update merged code to use new Origin types

* Use explicit conversion between H256 and AccountIds

* Make relayer fund account a config option in `message-lane` pallet

* Add note about deriving the same account on different chains

* Fix test weight

* Use AccountId instead of Public key when signing Calls

* Semi-hardcode relayer fund address into Message Lane pallet
  • Loading branch information
HCastano authored and serban300 committed Apr 8, 2024
1 parent 3e03e03 commit 66537a8
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 196 deletions.
5 changes: 4 additions & 1 deletion bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ impl pallet_bridge_call_dispatch::Trait for Runtime {
type Event = Event;
type MessageId = (bp_message_lane::LaneId, bp_message_lane::MessageNonce);
type Call = Call;
type SourceChainAccountPublic = MultiSigner;
type SourceChainAccountId = bp_rialto::AccountId;
type TargetChainAccountPublic = MultiSigner;
type TargetChainSignature = MultiSignature;
type AccountIdConverter = bp_millau::AccountIdConverter;
}

impl pallet_grandpa::Trait for Runtime {
Expand Down Expand Up @@ -336,6 +337,8 @@ impl pallet_message_lane::Trait for Runtime {
type InboundMessageFee = bp_rialto::Balance;
type InboundRelayer = bp_rialto::AccountId;

type AccountIdConverter = bp_millau::AccountIdConverter;

type TargetHeaderChain = crate::rialto_messages::Rialto;
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
type MessageDeliveryAndDispatchPayment =
Expand Down
5 changes: 4 additions & 1 deletion bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ impl pallet_bridge_call_dispatch::Trait for Runtime {
type Event = Event;
type MessageId = (bp_message_lane::LaneId, bp_message_lane::MessageNonce);
type Call = Call;
type SourceChainAccountPublic = MultiSigner;
type SourceChainAccountId = bp_millau::AccountId;
type TargetChainAccountPublic = MultiSigner;
type TargetChainSignature = MultiSignature;
type AccountIdConverter = bp_rialto::AccountIdConverter;
}

pub struct DepositInto;
Expand Down Expand Up @@ -443,6 +444,8 @@ impl pallet_message_lane::Trait for Runtime {
type InboundMessageFee = bp_millau::Balance;
type InboundRelayer = bp_millau::AccountId;

type AccountIdConverter = bp_rialto::AccountIdConverter;

type TargetHeaderChain = crate::millau_messages::Millau;
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type MessageDeliveryAndDispatchPayment =
Expand Down
12 changes: 6 additions & 6 deletions bridges/bin/runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub mod source {

/// Message payload for This -> Bridged chain messages.
pub type FromThisChainMessagePayload<B> = pallet_bridge_call_dispatch::MessagePayload<
SignerOf<ThisChain<B>>,
AccountIdOf<ThisChain<B>>,
SignerOf<BridgedChain<B>>,
SignatureOf<BridgedChain<B>>,
BridgedChainOpaqueCall,
Expand Down Expand Up @@ -238,14 +238,14 @@ pub mod target {

/// Call origin for Bridged -> This chain messages.
pub type FromBridgedChainMessageCallOrigin<B> = pallet_bridge_call_dispatch::CallOrigin<
SignerOf<BridgedChain<B>>,
AccountIdOf<BridgedChain<B>>,
SignerOf<ThisChain<B>>,
SignatureOf<ThisChain<B>>,
>;

/// Decoded Bridged -> This message payload.
pub type FromBridgedChainDecodedMessagePayload<B> = pallet_bridge_call_dispatch::MessagePayload<
SignerOf<BridgedChain<B>>,
AccountIdOf<BridgedChain<B>>,
SignerOf<ThisChain<B>>,
SignatureOf<ThisChain<B>>,
CallOf<ThisChain<B>>,
Expand Down Expand Up @@ -614,7 +614,7 @@ mod tests {
let message_on_bridged_chain = source::FromThisChainMessagePayload::<OnBridgedChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::BridgeAccount,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
call: ThisChainCall::Transfer.encode(),
}
.encode();
Expand All @@ -628,7 +628,7 @@ mod tests {
target::FromBridgedChainDecodedMessagePayload::<OnThisChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::BridgeAccount,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
call: ThisChainCall::Transfer,
}
);
Expand All @@ -642,7 +642,7 @@ mod tests {
let payload = source::FromThisChainMessagePayload::<OnThisChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::BridgeAccount,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
call: vec![42],
};

Expand Down
3 changes: 2 additions & 1 deletion bridges/modules/call-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ bp-runtime = { path = "../../primitives/runtime", default-features = false }

frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" , default-features = false }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "master" }

[features]
Expand All @@ -32,6 +32,7 @@ std = [
"bp-runtime/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]
Loading

0 comments on commit 66537a8

Please sign in to comment.