Skip to content

Commit 7a1620f

Browse files
committed
init
1 parent 8599efc commit 7a1620f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+18110
-563
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ edition = "2021"
88
[workspace]
99
members = [
1010
"node",
11-
"pallets/template",
11+
"pallets/network",
12+
"pallets/subnet-democracy",
1213
"runtime",
1314
]
1415
resolver = "2"
1516

1617
[workspace.dependencies]
1718
solochain-template-runtime = { path = "./runtime", default-features = false }
18-
pallet-template = { path = "./pallets/template", default-features = false }
1919
clap = { version = "4.5.3" }
2020
frame-benchmarking-cli = { version = "42.0.0", default-features = false }
2121
frame-system = { version = "37.0.0", default-features = false }
2222
futures = { version = "0.3.30" }
2323
jsonrpsee = { version = "0.23.2" }
24+
log = { version = "0.4.21", default-features = false }
2425
pallet-transaction-payment = { version = "37.0.0", default-features = false }
2526
pallet-transaction-payment-rpc = { version = "40.0.0", default-features = false }
2627
sc-basic-authorship = { version = "0.44.0", default-features = false }
28+
pallet-authorship = { version = "37.0.0", default-features = false }
2729
sc-cli = { version = "0.46.0", default-features = false }
2830
sc-client-api = { version = "37.0.0", default-features = false }
2931
sc-consensus = { version = "0.43.0", default-features = false }
@@ -37,7 +39,8 @@ sc-service = { version = "0.45.0", default-features = false }
3739
sc-telemetry = { version = "24.0.0", default-features = false }
3840
sc-transaction-pool = { version = "37.0.0", default-features = false }
3941
sc-transaction-pool-api = { version = "37.0.0", default-features = false }
40-
serde_json = { version = "1.0.114", default-features = false }
42+
serde = { version = "1.0.199", default-features = false }
43+
serde_json = { version = "1.0.116", default-features = false }
4144
sp-api = { version = "34.0.0", default-features = false }
4245
sp-block-builder = { version = "34.0.0", default-features = false }
4346
sp-blockchain = { version = "37.0.0", default-features = false }
@@ -49,6 +52,8 @@ sp-io = { version = "38.0.0", default-features = false }
4952
sp-keyring = { version = "39.0.0", default-features = false }
5053
sp-runtime = { version = "39.0.0", default-features = false }
5154
sp-timestamp = { version = "34.0.0", default-features = false }
55+
sp-std = { version = "14.0.0", default-features = false }
56+
sp-rpc = { version = "32.0.0", default-features = false }
5257
substrate-frame-rpc-system = { version = "38.0.0", default-features = false }
5358
substrate-build-script-utils = { version = "11.0.0", default-features = false }
5459
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
@@ -64,6 +69,8 @@ pallet-grandpa = { version = "37.0.0", default-features = false }
6469
pallet-sudo = { version = "37.0.0", default-features = false }
6570
pallet-timestamp = { version = "36.0.0", default-features = false }
6671
pallet-transaction-payment-rpc-runtime-api = { version = "37.0.0", default-features = false }
72+
pallet-multisig = { version = "37.0.0", default-features = false }
73+
pallet-insecure-randomness-collective-flip = { version = "25.0.0", default-features = false }
6774
scale-info = { version = "2.11.1", default-features = false }
6875
sp-genesis-builder = { version = "0.15.0", default-features = false }
6976
sp-offchain = { version = "34.0.0", default-features = false }
@@ -72,3 +79,5 @@ sp-storage = { version = "21.0.0", default-features = false }
7279
sp-transaction-pool = { version = "34.0.0", default-features = false }
7380
sp-version = { version = "37.0.0", default-features = false }
7481
substrate-wasm-builder = { version = "24.0.0", default-features = false }
82+
sp-tracing = { version = "17.0.0", default-features = false }
83+
frame-metadata = "16"

node/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ frame-benchmarking-cli.workspace = true
8080
frame-benchmarking-cli.default-features = true
8181
solochain-template-runtime.workspace = true
8282

83+
network-custom-rpc = { path = "../pallets/network/rpc" }
84+
network-custom-rpc-runtime-api = { path = "../pallets/network/runtime-api" }
85+
8386
[build-dependencies]
8487
substrate-build-script-utils.workspace = true
8588
substrate-build-script-utils.default-features = true

node/src/chain_spec.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,14 @@ fn testnet_genesis(
113113
// Assign network admin rights.
114114
"key": Some(root_key),
115115
},
116+
// "pallet_network": {
117+
// "subnet_path": "bigscience/bloom-560m".into(),
118+
// "memory_mb": 560,
119+
// "subnet_nodes": vec![],
120+
// "accounts": vec![],
121+
// "blank": {
122+
// Some(root_key.clone())
123+
// },
124+
// },
116125
})
117126
}

node/src/rpc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ where
3737
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
3838
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
3939
C::Api: BlockBuilder<Block>,
40+
C::Api: network_custom_rpc_runtime_api::NetworkRuntimeApi<Block>,
4041
P: TransactionPool + 'static,
4142
{
4243
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
4344
use substrate_frame_rpc_system::{System, SystemApiServer};
45+
use network_custom_rpc::{NetworkCustom, NetworkCustomApiServer};
4446

4547
let mut module = RpcModule::new(());
4648
let FullDeps { client, pool, deny_unsafe } = deps;
4749

4850
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
49-
module.merge(TransactionPayment::new(client).into_rpc())?;
51+
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
52+
module.merge(NetworkCustom::new(client.clone()).into_rpc())?;
5053

5154
// Extend this RPC with a custom API by using the following syntax.
5255
// `YourRpcStruct` should have a reference to a client, which is needed

pallets/admin/Cargo.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[package]
2+
name = "pallet-admin"
3+
version = "4.0.0-dev"
4+
description = "FRAME pallet template for defining custom runtime logic."
5+
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
6+
homepage = "https://substrate.io"
7+
edition = "2021"
8+
license = "MIT-0"
9+
publish = false
10+
repository = "https://github.com/substrate-developer-hub/substrate-node-template/"
11+
12+
[package.metadata.docs.rs]
13+
targets = ["x86_64-unknown-linux-gnu"]
14+
15+
[dependencies]
16+
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [
17+
"derive",
18+
] }
19+
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
20+
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
21+
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
22+
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
23+
log = "0.4"
24+
pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
25+
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
26+
27+
pallet-network = { version = "4.0.0-dev", default-features = false, path = "../network" }
28+
pallet-subnet-democracy = { version = "4.0.0-dev", default-features = false, path = "../subnet-democracy" }
29+
30+
# Randomness
31+
pallet-insecure-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
32+
33+
[dev-dependencies]
34+
sp-core = { version = "21.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
35+
sp-io = { version = "23.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
36+
sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
37+
38+
[features]
39+
default = ["std"]
40+
std = [
41+
"codec/std",
42+
"frame-benchmarking?/std",
43+
"frame-support/std",
44+
"frame-system/std",
45+
"scale-info/std",
46+
"pallet-network/std",
47+
"pallet-subnet-democracy/std",
48+
"pallet-sudo/std",
49+
"pallet-insecure-randomness-collective-flip/std",
50+
]
51+
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
52+
try-runtime = ["frame-support/try-runtime"]

pallets/admin/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
License: MIT-0

pallets/admin/src/benchmarking.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (C) Hypertensor.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// https://blog.oak.tech/tutorial-benchmarking-for-parity-substrate-pallet-development-9cb68bf87ea2
17+
// https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs
18+
// Executed Command:
19+
// ./target/release/node-template benchmark pallet --chain=dev --wasm-execution=compiled --pallet=pallet_admin --extrinsic=* --steps=1 --repeat=1 --output="pallets/admin/src/weights.rs" --template ./.maintain/frame-weight-template.hbs
20+
21+
// cargo build --release --features runtime-benchmarks
22+
// cargo test --release --features runtime-benchmarks
23+
// cargo build --package pallet-admin --features runtime-benchmarks
24+
use super::*;
25+
// use crate::mock::*;
26+
use frame_benchmarking::{account, benchmarks, whitelist_account, BenchmarkError};
27+
use frame_support::{
28+
assert_noop, assert_ok,
29+
traits::Currency,
30+
};
31+
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
32+
use crate::Pallet as Admin;
33+
use frame_support::dispatch::Vec;
34+
use scale_info::prelude::vec;
35+
// use crate::mock::Network;
36+
37+
const SEED: u32 = 0;
38+
39+
// fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
40+
// let caller: T::AccountId = account(name, index, SEED);
41+
// // Give the account half of the maximum value of the `Balance` type.
42+
// // Otherwise some transfers will fail with an overflow error.
43+
// let deposit_amount: u128 = 10000000000000000000000;
44+
// T::Currency::deposit_creating(&caller, deposit_amount.try_into().ok().expect("REASON"));
45+
// caller
46+
// }
47+
48+
benchmarks! {
49+
set_vote_model_in {
50+
let model_path: Vec<u8> = "petals-team-3/StableBeluga2".into();
51+
}: set_vote_model_in(RawOrigin::Root, model_path.clone(), 50000)
52+
verify {
53+
// let value = pallet_network::SubnetVoteIn::get(model_path.clone());
54+
// let value = pallet_network::<T>::SubnetVoteIn::get(model_path.clone()).unwrap();
55+
// let value = pallet_network::SubnetVoteIn::get(model_path.clone());
56+
// let value1 = pallet_network::SubnetVoteIn::<T>::get(model_path.clone());
57+
// let value = pallet_network::model_vote_in(model_path.clone());
58+
59+
// assert_eq!(value, Some(true));
60+
// let value = pallet_network::SubnetVoteOut::<T>::get(model_path.clone());
61+
// assert_eq!(value, Some(false));
62+
assert_eq!(Some(true), Some(true));
63+
64+
}
65+
66+
impl_benchmark_test_suite!(
67+
Admin,
68+
crate::mock::new_test_ext(),
69+
crate::mock::Test
70+
);
71+
}

0 commit comments

Comments
 (0)