Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 72c2775

Browse files
atheitomusdrwpepyakin
authored
Integrate pallet_contracts gas with the weight system (#5712)
Co-Authored-By: Tomasz Drwięga <[email protected]> Co-Authored-By: Sergei Pepyakin <[email protected]>
1 parent 45b1247 commit 72c2775

File tree

20 files changed

+386
-680
lines changed

20 files changed

+386
-680
lines changed

Cargo.lock

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

bin/node/cli/src/chain_spec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ pub fn testnet_genesis(
292292
enable_println, // this should only be enabled on development chains
293293
..Default::default()
294294
},
295-
gas_price: 1 * MILLICENTS,
296295
}),
297296
pallet_sudo: Some(SudoConfig {
298297
key: root_key,

bin/node/cli/src/factory_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl<Number> FactoryState<Number> {
5757
frame_system::CheckNonce::from(index),
5858
frame_system::CheckWeight::new(),
5959
pallet_transaction_payment::ChargeTransactionPayment::from(0),
60-
Default::default(),
6160
)
6261
}
6362
}
@@ -122,7 +121,7 @@ impl RuntimeAdapter for FactoryState<Number> {
122121
(*amount).into()
123122
)
124123
)
125-
}, key, (version, genesis_hash.clone(), prior_block_hash.clone(), (), (), (), ()))
124+
}, key, (version, genesis_hash.clone(), prior_block_hash.clone(), (), (), ()))
126125
}
127126

128127
fn inherent_extrinsics(&self) -> InherentData {

bin/node/cli/src/service.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,11 @@ mod tests {
633633
check_nonce,
634634
check_weight,
635635
payment,
636-
Default::default(),
637636
);
638637
let raw_payload = SignedPayload::from_raw(
639638
function,
640639
extra,
641-
(version, genesis_hash, genesis_hash, (), (), (), ())
640+
(version, genesis_hash, genesis_hash, (), (), ())
642641
);
643642
let signature = raw_payload.using_encoded(|payload| {
644643
signer.sign(payload)

bin/node/executor/tests/basic.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,18 @@ fn deploying_wasm_contract_should_work() {
606606
CheckedExtrinsic {
607607
signed: Some((charlie(), signed_extra(0, 0))),
608608
function: Call::Contracts(
609-
pallet_contracts::Call::put_code::<Runtime>(10_000, transfer_code)
609+
pallet_contracts::Call::put_code::<Runtime>(transfer_code)
610610
),
611611
},
612612
CheckedExtrinsic {
613613
signed: Some((charlie(), signed_extra(1, 0))),
614614
function: Call::Contracts(
615-
pallet_contracts::Call::instantiate::<Runtime>(1 * DOLLARS, 10_000, transfer_ch, Vec::new())
615+
pallet_contracts::Call::instantiate::<Runtime>(
616+
1 * DOLLARS,
617+
500_000_000,
618+
transfer_ch,
619+
Vec::new()
620+
)
616621
),
617622
},
618623
CheckedExtrinsic {
@@ -621,7 +626,7 @@ fn deploying_wasm_contract_should_work() {
621626
pallet_contracts::Call::call::<Runtime>(
622627
pallet_indices::address::Address::Id(addr.clone()),
623628
10,
624-
10_000,
629+
500_000_000,
625630
vec![0x00, 0x01, 0x02, 0x03]
626631
)
627632
),

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ use constants::{time::*, currency::*};
7373
#[cfg(feature = "std")]
7474
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
7575

76-
7776
/// Runtime version.
7877
pub const VERSION: RuntimeVersion = RuntimeVersion {
7978
spec_name: create_runtime_str!("node"),
@@ -460,40 +459,28 @@ impl pallet_treasury::Trait for Runtime {
460459
}
461460

462461
parameter_types! {
463-
pub const ContractTransactionBaseFee: Balance = 1 * CENTS;
464-
pub const ContractTransactionByteFee: Balance = 10 * MILLICENTS;
465-
pub const ContractFee: Balance = 1 * CENTS;
466462
pub const TombstoneDeposit: Balance = 1 * DOLLARS;
467463
pub const RentByteFee: Balance = 1 * DOLLARS;
468464
pub const RentDepositOffset: Balance = 1000 * DOLLARS;
469465
pub const SurchargeReward: Balance = 150 * DOLLARS;
470466
}
471467

472468
impl pallet_contracts::Trait for Runtime {
473-
type Currency = Balances;
474469
type Time = Timestamp;
475470
type Randomness = RandomnessCollectiveFlip;
476471
type Call = Call;
477472
type Event = Event;
478473
type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;
479-
type ComputeDispatchFee = pallet_contracts::DefaultDispatchFeeComputor<Runtime>;
480474
type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;
481-
type GasPayment = ();
482475
type RentPayment = ();
483476
type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;
484477
type TombstoneDeposit = TombstoneDeposit;
485478
type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;
486479
type RentByteFee = RentByteFee;
487480
type RentDepositOffset = RentDepositOffset;
488481
type SurchargeReward = SurchargeReward;
489-
type TransactionBaseFee = ContractTransactionBaseFee;
490-
type TransactionByteFee = ContractTransactionByteFee;
491-
type ContractFee = ContractFee;
492-
type CallBaseFee = pallet_contracts::DefaultCallBaseFee;
493-
type InstantiateBaseFee = pallet_contracts::DefaultInstantiateBaseFee;
494482
type MaxDepth = pallet_contracts::DefaultMaxDepth;
495483
type MaxValueSize = pallet_contracts::DefaultMaxValueSize;
496-
type BlockGasLimit = pallet_contracts::DefaultBlockGasLimit;
497484
}
498485

499486
impl pallet_sudo::Trait for Runtime {
@@ -536,7 +523,6 @@ impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for R
536523
frame_system::CheckNonce::<Runtime>::from(nonce),
537524
frame_system::CheckWeight::<Runtime>::new(),
538525
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
539-
Default::default(),
540526
);
541527
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
542528
debug::warn!("Unable to create signed payload: {:?}", e);
@@ -692,7 +678,7 @@ construct_runtime!(
692678
FinalityTracker: pallet_finality_tracker::{Module, Call, Inherent},
693679
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
694680
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
695-
Contracts: pallet_contracts::{Module, Call, Config<T>, Storage, Event<T>},
681+
Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},
696682
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
697683
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
698684
AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config},
@@ -724,7 +710,6 @@ pub type SignedExtra = (
724710
frame_system::CheckNonce<Runtime>,
725711
frame_system::CheckWeight<Runtime>,
726712
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
727-
pallet_contracts::CheckBlockGasLimit<Runtime>,
728713
);
729714
/// Unchecked extrinsic type as expected by this runtime.
730715
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;

bin/node/testing/src/genesis.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub fn config_endowed(
9797
}),
9898
pallet_contracts: Some(ContractsConfig {
9999
current_schedule: Default::default(),
100-
gas_price: 1 * MILLICENTS,
101100
}),
102101
pallet_babe: Some(Default::default()),
103102
pallet_grandpa: Some(GrandpaConfig {

bin/node/testing/src/keyring.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
7474
frame_system::CheckNonce::from(nonce),
7575
frame_system::CheckWeight::new(),
7676
pallet_transaction_payment::ChargeTransactionPayment::from(extra_fee),
77-
Default::default(),
7877
)
7978
}
8079

bin/utils/subkey/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ fn create_extrinsic<C: Crypto>(
708708
frame_system::CheckNonce::<Runtime>::from(i),
709709
frame_system::CheckWeight::<Runtime>::new(),
710710
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(f),
711-
Default::default(),
712711
)
713712
};
714713
let raw_payload = SignedPayload::from_raw(
@@ -721,7 +720,6 @@ fn create_extrinsic<C: Crypto>(
721720
(),
722721
(),
723722
(),
724-
(),
725723
),
726724
);
727725
let signature = raw_payload.using_encoded(|payload| signer.sign(payload)).into_runtime();

frame/contracts/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sp-sandbox = { version = "0.8.0-dev", default-features = false, path = "../../pr
2525
frame-support = { version = "2.0.0-dev", default-features = false, path = "../support" }
2626
frame-system = { version = "2.0.0-dev", default-features = false, path = "../system" }
2727
pallet-contracts-primitives = { version = "2.0.0-dev", default-features = false, path = "common" }
28+
pallet-transaction-payment = { version = "2.0.0-dev", default-features = false, path = "../transaction-payment" }
2829

2930
[dev-dependencies]
3031
wabt = "0.9.2"

frame/contracts/rpc/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ const CONTRACT_IS_A_TOMBSTONE: i64 = 3;
4646
/// This value is used to set the upper bound for maximal contract calls to
4747
/// prevent blocking the RPC for too long.
4848
///
49-
/// Based on W3F research spreadsheet:
50-
/// https://docs.google.com/spreadsheets/d/1h0RqncdqiWI4KgxO0z9JIpZEJESXjX_ZCK6LFX6veDo/view
51-
const GAS_PER_SECOND: u64 = 1_000_000_000;
49+
/// As 1 gas is equal to 1 weight we base this on the conducted benchmarks which
50+
/// determined runtime weights:
51+
/// https://github.com/paritytech/substrate/pull/5446
52+
const GAS_PER_SECOND: u64 = 1_000_000_000_000;
5253

5354
/// A private newtype for converting `ContractAccessError` into an RPC error.
5455
struct ContractAccessError(pallet_contracts_primitives::ContractAccessError);

0 commit comments

Comments
 (0)