mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Use DecodeLimit for decoding XCM messages (#605)
* Use DecodeLimit for decoding XCM messages * Use decode_all_with_depth_limit in appropriate places * Use decode_all while decoding byte vector * cargo fmt
This commit is contained in:
@@ -6,10 +6,10 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
# Other dependencies
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "derive" ], default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "2.3.0", features = [ "derive" ], default-features = false }
|
||||
rand_chacha = { version = "0.3.0", default-features = false }
|
||||
scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
log = { version = "0.4.14", default-features = false }
|
||||
rand_chacha = { version = "0.3.0", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
@@ -31,7 +31,7 @@ mod mock;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use codec::{Decode, DecodeAll, DecodeLimit, Encode};
|
||||
use cumulus_primitives_core::{
|
||||
relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError,
|
||||
ParaId, XcmpMessageFormat, XcmpMessageHandler, XcmpMessageSource,
|
||||
@@ -44,7 +44,7 @@ use rand_chacha::{
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{traits::Hash, RuntimeDebug};
|
||||
use sp_std::{convert::TryFrom, prelude::*};
|
||||
use xcm::{latest::prelude::*, VersionedXcm, WrapVersion};
|
||||
use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH};
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
@@ -249,7 +249,11 @@ impl<T: Config> Pallet<T> {
|
||||
let have_active = s[index].4 > s[index].3;
|
||||
let appended = have_active &&
|
||||
<OutboundXcmpMessages<T>>::mutate(recipient, s[index].4 - 1, |s| {
|
||||
if XcmpMessageFormat::decode(&mut &s[..]) != Ok(format) {
|
||||
if XcmpMessageFormat::decode_and_advance_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut &s[..],
|
||||
) != Ok(format)
|
||||
{
|
||||
return false
|
||||
}
|
||||
if s.len() + data.len() > max_message_size {
|
||||
@@ -371,7 +375,10 @@ impl<T: Config> Pallet<T> {
|
||||
XcmpMessageFormat::ConcatenatedVersionedXcm => {
|
||||
while !remaining_fragments.is_empty() {
|
||||
last_remaining_fragments = remaining_fragments;
|
||||
if let Ok(xcm) = VersionedXcm::<T::Call>::decode(&mut remaining_fragments) {
|
||||
if let Ok(xcm) = VersionedXcm::<T::Call>::decode_and_advance_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut remaining_fragments,
|
||||
) {
|
||||
let weight = max_weight - weight_used;
|
||||
match Self::handle_xcm_message(sender, sent_at, xcm, weight) {
|
||||
Ok(used) => weight_used = weight_used.saturating_add(used),
|
||||
@@ -394,7 +401,7 @@ impl<T: Config> Pallet<T> {
|
||||
XcmpMessageFormat::ConcatenatedEncodedBlob => {
|
||||
while !remaining_fragments.is_empty() {
|
||||
last_remaining_fragments = remaining_fragments;
|
||||
if let Ok(blob) = <Vec<u8>>::decode(&mut remaining_fragments) {
|
||||
if let Ok(blob) = <Vec<u8>>::decode_all(&mut remaining_fragments) {
|
||||
let weight = max_weight - weight_used;
|
||||
match Self::handle_blob_message(sender, sent_at, blob, weight) {
|
||||
Ok(used) => weight_used = weight_used.saturating_add(used),
|
||||
@@ -588,7 +595,10 @@ impl<T: Config> XcmpMessageHandler for Pallet<T> {
|
||||
for (sender, sent_at, data) in iter {
|
||||
// Figure out the message format.
|
||||
let mut data_ref = data;
|
||||
let format = match XcmpMessageFormat::decode(&mut data_ref) {
|
||||
let format = match XcmpMessageFormat::decode_and_advance_with_depth_limit(
|
||||
MAX_XCM_DECODE_DEPTH,
|
||||
&mut data_ref,
|
||||
) {
|
||||
Ok(f) => f,
|
||||
Err(_) => {
|
||||
debug_assert!(false, "Unknown XCMP message format. Silently dropping message");
|
||||
|
||||
Reference in New Issue
Block a user