Skip to content

Commit 4d3a1f9

Browse files
committed
Rework gas mapping
1 parent 6156ddd commit 4d3a1f9

File tree

38 files changed

+1096
-974
lines changed

38 files changed

+1096
-974
lines changed

cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use sp_runtime::{
8989
use sp_version::NativeVersion;
9090
use sp_version::RuntimeVersion;
9191
use testnet_parachains_constants::westend::{
92-
consensus::*, currency::*, fee::WeightToFee, snowbridge::EthereumNetwork, time::*,
92+
consensus::*, currency::*, snowbridge::EthereumNetwork, time::*,
9393
};
9494
use westend_runtime_constants::time::DAYS as RC_DAYS;
9595
use xcm_config::{
@@ -248,6 +248,18 @@ parameter_types! {
248248
pub const TransactionByteFee: Balance = MILLICENTS;
249249
}
250250

251+
/// `pallet_revive` requires this specific `WeightToFee` implementation.
252+
///
253+
/// This is needed because we make certain assumptions about how weight
254+
/// is mapped to fees. Enforced at compile time.
255+
type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<
256+
// p
257+
CENTS,
258+
// q
259+
{ 100 * ExtrinsicBaseWeight::get().ref_time() as u128 },
260+
Runtime,
261+
>;
262+
251263
impl pallet_transaction_payment::Config for Runtime {
252264
type RuntimeEvent = RuntimeEvent;
253265
type OnChargeTransaction =
@@ -1169,7 +1181,6 @@ impl pallet_revive::Config for Runtime {
11691181
type RuntimeCall = RuntimeCall;
11701182
type DepositPerItem = DepositPerItem;
11711183
type DepositPerByte = DepositPerByte;
1172-
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
11731184
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
11741185
type Precompiles = (
11751186
ERC20<Self, InlineIdConfig<0x120>, TrustBackedAssetsInstance>,
@@ -1190,8 +1201,8 @@ impl pallet_revive::Config for Runtime {
11901201
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
11911202
type ChainId = ConstU64<420_420_421>;
11921203
type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
1193-
type EthGasEncoder = ();
11941204
type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
1205+
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
11951206
}
11961207

11971208
parameter_types! {

cumulus/parachains/runtimes/assets/asset-hub-westend/tests/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use frame_support::{
5757
use hex_literal::hex;
5858
use pallet_revive::{
5959
test_utils::builder::{BareInstantiateBuilder, Contract},
60-
Code, DepositLimit,
60+
Code,
6161
};
6262
use pallet_revive_fixtures::compile_module;
6363
use pallet_uniques::{asset_ops::Item, asset_strategies::Attribute};
@@ -1689,7 +1689,7 @@ fn withdraw_and_deposit_erc20s() {
16891689
let constructor_data = sol_data::Uint::<256>::abi_encode(&initial_amount_u256);
16901690
let Contract { addr: erc20_address, .. } = bare_instantiate(&sender, code)
16911691
.gas_limit(Weight::from_parts(2_000_000_000, 200_000))
1692-
.storage_deposit_limit(DepositLimit::Balance(Balance::MAX))
1692+
.storage_deposit_limit(Balance::MAX)
16931693
.data(constructor_data)
16941694
.build_and_unwrap_contract();
16951695

@@ -1802,7 +1802,7 @@ fn smart_contract_not_erc20_will_error() {
18021802

18031803
let Contract { addr: non_erc20_address, .. } = bare_instantiate(&sender, code)
18041804
.gas_limit(Weight::from_parts(2_000_000_000, 200_000))
1805-
.storage_deposit_limit(DepositLimit::Balance(Balance::MAX))
1805+
.storage_deposit_limit(Balance::MAX)
18061806
.build_and_unwrap_contract();
18071807

18081808
let wnd_amount_for_fees = 1_000_000_000_000u128;
@@ -1860,7 +1860,7 @@ fn smart_contract_does_not_return_bool_fails() {
18601860

18611861
let Contract { addr: non_erc20_address, .. } = bare_instantiate(&sender, code)
18621862
.gas_limit(Weight::from_parts(2_000_000_000, 200_000))
1863-
.storage_deposit_limit(DepositLimit::Balance(Balance::MAX))
1863+
.storage_deposit_limit(Balance::MAX)
18641864
.data(constructor_data)
18651865
.build_and_unwrap_contract();
18661866

@@ -1916,7 +1916,7 @@ fn expensive_erc20_runs_out_of_gas() {
19161916
let constructor_data = sol_data::Uint::<256>::abi_encode(&initial_amount_u256);
19171917
let Contract { addr: non_erc20_address, .. } = bare_instantiate(&sender, code)
19181918
.gas_limit(Weight::from_parts(2_000_000_000, 200_000))
1919-
.storage_deposit_limit(DepositLimit::Balance(Balance::MAX))
1919+
.storage_deposit_limit(Balance::MAX)
19201920
.data(constructor_data)
19211921
.build_and_unwrap_contract();
19221922

cumulus/parachains/runtimes/assets/common/src/erc20_transactor.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use pallet_revive::{
2424
primitives::{Address, U256 as EU256},
2525
sol_types::SolCall,
2626
},
27-
AddressMapper, ContractResult, DepositLimit, MomentOf,
27+
AddressMapper, ContractResult, ExecConfig, MomentOf,
2828
};
2929
use sp_core::{Get, H160, H256, U256};
3030
use sp_runtime::Weight;
@@ -126,8 +126,9 @@ where
126126
asset_id,
127127
U256::zero(),
128128
gas_limit,
129-
DepositLimit::Balance(StorageDepositLimit::get()),
129+
StorageDepositLimit::get(),
130130
data,
131+
ExecConfig::new_substrate_tx(),
131132
);
132133
// We need to return this surplus for the executor to allow refunding it.
133134
let surplus = gas_limit.saturating_sub(gas_consumed);
@@ -184,8 +185,9 @@ where
184185
asset_id,
185186
U256::zero(),
186187
gas_limit,
187-
DepositLimit::Balance(StorageDepositLimit::get()),
188+
StorageDepositLimit::get(),
188189
data,
190+
ExecConfig::new_substrate_tx(),
189191
);
190192
// We need to return this surplus for the executor to allow refunding it.
191193
let surplus = gas_limit.saturating_sub(gas_consumed);

cumulus/parachains/runtimes/testing/penpal/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ parameter_types! {
441441
impl pallet_transaction_payment::Config for Runtime {
442442
type RuntimeEvent = RuntimeEvent;
443443
type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, ()>;
444-
type WeightToFee = WeightToFee;
444+
type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<1, 1, Self>;
445445
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
446446
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
447447
type OperationalFeeMultiplier = ConstU8<5>;
@@ -815,7 +815,6 @@ impl pallet_revive::Config for Runtime {
815815
type RuntimeCall = RuntimeCall;
816816
type DepositPerItem = DepositPerItem;
817817
type DepositPerByte = DepositPerByte;
818-
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
819818
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
820819
type Precompiles = ();
821820
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
@@ -829,8 +828,8 @@ impl pallet_revive::Config for Runtime {
829828
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
830829
type ChainId = ConstU64<420_420_999>;
831830
type NativeToEthRatio = ConstU32<1_000_000>; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
832-
type EthGasEncoder = ();
833831
type FindAuthor = <Runtime as pallet_authorship::Config>::FindAuthor;
832+
type FeeInfo = pallet_revive::evm::fees::Info<Address, Signature, EthExtraImpl>;
834833
}
835834

836835
impl pallet_sudo::Config for Runtime {
@@ -906,7 +905,11 @@ mod benches {
906905
);
907906
}
908907

909-
impl_runtime_apis! {
908+
pallet_revive::impl_runtime_apis_plus_revive!(
909+
Runtime,
910+
Executive,
911+
EthExtraImpl,
912+
910913
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
911914
fn slot_duration() -> sp_consensus_aura::SlotDuration {
912915
sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION)
@@ -1211,7 +1214,7 @@ impl_runtime_apis! {
12111214
ConsensusHook::can_build_upon(included_hash, slot)
12121215
}
12131216
}
1214-
}
1217+
);
12151218

12161219
cumulus_pallet_parachain_system::register_validate_block! {
12171220
Runtime = Runtime,

polkadot/xcm/pallet-xcm/src/precompiles.rs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ mod test {
184184
},
185185
H160,
186186
},
187-
DepositLimit, U256,
187+
ExecConfig, U256,
188188
};
189189
use polkadot_parachain_primitives::primitives::Id as ParaId;
190190
use sp_runtime::traits::AccountIdConversion;
@@ -231,8 +231,9 @@ mod test {
231231
xcm_precompile_addr,
232232
U256::zero(),
233233
Weight::MAX,
234-
DepositLimit::UnsafeOnlyForDryRun,
234+
u128::MAX,
235235
encoded_call,
236+
ExecConfig::new_substrate_tx(),
236237
);
237238
assert!(result.result.is_ok());
238239
let sent_message = Xcm(Some(DescendOrigin(sender.clone().try_into().unwrap()))
@@ -279,8 +280,9 @@ mod test {
279280
xcm_precompile_addr,
280281
U256::zero(),
281282
Weight::MAX,
282-
DepositLimit::UnsafeOnlyForDryRun,
283+
u128::MAX,
283284
encoded_call,
285+
ExecConfig::new_substrate_tx(),
284286
);
285287

286288
assert!(result.result.is_ok());
@@ -327,8 +329,9 @@ mod test {
327329
xcm_precompile_addr,
328330
U256::zero(),
329331
Weight::MAX,
330-
DepositLimit::UnsafeOnlyForDryRun,
332+
u128::MAX,
331333
encoded_call,
334+
ExecConfig::new_substrate_tx(),
332335
);
333336
let return_value = match result.result {
334337
Ok(value) => value,
@@ -376,8 +379,9 @@ mod test {
376379
xcm_precompile_addr,
377380
U256::zero(),
378381
Weight::MAX,
379-
DepositLimit::UnsafeOnlyForDryRun,
382+
u128::MAX,
380383
encoded_call,
384+
ExecConfig::new_substrate_tx(),
381385
);
382386
let return_value = match result.result {
383387
Ok(value) => value,
@@ -402,8 +406,9 @@ mod test {
402406
xcm_precompile_addr,
403407
U256::zero(),
404408
Weight::MAX,
405-
DepositLimit::UnsafeOnlyForDryRun,
409+
u128::MAX,
406410
encoded_call,
411+
ExecConfig::new_substrate_tx(),
407412
);
408413
let return_value = match result.result {
409414
Ok(value) => value,
@@ -451,8 +456,9 @@ mod test {
451456
xcm_precompile_addr,
452457
U256::zero(),
453458
Weight::MAX,
454-
DepositLimit::UnsafeOnlyForDryRun,
459+
u128::MAX,
455460
encoded_call,
461+
ExecConfig::new_substrate_tx(),
456462
);
457463
let return_value = match result.result {
458464
Ok(value) => value,
@@ -478,8 +484,9 @@ mod test {
478484
xcm_precompile_addr,
479485
U256::zero(),
480486
Weight::MAX,
481-
DepositLimit::UnsafeOnlyForDryRun,
487+
u128::MAX,
482488
encoded_call,
489+
ExecConfig::new_substrate_tx(),
483490
);
484491
let return_value = match result.result {
485492
Ok(value) => value,
@@ -520,8 +527,9 @@ mod test {
520527
xcm_precompile_addr,
521528
U256::zero(),
522529
Weight::MAX,
523-
DepositLimit::UnsafeOnlyForDryRun,
530+
u128::MAX,
524531
encoded_weight_call,
532+
ExecConfig::new_substrate_tx(),
525533
);
526534

527535
let weight_result = match xcm_weight_results.result {
@@ -542,8 +550,9 @@ mod test {
542550
xcm_precompile_addr,
543551
U256::zero(),
544552
Weight::MAX,
545-
DepositLimit::UnsafeOnlyForDryRun,
553+
u128::MAX,
546554
encoded_call,
555+
ExecConfig::new_substrate_tx(),
547556
);
548557

549558
assert!(result.result.is_ok());
@@ -580,8 +589,9 @@ mod test {
580589
xcm_precompile_addr,
581590
U256::zero(),
582591
Weight::MAX,
583-
DepositLimit::UnsafeOnlyForDryRun,
592+
u128::MAX,
584593
encoded_weight_call,
594+
ExecConfig::new_substrate_tx(),
585595
);
586596

587597
let weight_result = match xcm_weight_results.result {
@@ -602,8 +612,9 @@ mod test {
602612
xcm_precompile_addr,
603613
U256::zero(),
604614
Weight::MAX,
605-
DepositLimit::UnsafeOnlyForDryRun,
615+
u128::MAX,
606616
encoded_call,
617+
ExecConfig::new_substrate_tx(),
607618
);
608619

609620
let return_value = match result.result {
@@ -648,8 +659,9 @@ mod test {
648659
xcm_precompile_addr,
649660
U256::zero(),
650661
Weight::MAX,
651-
DepositLimit::UnsafeOnlyForDryRun,
662+
u128::MAX,
652663
encoded_weight_call,
664+
ExecConfig::new_substrate_tx(),
653665
);
654666

655667
let weight_result = match xcm_weight_results.result {
@@ -670,8 +682,9 @@ mod test {
670682
xcm_precompile_addr,
671683
U256::zero(),
672684
Weight::MAX,
673-
DepositLimit::UnsafeOnlyForDryRun,
685+
u128::MAX,
674686
encoded_call,
687+
ExecConfig::new_substrate_tx(),
675688
);
676689
let return_value = match result.result {
677690
Ok(value) => value,
@@ -715,8 +728,9 @@ mod test {
715728
xcm_precompile_addr,
716729
U256::zero(),
717730
Weight::MAX,
718-
DepositLimit::UnsafeOnlyForDryRun,
731+
u128::MAX,
719732
encoded_weight_call,
733+
ExecConfig::new_substrate_tx(),
720734
);
721735

722736
let weight_result = match xcm_weight_results.result {
@@ -744,8 +758,9 @@ mod test {
744758
xcm_precompile_addr,
745759
U256::zero(),
746760
Weight::MAX,
747-
DepositLimit::UnsafeOnlyForDryRun,
761+
u128::MAX,
748762
encoded_call,
763+
ExecConfig::new_substrate_tx(),
749764
);
750765

751766
let return_value = match result.result {
@@ -770,8 +785,9 @@ mod test {
770785
xcm_precompile_addr,
771786
U256::zero(),
772787
Weight::MAX,
773-
DepositLimit::UnsafeOnlyForDryRun,
788+
u128::MAX,
774789
encoded_call,
790+
ExecConfig::new_substrate_tx(),
775791
);
776792

777793
let return_value = match result.result {
@@ -818,8 +834,9 @@ mod test {
818834
xcm_precompile_addr,
819835
U256::zero(),
820836
Weight::MAX,
821-
DepositLimit::UnsafeOnlyForDryRun,
837+
u128::MAX,
822838
encoded_weight_call,
839+
ExecConfig::new_substrate_tx(),
823840
);
824841

825842
let result = match xcm_weight_results.result {
@@ -842,8 +859,9 @@ mod test {
842859
xcm_precompile_addr,
843860
U256::zero(),
844861
Weight::MAX,
845-
DepositLimit::UnsafeOnlyForDryRun,
862+
u128::MAX,
846863
encoded_weight_call,
864+
ExecConfig::new_substrate_tx(),
847865
);
848866

849867
let result = match xcm_weight_results.result {

0 commit comments

Comments
 (0)