mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Merge commit 'f9c24ef0db390c355241445af37a5c7999a7dc66' into hc-bump-bridges-subtree-take-2
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use bp_message_dispatch::{MessageDispatch, Weight};
|
||||
use bp_runtime::{derive_account_id, InstanceId, Size, SourceAccount};
|
||||
use bp_message_dispatch::{CallOrigin, MessageDispatch, MessagePayload, SpecVersion, Weight};
|
||||
use bp_runtime::{derive_account_id, InstanceId, SourceAccount};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
decl_event, decl_module, decl_storage,
|
||||
@@ -33,7 +33,6 @@ use frame_support::{
|
||||
ensure,
|
||||
traits::{Filter, Get},
|
||||
weights::{extract_actual_weight, GetDispatchInfo},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::{
|
||||
@@ -42,78 +41,6 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_std::{fmt::Debug, marker::PhantomData, prelude::*};
|
||||
|
||||
/// Spec version type.
|
||||
pub type SpecVersion = u32;
|
||||
|
||||
// TODO [#895] move to primitives
|
||||
/// Origin of a Call when it is dispatched on the target chain.
|
||||
///
|
||||
/// The source chain can (and should) verify that the message can be dispatched on the target chain
|
||||
/// with a particular origin given the source chain's origin. This can be done with the
|
||||
/// `verify_message_origin()` function.
|
||||
#[derive(RuntimeDebug, Encode, Decode, Clone, PartialEq, Eq)]
|
||||
pub enum CallOrigin<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature> {
|
||||
/// Call is sent by the Root origin on the source chain. On the target chain it is dispatched
|
||||
/// from a derived account.
|
||||
///
|
||||
/// The derived account represents the source Root account on the target chain. This is useful
|
||||
/// if the target chain needs some way of knowing that a call came from a priviledged origin on
|
||||
/// the source chain (maybe to allow a configuration change for example).
|
||||
SourceRoot,
|
||||
|
||||
/// Call is sent by `SourceChainAccountId` on the source chain. On the target chain it is
|
||||
/// dispatched from an account controlled by a private key on the target chain.
|
||||
///
|
||||
/// The account can be identified by `TargetChainAccountPublic`. The proof that the
|
||||
/// `SourceChainAccountId` controls `TargetChainAccountPublic` is the `TargetChainSignature`
|
||||
/// over `(Call, SourceChainAccountId, TargetChainSpecVersion, SourceChainBridgeId).encode()`.
|
||||
///
|
||||
/// NOTE sending messages using this origin (or any other) does not have replay protection!
|
||||
/// The assumption is that both the source account and the target account is controlled by
|
||||
/// the same entity, so source-chain replay protection is sufficient.
|
||||
/// As a consequence, it's extremely important for the target chain user to never produce
|
||||
/// a signature with their target-private key on something that could be sent over the bridge,
|
||||
/// i.e. if the target user signs `(<some-source-account-id>, Call::Transfer(X, 5))`
|
||||
/// The owner of `some-source-account-id` can send that message multiple times, which would
|
||||
/// result with multiple transfer calls being dispatched on the target chain.
|
||||
/// So please, NEVER USE YOUR PRIVATE KEY TO SIGN SOMETHING YOU DON'T FULLY UNDERSTAND!
|
||||
TargetAccount(SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature),
|
||||
|
||||
/// Call is sent by the `SourceChainAccountId` on the source chain. On the target chain it is
|
||||
/// dispatched from a derived account ID.
|
||||
///
|
||||
/// The account ID on the target chain is derived from the source account ID This is useful if
|
||||
/// you need a way to represent foreign accounts on this chain for call dispatch purposes.
|
||||
///
|
||||
/// Note that the derived account does not need to have a private key on the target chain. This
|
||||
/// origin can therefore represent proxies, pallets, etc. as well as "regular" accounts.
|
||||
SourceAccount(SourceChainAccountId),
|
||||
}
|
||||
|
||||
// TODO [#895] move to primitives
|
||||
/// 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
|
||||
/// runtime version. Otherwise we risk to misinterpret encoded calls.
|
||||
pub spec_version: SpecVersion,
|
||||
/// Weight of the call, declared by the message sender. If it is less than actual
|
||||
/// static weight, the call is not dispatched.
|
||||
pub weight: Weight,
|
||||
/// Call origin to be used during dispatch.
|
||||
pub origin: CallOrigin<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature>,
|
||||
/// The call itself.
|
||||
pub call: Call,
|
||||
}
|
||||
|
||||
impl<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature> Size
|
||||
for MessagePayload<SourceChainAccountId, TargetChainAccountPublic, TargetChainSignature, Vec<u8>>
|
||||
{
|
||||
fn size_hint(&self) -> u32 {
|
||||
self.call.len() as _
|
||||
}
|
||||
}
|
||||
|
||||
/// The module configuration trait.
|
||||
pub trait Config<I = DefaultInstance>: frame_system::Config {
|
||||
/// The overarching event type.
|
||||
@@ -314,8 +241,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::MessageId> for Pallet<T, I> {
|
||||
|
||||
// finally dispatch message
|
||||
let origin = RawOrigin::Signed(origin_account).into();
|
||||
|
||||
log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:?}", &call);
|
||||
log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:.4096?}", &call);
|
||||
let dispatch_result = call.dispatch(origin);
|
||||
let actual_call_weight = extract_actual_weight(&dispatch_result, &dispatch_info);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user