Skip to content

Commit 0ce8638

Browse files
committed
Merge branch 'main' into fix/chainspecs
2 parents 15878cb + f62d824 commit 0ce8638

Some content is hidden

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

56 files changed

+562
-302
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ members = [
88
resolver = "2"
99

1010
[workspace.lints.clippy]
11+
indexing-slicing = "deny"
12+
arithmetic-side-effects = "deny"
1113
type_complexity = "allow"
14+
unwrap-used = "deny"
1215

1316
[workspace.dependencies]
1417
cargo-husky = { version = "1", default-features = false }

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ COPY Cargo.lock Cargo.toml /subtensor/
3838

3939
# Specs
4040
COPY ./snapshot.json /subtensor/snapshot.json
41+
COPY ./raw_spec_testfinney.json /subtensor/raw_spec_testfinney.json
42+
COPY ./raw_spec_finney.json /subtensor/raw_spec_finney.json
4143

4244
# Copy our sources
4345
COPY ./node /subtensor/node
@@ -50,11 +52,13 @@ RUN /subtensor/scripts/init.sh
5052

5153
# Cargo build
5254
WORKDIR /subtensor
53-
RUN cargo build --release --features runtime-benchmarks --locked
55+
RUN cargo build --profile production --features runtime-benchmarks --locked
5456
EXPOSE 30333 9933 9944
5557

5658

5759
FROM $BASE_IMAGE AS subtensor
5860

5961
COPY --from=builder /subtensor/snapshot.json /
60-
COPY --from=builder /subtensor/target/release/node-subtensor /usr/local/bin
62+
COPY --from=builder /subtensor/raw_spec_testfinney.json /
63+
COPY --from=builder /subtensor/raw_spec_finney.json /
64+
COPY --from=builder /subtensor/target/production/node-subtensor /usr/local/bin

docs/running-subtensor-locally.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ rm -rf /tmp/blockchain
162162
Install subtensor by compiling with `cargo`:
163163

164164
```bash
165-
cargo build --release --features=runtime-benchmarks
165+
cargo build --profile production --features=runtime-benchmarks
166166
```
167167

168168
## Run the subtensor node
@@ -174,31 +174,31 @@ You can now run the public subtensor node either as a lite node or as an archive
174174
To run a lite node connected to the mainchain, execute the below command (note the `--sync=warp` flag which runs the subtensor node in lite mode):
175175

176176
```bash title="With --sync=warp setting, for lite node"
177-
./target/release/node-subtensor --chain raw_spec_finney.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
177+
./target/production/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=warp --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
178178
```
179179

180180
### Archive node on mainchain
181181

182182
To run an archive node connected to the mainchain, execute the below command (note the `--sync=full` which syncs the node to the full chain and `--pruning archive` flags, which disables the node's automatic pruning of older historical data):
183183

184184
```bash title="With --sync=full and --pruning archive setting, for archive node"
185-
./target/release/node-subtensor --chain raw_spec_finney.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
185+
./target/production/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=full --pruning archive --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
186186
```
187187

188188
### Lite node on testchain
189189

190190
To run a lite node connected to the testchain, execute the below command:
191191

192192
```bash title="With bootnodes set to testnet and --sync=warp setting, for lite node."
193-
./target/release/node-subtensor --chain raw_spec_testfinney.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
193+
./target/production/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=warp --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
194194
```
195195

196196
### Archive node on testchain
197197

198198
To run an archive node connected to the testchain, execute the below command:
199199

200200
```bash title="With bootnodes set to testnet and --sync=full and --pruning archive setting, for archive node"
201-
./target/release/node-subtensor --chain raw_spec_testfinney.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
201+
./target/production/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=full --pruning archive --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
202202
```
203203

204204
## Running on cloud

docs/rust-setup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
title: Installation
33
---
4-
5-
This guide is for reference only, please check the latest information on getting starting with Substrate
4+
This guide is for reference only, please check the latest information on getting starting with Substrate
65
[here](https://docs.substrate.io/main-docs/install/).
76

87
This page will guide you through the **2 steps** needed to prepare a computer for **Substrate** development.
@@ -207,7 +206,7 @@ Use the `WASM_BUILD_TOOLCHAIN` environment variable to specify the Rust nightly
207206
project should use for Wasm compilation:
208207

209208
```bash
210-
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --release
209+
WASM_BUILD_TOOLCHAIN=nightly-<yyyy-MM-dd> cargo build --profile production
211210
```
212211

213212
> Note that this only builds _the runtime_ with the specified nightly. The rest of project will be
@@ -223,3 +222,4 @@ rustup uninstall nightly
223222
rustup install nightly-<yyyy-MM-dd>
224223
rustup target add wasm32-unknown-unknown --toolchain nightly-<yyyy-MM-dd>
225224
```
225+

justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export RUST_BACKTRACE := "full"
44
export SKIP_WASM_BUILD := "1"
55
export RUST_BIN_DIR := "target/x86_64-unknown-linux-gnu"
66
export TARGET := "x86_64-unknown-linux-gnu"
7-
export RUSTV := "nightly-2024-03-05"
7+
export RUSTV := "stable"
88
export RELEASE_NAME := "development"
99

1010
fmt:
@@ -25,13 +25,13 @@ benchmarks:
2525

2626
clippy:
2727
@echo "Running cargo clippy..."
28-
cargo +{{RUSTV}} clippy -- -D clippy::panic \
28+
cargo +{{RUSTV}} clippy --workspace --all-targets -- -D \
2929
-D clippy::todo \
3030
-D clippy::unimplemented
3131

3232
clippy-fix:
3333
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
34-
cargo +{{RUSTV}} clippy --fix --allow-dirty -- -A clippy::panic \
34+
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- -A \
3535
-A clippy::todo \
3636
-A clippy::unimplemented
3737
fix:

node/src/chain_spec/finney.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::*;
55

66
pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
77
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
8-
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
8+
let wasm_binary = WASM_BINARY.ok_or("Development wasm not available".to_string())?;
99

1010
// We mmap the file into memory first, as this is *a lot* faster than using
1111
// `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160
@@ -53,7 +53,9 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
5353
let key_account = sp_runtime::AccountId32::from(key);
5454

5555
processed_balances.push((key_account, *amount));
56-
balances_issuance += *amount;
56+
balances_issuance = balances_issuance
57+
.checked_add(*amount)
58+
.ok_or("Balances issuance overflowed".to_string())?;
5759
}
5860

5961
// Give front-ends necessary data to present to users

node/src/chain_spec/testnet.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
2020
};
2121

2222
let old_state: ColdkeyHotkeys =
23-
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?;
23+
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {e}"))?;
2424

2525
let mut processed_stakes: Vec<(
2626
sp_runtime::AccountId32,
@@ -53,7 +53,9 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
5353
let key_account = sp_runtime::AccountId32::from(key);
5454

5555
processed_balances.push((key_account, *amount));
56-
balances_issuance += *amount;
56+
balances_issuance = balances_issuance
57+
.checked_add(*amount)
58+
.ok_or("Balances issuance overflowed".to_string())?;
5759
}
5860

5961
// Give front-ends necessary data to present to users

node/src/command.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use sp_runtime::traits::HashingFor;
1717

1818
use node_subtensor_runtime::Block;
1919
use sc_cli::SubstrateCli;
20-
use sc_service::PartialComponents;
20+
use sc_service::{Configuration, PartialComponents};
2121

2222
impl SubstrateCli for Cli {
2323
fn impl_name() -> String {
@@ -209,8 +209,56 @@ pub fn run() -> sc_cli::Result<()> {
209209
None => {
210210
let runner = cli.create_runner(&cli.run)?;
211211
runner.run_node_until_exit(|config| async move {
212+
let config = override_default_heap_pages(config, 60_000);
212213
service::new_full(config).map_err(sc_cli::Error::Service)
213214
})
214215
}
215216
}
216217
}
218+
219+
/// Override default heap pages
220+
fn override_default_heap_pages(config: Configuration, pages: u64) -> Configuration {
221+
Configuration {
222+
default_heap_pages: Some(pages),
223+
impl_name: config.impl_name,
224+
impl_version: config.impl_version,
225+
role: config.role,
226+
tokio_handle: config.tokio_handle,
227+
transaction_pool: config.transaction_pool,
228+
network: config.network,
229+
keystore: config.keystore,
230+
database: config.database,
231+
trie_cache_maximum_size: config.trie_cache_maximum_size,
232+
state_pruning: config.state_pruning,
233+
blocks_pruning: config.blocks_pruning,
234+
chain_spec: config.chain_spec,
235+
wasm_method: config.wasm_method,
236+
wasm_runtime_overrides: config.wasm_runtime_overrides,
237+
rpc_addr: config.rpc_addr,
238+
rpc_max_connections: config.rpc_max_connections,
239+
rpc_cors: config.rpc_cors,
240+
rpc_methods: config.rpc_methods,
241+
rpc_max_request_size: config.rpc_max_request_size,
242+
rpc_max_response_size: config.rpc_max_response_size,
243+
rpc_id_provider: config.rpc_id_provider,
244+
rpc_max_subs_per_conn: config.rpc_max_subs_per_conn,
245+
rpc_port: config.rpc_port,
246+
rpc_message_buffer_capacity: config.rpc_message_buffer_capacity,
247+
rpc_batch_config: config.rpc_batch_config,
248+
rpc_rate_limit: config.rpc_rate_limit,
249+
prometheus_config: config.prometheus_config,
250+
telemetry_endpoints: config.telemetry_endpoints,
251+
offchain_worker: config.offchain_worker,
252+
force_authoring: config.force_authoring,
253+
disable_grandpa: config.disable_grandpa,
254+
dev_key_seed: config.dev_key_seed,
255+
tracing_targets: config.tracing_targets,
256+
tracing_receiver: config.tracing_receiver,
257+
max_runtime_instances: config.max_runtime_instances,
258+
announce_block: config.announce_block,
259+
data_path: config.data_path,
260+
base_path: config.base_path,
261+
informant_output_format: config.informant_output_format,
262+
runtime_cache_size: config.runtime_cache_size,
263+
}
264+
}
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
cargo build --release --features runtime-benchmarks
2-
./target/release/node-subtensor benchmark pallet \
3-
--chain=local \
4-
--execution=wasm \
5-
--wasm-execution=compiled \
6-
--pallet=pallet_admin_utils \
7-
--extrinsic="*" \
8-
--steps 50 \
9-
--repeat 20 \
10-
--output=pallets/admin-utils/src/weights.rs \
11-
--template=./.maintain/frame-weight-template.hbs
1+
cargo build --profile production --features runtime-benchmarks
2+
./target/production/node-subtensor benchmark pallet \
3+
--chain=local \
4+
--pallet=pallet_admin_utils \
5+
--extrinsic="*" \
6+
--steps 50 \
7+
--repeat 20 \
8+
--output=pallets/admin-utils/src/weights.rs \
9+
--template=./.maintain/frame-weight-template.hbs

pallets/admin-utils/src/benchmarking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Benchmarking setup
22
#![cfg(feature = "runtime-benchmarks")]
3+
#![allow(clippy::arithmetic_side_effects)]
34
use super::*;
45

56
#[allow(unused)]

pallets/admin-utils/tests/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
2+
13
use frame_support::{
24
assert_ok, derive_impl, parameter_types,
35
traits::{Everything, Hooks},

pallets/collective/src/benchmarking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717

1818
//! Staking pallet benchmarking.
19+
#![allow(clippy::arithmetic_side_effects, clippy::indexing_slicing)]
1920

2021
use super::*;
2122
use crate::Pallet as Collective;
@@ -70,7 +71,7 @@ benchmarks_instance_pallet! {
7071
// Proposals should be different so that different proposal hashes are generated
7172
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, length) }.into();
7273
Collective::<T, I>::propose(
73-
SystemOrigin::Signed(old_members.last().unwrap().clone()).into(),
74+
SystemOrigin::Signed(old_members.last().expect("m is greater than 0; old_members must have at least 1 element; qed").clone()).into(),
7475
Box::new(proposal.clone()),
7576
MAX_BYTES,
7677
TryInto::<BlockNumberFor<T>>::try_into(3u64).ok().expect("convert u64 to block number.")

pallets/collective/src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use frame_support::{
5454
use scale_info::TypeInfo;
5555
use sp_io::storage;
5656
use sp_runtime::traits::Dispatchable;
57-
use sp_runtime::{traits::Hash, RuntimeDebug};
57+
use sp_runtime::{traits::Hash, RuntimeDebug, Saturating};
5858
use sp_std::{marker::PhantomData, prelude::*, result};
5959

6060
#[cfg(test)]
@@ -119,7 +119,7 @@ impl DefaultVote for MoreThanMajorityThenPrimeDefaultVote {
119119
_no_votes: MemberCount,
120120
len: MemberCount,
121121
) -> bool {
122-
let more_than_majority = yes_votes * 2 > len;
122+
let more_than_majority = yes_votes.saturating_mul(2) > len;
123123
more_than_majority || prime_vote.unwrap_or(false)
124124
}
125125
}
@@ -545,7 +545,9 @@ pub mod pallet {
545545
Error::<T, I>::DurationLowerThanConfiguredMotionDuration
546546
);
547547

548-
let threshold = (T::GetVotingMembers::get_count() / 2) + 1;
548+
let threshold = T::GetVotingMembers::get_count()
549+
.saturating_div(2)
550+
.saturating_add(1);
549551

550552
let members = Self::members();
551553
let (proposal_len, active_proposals) =
@@ -716,10 +718,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
716718
})?;
717719

718720
let index = Self::proposal_count();
719-
<ProposalCount<T, I>>::mutate(|i| *i += 1);
721+
<ProposalCount<T, I>>::try_mutate(|i| {
722+
*i = i
723+
.checked_add(1)
724+
.ok_or(Error::<T, I>::TooManyActiveProposals)?;
725+
Ok::<(), Error<T, I>>(())
726+
})?;
720727
<ProposalOf<T, I>>::insert(proposal_hash, proposal);
721728
let votes = {
722-
let end = frame_system::Pallet::<T>::block_number() + duration;
729+
let end = frame_system::Pallet::<T>::block_number().saturating_add(duration);
723730
Votes {
724731
index,
725732
threshold,
@@ -862,10 +869,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
862869
// default voting strategy.
863870
let default = T::DefaultVote::default_vote(prime_vote, yes_votes, no_votes, seats);
864871

865-
let abstentions = seats - (yes_votes + no_votes);
872+
let abstentions = seats.saturating_sub(yes_votes.saturating_add(no_votes));
866873
match default {
867-
true => yes_votes += abstentions,
868-
false => no_votes += abstentions,
874+
true => yes_votes = yes_votes.saturating_add(abstentions),
875+
false => no_votes = no_votes.saturating_add(abstentions),
869876
}
870877
let approved = yes_votes >= voting.threshold;
871878

@@ -981,7 +988,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
981988
Voting::<T, I>::remove(proposal_hash);
982989
let num_proposals = Proposals::<T, I>::mutate(|proposals| {
983990
proposals.retain(|h| h != &proposal_hash);
984-
proposals.len() + 1 // calculate weight based on original length
991+
proposals.len().saturating_add(1) // calculate weight based on original length
985992
});
986993
num_proposals as u32
987994
}
@@ -1154,7 +1161,7 @@ impl<
11541161
type Success = ();
11551162
fn try_origin(o: O) -> Result<Self::Success, O> {
11561163
o.into().and_then(|o| match o {
1157-
RawOrigin::Members(n, m) if n * D > N * m => Ok(()),
1164+
RawOrigin::Members(n, m) if n.saturating_mul(D) > N.saturating_mul(m) => Ok(()),
11581165
r => Err(O::from(r)),
11591166
})
11601167
}
@@ -1179,7 +1186,7 @@ impl<
11791186
type Success = ();
11801187
fn try_origin(o: O) -> Result<Self::Success, O> {
11811188
o.into().and_then(|o| match o {
1182-
RawOrigin::Members(n, m) if n * D >= N * m => Ok(()),
1189+
RawOrigin::Members(n, m) if n.saturating_mul(D) >= N.saturating_mul(m) => Ok(()),
11831190
r => Err(O::from(r)),
11841191
})
11851192
}

pallets/collective/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
1717

18-
#![allow(non_camel_case_types)]
18+
#![allow(non_camel_case_types, clippy::indexing_slicing, clippy::unwrap_used)]
1919

2020
use super::{Event as CollectiveEvent, *};
2121
use crate as pallet_collective;

0 commit comments

Comments
 (0)