Skip to content

Commit f6fff7f

Browse files
authored
fix(frame): CheckWeight controls should be applied on pre_dispatch (#749)
1 parent 6ffdcff commit f6fff7f

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

frame/ethereum/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ where
125125
pub fn pre_dispatch_self_contained(
126126
&self,
127127
origin: &H160,
128+
dispatch_info: &DispatchInfoOf<T::Call>,
129+
len: usize,
128130
) -> Option<Result<(), TransactionValidityError>> {
129131
if let Call::transact { transaction } = self {
132+
if let Err(e) = CheckWeight::<T>::do_pre_dispatch(dispatch_info, len) {
133+
return Some(Err(e));
134+
}
135+
130136
Some(Pallet::<T>::validate_transaction_in_block(
131137
*origin,
132138
transaction,

frame/ethereum/src/mock.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ impl fp_self_contained::SelfContainedCall for Call {
207207
fn pre_dispatch_self_contained(
208208
&self,
209209
info: &Self::SignedInfo,
210+
dispatch_info: &DispatchInfoOf<Call>,
211+
len: usize,
210212
) -> Option<Result<(), TransactionValidityError>> {
211213
match self {
212-
Call::Ethereum(call) => call.pre_dispatch_self_contained(info),
214+
Call::Ethereum(call) => call.pre_dispatch_self_contained(info, dispatch_info, len),
213215
_ => None,
214216
}
215217
}

primitives/self-contained/src/checked_extrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ where
140140
CheckedSignature::SelfContained(signed_info) => {
141141
// If pre-dispatch fail, the block must be considered invalid
142142
self.function
143-
.pre_dispatch_self_contained(&signed_info)
143+
.pre_dispatch_self_contained(&signed_info, info, len)
144144
.ok_or(TransactionValidityError::Invalid(
145145
InvalidTransaction::BadProof,
146146
))??;

primitives/self-contained/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ pub trait SelfContainedCall: Dispatchable {
6262
fn pre_dispatch_self_contained(
6363
&self,
6464
info: &Self::SignedInfo,
65-
) -> Option<Result<(), TransactionValidityError>>;
65+
dispatch_info: &DispatchInfoOf<Self>,
66+
len: usize,
67+
) -> Option<Result<(), TransactionValidityError>> {
68+
self.validate_self_contained(info, dispatch_info, len)
69+
.map(|res| res.map(|_| ()))
70+
}
6671
/// Apply a self-contained function. Returns `None` if the
6772
/// function is not a self-contained.
6873
fn apply_self_contained(

template/runtime/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,11 @@ impl fp_self_contained::SelfContainedCall for Call {
502502
fn pre_dispatch_self_contained(
503503
&self,
504504
info: &Self::SignedInfo,
505+
dispatch_info: &DispatchInfoOf<Call>,
506+
len: usize,
505507
) -> Option<Result<(), TransactionValidityError>> {
506508
match self {
507-
Call::Ethereum(call) => call.pre_dispatch_self_contained(info),
509+
Call::Ethereum(call) => call.pre_dispatch_self_contained(info, dispatch_info, len),
508510
_ => None,
509511
}
510512
}

0 commit comments

Comments
 (0)