Rename Finality Verifier and Call Dispatch Pallets (#838)

* Rename `pallet-finality-verifier` to `pallet-bridge-grandpa`

* Missed some CamelCase ones

* Update logging target in GRANDPA pallet

* Rename `pallet-bridge-call-dispatch` to `pallet-bridge-dispatch`

* Rename the dispatch pallet folder

* Update logging target in Dispatch pallet

* Missed a couple

* Format the repo

* Stop listing individual pallets in Compose logs

* Use correct pallet name in module doc comments

* Add `pallet-bridge-dispatch` to README project layout

* Sort crate names in TOML files

* Rename `pallet-bridge-grandpa` runtime Call alias
This commit is contained in:
Hernando Castano
2021-03-23 11:37:41 -04:00
committed by Bastian Köcher
parent acb872fbb0
commit 8d122b03f1
26 changed files with 165 additions and 160 deletions
+5 -5
View File
@@ -17,9 +17,9 @@ hash-db = { version = "0.15.2", default-features = false }
bp-message-dispatch = { path = "../../primitives/message-dispatch", default-features = false }
bp-messages = { path = "../../primitives/messages", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
pallet-bridge-call-dispatch = { path = "../../modules/call-dispatch", default-features = false }
pallet-bridge-dispatch = { path = "../../modules/dispatch", default-features = false }
pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false }
pallet-bridge-messages = { path = "../../modules/messages", default-features = false }
pallet-finality-verifier = { path = "../../modules/finality-verifier", default-features = false }
# Substrate dependencies
@@ -39,8 +39,8 @@ std = [
"codec/std",
"frame-support/std",
"hash-db/std",
"pallet-bridge-call-dispatch/std",
"pallet-finality-verifier/std",
"pallet-bridge-dispatch/std",
"pallet-bridge-grandpa/std",
"pallet-bridge-messages/std",
"sp-core/std",
"sp-runtime/std",
@@ -50,7 +50,7 @@ std = [
]
runtime-benchmarks = [
"ed25519-dalek/u64_backend",
"pallet-finality-verifier/runtime-benchmarks",
"pallet-bridge-grandpa/runtime-benchmarks",
"pallet-bridge-messages/runtime-benchmarks",
"sp-state-machine",
]
+6 -6
View File
@@ -4,11 +4,11 @@ The [`messages`](./src/messages.rs) module of this crate contains a bunch of hel
messages module into your runtime. Basic prerequisites of these helpers are:
- we're going to bridge Substrate-based chain with another Substrate-based chain;
- both chains have [messages module](../../modules/messages/README.md), Substrate bridge
module and the [call dispatch module](../../modules/call-dispatch/README.md);
module and the [call dispatch module](../../modules/dispatch/README.md);
- all message lanes are identical and may be used to transfer the same messages;
- the messages sent over the bridge are dispatched using
[call dispatch module](../../modules/call-dispatch/README.md);
- the messages are `pallet_bridge_call_dispatch::MessagePayload` structures, where `call` field is
[call dispatch module](../../modules/dispatch/README.md);
- the messages are `pallet_bridge_dispatch::MessagePayload` structures, where `call` field is
encoded `Call` of the target chain. This means that the `Call` is opaque to the
[messages module](../../modules/messages/README.md) instance at the source chain.
It is pre-encoded by the message submitter;
@@ -118,7 +118,7 @@ are: `maximal_message_size`, `verify_chain_message`, `verify_messages_delivery_p
`estimate_message_dispatch_and_delivery_fee`.
`FromThisChainMessagePayload` is a message that the sender sends through our bridge. It is the
`pallet_bridge_call_dispatch::MessagePayload`, where `call` field is encoded target chain call. So
`pallet_bridge_dispatch::MessagePayload`, where `call` field is encoded target chain call. So
at this chain we don't see internals of this call - we just know its size.
`FromThisChainMessageVerifier` is an implementation of `bp_messages::LaneMessageVerifier`. It
@@ -131,8 +131,8 @@ has following checks in its `verify_message` method:
1. it'll reject a message if it has the wrong dispatch origin declared. Like if the submitter is not
the root of this chain, but it tries to dispatch the message at the target chain using
`pallet_bridge_call_dispatch::CallOrigin::SourceRoot` origin. Or he has provided wrong signature
in the `pallet_bridge_call_dispatch::CallOrigin::TargetAccount` origin;
`pallet_bridge_dispatch::CallOrigin::SourceRoot` origin. Or he has provided wrong signature
in the `pallet_bridge_dispatch::CallOrigin::TargetAccount` origin;
1. it'll reject a message if the delivery and dispatch fee that the submitter wants to pay is lesser
than the fee that is computed using the `estimate_message_dispatch_and_delivery_fee` function.
+34 -36
View File
@@ -54,7 +54,7 @@ pub trait MessageBridge {
fn bridged_balance_to_this_balance(bridged_balance: BalanceOf<BridgedChain<Self>>) -> BalanceOf<ThisChain<Self>>;
}
/// Chain that has `pallet-bridge-messages` and `call-dispatch` modules.
/// Chain that has `pallet-bridge-messages` and `dispatch` modules.
pub trait ChainWithMessages {
/// Hash used in the chain.
type Hash: Decode;
@@ -85,7 +85,7 @@ pub struct MessageTransaction<Weight> {
pub size: u32,
}
/// This chain that has `pallet-bridge-messages` and `call-dispatch` modules.
/// This chain that has `pallet-bridge-messages` and `dispatch` modules.
pub trait ThisChainWithMessages: ChainWithMessages {
/// Call type on the chain.
type Call: Encode + Decode;
@@ -105,7 +105,7 @@ pub trait ThisChainWithMessages: ChainWithMessages {
fn transaction_payment(transaction: MessageTransaction<WeightOf<Self>>) -> BalanceOf<Self>;
}
/// Bridged chain that has `pallet-bridge-messages` and `call-dispatch` modules.
/// Bridged chain that has `pallet-bridge-messages` and `dispatch` modules.
pub trait BridgedChainWithMessages: ChainWithMessages {
/// Maximal extrinsic size at Bridged chain.
fn maximal_extrinsic_size() -> u32;
@@ -180,7 +180,7 @@ pub mod source {
pub type BridgedChainOpaqueCall = Vec<u8>;
/// Message payload for This -> Bridged chain messages.
pub type FromThisChainMessagePayload<B> = pallet_bridge_call_dispatch::MessagePayload<
pub type FromThisChainMessagePayload<B> = pallet_bridge_dispatch::MessagePayload<
AccountIdOf<ThisChain<B>>,
SignerOf<BridgedChain<B>>,
SignatureOf<BridgedChain<B>>,
@@ -221,7 +221,7 @@ pub mod source {
/// This verifier assumes following:
///
/// - all message lanes are equivalent, so all checks are the same;
/// - messages are being dispatched using `pallet-bridge-call-dispatch` pallet on the target chain.
/// - messages are being dispatched using `pallet-bridge-dispatch` pallet on the target chain.
///
/// Following checks are made:
///
@@ -267,8 +267,8 @@ pub mod source {
}
// Do the dispatch-specific check. We assume that the target chain uses
// `CallDispatch`, so we verify the message accordingly.
pallet_bridge_call_dispatch::verify_message_origin(submitter, payload).map_err(|_| BAD_ORIGIN)?;
// `Dispatch`, so we verify the message accordingly.
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)?;
@@ -356,17 +356,16 @@ pub mod source {
proof: FromBridgedChainMessagesDeliveryProof<HashOf<BridgedChain<B>>>,
) -> Result<ParsedMessagesDeliveryProofFromBridgedChain<B>, &'static str>
where
ThisRuntime: pallet_finality_verifier::Config,
ThisRuntime: pallet_bridge_grandpa::Config,
ThisRuntime: pallet_bridge_messages::Config<MessagesInstanceOf<BridgedChain<B>>>,
HashOf<BridgedChain<B>>:
Into<bp_runtime::HashOf<<ThisRuntime as pallet_finality_verifier::Config>::BridgedChain>>,
HashOf<BridgedChain<B>>: Into<bp_runtime::HashOf<<ThisRuntime as pallet_bridge_grandpa::Config>::BridgedChain>>,
{
let FromBridgedChainMessagesDeliveryProof {
bridged_header_hash,
storage_proof,
lane,
} = proof;
pallet_finality_verifier::Module::<ThisRuntime>::parse_finalized_storage_proof(
pallet_bridge_grandpa::Module::<ThisRuntime>::parse_finalized_storage_proof(
bridged_header_hash.into(),
StorageProof::new(storage_proof),
|storage| {
@@ -395,14 +394,14 @@ pub mod target {
use super::*;
/// Call origin for Bridged -> This chain messages.
pub type FromBridgedChainMessageCallOrigin<B> = pallet_bridge_call_dispatch::CallOrigin<
pub type FromBridgedChainMessageCallOrigin<B> = pallet_bridge_dispatch::CallOrigin<
AccountIdOf<BridgedChain<B>>,
SignerOf<ThisChain<B>>,
SignatureOf<ThisChain<B>>,
>;
/// Decoded Bridged -> This message payload.
pub type FromBridgedChainMessagePayload<B> = pallet_bridge_call_dispatch::MessagePayload<
pub type FromBridgedChainMessagePayload<B> = pallet_bridge_dispatch::MessagePayload<
AccountIdOf<BridgedChain<B>>,
SignerOf<ThisChain<B>>,
SignatureOf<ThisChain<B>>,
@@ -457,19 +456,19 @@ pub mod target {
/// Dispatching Bridged -> This chain messages.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct FromBridgedChainMessageDispatch<B, ThisRuntime, ThisCallDispatchInstance> {
_marker: PhantomData<(B, ThisRuntime, ThisCallDispatchInstance)>,
pub struct FromBridgedChainMessageDispatch<B, ThisRuntime, ThisDispatchInstance> {
_marker: PhantomData<(B, ThisRuntime, ThisDispatchInstance)>,
}
impl<B: MessageBridge, ThisRuntime, ThisCallDispatchInstance>
impl<B: MessageBridge, ThisRuntime, ThisDispatchInstance>
MessageDispatch<<BridgedChain<B> as ChainWithMessages>::Balance>
for FromBridgedChainMessageDispatch<B, ThisRuntime, ThisCallDispatchInstance>
for FromBridgedChainMessageDispatch<B, ThisRuntime, ThisDispatchInstance>
where
ThisCallDispatchInstance: frame_support::traits::Instance,
ThisRuntime: pallet_bridge_call_dispatch::Config<ThisCallDispatchInstance, MessageId = (LaneId, MessageNonce)>,
<ThisRuntime as pallet_bridge_call_dispatch::Config<ThisCallDispatchInstance>>::Event:
From<pallet_bridge_call_dispatch::RawEvent<(LaneId, MessageNonce), ThisCallDispatchInstance>>,
pallet_bridge_call_dispatch::Module<ThisRuntime, ThisCallDispatchInstance>:
ThisDispatchInstance: frame_support::traits::Instance,
ThisRuntime: pallet_bridge_dispatch::Config<ThisDispatchInstance, MessageId = (LaneId, MessageNonce)>,
<ThisRuntime as pallet_bridge_dispatch::Config<ThisDispatchInstance>>::Event:
From<pallet_bridge_dispatch::RawEvent<(LaneId, MessageNonce), ThisDispatchInstance>>,
pallet_bridge_dispatch::Module<ThisRuntime, ThisDispatchInstance>:
bp_message_dispatch::MessageDispatch<(LaneId, MessageNonce), Message = FromBridgedChainMessagePayload<B>>,
{
type DispatchPayload = FromBridgedChainMessagePayload<B>;
@@ -482,7 +481,7 @@ pub mod target {
fn dispatch(message: DispatchMessage<Self::DispatchPayload, BalanceOf<BridgedChain<B>>>) {
let message_id = (message.key.lane_id, message.key.nonce);
pallet_bridge_call_dispatch::Module::<ThisRuntime, ThisCallDispatchInstance>::dispatch(
pallet_bridge_dispatch::Module::<ThisRuntime, ThisDispatchInstance>::dispatch(
B::INSTANCE,
message_id,
message.data.payload.map_err(drop),
@@ -510,16 +509,15 @@ pub mod target {
messages_count: u32,
) -> Result<ProvedMessages<Message<BalanceOf<BridgedChain<B>>>>, &'static str>
where
ThisRuntime: pallet_finality_verifier::Config,
ThisRuntime: pallet_bridge_grandpa::Config,
ThisRuntime: pallet_bridge_messages::Config<MessagesInstanceOf<BridgedChain<B>>>,
HashOf<BridgedChain<B>>:
Into<bp_runtime::HashOf<<ThisRuntime as pallet_finality_verifier::Config>::BridgedChain>>,
HashOf<BridgedChain<B>>: Into<bp_runtime::HashOf<<ThisRuntime as pallet_bridge_grandpa::Config>::BridgedChain>>,
{
verify_messages_proof_with_parser::<B, _, _>(
proof,
messages_count,
|bridged_header_hash, bridged_storage_proof| {
pallet_finality_verifier::Module::<ThisRuntime>::parse_finalized_storage_proof(
pallet_bridge_grandpa::Module::<ThisRuntime>::parse_finalized_storage_proof(
bridged_header_hash.into(),
StorageProof::new(bridged_storage_proof),
|storage_adapter| storage_adapter,
@@ -931,7 +929,7 @@ mod tests {
let message_on_bridged_chain = source::FromThisChainMessagePayload::<OnBridgedChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: ThisChainCall::Transfer.encode(),
}
.encode();
@@ -945,7 +943,7 @@ mod tests {
target::FromBridgedChainMessagePayload::<OnThisChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: target::FromBridgedChainEncodedMessageCall::<OnThisChainBridge> {
encoded_call: ThisChainCall::Transfer.encode(),
_marker: PhantomData::default(),
@@ -962,7 +960,7 @@ mod tests {
source::FromThisChainMessagePayload::<OnThisChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: vec![42],
}
}
@@ -1012,7 +1010,7 @@ mod tests {
let payload = source::FromThisChainMessagePayload::<OnThisChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: vec![42],
};
@@ -1055,7 +1053,7 @@ mod tests {
let payload = source::FromThisChainMessagePayload::<OnThisChainBridge> {
spec_version: 1,
weight: 100,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceAccount(ThisChainAccountId(1)),
origin: pallet_bridge_dispatch::CallOrigin::SourceAccount(ThisChainAccountId(1)),
call: vec![42],
};
@@ -1122,7 +1120,7 @@ mod tests {
> {
spec_version: 1,
weight: 5,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: vec![1, 2, 3, 4, 5, 6],
},)
.is_err()
@@ -1137,7 +1135,7 @@ mod tests {
> {
spec_version: 1,
weight: BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT + 1,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: vec![1, 2, 3, 4, 5, 6],
},)
.is_err()
@@ -1152,7 +1150,7 @@ mod tests {
> {
spec_version: 1,
weight: BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: vec![0; source::maximal_message_size::<OnThisChainBridge>() as usize + 1],
},)
.is_err()
@@ -1167,7 +1165,7 @@ mod tests {
> {
spec_version: 1,
weight: BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT,
origin: pallet_bridge_call_dispatch::CallOrigin::SourceRoot,
origin: pallet_bridge_dispatch::CallOrigin::SourceRoot,
call: vec![0; source::maximal_message_size::<OnThisChainBridge>() as _],
},),
Ok(()),
@@ -73,7 +73,7 @@ pub fn prepare_message_proof<B, H, R, FI, MM, ML, MH>(
where
B: MessageBridge,
H: Hasher,
R: pallet_finality_verifier::Config<FI>,
R: pallet_bridge_grandpa::Config<FI>,
FI: 'static,
<R::BridgedChain as bp_runtime::Chain>::Hash: Into<HashOf<BridgedChain<B>>>,
MM: Fn(MessageKey) -> Vec<u8>,
@@ -130,7 +130,7 @@ where
// prepare Bridged chain header and insert it into the Substrate pallet
let bridged_header = make_bridged_header(root);
let bridged_header_hash = bridged_header.hash();
pallet_finality_verifier::initialize_for_benchmarks::<R, FI>(bridged_header);
pallet_bridge_grandpa::initialize_for_benchmarks::<R, FI>(bridged_header);
(
FromBridgedChainMessagesProof {
@@ -155,7 +155,7 @@ pub fn prepare_message_delivery_proof<B, H, R, FI, ML, MH>(
where
B: MessageBridge,
H: Hasher,
R: pallet_finality_verifier::Config<FI>,
R: pallet_bridge_grandpa::Config<FI>,
FI: 'static,
<R::BridgedChain as bp_runtime::Chain>::Hash: Into<HashOf<BridgedChain<B>>>,
ML: Fn(LaneId) -> Vec<u8>,
@@ -183,7 +183,7 @@ where
// prepare Bridged chain header and insert it into the Substrate pallet
let bridged_header = make_bridged_header(root);
let bridged_header_hash = bridged_header.hash();
pallet_finality_verifier::initialize_for_benchmarks::<R, FI>(bridged_header);
pallet_bridge_grandpa::initialize_for_benchmarks::<R, FI>(bridged_header);
FromBridgedChainMessagesDeliveryProof {
bridged_header_hash: bridged_header_hash.into(),