Skip to content

Commit c364169

Browse files
committed
fix
1 parent 9139881 commit c364169

File tree

4 files changed

+35
-121
lines changed

4 files changed

+35
-121
lines changed

pallets/erc20-xcm-bridge/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub mod pallet {
126126
false,
127127
false,
128128
Some(weight_limit),
129-
Some(0),
129+
0,
130130
&<T as pallet_evm::Config>::config(),
131131
)
132132
.map_err(|_| Erc20TransferError::EvmCallFail)?;

pallets/moonbeam-foreign-assets/src/evm.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<T: crate::Config> EvmCaller<T> {
137137
false,
138138
false,
139139
None,
140-
None,
140+
0,
141141
&<T as pallet_evm::Config>::config(),
142142
contract_adress,
143143
)
@@ -186,7 +186,7 @@ impl<T: crate::Config> EvmCaller<T> {
186186
false,
187187
false,
188188
Some(weight_limit),
189-
Some(0),
189+
0,
190190
&<T as pallet_evm::Config>::config(),
191191
)
192192
.map_err(|err| EvmError::MintIntoFail(format!("{:?}", err.error.into())))?;
@@ -235,7 +235,7 @@ impl<T: crate::Config> EvmCaller<T> {
235235
false,
236236
false,
237237
Some(weight_limit),
238-
Some(0),
238+
0,
239239
&<T as pallet_evm::Config>::config(),
240240
)
241241
.map_err(|err| EvmError::TransferFail(format!("{:?}", err.error.into())))?;
@@ -293,7 +293,7 @@ impl<T: crate::Config> EvmCaller<T> {
293293
false,
294294
false,
295295
Some(weight_limit),
296-
Some(0),
296+
0,
297297
&<T as pallet_evm::Config>::config(),
298298
)
299299
.map_err(|err| EvmError::EvmCallFail(format!("{:?}", err.error.into())))?;
@@ -341,7 +341,7 @@ impl<T: crate::Config> EvmCaller<T> {
341341
false,
342342
false,
343343
Some(weight_limit),
344-
Some(0),
344+
0,
345345
&<T as pallet_evm::Config>::config(),
346346
)
347347
.map_err(|err| EvmError::EvmCallFail(format!("{:?}", err.error.into())))?;
@@ -381,7 +381,7 @@ impl<T: crate::Config> EvmCaller<T> {
381381
false,
382382
false,
383383
Some(weight_limit),
384-
Some(0),
384+
0,
385385
&<T as pallet_evm::Config>::config(),
386386
)
387387
.map_err(|err| {
@@ -426,7 +426,7 @@ impl<T: crate::Config> EvmCaller<T> {
426426
false,
427427
false,
428428
Some(weight_limit),
429-
Some(0),
429+
0,
430430
&<T as pallet_evm::Config>::config(),
431431
)
432432
.map_err(|err| {

runtime/common/src/apis.rs

+22-108
Original file line numberDiff line numberDiff line change
@@ -340,41 +340,13 @@ macro_rules! impl_runtime_apis_plus_common {
340340
let without_base_extrinsic_weight = true;
341341

342342

343-
// Estimated encoded transaction size must be based on the transaction
344-
// type (TransactionData) to be compatible with all transaction types.
345-
// TODO: remove, since we will get rid of base_cost
346-
let mut estimated_transaction_len = data.len() +
347-
// pallet ethereum index: 1
348-
// transact call index: 1
349-
// Transaction enum variant: 1
350-
// chain_id 9 bytes (some varient)
351-
// nonce: 32
352-
// max_priority_fee_per_gas: 33 (some varient)
353-
// max_fee_per_gas: 33 (some varient)
354-
// gas_price: 1 (none varient)
355-
// gas_limit: 32
356-
// action: 21 (enum varianrt + call address)
357-
// value: 32
358-
// access_list: 1 (empty vec size)
359-
// 65 bytes signature
360-
261;
361-
362-
if access_list.is_some() {
363-
estimated_transaction_len += access_list.encoded_size();
364-
}
365-
366-
let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
367-
368-
let (weight_limit, proof_size_base_cost) =
369-
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
370-
gas_limit,
371-
without_base_extrinsic_weight
372-
) {
373-
weight_limit if weight_limit.proof_size() > 0 => {
374-
(Some(weight_limit), Some(estimated_transaction_len as u64))
375-
}
376-
_ => (None, None),
377-
};
343+
let gas_limit = if gas_limit > U256::from(u64::MAX) {
344+
u64::MAX
345+
} else {
346+
gas_limit.low_u64()
347+
};
348+
let weight_limit = <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(gas_limit, true);
349+
let proof_size_pre_execution = cumulus_primitives_storage_weight_reclaim::get_proof_size().unwrap_or_default();
378350

379351
let _ = <Runtime as pallet_evm::Config>::Runner::call(
380352
from,
@@ -388,8 +360,8 @@ macro_rules! impl_runtime_apis_plus_common {
388360
access_list.unwrap_or_default(),
389361
is_transactional,
390362
validate,
391-
weight_limit,
392-
proof_size_base_cost,
363+
Some(weight_limit),
364+
proof_size_pre_execution,
393365
<Runtime as pallet_evm::Config>::config(),
394366
);
395367
});
@@ -477,42 +449,13 @@ macro_rules! impl_runtime_apis_plus_common {
477449
let is_transactional = false;
478450
let validate = true;
479451

480-
// Estimated encoded transaction size must be based on the transaction
481-
// type (TransactionData) to be compatible with all transaction types.
482-
// TODO: remove, since we will get rid of base_cost
483-
let mut estimated_transaction_len = data.len() +
484-
// pallet ethereum index: 1
485-
// transact call index: 1
486-
// Transaction enum variant: 1
487-
// chain_id 9 bytes (some varient)
488-
// nonce: 32
489-
// max_priority_fee_per_gas: 33 (some varient)
490-
// max_fee_per_gas: 33 (some varient)
491-
// gas_price: 1 (none varient)
492-
// gas_limit: 32
493-
// action: 21 (enum varianrt + call address)
494-
// value: 32
495-
// access_list: 1 (empty vec size)
496-
// 65 bytes signature
497-
261;
498-
499-
if access_list.is_some() {
500-
estimated_transaction_len += access_list.encoded_size();
501-
}
502-
503-
let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
504-
let without_base_extrinsic_weight = true;
505-
506-
let (weight_limit, proof_size_base_cost) =
507-
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
508-
gas_limit,
509-
without_base_extrinsic_weight
510-
) {
511-
weight_limit if weight_limit.proof_size() > 0 => {
512-
(Some(weight_limit), Some(estimated_transaction_len as u64))
513-
}
514-
_ => (None, None),
515-
};
452+
let gas_limit = if gas_limit > U256::from(u64::MAX) {
453+
u64::MAX
454+
} else {
455+
gas_limit.low_u64()
456+
};
457+
let weight_limit = <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(gas_limit, true);
458+
let proof_size_pre_execution = cumulus_primitives_storage_weight_reclaim::get_proof_size().unwrap_or_default();
516459

517460
<Runtime as pallet_evm::Config>::Runner::call(
518461
from,
@@ -526,8 +469,8 @@ macro_rules! impl_runtime_apis_plus_common {
526469
access_list.unwrap_or_default(),
527470
is_transactional,
528471
validate,
529-
weight_limit,
530-
proof_size_base_cost,
472+
Some(weight_limit),
473+
proof_size_pre_execution,
531474
config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),
532475
).map_err(|err| err.error.into())
533476
}
@@ -553,43 +496,14 @@ macro_rules! impl_runtime_apis_plus_common {
553496
let is_transactional = false;
554497
let validate = true;
555498

556-
let mut estimated_transaction_len = data.len() +
557-
// from: 20
558-
// value: 32
559-
// gas_limit: 32
560-
// nonce: 32
561-
// 1 byte transaction action variant
562-
// chain id 8 bytes
563-
// 65 bytes signature
564-
190;
565-
566-
if max_fee_per_gas.is_some() {
567-
estimated_transaction_len += 32;
568-
}
569-
if max_priority_fee_per_gas.is_some() {
570-
estimated_transaction_len += 32;
571-
}
572-
if access_list.is_some() {
573-
estimated_transaction_len += access_list.encoded_size();
574-
}
575-
576499
let gas_limit = if gas_limit > U256::from(u64::MAX) {
577500
u64::MAX
578501
} else {
579502
gas_limit.low_u64()
580503
};
581-
let without_base_extrinsic_weight = true;
582504

583-
let (weight_limit, proof_size_base_cost) =
584-
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
585-
gas_limit,
586-
without_base_extrinsic_weight
587-
) {
588-
weight_limit if weight_limit.proof_size() > 0 => {
589-
(Some(weight_limit), Some(estimated_transaction_len as u64))
590-
}
591-
_ => (None, None),
592-
};
505+
let weight_limit = <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(gas_limit, true);
506+
let proof_size_pre_execution = cumulus_primitives_storage_weight_reclaim::get_proof_size().unwrap_or_default();
593507

594508
#[allow(clippy::or_fun_call)] // suggestion not helpful here
595509
<Runtime as pallet_evm::Config>::Runner::create(
@@ -603,8 +517,8 @@ macro_rules! impl_runtime_apis_plus_common {
603517
access_list.unwrap_or_default(),
604518
is_transactional,
605519
validate,
606-
weight_limit,
607-
proof_size_base_cost,
520+
Some(weight_limit),
521+
proof_size_pre_execution,
608522
config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),
609523
).map_err(|err| err.error.into())
610524
}

runtime/common/src/impl_xcm_evm_runner.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
5252
_is_transactional: bool,
5353
_validate: bool,
5454
_weight_limit: Option<Weight>,
55-
_transaction_len: Option<u64>,
55+
_transaction_len: u64,
5656
_config: &fp_evm::Config,
5757
) -> Result<CallInfo, RunnerError<Self::Error>> {
5858
// The `with_precompile_handle` function will execute the closure (and return the
@@ -140,7 +140,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
140140
_is_transactional: bool,
141141
_validate: bool,
142142
_weight_limit: Option<Weight>,
143-
_transaction_len: Option<u64>,
143+
_transaction_len: u64,
144144
_config: &fp_evm::Config,
145145
) -> Result<fp_evm::CreateInfo, RunnerError<Self::Error>> {
146146
unimplemented!()
@@ -159,7 +159,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
159159
_is_transactional: bool,
160160
_validate: bool,
161161
_weight_limit: Option<Weight>,
162-
_transaction_len: Option<u64>,
162+
_transaction_len: u64,
163163
_config: &fp_evm::Config,
164164
) -> Result<fp_evm::CreateInfo, RunnerError<Self::Error>> {
165165
unimplemented!()
@@ -177,7 +177,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
177177
is_transactional: bool,
178178
validate: bool,
179179
weight_limit: Option<Weight>,
180-
transaction_len: Option<u64>,
180+
transaction_len: u64,
181181
config: &fp_evm::Config,
182182
force_address: H160,
183183
) -> Result<fp_evm::CreateInfo, RunnerError<Self::Error>> {
@@ -231,7 +231,7 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm {
231231
_access_list: Vec<(H160, Vec<H256>)>,
232232
_is_transactional: bool,
233233
_weight_limit: Option<Weight>,
234-
_transaction_len: Option<u64>,
234+
_transaction_len: u64,
235235
_evm_config: &fp_evm::Config,
236236
) -> Result<(), RunnerError<Self::Error>> {
237237
unimplemented!()

0 commit comments

Comments
 (0)