Skip to content

Commit 31938d3

Browse files
committed
remove fp-self-contained and migrate template to use new extrinsic format
1 parent 561dffa commit 31938d3

File tree

17 files changed

+148
-895
lines changed

17 files changed

+148
-895
lines changed

Cargo.lock

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ members = [
3232
"primitives/dynamic-fee",
3333
"primitives/evm",
3434
"primitives/rpc",
35-
"primitives/self-contained",
3635
"template/node",
3736
"template/runtime",
3837
"precompiles",
@@ -190,7 +189,6 @@ fp-dynamic-fee = { path = "primitives/dynamic-fee", default-features = false }
190189
fp-ethereum = { path = "primitives/ethereum", default-features = false }
191190
fp-evm = { path = "primitives/evm", default-features = false }
192191
fp-rpc = { path = "primitives/rpc", default-features = false }
193-
fp-self-contained = { path = "primitives/self-contained", default-features = false }
194192
fp-storage = { path = "primitives/storage", default-features = false }
195193
# Frontier FRAME
196194
pallet-base-fee = { path = "frame/base-fee", default-features = false }

frame/ethereum/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ rlp = { workspace = true }
3838
pallet-balances = { workspace = true, features = ["default", "insecure_zero_ed"] }
3939
pallet-timestamp = { workspace = true, features = ["default"] }
4040
sp-core = { workspace = true, features = ["default"] }
41-
# Frontier
42-
fp-self-contained = { workspace = true, features = ["default"] }
4341

4442
[features]
4543
default = ["std"]

frame/ethereum/src/lib.rs

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ use scale_codec::{Decode, Encode, MaxEncodedLen};
4545
use scale_info::TypeInfo;
4646
// Substrate
4747
use frame_support::{
48-
dispatch::{
49-
DispatchErrorWithPostInfo, DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo,
50-
},
48+
dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
5149
traits::{EnsureOrigin, Get, PalletInfoAccess, Time},
5250
weights::Weight,
5351
};
54-
use frame_system::{pallet_prelude::OriginFor, CheckWeight, WeightInfo};
52+
use frame_system::{pallet_prelude::OriginFor, WeightInfo};
5553
use sp_runtime::{
5654
generic::DigestItem,
57-
traits::{DispatchInfoOf, Dispatchable, One, Saturating, UniqueSaturatedInto, Zero},
55+
traits::{One, Saturating, UniqueSaturatedInto, Zero},
5856
transaction_validity::{
5957
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransactionBuilder,
6058
},
@@ -105,76 +103,6 @@ impl<O: Into<Result<RawOrigin, O>> + From<RawOrigin>> EnsureOrigin<O>
105103
}
106104
}
107105

108-
impl<T> Call<T>
109-
where
110-
OriginFor<T>: Into<Result<RawOrigin, OriginFor<T>>>,
111-
T: Send + Sync + Config,
112-
T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
113-
{
114-
pub fn is_self_contained(&self) -> bool {
115-
matches!(self, Call::transact { .. })
116-
}
117-
118-
pub fn check_self_contained(&self) -> Option<Result<H160, TransactionValidityError>> {
119-
if let Call::transact { transaction } = self {
120-
let check = || {
121-
let origin = Pallet::<T>::recover_signer(transaction).ok_or(
122-
InvalidTransaction::Custom(TransactionValidationError::InvalidSignature as u8),
123-
)?;
124-
125-
Ok(origin)
126-
};
127-
128-
Some(check())
129-
} else {
130-
None
131-
}
132-
}
133-
134-
pub fn pre_dispatch_self_contained(
135-
&self,
136-
origin: &H160,
137-
dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
138-
len: usize,
139-
) -> Option<Result<(), TransactionValidityError>> {
140-
if let Call::transact { transaction } = self {
141-
if let Err(e) =
142-
CheckWeight::<T>::do_validate(dispatch_info, len).and_then(|(_, next_len)| {
143-
CheckWeight::<T>::do_prepare(dispatch_info, len, next_len)
144-
}) {
145-
return Some(Err(e));
146-
}
147-
148-
Some(Pallet::<T>::validate_transaction_in_block(
149-
*origin,
150-
transaction,
151-
))
152-
} else {
153-
None
154-
}
155-
}
156-
157-
pub fn validate_self_contained(
158-
&self,
159-
origin: &H160,
160-
dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
161-
len: usize,
162-
) -> Option<TransactionValidity> {
163-
if let Call::transact { transaction } = self {
164-
if let Err(e) = CheckWeight::<T>::do_validate(dispatch_info, len) {
165-
return Some(Err(e));
166-
}
167-
168-
Some(Pallet::<T>::validate_transaction_in_pool(
169-
*origin,
170-
transaction,
171-
))
172-
} else {
173-
None
174-
}
175-
}
176-
}
177-
178106
#[derive(Copy, Clone, Eq, PartialEq, Default)]
179107
pub enum PostLogContent {
180108
#[default]

frame/ethereum/src/mock.rs

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ use ethereum::{TransactionAction, TransactionSignature};
2121
use rlp::RlpStream;
2222
// Substrate
2323
use frame_support::{derive_impl, parameter_types, traits::FindAuthor, ConsensusEngineId};
24+
use frame_system::{CheckSpecVersion, CheckWeight};
2425
use sp_core::{hashing::keccak_256, H160, H256, U256};
25-
use sp_runtime::{
26-
traits::{Dispatchable, IdentityLookup},
27-
AccountId32, BuildStorage,
28-
};
26+
use sp_runtime::generic::{CheckedExtrinsic, ExtrinsicFormat};
27+
use sp_runtime::{traits::IdentityLookup, AccountId32, BuildStorage};
2928
// Frontier
30-
use pallet_evm::{config_preludes::ChainId, AddressMapping};
31-
3229
use super::*;
30+
use crate::extension::EthereumExtension;
31+
use pallet_evm::{config_preludes::ChainId, AddressMapping};
3332

34-
pub type SignedExtra = (frame_system::CheckSpecVersion<Test>,);
33+
pub type SignedExtra = (
34+
frame_system::CheckSpecVersion<Test>,
35+
frame_system::CheckWeight<Test>,
36+
crate::extension::EthereumExtension<Test>,
37+
);
3538

3639
frame_support::construct_runtime! {
3740
pub enum Test {
@@ -104,62 +107,14 @@ impl pallet_evm::Config for Test {
104107
#[derive_impl(crate::config_preludes::TestDefaultConfig)]
105108
impl Config for Test {}
106109

107-
impl fp_self_contained::SelfContainedCall for RuntimeCall {
108-
type SignedInfo = H160;
109-
110-
fn is_self_contained(&self) -> bool {
111-
match self {
112-
RuntimeCall::Ethereum(call) => call.is_self_contained(),
113-
_ => false,
114-
}
115-
}
116-
117-
fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {
118-
match self {
119-
RuntimeCall::Ethereum(call) => call.check_self_contained(),
120-
_ => None,
121-
}
122-
}
123-
124-
fn validate_self_contained(
125-
&self,
126-
info: &Self::SignedInfo,
127-
dispatch_info: &DispatchInfoOf<RuntimeCall>,
128-
len: usize,
129-
) -> Option<TransactionValidity> {
130-
match self {
131-
RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len),
132-
_ => None,
133-
}
134-
}
135-
136-
fn pre_dispatch_self_contained(
137-
&self,
138-
info: &Self::SignedInfo,
139-
dispatch_info: &DispatchInfoOf<RuntimeCall>,
140-
len: usize,
141-
) -> Option<Result<(), TransactionValidityError>> {
142-
match self {
143-
RuntimeCall::Ethereum(call) => {
144-
call.pre_dispatch_self_contained(info, dispatch_info, len)
145-
}
146-
_ => None,
147-
}
148-
}
149-
150-
fn apply_self_contained(
151-
self,
152-
info: Self::SignedInfo,
153-
) -> Option<sp_runtime::DispatchResultWithInfo<sp_runtime::traits::PostDispatchInfoOf<Self>>> {
110+
impl crate::extension::EthereumTransactionHook<Test> for RuntimeCall {
111+
fn maybe_ethereum_call(&self) -> Option<&Call<Test>> {
154112
match self {
155-
call @ RuntimeCall::Ethereum(crate::Call::transact { .. }) => {
156-
Some(call.dispatch(RuntimeOrigin::from(RawOrigin::EthereumTransaction(info))))
157-
}
113+
RuntimeCall::Ethereum(call) => Some(call),
158114
_ => None,
159115
}
160116
}
161117
}
162-
163118
pub struct AccountInfo {
164119
pub address: H160,
165120
pub account_id: AccountId32,
@@ -402,3 +357,66 @@ impl EIP1559UnsignedTransaction {
402357
})
403358
}
404359
}
360+
361+
pub(crate) fn create_checked_extrinsic(
362+
call: crate::Call<Test>,
363+
) -> CheckedExtrinsic<AccountId32, RuntimeCall, SignedExtra> {
364+
CheckedExtrinsic::<_, _, SignedExtra> {
365+
format: ExtrinsicFormat::General(
366+
0,
367+
(
368+
CheckSpecVersion::<Test>::new(),
369+
CheckWeight::<Test>::new(),
370+
EthereumExtension::<Test>::new(),
371+
),
372+
),
373+
function: RuntimeCall::Ethereum(call),
374+
}
375+
}
376+
377+
impl<T> Call<T>
378+
where
379+
OriginFor<T>: Into<Result<RawOrigin, OriginFor<T>>>,
380+
T: Send + Sync + Config,
381+
{
382+
pub fn check_ethereum_call(&self) -> Option<Result<H160, TransactionValidityError>> {
383+
if let Call::transact { transaction } = self {
384+
let check = || {
385+
let origin = Pallet::<T>::recover_signer(transaction).ok_or(
386+
InvalidTransaction::Custom(TransactionValidationError::InvalidSignature as u8),
387+
)?;
388+
389+
Ok(origin)
390+
};
391+
392+
Some(check())
393+
} else {
394+
None
395+
}
396+
}
397+
398+
pub fn pre_dispatch_ethereum_call(
399+
&self,
400+
origin: &H160,
401+
) -> Option<Result<(), TransactionValidityError>> {
402+
if let Call::transact { transaction } = self {
403+
Some(Pallet::<T>::validate_transaction_in_block(
404+
*origin,
405+
transaction,
406+
))
407+
} else {
408+
None
409+
}
410+
}
411+
412+
pub fn validate_ethereum_call(&self, origin: &H160) -> Option<TransactionValidity> {
413+
if let Call::transact { transaction } = self {
414+
Some(Pallet::<T>::validate_transaction_in_pool(
415+
*origin,
416+
transaction,
417+
))
418+
} else {
419+
None
420+
}
421+
}
422+
}

0 commit comments

Comments
 (0)