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
@@ -1,5 +1,5 @@
[package]
name = "pallet-bridge-call-dispatch"
name = "pallet-bridge-dispatch"
description = "A Substrate Runtime module that dispatches a bridge message, treating it simply as encoded Call"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
@@ -1,7 +1,7 @@
# Call Dispatch Module
The call dispatch module has a single internal (only callable by other runtime modules) entry point
for dispatching encoded calls (`pallet_bridge_call_dispatch::Module::dispatch`). Every dispatch
for dispatching encoded calls (`pallet_bridge_dispatch::Module::dispatch`). Every dispatch
(successful or not) emits a corresponding module event. The module doesn't have any call-related
requirements - they may come from the bridged chain over some message lane, or they may be crafted
locally. But in this document we'll mostly talk about this module in the context of bridges.
@@ -13,7 +13,7 @@ Every message that is being dispatched has three main characteristics:
- `id` is the unique id of the message within the given bridge. For messages coming from the
[messages module](../messages/README.md), it may worth to use a tuple
`(LaneId, MessageNonce)` to identify a message;
- `message` is the `pallet_bridge_call_dispatch::MessagePayload` structure. The `call` field is set
- `message` is the `pallet_bridge_dispatch::MessagePayload` structure. The `call` field is set
to the (potentially) encoded `Call` of this chain.
The easiest way to understand what is happening when a `Call` is being dispatched, is to look at the
@@ -33,7 +33,7 @@ module events set:
chain storage has been corrupted. The `Call` is decoded after `spec_version` check, so we'll never
try to decode `Call` from other runtime version;
- `MessageSignatureMismatch` event is emitted if submitter has chose to dispatch message using
specified this chain account (`pallet_bridge_call_dispatch::CallOrigin::TargetAccount` origin),
specified this chain account (`pallet_bridge_dispatch::CallOrigin::TargetAccount` origin),
but he has failed to prove that he owns the private key for this account;
- `MessageCallRejected` event is emitted if the module has been deployed with some call filter and
this filter has rejected the `Call`. In your bridge you may choose to reject all messages except
@@ -89,7 +89,7 @@ pub enum CallOrigin<SourceChainAccountId, TargetChainAccountPublic, TargetChainS
SourceAccount(SourceChainAccountId),
}
/// Message payload type used by call-dispatch module.
/// Message payload type used by dispatch module.
#[derive(RuntimeDebug, Encode, Decode, Clone, PartialEq, Eq)]
pub struct MessagePayload<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature, Call> {
/// Runtime specification version. We only dispatch messages that have the same
@@ -153,7 +153,7 @@ pub trait Config<I = DefaultInstance>: frame_system::Config {
}
decl_storage! {
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as CallDispatch {}
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as Dispatch {}
}
decl_event!(
@@ -202,7 +202,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let message = match message {
Ok(message) => message,
Err(_) => {
log::trace!("Message {:?}/{:?}: rejected before actual dispatch", bridge, id);
log::trace!(target: "runtime::bridge-dispatch", "Message {:?}/{:?}: rejected before actual dispatch", bridge, id);
Self::deposit_event(RawEvent::MessageRejected(bridge, id));
return;
}
@@ -232,7 +232,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let call = match message.call.into() {
Ok(call) => call,
Err(_) => {
log::trace!("Failed to decode Call from message {:?}/{:?}", bridge, id,);
log::trace!(target: "runtime::bridge-dispatch", "Failed to decode Call from message {:?}/{:?}", bridge, id,);
Self::deposit_event(RawEvent::MessageCallDecodeFailed(bridge, id));
return;
}
@@ -243,7 +243,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
CallOrigin::SourceRoot => {
let hex_id = derive_account_id::<T::SourceChainAccountId>(bridge, SourceAccount::Root);
let target_id = T::AccountIdConverter::convert(hex_id);
log::trace!("Root Account: {:?}", &target_id);
log::trace!(target: "runtime::bridge-dispatch", "Root Account: {:?}", &target_id);
target_id
}
CallOrigin::TargetAccount(source_account_id, target_public, target_signature) => {
@@ -252,6 +252,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let target_account = target_public.into_account();
if !target_signature.verify(&digest[..], &target_account) {
log::trace!(
target: "runtime::bridge-dispatch",
"Message {:?}/{:?}: origin proof is invalid. Expected account: {:?} from signature: {:?}",
bridge,
id,
@@ -262,13 +263,13 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
return;
}
log::trace!("Target Account: {:?}", &target_account);
log::trace!(target: "runtime::bridge-dispatch", "Target Account: {:?}", &target_account);
target_account
}
CallOrigin::SourceAccount(source_account_id) => {
let hex_id = derive_account_id(bridge, SourceAccount::Account(source_account_id));
let target_id = T::AccountIdConverter::convert(hex_id);
log::trace!("Source Account: {:?}", &target_id);
log::trace!(target: "runtime::bridge-dispatch", "Source Account: {:?}", &target_id);
target_id
}
};
@@ -276,6 +277,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
// filter the call
if !T::CallFilter::filter(&call) {
log::trace!(
target: "runtime::bridge-dispatch",
"Message {:?}/{:?}: the call ({:?}) is rejected by filter",
bridge,
id,
@@ -292,6 +294,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
let expected_weight = dispatch_info.weight;
if message.weight < expected_weight {
log::trace!(
target: "runtime::bridge-dispatch",
"Message {:?}/{:?}: passed weight is too low. Expected at least {:?}, got {:?}",
bridge,
id,
@@ -310,11 +313,12 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Module<T, I> {
// finally dispatch message
let origin = RawOrigin::Signed(origin_account).into();
log::trace!("Message being dispatched is: {:?}", &call);
log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:?}", &call);
let dispatch_result = call.dispatch(origin);
let actual_call_weight = extract_actual_weight(&dispatch_result, &dispatch_info);
log::trace!(
target: "runtime::bridge-dispatch",
"Message {:?}/{:?} has been dispatched. Weight: {} of {}. Result: {:?}",
bridge,
id,
@@ -452,7 +456,7 @@ mod tests {
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
CallDispatch: call_dispatch::{Module, Call, Event<T>},
Dispatch: call_dispatch::{Module, Call, Event<T>},
}
}
@@ -571,7 +575,7 @@ mod tests {
message.spec_version = BAD_SPEC_VERSION;
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -599,7 +603,7 @@ mod tests {
message.weight = 0;
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -627,7 +631,7 @@ mod tests {
);
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -649,7 +653,7 @@ mod tests {
let id = [0; 4];
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Err(()));
Dispatch::dispatch(bridge, id, Err(()));
assert_eq!(
System::events(),
@@ -673,7 +677,7 @@ mod tests {
message.call.0 = vec![];
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -700,7 +704,7 @@ mod tests {
message.weight = weight;
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -721,7 +725,7 @@ mod tests {
let message = prepare_root_message(Call::System(<frame_system::Call<TestRuntime>>::remark(vec![1, 2, 3])));
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -748,7 +752,7 @@ mod tests {
let message = prepare_target_message(call);
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -775,7 +779,7 @@ mod tests {
let message = prepare_source_message(call);
System::set_block_number(1);
CallDispatch::dispatch(bridge, id, Ok(message));
Dispatch::dispatch(bridge, id, Ok(message));
assert_eq!(
System::events(),
@@ -1,5 +1,5 @@
[package]
name = "pallet-finality-verifier"
name = "pallet-bridge-grandpa"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
//! Substrate Finality Verifier Pallet
//! Substrate GRANDPA Pallet
//!
//! This pallet is an on-chain GRANDPA light client for Substrate based chains.
//!
@@ -122,7 +122,7 @@ pub mod pallet {
);
let (hash, number) = (finality_target.hash(), finality_target.number());
log::trace!("Going to try and finalize header {:?}", finality_target);
log::trace!(target: "runtime::bridge-grandpa", "Going to try and finalize header {:?}", finality_target);
let best_finalized = <ImportedHeaders<T, I>>::get(<BestFinalized<T, I>>::get()).expect(
"In order to reach this point the bridge must have been initialized. Afterwards,
@@ -141,7 +141,7 @@ pub mod pallet {
<ImportedHeaders<T, I>>::insert(hash, finality_target);
<RequestCount<T, I>>::mutate(|count| *count += 1);
log::info!("Succesfully imported finalized header with hash {:?}!", hash);
log::info!(target: "runtime::bridge-grandpa", "Succesfully imported finalized header with hash {:?}!", hash);
Ok(().into())
}
@@ -167,6 +167,7 @@ pub mod pallet {
initialize_bridge::<T, I>(init_data.clone());
log::info!(
target: "runtime::bridge-grandpa",
"Pallet has been initialized with the following parameters: {:?}",
init_data
);
@@ -183,11 +184,11 @@ pub mod pallet {
match new_owner {
Some(new_owner) => {
ModuleOwner::<T, I>::put(&new_owner);
log::info!("Setting pallet Owner to: {:?}", new_owner);
log::info!(target: "runtime::bridge-grandpa", "Setting pallet Owner to: {:?}", new_owner);
}
None => {
ModuleOwner::<T, I>::kill();
log::info!("Removed Owner of pallet.");
log::info!(target: "runtime::bridge-grandpa", "Removed Owner of pallet.");
}
}
@@ -203,9 +204,9 @@ pub mod pallet {
<IsHalted<T, I>>::put(operational);
if operational {
log::info!("Resuming pallet operations.");
log::info!(target: "runtime::bridge-grandpa", "Resuming pallet operations.");
} else {
log::warn!("Stopping pallet operations.");
log::warn!(target: "runtime::bridge-grandpa", "Stopping pallet operations.");
}
Ok(().into())
@@ -343,6 +344,7 @@ pub mod pallet {
<CurrentAuthoritySet<T, I>>::put(&next_authorities);
log::info!(
target: "runtime::bridge-grandpa",
"Transitioned from authority set {} to {}! New authorities are: {:?}",
current_set_id,
current_set_id + 1,
@@ -370,7 +372,7 @@ pub mod pallet {
Ok(
verify_justification::<BridgedHeader<T, I>>((hash, number), set_id, &voter_set, &justification).map_err(
|e| {
log::error!("Received invalid justification for {:?}: {:?}", hash, e);
log::error!(target: "runtime::bridge-grandpa", "Received invalid justification for {:?}: {:?}", hash, e);
<Error<T, I>>::InvalidJustification
},
)?,
@@ -33,7 +33,7 @@ pub type TestHash = crate::BridgedBlockHash<TestRuntime, ()>;
type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;
use crate as finality_verifier;
use crate as grandpa;
construct_runtime! {
pub enum TestRuntime where
@@ -42,7 +42,7 @@ construct_runtime! {
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
FinalityVerifier: finality_verifier::{Module},
Grandpa: grandpa::{Module},
}
}
@@ -82,7 +82,7 @@ parameter_types! {
pub const MaxRequests: u32 = 2;
}
impl finality_verifier::Config for TestRuntime {
impl grandpa::Config for TestRuntime {
type BridgedChain = TestBridgedChain;
type MaxRequests = MaxRequests;
}