Skip to content

Commit 08321ba

Browse files
authored
Verify rent contract state on node contract creation (#1008)
* fix: verify rent contract state on node contract creation * chore: update benchmark `weights.rs` file for all pallets
1 parent 1c787e1 commit 08321ba

File tree

11 files changed

+399
-358
lines changed

11 files changed

+399
-358
lines changed

substrate-node/pallets/pallet-burning/src/weights.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//! Autogenerated weights for pallet_burning
33
//!
44
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
5-
//! DATE: 2024-08-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
5+
//! DATE: 2024-09-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
66
//! WORST CASE MAP SIZE: `1000000`
7-
//! HOSTNAME: `66e77d0da08f`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
7+
//! HOSTNAME: `da081090f983`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
88
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
99
1010
// Executed Command:
@@ -45,8 +45,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
4545
// Proof Size summary in bytes:
4646
// Measured: `109`
4747
// Estimated: `1594`
48-
// Minimum execution time: 26_780_000 picoseconds.
49-
Weight::from_parts(27_291_000, 1594)
48+
// Minimum execution time: 26_741_000 picoseconds.
49+
Weight::from_parts(27_212_000, 1594)
5050
.saturating_add(T::DbWeight::get().reads(1_u64))
5151
.saturating_add(T::DbWeight::get().writes(1_u64))
5252
}
@@ -60,8 +60,8 @@ impl WeightInfo for () {
6060
// Proof Size summary in bytes:
6161
// Measured: `109`
6262
// Estimated: `1594`
63-
// Minimum execution time: 26_780_000 picoseconds.
64-
Weight::from_parts(27_291_000, 1594)
63+
// Minimum execution time: 26_741_000 picoseconds.
64+
Weight::from_parts(27_212_000, 1594)
6565
.saturating_add(RocksDbWeight::get().reads(1_u64))
6666
.saturating_add(RocksDbWeight::get().writes(1_u64))
6767
}

substrate-node/pallets/pallet-dao/src/weights.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//! Autogenerated weights for pallet_dao
33
//!
44
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
5-
//! DATE: 2024-08-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
5+
//! DATE: 2024-09-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
66
//! WORST CASE MAP SIZE: `1000000`
7-
//! HOSTNAME: `66e77d0da08f`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
7+
//! HOSTNAME: `da081090f983`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
88
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
99
1010
// Executed Command:
@@ -58,8 +58,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
5858
// Proof Size summary in bytes:
5959
// Measured: `208`
6060
// Estimated: `4687`
61-
// Minimum execution time: 19_277_000 picoseconds.
62-
Weight::from_parts(20_188_000, 4687)
61+
// Minimum execution time: 19_888_000 picoseconds.
62+
Weight::from_parts(20_368_000, 4687)
6363
.saturating_add(T::DbWeight::get().reads(4_u64))
6464
.saturating_add(T::DbWeight::get().writes(5_u64))
6565
}
@@ -77,8 +77,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
7777
// Proof Size summary in bytes:
7878
// Measured: `979`
7979
// Estimated: `4444`
80-
// Minimum execution time: 26_390_000 picoseconds.
81-
Weight::from_parts(26_840_000, 4444)
80+
// Minimum execution time: 26_991_000 picoseconds.
81+
Weight::from_parts(27_542_000, 4444)
8282
.saturating_add(T::DbWeight::get().reads(5_u64))
8383
.saturating_add(T::DbWeight::get().writes(1_u64))
8484
}
@@ -92,8 +92,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
9292
// Proof Size summary in bytes:
9393
// Measured: `487`
9494
// Estimated: `4687`
95-
// Minimum execution time: 18_616_000 picoseconds.
96-
Weight::from_parts(18_985_000, 4687)
95+
// Minimum execution time: 18_766_000 picoseconds.
96+
Weight::from_parts(19_256_000, 4687)
9797
.saturating_add(T::DbWeight::get().reads(3_u64))
9898
.saturating_add(T::DbWeight::get().writes(1_u64))
9999
}
@@ -111,8 +111,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
111111
// Proof Size summary in bytes:
112112
// Measured: `521`
113113
// Estimated: `4687`
114-
// Minimum execution time: 25_117_000 picoseconds.
115-
Weight::from_parts(25_498_000, 4687)
114+
// Minimum execution time: 25_348_000 picoseconds.
115+
Weight::from_parts(26_310_000, 4687)
116116
.saturating_add(T::DbWeight::get().reads(3_u64))
117117
.saturating_add(T::DbWeight::get().writes(4_u64))
118118
}
@@ -136,8 +136,8 @@ impl WeightInfo for () {
136136
// Proof Size summary in bytes:
137137
// Measured: `208`
138138
// Estimated: `4687`
139-
// Minimum execution time: 19_277_000 picoseconds.
140-
Weight::from_parts(20_188_000, 4687)
139+
// Minimum execution time: 19_888_000 picoseconds.
140+
Weight::from_parts(20_368_000, 4687)
141141
.saturating_add(RocksDbWeight::get().reads(4_u64))
142142
.saturating_add(RocksDbWeight::get().writes(5_u64))
143143
}
@@ -155,8 +155,8 @@ impl WeightInfo for () {
155155
// Proof Size summary in bytes:
156156
// Measured: `979`
157157
// Estimated: `4444`
158-
// Minimum execution time: 26_390_000 picoseconds.
159-
Weight::from_parts(26_840_000, 4444)
158+
// Minimum execution time: 26_991_000 picoseconds.
159+
Weight::from_parts(27_542_000, 4444)
160160
.saturating_add(RocksDbWeight::get().reads(5_u64))
161161
.saturating_add(RocksDbWeight::get().writes(1_u64))
162162
}
@@ -170,8 +170,8 @@ impl WeightInfo for () {
170170
// Proof Size summary in bytes:
171171
// Measured: `487`
172172
// Estimated: `4687`
173-
// Minimum execution time: 18_616_000 picoseconds.
174-
Weight::from_parts(18_985_000, 4687)
173+
// Minimum execution time: 18_766_000 picoseconds.
174+
Weight::from_parts(19_256_000, 4687)
175175
.saturating_add(RocksDbWeight::get().reads(3_u64))
176176
.saturating_add(RocksDbWeight::get().writes(1_u64))
177177
}
@@ -189,8 +189,8 @@ impl WeightInfo for () {
189189
// Proof Size summary in bytes:
190190
// Measured: `521`
191191
// Estimated: `4687`
192-
// Minimum execution time: 25_117_000 picoseconds.
193-
Weight::from_parts(25_498_000, 4687)
192+
// Minimum execution time: 25_348_000 picoseconds.
193+
Weight::from_parts(26_310_000, 4687)
194194
.saturating_add(RocksDbWeight::get().reads(3_u64))
195195
.saturating_add(RocksDbWeight::get().writes(4_u64))
196196
}

substrate-node/pallets/pallet-kvstore/src/weights.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//! Autogenerated weights for pallet_kvstore
33
//!
44
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
5-
//! DATE: 2024-08-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
5+
//! DATE: 2024-09-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
66
//! WORST CASE MAP SIZE: `1000000`
7-
//! HOSTNAME: `66e77d0da08f`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
7+
//! HOSTNAME: `da081090f983`, CPU: `AMD Ryzen 7 5800X 8-Core Processor`
88
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
99
1010
// Executed Command:
@@ -46,8 +46,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
4646
// Proof Size summary in bytes:
4747
// Measured: `0`
4848
// Estimated: `0`
49-
// Minimum execution time: 11_372_000 picoseconds.
50-
Weight::from_parts(12_032_000, 0)
49+
// Minimum execution time: 7_054_000 picoseconds.
50+
Weight::from_parts(7_274_000, 0)
5151
.saturating_add(T::DbWeight::get().writes(1_u64))
5252
}
5353
/// Storage: `TFKVStore::TFKVStore` (r:1 w:1)
@@ -56,8 +56,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
5656
// Proof Size summary in bytes:
5757
// Measured: `146`
5858
// Estimated: `3611`
59-
// Minimum execution time: 12_414_000 picoseconds.
60-
Weight::from_parts(12_854_000, 3611)
59+
// Minimum execution time: 12_263_000 picoseconds.
60+
Weight::from_parts(12_824_000, 3611)
6161
.saturating_add(T::DbWeight::get().reads(1_u64))
6262
.saturating_add(T::DbWeight::get().writes(1_u64))
6363
}
@@ -71,8 +71,8 @@ impl WeightInfo for () {
7171
// Proof Size summary in bytes:
7272
// Measured: `0`
7373
// Estimated: `0`
74-
// Minimum execution time: 11_372_000 picoseconds.
75-
Weight::from_parts(12_032_000, 0)
74+
// Minimum execution time: 7_054_000 picoseconds.
75+
Weight::from_parts(7_274_000, 0)
7676
.saturating_add(RocksDbWeight::get().writes(1_u64))
7777
}
7878
/// Storage: `TFKVStore::TFKVStore` (r:1 w:1)
@@ -81,8 +81,8 @@ impl WeightInfo for () {
8181
// Proof Size summary in bytes:
8282
// Measured: `146`
8383
// Estimated: `3611`
84-
// Minimum execution time: 12_414_000 picoseconds.
85-
Weight::from_parts(12_854_000, 3611)
84+
// Minimum execution time: 12_263_000 picoseconds.
85+
Weight::from_parts(12_824_000, 3611)
8686
.saturating_add(RocksDbWeight::get().reads(1_u64))
8787
.saturating_add(RocksDbWeight::get().writes(1_u64))
8888
}

substrate-node/pallets/pallet-smart-contract/src/grid_contract.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ impl<T: Config> Pallet<T> {
4141
let node_is_dedicated =
4242
DedicatedNodesExtraFee::<T>::get(node_id) > 0 || farm.dedicated_farm;
4343

44-
// In case there is a rent contract make sure only the contract owner can deploy
44+
// In case there is a rent contract:
45+
// 1. Ensure only the contract owner can deploy, and
46+
// 2. The rent contract is in the 'created' state
4547
// If not, allow to deploy only if node is not dedicated
4648
match ActiveRentContractForNode::<T>::get(node_id) {
4749
Some(contract_id) => {
4850
let rent_contract =
4951
Contracts::<T>::get(contract_id).ok_or(Error::<T>::ContractNotExists)?;
50-
if rent_contract.twin_id != twin_id {
52+
if rent_contract.twin_id != twin_id || !matches!(rent_contract.state, types::ContractState::Created) {
5153
return Err(Error::<T>::NodeNotAvailableToDeploy.into());
5254
}
5355
}

substrate-node/pallets/pallet-smart-contract/src/tests.rs

+39
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,45 @@ fn test_create_node_contract_on_dedicated_node_rented_by_other_fails() {
934934
})
935935
}
936936

937+
#[test]
938+
fn test_create_node_contract_when_having_a_rentcontract_in_graceperiod_fails() {
939+
let (mut ext, mut pool_state) = new_test_ext_with_pool_state(0);
940+
ext.execute_with(|| {
941+
run_to_block(1, None);
942+
prepare_dedicated_farm_and_node();
943+
let node_id = 1;
944+
let contract_id = 1;
945+
assert_ok!(SmartContractModule::create_rent_contract(
946+
RuntimeOrigin::signed(charlie()),
947+
node_id,
948+
None
949+
));
950+
951+
// Cycle 1
952+
// User does not have enough funds to pay
953+
pool_state
954+
.write()
955+
.should_call_bill_contract(contract_id, Ok(Pays::Yes.into()), 11);
956+
run_to_block(11, Some(&mut pool_state));
957+
958+
let r = SmartContractModule::contracts(1).unwrap();
959+
assert_eq!(r.state, types::ContractState::GracePeriod(11));
960+
961+
// try to create node contract
962+
assert_noop!(
963+
SmartContractModule::create_node_contract(
964+
RuntimeOrigin::signed(charlie()),
965+
node_id,
966+
generate_deployment_hash(),
967+
get_deployment_data(),
968+
1,
969+
None
970+
),
971+
Error::<TestRuntime>::NodeNotAvailableToDeploy
972+
);
973+
})
974+
}
975+
937976
#[test]
938977
fn test_cancel_rent_contract_with_active_node_contracts_fails() {
939978
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)