Skip to content

Commit aa89c59

Browse files
committed
Let's move some stuff
1 parent bbc435c commit aa89c59

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

substrate/frame/executive/src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ use ::{
192192
#[allow(dead_code)]
193193
const LOG_TARGET: &str = "runtime::executive";
194194

195+
/// Maximum nesting level for extrinsics.
196+
pub const MAX_EXTRINSIC_DEPTH: u32 = 256;
197+
195198
pub type CheckedOf<E, C> = <E as Checkable<C>>::Checked;
196199
pub type CallOf<E, C> = <CheckedOf<E, C> as Applyable>::Call;
197200
pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::RuntimeOrigin;
@@ -776,7 +779,13 @@ where
776779
let encoded = uxt.encode();
777780
let encoded_len = encoded.len();
778781
sp_tracing::enter_span!(sp_tracing::info_span!("apply_extrinsic",
779-
ext=?sp_core::hexdisplay::HexDisplay::from(&encoded)));
782+
ext=?sp_core::hexdisplay::HexDisplay::from(&encoded)));
783+
784+
let uxt = <Block::Extrinsic as codec::DecodeLimit>::decode_all_with_depth_limit(
785+
MAX_EXTRINSIC_DEPTH,
786+
&mut &encoded[..],
787+
)
788+
.expect("Decoding the encoded transaction works; qed");
780789

781790
// We use the dedicated `is_inherent` check here, since just relying on `Mandatory` dispatch
782791
// class does not capture optional inherents.
@@ -861,10 +870,16 @@ where
861870

862871
enter_span! { sp_tracing::Level::TRACE, "validate_transaction" };
863872

864-
let encoded_len = within_span! { sp_tracing::Level::TRACE, "using_encoded";
865-
uxt.using_encoded(|d| d.len())
873+
let encoded = within_span! { sp_tracing::Level::TRACE, "using_encoded";
874+
uxt.encode()
866875
};
867876

877+
let uxt = <Block::Extrinsic as codec::DecodeLimit>::decode_all_with_depth_limit(
878+
MAX_EXTRINSIC_DEPTH,
879+
&mut &encoded[..],
880+
)
881+
.map_err(|_| InvalidTransaction::Call)?;
882+
868883
let xt = within_span! { sp_tracing::Level::TRACE, "check";
869884
uxt.check(&Default::default())
870885
}?;
@@ -879,7 +894,7 @@ where
879894

880895
within_span! {
881896
sp_tracing::Level::TRACE, "validate";
882-
xt.validate::<UnsignedValidator>(source, &dispatch_info, encoded_len)
897+
xt.validate::<UnsignedValidator>(source, &dispatch_info, encoded.len())
883898
}
884899
}
885900

substrate/primitives/api/proc-macro/src/impl_runtime_apis.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ fn generate_impl_call(
100100

101101
quote!(
102102
#let_binding =
103-
match #c::DecodeLimit::decode_all_with_depth_limit(
104-
#c::MAX_EXTRINSIC_DEPTH,
103+
match #c::Decode::decode(
105104
&mut #input,
106105
) {
107106
Ok(res) => res,

0 commit comments

Comments
 (0)