mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 18:35:41 +00:00
4c7539cab5
* Use beefy branch with scale-info * Add patches * Sprinkle some TypeInfo derives * Add some TypeInfo deriv * Cargo.lock * Derive TypeInfo and skip type params for Xcm types * Cargo.lock * Fix up scale_info bounds attributes * Fix up dependencies * Use my own beefy-primitives branch * Bump BEEFY * Update patches * Add some scale-info dependencies and TypeInfo derives * More TypeInfo decoration * Update scale-info * Some TypeInfos and remove more Event pallet::metadata * Moar TypeInfos * TypeInfos galore, fix up metadata runtime API * TypeInfo * TypeInfos, update other runtime metadata APIs * Fix up Kusama, comment out some `usize` QueueSize parameter types * Remove local diener patches * Cargo.lock * Cargo.lock * Update to scale-info crates.io release * Update primitive-types branch * Update pallet-beefy to use custom branch * Update other parity-common deps * Update parity-common patches * bump a bunch of deps in parity-common * Remove parity-common patches * Bump finality-grandpa version * Cargo.lock * Update scale-info to 0.9.1 * Add recursion_limit for runtime-parachains * Add some scale_info attributes * Cargo.lock * Revert finality-grandpa bump * Cargo.lock, scale-info update * cargo update * Make sure using patched version of finality-grandpa * Use patched scale-info * Update to scale-info 0.10.0 * Update finality-grandpa * Cargo.lock * Update beefy deps * Update beefy deps again * Add scale-info dependency * Remove deprecated pallet::metadata attributes. * Add some missing scale-info deps and derives * Use some variant struct call syntax * Add missing TypeInfo impl * Add some more TypeInfo impls * Convert some call enum struct variant constructors * More scale-info deps and derives * Call enum struct variants * TypeInfo derives * Call enum variant structs * scale-info deps and derives * Call enum variant struct constructors * Use beefy-primitives scale-info feature * Use grandpa-bridge-gadget master branch * Remove finality-grandpa patch * Add missing scale_info dependency and derive * Fix up some call variant constructors * Add missing scale_info dependency * Fix some test errors * More TypeInfo derives * More call variant structs * Call variant structs in tests * Cargo.lock * Fmt * Fix more call struct variants * Another call struct variant * add scale-info/std features explicitly * More call struct variants * Add missing scale-info dependency * Fmt * review: activate scale-info/std where missing * Remove some duplicate std feature activation * review: add scale_info bounds() attr * More call variant structs * Remove recursion limit * Update beefy-primitives * Update beefy-primitives * Fix simnet call variant struct errors * Fmt * cargo update -p beefy-primitives * Add some missing TypeInfo derives * Fix some call variants * Fix some call variant underscores * Cargo.lock * Cargo.lock * Add missing TypeInfo derive * Add some more missing TypeInfo derives * Even more missing TypeInfo derives * Add TypeInfo derives to new xcm types * Fmt * Cargo.lock * Add missing TypeInfo impls * Cargo.lock * More missing TypeInfos * Fixes * Cargo.lock * Cargo.lock * Add TypeInfo impls to xcm v2 * Update to scale-info 1.0 * Update finality-grandpa 0.14.4, patch for now * Update beefy * Remove patched finality-grandpa * Add TypeInfo impl to Outcome * Fixes * Call variant struct * Call variant struct * Fix test * Add TypeInfo impl * Cargo.lock * Cargo.lock * Cargo.lock * git checkout master Cargo.lock * update Substrate * Add missing scale-info features for beefy-primitives * Fmt * Remove check for now * Update beefy-primitives, removes scale-info feature * Update beefy-primitives again Co-authored-by: adoerr <0xad@gmx.net> Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: thiolliere <gui.thiolliere@gmail.com> Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <info@kchr.de>
174 lines
6.1 KiB
Rust
174 lines
6.1 KiB
Rust
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Bridges Common.
|
|
|
|
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Bridges Common is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// 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/>.
|
|
|
|
//! Primitives of messages module, that are used on the target chain.
|
|
|
|
use crate::{LaneId, Message, MessageData, MessageKey, OutboundLaneData};
|
|
|
|
use bp_runtime::{messages::MessageDispatchResult, Size};
|
|
use codec::{Decode, Encode, Error as CodecError};
|
|
use frame_support::{weights::Weight, Parameter, RuntimeDebug};
|
|
use scale_info::TypeInfo;
|
|
use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, prelude::*};
|
|
|
|
/// Proved messages from the source chain.
|
|
pub type ProvedMessages<Message> = BTreeMap<LaneId, ProvedLaneMessages<Message>>;
|
|
|
|
/// Proved messages from single lane of the source chain.
|
|
#[derive(RuntimeDebug, Encode, Decode, Clone, PartialEq, Eq, TypeInfo)]
|
|
pub struct ProvedLaneMessages<Message> {
|
|
/// Optional outbound lane state.
|
|
pub lane_state: Option<OutboundLaneData>,
|
|
/// Messages sent through this lane.
|
|
pub messages: Vec<Message>,
|
|
}
|
|
|
|
/// Message data with decoded dispatch payload.
|
|
#[derive(RuntimeDebug)]
|
|
pub struct DispatchMessageData<DispatchPayload, Fee> {
|
|
/// Result of dispatch payload decoding.
|
|
pub payload: Result<DispatchPayload, CodecError>,
|
|
/// Message delivery and dispatch fee, paid by the submitter.
|
|
pub fee: Fee,
|
|
}
|
|
|
|
/// Message with decoded dispatch payload.
|
|
#[derive(RuntimeDebug)]
|
|
pub struct DispatchMessage<DispatchPayload, Fee> {
|
|
/// Message key.
|
|
pub key: MessageKey,
|
|
/// Message data with decoded dispatch payload.
|
|
pub data: DispatchMessageData<DispatchPayload, Fee>,
|
|
}
|
|
|
|
/// Source chain API. Used by target chain, to verify source chain proofs.
|
|
///
|
|
/// All implementations of this trait should only work with finalized data that
|
|
/// can't change. Wrong implementation may lead to invalid lane states (i.e. lane
|
|
/// that's stuck) and/or processing messages without paying fees.
|
|
pub trait SourceHeaderChain<Fee> {
|
|
/// Error type.
|
|
type Error: Debug + Into<&'static str>;
|
|
|
|
/// Proof that messages are sent from source chain. This may also include proof
|
|
/// of corresponding outbound lane states.
|
|
type MessagesProof: Parameter + Size;
|
|
|
|
/// Verify messages proof and return proved messages.
|
|
///
|
|
/// Returns error if either proof is incorrect, or the number of messages in the proof
|
|
/// is not matching the `messages_count`.
|
|
///
|
|
/// Messages vector is required to be sorted by nonce within each lane. Out-of-order
|
|
/// messages will be rejected.
|
|
///
|
|
/// The `messages_count` argument verification (sane limits) is supposed to be made
|
|
/// outside of this function. This function only verifies that the proof declares exactly
|
|
/// `messages_count` messages.
|
|
fn verify_messages_proof(
|
|
proof: Self::MessagesProof,
|
|
messages_count: u32,
|
|
) -> Result<ProvedMessages<Message<Fee>>, Self::Error>;
|
|
}
|
|
|
|
/// Called when inbound message is received.
|
|
pub trait MessageDispatch<AccountId, Fee> {
|
|
/// Decoded message payload type. Valid message may contain invalid payload. In this case
|
|
/// message is delivered, but dispatch fails. Therefore, two separate types of payload
|
|
/// (opaque `MessagePayload` used in delivery and this `DispatchPayload` used in dispatch).
|
|
type DispatchPayload: Decode;
|
|
|
|
/// Estimate dispatch weight.
|
|
///
|
|
/// This function must: (1) be instant and (2) return correct upper bound
|
|
/// of dispatch weight.
|
|
fn dispatch_weight(message: &DispatchMessage<Self::DispatchPayload, Fee>) -> Weight;
|
|
|
|
/// Called when inbound message is received.
|
|
///
|
|
/// It is up to the implementers of this trait to determine whether the message
|
|
/// is invalid (i.e. improperly encoded, has too large weight, ...) or not.
|
|
///
|
|
/// If your configuration allows paying dispatch fee at the target chain, then
|
|
/// it must be paid inside this method to the `relayer_account`.
|
|
fn dispatch(
|
|
relayer_account: &AccountId,
|
|
message: DispatchMessage<Self::DispatchPayload, Fee>,
|
|
) -> MessageDispatchResult;
|
|
}
|
|
|
|
impl<Message> Default for ProvedLaneMessages<Message> {
|
|
fn default() -> Self {
|
|
ProvedLaneMessages {
|
|
lane_state: None,
|
|
messages: Vec::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<DispatchPayload: Decode, Fee> From<Message<Fee>> for DispatchMessage<DispatchPayload, Fee> {
|
|
fn from(message: Message<Fee>) -> Self {
|
|
DispatchMessage {
|
|
key: message.key,
|
|
data: message.data.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<DispatchPayload: Decode, Fee> From<MessageData<Fee>> for DispatchMessageData<DispatchPayload, Fee> {
|
|
fn from(data: MessageData<Fee>) -> Self {
|
|
DispatchMessageData {
|
|
payload: DispatchPayload::decode(&mut &data.payload[..]),
|
|
fee: data.fee,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Structure that may be used in place of `SourceHeaderChain` and `MessageDispatch` on chains,
|
|
/// where inbound messages are forbidden.
|
|
pub struct ForbidInboundMessages;
|
|
|
|
/// Error message that is used in `ForbidOutboundMessages` implementation.
|
|
const ALL_INBOUND_MESSAGES_REJECTED: &str = "This chain is configured to reject all inbound messages";
|
|
|
|
impl<Fee> SourceHeaderChain<Fee> for ForbidInboundMessages {
|
|
type Error = &'static str;
|
|
type MessagesProof = ();
|
|
|
|
fn verify_messages_proof(
|
|
_proof: Self::MessagesProof,
|
|
_messages_count: u32,
|
|
) -> Result<ProvedMessages<Message<Fee>>, Self::Error> {
|
|
Err(ALL_INBOUND_MESSAGES_REJECTED)
|
|
}
|
|
}
|
|
|
|
impl<AccountId, Fee> MessageDispatch<AccountId, Fee> for ForbidInboundMessages {
|
|
type DispatchPayload = ();
|
|
|
|
fn dispatch_weight(_message: &DispatchMessage<Self::DispatchPayload, Fee>) -> Weight {
|
|
Weight::MAX
|
|
}
|
|
|
|
fn dispatch(_: &AccountId, _: DispatchMessage<Self::DispatchPayload, Fee>) -> MessageDispatchResult {
|
|
MessageDispatchResult {
|
|
dispatch_result: false,
|
|
unspent_weight: 0,
|
|
dispatch_fee_paid_during_dispatch: false,
|
|
}
|
|
}
|
|
}
|