@@ -19,7 +19,8 @@ use core::mem;
19
19
pub use domain_runtime_primitives:: opaque:: Header ;
20
20
use domain_runtime_primitives:: {
21
21
block_weights, maximum_block_length, maximum_domain_block_weight, EthereumAccountId ,
22
- ERR_BALANCE_OVERFLOW , ERR_NONCE_OVERFLOW , EXISTENTIAL_DEPOSIT , SLOT_DURATION ,
22
+ ERR_BALANCE_OVERFLOW , ERR_CONTRACT_CREATION_NOT_ALLOWED , ERR_NONCE_OVERFLOW ,
23
+ EXISTENTIAL_DEPOSIT , SLOT_DURATION ,
23
24
} ;
24
25
pub use domain_runtime_primitives:: {
25
26
opaque, Balance , BlockNumber , CheckExtrinsicsValidityError , DecodeExtrinsicError ,
@@ -38,6 +39,7 @@ use frame_support::weights::constants::{ParityDbWeight, WEIGHT_REF_TIME_PER_SECO
38
39
use frame_support:: weights:: { ConstantMultiplier , Weight } ;
39
40
use frame_support:: { construct_runtime, parameter_types} ;
40
41
use frame_system:: limits:: { BlockLength , BlockWeights } ;
42
+ use frame_system:: pallet_prelude:: { BlockNumberFor , RuntimeCallFor } ;
41
43
use pallet_block_fees:: fees:: OnChargeDomainTransaction ;
42
44
use pallet_ethereum:: Call :: transact;
43
45
use pallet_ethereum:: {
@@ -47,6 +49,7 @@ use pallet_evm::{
47
49
Account as EVMAccount , EnsureAddressNever , EnsureAddressRoot , FeeCalculator ,
48
50
IdentityAddressMapping , Runner ,
49
51
} ;
52
+ use pallet_evm_tracker:: create_contract:: is_create_contract_allowed;
50
53
use pallet_evm_tracker:: traits:: { MaybeIntoEthCall , MaybeIntoEvmCall } ;
51
54
use pallet_transporter:: EndpointHandler ;
52
55
use sp_api:: impl_runtime_apis;
@@ -61,7 +64,7 @@ use sp_messenger::messages::{
61
64
use sp_messenger:: { ChannelNonce , XdmId } ;
62
65
use sp_messenger_host_functions:: { get_storage_key, StorageKeyRequest } ;
63
66
use sp_mmr_primitives:: EncodableOpaqueLeaf ;
64
- use sp_runtime:: generic:: Era ;
67
+ use sp_runtime:: generic:: { Era , SignedPayload } ;
65
68
use sp_runtime:: traits:: {
66
69
BlakeTwo256 , Block as BlockT , Checkable , DispatchInfoOf , Dispatchable , IdentityLookup ,
67
70
Keccak256 , NumberFor , One , PostDispatchInfoOf , SignedExtension , UniqueSaturatedInto ,
@@ -72,7 +75,7 @@ use sp_runtime::transaction_validity::{
72
75
} ;
73
76
use sp_runtime:: {
74
77
generic, impl_opaque_keys, ApplyExtrinsicResult , ConsensusEngineId , Digest ,
75
- ExtrinsicInclusionMode ,
78
+ ExtrinsicInclusionMode , SaturatedConversion ,
76
79
} ;
77
80
pub use sp_runtime:: { MultiAddress , Perbill , Permill } ;
78
81
use sp_std:: cmp:: { max, Ordering } ;
@@ -84,6 +87,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{
84
87
} ;
85
88
use sp_subspace_mmr:: { ConsensusChainMmrLeafProof , MmrLeaf } ;
86
89
use sp_version:: RuntimeVersion ;
90
+ use subspace_runtime_primitives:: utility:: MaybeIntoUtilityCall ;
87
91
use subspace_runtime_primitives:: {
88
92
BlockNumber as ConsensusBlockNumber , Hash as ConsensusBlockHash , Moment , SHANNON , SSC ,
89
93
} ;
@@ -113,6 +117,7 @@ pub type SignedExtra = (
113
117
frame_system:: CheckNonce < Runtime > ,
114
118
domain_check_weight:: CheckWeight < Runtime > ,
115
119
pallet_transaction_payment:: ChargeTransactionPayment < Runtime > ,
120
+ pallet_evm_tracker:: create_contract:: CheckContractCreation < Runtime > ,
116
121
) ;
117
122
118
123
/// Custom signed extra for check_and_pre_dispatch.
@@ -126,6 +131,7 @@ type CustomSignedExtra = (
126
131
pallet_evm_tracker:: CheckNonce < Runtime > ,
127
132
domain_check_weight:: CheckWeight < Runtime > ,
128
133
pallet_transaction_payment:: ChargeTransactionPayment < Runtime > ,
134
+ pallet_evm_tracker:: create_contract:: CheckContractCreation < Runtime > ,
129
135
) ;
130
136
131
137
/// Unchecked extrinsic type as expected by this runtime.
@@ -136,6 +142,60 @@ pub type UncheckedExtrinsic =
136
142
pub type CheckedExtrinsic =
137
143
fp_self_contained:: CheckedExtrinsic < AccountId , RuntimeCall , SignedExtra , H160 > ;
138
144
145
+ type BalanceOf < T > = <<T as pallet_transaction_payment:: Config >:: OnChargeTransaction as pallet_transaction_payment:: OnChargeTransaction < T > >:: Balance ;
146
+
147
+ pub fn construct_extrinsic_raw_payload (
148
+ current_block_hash : H256 ,
149
+ current_block : BlockNumberFor < Runtime > ,
150
+ genesis_block_hash : H256 ,
151
+ function : RuntimeCallFor < Runtime > ,
152
+ immortal : bool ,
153
+ nonce : u32 ,
154
+ tip : BalanceOf < Runtime > ,
155
+ ) -> (
156
+ SignedPayload < RuntimeCallFor < Runtime > , SignedExtra > ,
157
+ SignedExtra ,
158
+ ) {
159
+ let current_block = current_block. saturated_into ( ) ;
160
+ let period = u64:: from ( <Runtime as frame_system:: Config >:: BlockHashCount :: get ( ) )
161
+ . checked_next_power_of_two ( )
162
+ . map ( |c| c / 2 )
163
+ . unwrap_or ( 2 ) ;
164
+ let extra: SignedExtra = (
165
+ frame_system:: CheckNonZeroSender :: < Runtime > :: new ( ) ,
166
+ frame_system:: CheckSpecVersion :: < Runtime > :: new ( ) ,
167
+ frame_system:: CheckTxVersion :: < Runtime > :: new ( ) ,
168
+ frame_system:: CheckGenesis :: < Runtime > :: new ( ) ,
169
+ frame_system:: CheckMortality :: < Runtime > :: from ( if immortal {
170
+ generic:: Era :: Immortal
171
+ } else {
172
+ generic:: Era :: mortal ( period, current_block)
173
+ } ) ,
174
+ frame_system:: CheckNonce :: < Runtime > :: from ( nonce) ,
175
+ domain_check_weight:: CheckWeight :: < Runtime > :: new ( ) ,
176
+ pallet_transaction_payment:: ChargeTransactionPayment :: < Runtime > :: from ( tip) ,
177
+ pallet_evm_tracker:: create_contract:: CheckContractCreation :: < Runtime > :: new ( ) ,
178
+ ) ;
179
+ (
180
+ generic:: SignedPayload :: < RuntimeCallFor < Runtime > , SignedExtra > :: from_raw (
181
+ function,
182
+ extra. clone ( ) ,
183
+ (
184
+ ( ) ,
185
+ 1 ,
186
+ 0 ,
187
+ genesis_block_hash,
188
+ current_block_hash,
189
+ ( ) ,
190
+ ( ) ,
191
+ ( ) ,
192
+ ( ) ,
193
+ ) ,
194
+ ) ,
195
+ extra,
196
+ )
197
+ }
198
+
139
199
/// Executive: handles dispatch to the various modules.
140
200
pub type Executive = domain_pallet_executive:: Executive <
141
201
Runtime ,
@@ -167,9 +227,18 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {
167
227
dispatch_info : & DispatchInfoOf < RuntimeCall > ,
168
228
len : usize ,
169
229
) -> Option < TransactionValidity > {
230
+ if !is_create_contract_allowed :: < Runtime > ( self , & ( * info) . into ( ) ) {
231
+ return Some ( Err ( InvalidTransaction :: Custom (
232
+ ERR_CONTRACT_CREATION_NOT_ALLOWED ,
233
+ )
234
+ . into ( ) ) ) ;
235
+ }
236
+
237
+ // TODO: move this code into pallet-block-fees, so it can be used from the production and
238
+ // test runtimes.
170
239
match self {
171
240
RuntimeCall :: Ethereum ( call) => {
172
- // Ensure the caller can pay the consensus chain storage fee
241
+ // Ensure the caller can pay for the consensus chain storage fee
173
242
let consensus_storage_fee =
174
243
BlockFees :: consensus_chain_byte_fee ( ) . checked_mul ( Balance :: from ( len as u32 ) ) ?;
175
244
let withdraw_res = <InnerEVMCurrencyAdapter as pallet_evm:: OnChargeEVMTransaction <
@@ -191,6 +260,15 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {
191
260
dispatch_info : & DispatchInfoOf < RuntimeCall > ,
192
261
len : usize ,
193
262
) -> Option < Result < ( ) , TransactionValidityError > > {
263
+ if !is_create_contract_allowed :: < Runtime > ( self , & ( * info) . into ( ) ) {
264
+ return Some ( Err ( InvalidTransaction :: Custom (
265
+ ERR_CONTRACT_CREATION_NOT_ALLOWED ,
266
+ )
267
+ . into ( ) ) ) ;
268
+ }
269
+
270
+ // TODO: move this code into pallet-block-fees, so it can be used from the production and
271
+ // test runtimes.
194
272
match self {
195
273
RuntimeCall :: Ethereum ( call) => {
196
274
// Withdraw the consensus chain storage fee from the caller and record
@@ -208,8 +286,8 @@ impl fp_self_contained::SelfContainedCall for RuntimeCall {
208
286
Err ( _) => return Some ( Err ( InvalidTransaction :: Payment . into ( ) ) ) ,
209
287
}
210
288
211
- // Copy from [`pallet_ethereum::Call::pre_dispatch_self_contained`] with `frame_system::CheckWeight`
212
- // replaced to `domain_check_weight::CheckWeight`
289
+ // Copied from [`pallet_ethereum::Call::pre_dispatch_self_contained`] with `frame_system::CheckWeight`
290
+ // replaced with `domain_check_weight::CheckWeight`
213
291
if let pallet_ethereum:: Call :: transact { transaction } = call {
214
292
if let Err ( e) = domain_check_weight:: CheckWeight :: < Runtime > :: do_pre_dispatch (
215
293
dispatch_info,
@@ -752,6 +830,16 @@ impl pallet_utility::Config for Runtime {
752
830
type WeightInfo = pallet_utility:: weights:: SubstrateWeight < Runtime > ;
753
831
}
754
832
833
+ impl MaybeIntoUtilityCall < Runtime > for RuntimeCall {
834
+ /// If this call is a `pallet_utility::Call<Runtime>` call, returns the inner call.
835
+ fn maybe_into_utility_call ( & self ) -> Option < & pallet_utility:: Call < Runtime > > {
836
+ match self {
837
+ RuntimeCall :: Utility ( call) => Some ( call) ,
838
+ _ => None ,
839
+ }
840
+ }
841
+ }
842
+
755
843
// Create the runtime by composing the FRAME pallets that were previously configured.
756
844
//
757
845
// NOTE: Currently domain runtime does not naturally support the pallets with inherent extrinsics.
@@ -993,6 +1081,7 @@ fn check_transaction_and_do_pre_dispatch_inner(
993
1081
pallet_evm_tracker:: CheckNonce :: from ( extra. 5 . 0 ) ,
994
1082
extra. 6 ,
995
1083
extra. 7 ,
1084
+ extra. 8 ,
996
1085
) ;
997
1086
998
1087
custom_extra
0 commit comments