Skip to content

Commit a6583f5

Browse files
authored
Merge branch 'main' into subnet_hyperparameters_fix
2 parents 24128cc + e607d7e commit a6583f5

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

+6207
-5508
lines changed

.github/workflows/check-rust.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ env:
4848
jobs:
4949
check:
5050
name: Tests targeting ${{ matrix.rust-target }} for OS ${{ matrix.os }}
51-
runs-on: ${{ matrix.os }}
51+
runs-on: SubtensorCI
5252

5353
##
5454
# Define multiple targets for builds and tests
@@ -86,8 +86,8 @@ jobs:
8686

8787
- name: Install dependencies
8888
run: |
89-
sudo apt update &&
90-
sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler
89+
sudo apt-get update &&
90+
sudo apt-get install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler
9191
9292
- name: Install Rust ${{ matrix.rust-branch }}
9393
uses: actions-rs/[email protected]
@@ -100,11 +100,13 @@ jobs:
100100
with:
101101
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}
102102

103+
- name: cargo fmt
104+
run: cargo fmt --check
105+
103106
## TODO: maybe use `if` conditions in tests to target `--package <name>`
104-
- name: Run tests
107+
- name: cargo test
105108
# timeout-minutes: 30
106-
run: |
107-
cargo test --tests
109+
run: cargo test --workspace
108110

109111
- name: Run benchmarks
110112
# timeout-minutes: 30
@@ -114,6 +116,5 @@ jobs:
114116
115117
- name: Build executable
116118
# timeout-minutes: 30
117-
run: |
118-
cargo build --release
119+
run: cargo build --release
119120

node/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name = "node-subtensor"
1818

1919
[dependencies]
2020
clap = { version = "4.0.9", features = ["derive"] }
21-
futures = { version = "0.3.21", features = ["thread-pool"]}
21+
futures = { version = "0.3.21", features = ["thread-pool"] }
2222
serde = { version = "1.0.145", features = ["derive"] }
2323

2424
# Storage import
@@ -47,7 +47,7 @@ sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/sub
4747
sp-keyring = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
4848
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
4949
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }
50-
pallet-commitments = {path="../pallets/commitments"}
50+
pallet-commitments = { path = "../pallets/commitments" }
5151

5252
# These dependencies are used for the subtensor's RPCs
5353
jsonrpsee = { version = "0.16.2", features = ["server"] }
@@ -87,4 +87,7 @@ pow-faucet = []
8787

8888
# Enable features that allow the runtime to be tried and debugged. Name might be subject to change
8989
# in the near future.
90-
try-runtime = ["node-subtensor-runtime/try-runtime", "try-runtime-cli/try-runtime"]
90+
try-runtime = [
91+
"node-subtensor-runtime/try-runtime",
92+
"try-runtime-cli/try-runtime",
93+
]

node/src/benchmarking.rs

Lines changed: 123 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -5,165 +5,173 @@
55
use crate::service::FullClient;
66

77
use node_subtensor_runtime as runtime;
8+
use node_subtensor_runtime::pallet_subtensor;
89
use runtime::{AccountId, Balance, BalancesCall, SystemCall};
910
use sc_cli::Result;
1011
use sc_client_api::BlockBackend;
1112
use sp_core::{Encode, Pair};
1213
use sp_inherents::{InherentData, InherentDataProvider};
1314
use sp_keyring::Sr25519Keyring;
1415
use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
15-
use node_subtensor_runtime::pallet_subtensor;
1616

1717
use std::{sync::Arc, time::Duration};
1818

1919
// Generates extrinsics for the `benchmark overhead` command.
2020
//
2121
// Note: Should only be used for benchmarking.
2222
pub struct RemarkBuilder {
23-
client: Arc<FullClient>,
23+
client: Arc<FullClient>,
2424
}
2525

2626
impl RemarkBuilder {
27-
// Creates a new [`Self`] from the given client.
28-
pub fn new(client: Arc<FullClient>) -> Self {
29-
Self { client }
30-
}
27+
// Creates a new [`Self`] from the given client.
28+
pub fn new(client: Arc<FullClient>) -> Self {
29+
Self { client }
30+
}
3131
}
3232

3333
impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
34-
fn pallet(&self) -> &str {
35-
"system"
36-
}
37-
38-
fn extrinsic(&self) -> &str {
39-
"remark"
40-
}
41-
42-
fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
43-
let acc = Sr25519Keyring::Bob.pair();
44-
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
45-
self.client.as_ref(),
46-
acc,
47-
SystemCall::remark { remark: vec![] }.into(),
48-
nonce,
49-
)
50-
.into();
51-
52-
Ok(extrinsic)
53-
}
34+
fn pallet(&self) -> &str {
35+
"system"
36+
}
37+
38+
fn extrinsic(&self) -> &str {
39+
"remark"
40+
}
41+
42+
fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
43+
let acc = Sr25519Keyring::Bob.pair();
44+
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
45+
self.client.as_ref(),
46+
acc,
47+
SystemCall::remark { remark: vec![] }.into(),
48+
nonce,
49+
)
50+
.into();
51+
52+
Ok(extrinsic)
53+
}
5454
}
5555

5656
// Generates `Balances::TransferKeepAlive` extrinsics for the benchmarks.
5757
//
5858
// Note: Should only be used for benchmarking.
5959
pub struct TransferKeepAliveBuilder {
60-
client: Arc<FullClient>,
61-
dest: AccountId,
62-
value: Balance,
60+
client: Arc<FullClient>,
61+
dest: AccountId,
62+
value: Balance,
6363
}
6464

6565
impl TransferKeepAliveBuilder {
66-
// Creates a new [`Self`] from the given client.
67-
pub fn new(client: Arc<FullClient>, dest: AccountId, value: Balance) -> Self {
68-
Self { client, dest, value }
69-
}
66+
// Creates a new [`Self`] from the given client.
67+
pub fn new(client: Arc<FullClient>, dest: AccountId, value: Balance) -> Self {
68+
Self {
69+
client,
70+
dest,
71+
value,
72+
}
73+
}
7074
}
7175

7276
impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
73-
fn pallet(&self) -> &str {
74-
"balances"
75-
}
76-
77-
fn extrinsic(&self) -> &str {
78-
"transfer_keep_alive"
79-
}
80-
81-
fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
82-
let acc = Sr25519Keyring::Bob.pair();
83-
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
84-
self.client.as_ref(),
85-
acc,
86-
BalancesCall::transfer_keep_alive {
87-
dest: self.dest.clone().into(),
88-
value: self.value.into(),
89-
}
90-
.into(),
91-
nonce,
92-
)
93-
.into();
94-
95-
Ok(extrinsic)
96-
}
77+
fn pallet(&self) -> &str {
78+
"balances"
79+
}
80+
81+
fn extrinsic(&self) -> &str {
82+
"transfer_keep_alive"
83+
}
84+
85+
fn build(&self, nonce: u32) -> std::result::Result<OpaqueExtrinsic, &'static str> {
86+
let acc = Sr25519Keyring::Bob.pair();
87+
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
88+
self.client.as_ref(),
89+
acc,
90+
BalancesCall::transfer_keep_alive {
91+
dest: self.dest.clone().into(),
92+
value: self.value.into(),
93+
}
94+
.into(),
95+
nonce,
96+
)
97+
.into();
98+
99+
Ok(extrinsic)
100+
}
97101
}
98102

99103
// Create a transaction using the given `call`.
100104
//
101105
// Note: Should only be used for benchmarking.
102106
pub fn create_benchmark_extrinsic(
103-
client: &FullClient,
104-
sender: sp_core::sr25519::Pair,
105-
call: runtime::RuntimeCall,
106-
nonce: u32,
107+
client: &FullClient,
108+
sender: sp_core::sr25519::Pair,
109+
call: runtime::RuntimeCall,
110+
nonce: u32,
107111
) -> runtime::UncheckedExtrinsic {
108-
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
109-
let best_hash = client.chain_info().best_hash;
110-
let best_block = client.chain_info().best_number;
111-
112-
let period = runtime::BlockHashCount::get()
113-
.checked_next_power_of_two()
114-
.map(|c| c / 2)
115-
.unwrap_or(2) as u64;
116-
let extra: runtime::SignedExtra = (
117-
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
118-
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
119-
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
120-
frame_system::CheckGenesis::<runtime::Runtime>::new(),
121-
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
122-
period,
123-
best_block.saturated_into(),
124-
)),
125-
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
126-
frame_system::CheckWeight::<runtime::Runtime>::new(),
127-
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
128-
pallet_subtensor::SubtensorSignedExtension::<runtime::Runtime>::new(),
129-
pallet_commitments::CommitmentsSignedExtension::<runtime::Runtime>::new()
130-
);
131-
132-
let raw_payload = runtime::SignedPayload::from_raw(
133-
call.clone(),
134-
extra.clone(),
135-
(
136-
(),
137-
runtime::VERSION.spec_version,
138-
runtime::VERSION.transaction_version,
139-
genesis_hash,
140-
best_hash,
141-
(),
142-
(),
143-
(),
144-
(),
145-
()
146-
),
147-
);
148-
let signature = raw_payload.using_encoded(|e| sender.sign(e));
149-
150-
runtime::UncheckedExtrinsic::new_signed(
151-
call.clone(),
152-
sp_runtime::AccountId32::from(sender.public()).into(),
153-
runtime::Signature::Sr25519(signature.clone()),
154-
extra.clone(),
155-
)
112+
let genesis_hash = client
113+
.block_hash(0)
114+
.ok()
115+
.flatten()
116+
.expect("Genesis block exists; qed");
117+
let best_hash = client.chain_info().best_hash;
118+
let best_block = client.chain_info().best_number;
119+
120+
let period = runtime::BlockHashCount::get()
121+
.checked_next_power_of_two()
122+
.map(|c| c / 2)
123+
.unwrap_or(2) as u64;
124+
let extra: runtime::SignedExtra = (
125+
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
126+
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
127+
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
128+
frame_system::CheckGenesis::<runtime::Runtime>::new(),
129+
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
130+
period,
131+
best_block.saturated_into(),
132+
)),
133+
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
134+
frame_system::CheckWeight::<runtime::Runtime>::new(),
135+
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
136+
pallet_subtensor::SubtensorSignedExtension::<runtime::Runtime>::new(),
137+
pallet_commitments::CommitmentsSignedExtension::<runtime::Runtime>::new(),
138+
);
139+
140+
let raw_payload = runtime::SignedPayload::from_raw(
141+
call.clone(),
142+
extra.clone(),
143+
(
144+
(),
145+
runtime::VERSION.spec_version,
146+
runtime::VERSION.transaction_version,
147+
genesis_hash,
148+
best_hash,
149+
(),
150+
(),
151+
(),
152+
(),
153+
(),
154+
),
155+
);
156+
let signature = raw_payload.using_encoded(|e| sender.sign(e));
157+
158+
runtime::UncheckedExtrinsic::new_signed(
159+
call.clone(),
160+
sp_runtime::AccountId32::from(sender.public()).into(),
161+
runtime::Signature::Sr25519(signature.clone()),
162+
extra.clone(),
163+
)
156164
}
157165

158166
// Generates inherent data for the `benchmark overhead` command.
159167
//
160168
// Note: Should only be used for benchmarking.
161169
pub fn inherent_benchmark_data() -> Result<InherentData> {
162-
let mut inherent_data = InherentData::new();
163-
let d = Duration::from_millis(0);
164-
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
170+
let mut inherent_data = InherentData::new();
171+
let d = Duration::from_millis(0);
172+
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
165173

166-
futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data))
167-
.map_err(|e| format!("creating inherent data: {:?}", e))?;
168-
Ok(inherent_data)
174+
futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data))
175+
.map_err(|e| format!("creating inherent data: {:?}", e))?;
176+
Ok(inherent_data)
169177
}

0 commit comments

Comments
 (0)