Skip to content

Commit 2772e89

Browse files
feat: only allow block creators to set price (#561)
1 parent 390a560 commit 2772e89

File tree

11 files changed

+267
-144
lines changed

11 files changed

+267
-144
lines changed

substrate-node/Cargo.lock

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

substrate-node/charts/substrate-node/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: substrate-node
33
description: Tfchain node
44
type: application
5-
version: 0.2.7
5+
version: 0.2.8
66
appVersion: '2.2.0-rc5'

substrate-node/charts/substrate-node/templates/deployment.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,6 @@ spec:
136136
- name: keys
137137
mountPath: /keys
138138
readOnly: true
139-
- name: insert-tft-key
140-
securityContext:
141-
{{- toYaml .Values.securityContext | nindent 12 }}
142-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
143-
imagePullPolicy: {{ .Values.image.pullPolicy }}
144-
args: [
145-
"key",
146-
"insert",
147-
"--keystore-path=/keystore",
148-
"--key-type", "tft!",
149-
"--suri","/keys/tft",
150-
"--scheme=sr25519"
151-
]
152-
volumeMounts:
153-
- name: keystore
154-
mountPath: /keystore
155-
- name: keys
156-
mountPath: /keys
157-
readOnly: true
158139
{{ end }}
159140
volumes:
160141
- name: keystore

substrate-node/charts/substrate-node/values.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ keys: []
5858
# secret: "kkjghjfkkj kjhgkkhhgg"
5959
# - name: node
6060
# secret: 1a...
61-
# - name: tft
62-
# secret: "kkjghjfkkj kjhgkkhhgg"
6361

6462
# boot_node: "/ip4/10.42.1.134/tcp/30333/p2p/12D3KooWGX8JFxZu2dDmGVpa9t9enZnFCLhH4NUBA7PDuhEVQTMg"
6563

substrate-node/node/src/chain_spec.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use sp_runtime::traits::{IdentifyAccount, Verify};
66
use tfchain_runtime::opaque::SessionKeys;
77
use tfchain_runtime::{
88
AccountId, AuraConfig, BalancesConfig, CouncilConfig, CouncilMembershipConfig, GenesisConfig,
9-
GrandpaConfig, SessionConfig, Signature, SudoConfig, SystemConfig, TFTBridgeModuleConfig,
10-
SmartContractModuleConfig, TFTPriceModuleConfig, TfgridModuleConfig, ValidatorSetConfig,
9+
GrandpaConfig, SessionConfig, Signature, SmartContractModuleConfig, SudoConfig, SystemConfig,
10+
TFTBridgeModuleConfig, TFTPriceModuleConfig, TfgridModuleConfig, ValidatorSetConfig,
1111
WASM_BINARY,
1212
};
1313

@@ -116,8 +116,6 @@ pub fn development_config() -> Result<ChainSpec, String> {
116116
],
117117
// Bridge fee account
118118
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
119-
// TFT price pallet allow account
120-
get_account_id_from_seed::<sr25519::Public>("Alice"),
121119
// TFT price pallet min price
122120
10,
123121
// TFT price pallet max price
@@ -206,8 +204,6 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
206204
],
207205
// Bridge fee account
208206
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
209-
// TFT price pallet allow account
210-
get_account_id_from_seed::<sr25519::Public>("Alice"),
211207
// TFT price pallet min price
212208
10,
213209
// TFT price pallet max price
@@ -241,10 +237,9 @@ fn testnet_genesis(
241237
_enable_println: bool,
242238
bridge_validator_accounts: Vec<AccountId>,
243239
bridge_fee_account: AccountId,
244-
tft_price_allowed_account: AccountId,
245240
min_tft_price: u32,
246241
max_tft_price: u32,
247-
billing_frequency: u64
242+
billing_frequency: u64,
248243
) -> GenesisConfig {
249244
GenesisConfig {
250245
system: SystemConfig {
@@ -331,12 +326,12 @@ fn testnet_genesis(
331326
},
332327
// just some default for development
333328
tft_price_module: TFTPriceModuleConfig {
334-
allowed_origin: Some(tft_price_allowed_account),
335329
min_tft_price,
336330
max_tft_price,
331+
_data: std::marker::PhantomData,
337332
},
338333
smart_contract_module: SmartContractModuleConfig {
339-
billing_frequency: billing_frequency
334+
billing_frequency: billing_frequency,
340335
},
341336
}
342337
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use sp_runtime::{
4545
AccountId32, MultiSignature,
4646
};
4747
use sp_std::convert::{TryFrom, TryInto};
48+
use sp_std::marker::PhantomData;
4849
use std::cell::RefCell;
4950
use tfchain_support::{constants::time::MINUTES, traits::ChangeNode};
5051

@@ -484,10 +485,15 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
484485
};
485486
genesis.assimilate_storage(&mut storage).unwrap();
486487

488+
let session_genesis = pallet_session::GenesisConfig::<TestRuntime> {
489+
keys: vec![(alice(), alice(), MockSessionKeys::from(UintAuthorityId(1)))],
490+
};
491+
session_genesis.assimilate_storage(&mut storage).unwrap();
492+
487493
let genesis = pallet_tft_price::GenesisConfig::<TestRuntime> {
488-
allowed_origin: Some(bob()),
489494
min_tft_price: 10,
490495
max_tft_price: 1000,
496+
_data: PhantomData,
491497
};
492498
genesis.assimilate_storage(&mut storage).unwrap();
493499

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ fn test_cancel_rent_contract_with_active_node_contracts_fails() {
709709
ext.execute_with(|| {
710710
prepare_dedicated_farm_and_node();
711711
run_to_block(1, Some(&mut pool_state));
712-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
712+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
713713

714714
let node_id = 1;
715715
assert_ok!(SmartContractModule::create_rent_contract(
@@ -743,7 +743,7 @@ fn test_node_contract_billing_details() {
743743
ext.execute_with(|| {
744744
prepare_farm_and_node();
745745
run_to_block(1, Some(&mut pool_state));
746-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
746+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
747747

748748
let twin = TfgridModule::twins(2).unwrap();
749749
let initial_twin_balance = Balances::free_balance(&twin.account_id);
@@ -830,7 +830,7 @@ fn test_node_contract_billing_details_with_solution_provider() {
830830
prepare_solution_provider();
831831

832832
run_to_block(1, Some(&mut pool_state));
833-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
833+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
834834

835835
let twin = TfgridModule::twins(2).unwrap();
836836
let initial_twin_balance = Balances::free_balance(&twin.account_id);
@@ -877,7 +877,7 @@ fn test_multiple_contracts_billing_loop_works() {
877877
ext.execute_with(|| {
878878
prepare_farm_and_node();
879879
run_to_block(1, Some(&mut pool_state));
880-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
880+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
881881

882882
assert_ok!(SmartContractModule::create_node_contract(
883883
Origin::signed(bob()),
@@ -921,7 +921,7 @@ fn test_node_contract_billing_cycles() {
921921
ext.execute_with(|| {
922922
prepare_farm_and_node();
923923
run_to_block(1, Some(&mut pool_state));
924-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
924+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
925925

926926
assert_ok!(SmartContractModule::create_node_contract(
927927
Origin::signed(bob()),
@@ -985,7 +985,7 @@ fn test_node_multiple_contract_billing_cycles() {
985985
ext.execute_with(|| {
986986
prepare_farm_and_node();
987987
run_to_block(1, Some(&mut pool_state));
988-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
988+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
989989

990990
assert_ok!(SmartContractModule::create_node_contract(
991991
Origin::signed(bob()),
@@ -1040,7 +1040,7 @@ fn test_node_contract_billing_cycles_delete_node_cancels_contract() {
10401040
ext.execute_with(|| {
10411041
prepare_farm_and_node();
10421042
run_to_block(1, Some(&mut pool_state));
1043-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1043+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
10441044

10451045
assert_ok!(SmartContractModule::create_node_contract(
10461046
Origin::signed(bob()),
@@ -1133,7 +1133,7 @@ fn test_node_contract_only_public_ip_billing_cycles() {
11331133
ext.execute_with(|| {
11341134
prepare_farm_and_node();
11351135
run_to_block(1, Some(&mut pool_state));
1136-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1136+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
11371137

11381138
assert_ok!(SmartContractModule::create_node_contract(
11391139
Origin::signed(bob()),
@@ -1183,7 +1183,7 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_works() {
11831183
ext.execute_with(|| {
11841184
prepare_farm_and_node();
11851185
run_to_block(1, Some(&mut pool_state));
1186-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1186+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
11871187

11881188
assert_ok!(SmartContractModule::create_node_contract(
11891189
Origin::signed(bob()),
@@ -1280,7 +1280,7 @@ fn test_node_contract_billing_cycles_cancel_contract_during_cycle_without_balanc
12801280
ext.execute_with(|| {
12811281
prepare_farm_and_node();
12821282
run_to_block(1, Some(&mut pool_state));
1283-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1283+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
12841284

12851285
let twin = TfgridModule::twins(2).unwrap();
12861286
let initial_twin_balance = Balances::free_balance(&twin.account_id);
@@ -1360,7 +1360,7 @@ fn test_node_contract_out_of_funds_should_move_state_to_graceperiod_works() {
13601360
ext.execute_with(|| {
13611361
prepare_farm_and_node();
13621362
run_to_block(1, Some(&mut pool_state));
1363-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1363+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
13641364

13651365
assert_ok!(SmartContractModule::create_node_contract(
13661366
Origin::signed(charlie()),
@@ -1410,7 +1410,7 @@ fn test_restore_node_contract_in_grace_works() {
14101410
ext.execute_with(|| {
14111411
prepare_farm_and_node();
14121412
run_to_block(1, Some(&mut pool_state));
1413-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1413+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
14141414

14151415
assert_ok!(SmartContractModule::create_node_contract(
14161416
Origin::signed(charlie()),
@@ -1469,7 +1469,7 @@ fn test_node_contract_grace_period_cancels_contract_when_grace_period_ends_works
14691469
ext.execute_with(|| {
14701470
prepare_farm_and_node();
14711471
run_to_block(1, Some(&mut pool_state));
1472-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1472+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
14731473
let twin = TfgridModule::twins(3).unwrap();
14741474
let initial_total_issuance = Balances::total_issuance();
14751475
let initial_twin_balance = Balances::free_balance(&twin.account_id);
@@ -1547,7 +1547,7 @@ fn test_name_contract_billing() {
15471547
ext.execute_with(|| {
15481548
prepare_farm_and_node();
15491549
run_to_block(1, Some(&mut pool_state));
1550-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1550+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
15511551

15521552
assert_ok!(SmartContractModule::create_name_contract(
15531553
Origin::signed(bob()),
@@ -1590,7 +1590,7 @@ fn test_rent_contract_billing() {
15901590
ext.execute_with(|| {
15911591
prepare_dedicated_farm_and_node();
15921592
run_to_block(1, Some(&mut pool_state));
1593-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1593+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
15941594

15951595
let node_id = 1;
15961596
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1623,7 +1623,7 @@ fn test_rent_contract_billing_cancel_should_bill_reserved_balance() {
16231623
ext.execute_with(|| {
16241624
prepare_dedicated_farm_and_node();
16251625
run_to_block(1, Some(&mut pool_state));
1626-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1626+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
16271627

16281628
let node_id = 1;
16291629
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1693,7 +1693,7 @@ fn test_rent_contract_canceled_mid_cycle_should_bill_for_remainder() {
16931693
ext.execute_with(|| {
16941694
prepare_dedicated_farm_and_node();
16951695
run_to_block(1, Some(&mut pool_state));
1696-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1696+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
16971697

16981698
let node_id = 1;
16991699
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1741,7 +1741,7 @@ fn test_create_rent_contract_and_node_contract_excludes_node_contract_from_billi
17411741
ext.execute_with(|| {
17421742
prepare_dedicated_farm_and_node();
17431743
run_to_block(1, Some(&mut pool_state));
1744-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1744+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
17451745

17461746
let node_id = 1;
17471747
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1786,7 +1786,7 @@ fn test_rent_contract_canceled_due_to_out_of_funds_should_cancel_node_contracts_
17861786
ext.execute_with(|| {
17871787
prepare_dedicated_farm_and_node();
17881788
run_to_block(1, Some(&mut pool_state));
1789-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1789+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
17901790

17911791
let node_id = 1;
17921792
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1875,7 +1875,7 @@ fn test_create_rent_contract_and_node_contract_with_ip_billing_works() {
18751875
ext.execute_with(|| {
18761876
prepare_dedicated_farm_and_node();
18771877
run_to_block(1, Some(&mut pool_state));
1878-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1878+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
18791879

18801880
let node_id = 1;
18811881
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1928,7 +1928,7 @@ fn test_rent_contract_out_of_funds_should_move_state_to_graceperiod_works() {
19281928
ext.execute_with(|| {
19291929
prepare_dedicated_farm_and_node();
19301930
run_to_block(1, Some(&mut pool_state));
1931-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1931+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
19321932

19331933
let node_id = 1;
19341934
assert_ok!(SmartContractModule::create_rent_contract(
@@ -1968,7 +1968,7 @@ fn test_restore_rent_contract_in_grace_works() {
19681968
ext.execute_with(|| {
19691969
prepare_dedicated_farm_and_node();
19701970
run_to_block(1, Some(&mut pool_state));
1971-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
1971+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
19721972

19731973
let node_id = 1;
19741974
assert_ok!(SmartContractModule::create_rent_contract(
@@ -2033,7 +2033,7 @@ fn test_restore_rent_contract_and_node_contracts_in_grace_works() {
20332033
ext.execute_with(|| {
20342034
prepare_dedicated_farm_and_node();
20352035
run_to_block(1, None);
2036-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
2036+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
20372037

20382038
let node_id = 1;
20392039
assert_ok!(SmartContractModule::create_rent_contract(
@@ -2156,7 +2156,7 @@ fn test_rent_contract_grace_period_cancels_contract_when_grace_period_ends_works
21562156
ext.execute_with(|| {
21572157
prepare_dedicated_farm_and_node();
21582158
run_to_block(1, Some(&mut pool_state));
2159-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
2159+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
21602160

21612161
let node_id = 1;
21622162
assert_ok!(SmartContractModule::create_rent_contract(
@@ -2209,7 +2209,7 @@ fn test_rent_contract_and_node_contract_canceled_when_node_is_deleted_works() {
22092209
ext.execute_with(|| {
22102210
prepare_dedicated_farm_and_node();
22112211
run_to_block(1, Some(&mut pool_state));
2212-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
2212+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
22132213

22142214
let node_id = 1;
22152215
assert_ok!(SmartContractModule::create_rent_contract(
@@ -2684,7 +2684,7 @@ pub fn prepare_farm(source: AccountId, dedicated: bool) {
26842684
}
26852685

26862686
pub fn prepare_farm_and_node() {
2687-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
2687+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
26882688

26892689
create_farming_policies();
26902690
prepare_twins();
@@ -2719,7 +2719,7 @@ pub fn prepare_farm_and_node() {
27192719
}
27202720

27212721
pub fn prepare_dedicated_farm_and_node() {
2722-
TFTPriceModule::set_prices(Origin::signed(bob()), 50, 101).unwrap();
2722+
TFTPriceModule::set_prices(Origin::signed(alice()), 50, 101).unwrap();
27232723
create_farming_policies();
27242724
prepare_twins();
27252725
prepare_farm(alice(), true);

0 commit comments

Comments
 (0)