Skip to content

Commit 6000266

Browse files
authored
Merge pull request #550 from opentensor/sam-add-freeze-layout-devnet
[devnet companion] prevent accidental changes to storage structs
2 parents 1a0d09f + 68ab335 commit 6000266

40 files changed

+564
-111
lines changed

.cargo-husky/hooks/prepare-commit-msg

-18
This file was deleted.

.github/workflows/check-rust.yml

+5-54
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
strategy:
7272
matrix:
7373
rust-branch:
74-
- nightly-2024-03-05
74+
- stable
7575
rust-target:
7676
- x86_64-unknown-linux-gnu
7777
# - x86_64-apple-darwin
@@ -119,55 +119,7 @@ jobs:
119119
strategy:
120120
matrix:
121121
rust-branch:
122-
- nightly-2024-03-05
123-
rust-target:
124-
- x86_64-unknown-linux-gnu
125-
# - x86_64-apple-darwin
126-
os:
127-
- ubuntu-latest
128-
# - macos-latest
129-
include:
130-
- os: ubuntu-latest
131-
# - os: macos-latest
132-
env:
133-
RELEASE_NAME: development
134-
# RUSTFLAGS: -A warnings
135-
RUSTV: ${{ matrix.rust-branch }}
136-
RUST_BACKTRACE: full
137-
RUST_BIN_DIR: target/${{ matrix.rust-target }}
138-
SKIP_WASM_BUILD: 1
139-
TARGET: ${{ matrix.rust-target }}
140-
steps:
141-
- name: Check-out repository under $GITHUB_WORKSPACE
142-
uses: actions/checkout@v2
143-
144-
- name: Install dependencies
145-
run: |
146-
sudo apt-get update &&
147-
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler
148-
149-
- name: Install Rust ${{ matrix.rust-branch }}
150-
uses: actions-rs/toolchain@v1.0.6
151-
with:
152-
toolchain: ${{ matrix.rust-branch }}
153-
components: rustfmt, clippy
154-
profile: minimal
155-
156-
- name: Utilize Shared Rust Cache
157-
uses: Swatinem/rust-cache@v2.2.1
158-
with:
159-
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}
160-
161-
- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
162-
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
163-
164-
cargo-clippy-all-features:
165-
name: cargo clippy --all-features
166-
runs-on: SubtensorCI
167-
strategy:
168-
matrix:
169-
rust-branch:
170-
- nightly-2024-03-05
122+
- stable
171123
rust-target:
172124
- x86_64-unknown-linux-gnu
173125
# - x86_64-apple-darwin
@@ -208,15 +160,14 @@ jobs:
208160

209161
- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
210162
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
211-
212163
# runs cargo test --workspace
213164
cargo-test:
214165
name: cargo test
215166
runs-on: SubtensorCI
216167
strategy:
217168
matrix:
218169
rust-branch:
219-
- nightly-2024-03-05
170+
- stable
220171
rust-target:
221172
- x86_64-unknown-linux-gnu
222173
# - x86_64-apple-darwin
@@ -265,7 +216,7 @@ jobs:
265216
strategy:
266217
matrix:
267218
rust-branch:
268-
- nightly-2024-03-05
219+
- stable
269220
rust-target:
270221
- x86_64-unknown-linux-gnu
271222
# - x86_64-apple-darwin
@@ -314,7 +265,7 @@ jobs:
314265
strategy:
315266
matrix:
316267
rust-branch:
317-
- nightly-2024-03-05
268+
- stable
318269
rust-target:
319270
- x86_64-unknown-linux-gnu
320271
# - x86_64-apple-darwin

.github/workflows/devnet-labels.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Tested on Devnet
22
on:
33
pull_request:
44
types: [opened, labeled, unlabeled, synchronize]
5+
branches: [main]
56
jobs:
67
check-labels:
78
runs-on: ubuntu-latest

.github/workflows/testnet-labels.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Tested on Testnet
22
on:
33
pull_request:
44
types: [opened, labeled, unlabeled, synchronize]
5+
branches: [main]
56
jobs:
67
check-labels:
78
runs-on: ubuntu-latest

CITATION.cft

Whitespace-only changes.

Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"pallets/commitments",
55
"pallets/subtensor",
66
"runtime",
7+
"support/macros",
78
]
89
resolver = "2"
910

@@ -36,6 +37,8 @@ serde_with = { version = "=2.0.0", default-features = false }
3637
smallvec = "1.13.2"
3738
litep2p = { git = "https://github.com/paritytech/litep2p", branch = "master" }
3839

40+
subtensor-macros = { path = "support/macros" }
41+
3942
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0", default-features = false }
4043
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
4144
frame-executive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0", default-features = false }

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ COPY ./raw_testspec.json /subtensor/raw_testspec.json
4545
COPY ./node /subtensor/node
4646
COPY ./pallets /subtensor/pallets
4747
COPY ./runtime /subtensor/runtime
48+
COPY ./support /subtensor/support
4849

49-
# Update to nightly toolchain
50+
# Copy our toolchain
5051
COPY rust-toolchain.toml /subtensor/
5152
RUN /subtensor/scripts/init.sh
5253

node/src/rpc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct FullDeps<C, P, B> {
4242
/// Grandpa block import setup.
4343
pub grandpa: GrandpaDeps<B>,
4444
/// Backend used by the node.
45-
pub backend: Arc<B>,
45+
pub _backend: Arc<B>,
4646
}
4747

4848
/// Instantiate all full RPC extensions.
@@ -74,7 +74,7 @@ where
7474
pool,
7575
deny_unsafe,
7676
grandpa,
77-
backend: _,
77+
_backend: _,
7878
} = deps;
7979

8080
// Custom RPC methods for Paratensor

node/src/service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
266266
subscription_executor: subscription_executor.clone(),
267267
finality_provider: finality_proof_provider.clone(),
268268
},
269-
backend: rpc_backend.clone(),
269+
_backend: rpc_backend.clone(),
270270
};
271271
crate::rpc::create_full(deps).map_err(Into::into)
272272
},

pallets/admin-utils/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
19+
subtensor-macros.workspace = true
1920
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
2021
"derive",
2122
] }

pallets/admin-utils/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub use weights::WeightInfo;
77
use sp_runtime::DispatchError;
88
use sp_runtime::{traits::Member, RuntimeAppPublic};
99

10-
#[cfg(feature = "runtime-benchmarks")]
1110
mod benchmarking;
1211

1312
#[deny(missing_docs)]

pallets/collective/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
19+
subtensor-macros.workspace = true
1920
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
2021
"derive",
2122
] }

pallets/collective/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ mod benchmarking;
6565
pub mod weights;
6666

6767
pub use pallet::*;
68+
use subtensor_macros::freeze_struct;
6869
pub use weights::WeightInfo;
6970

7071
const LOG_TARGET: &str = "runtime::collective";
@@ -150,6 +151,7 @@ impl<AccountId, I> GetBacking for RawOrigin<AccountId, I> {
150151
}
151152

152153
/// Info for keeping track of a motion being voted on.
154+
#[freeze_struct("5959418cdb31993b")]
153155
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
154156
pub struct Votes<AccountId, BlockNumber> {
155157
/// The proposal's unique index.

pallets/commitments/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
19+
subtensor-macros.workspace = true
1920
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
2021
"derive",
2122
"max-encoded-len",

pallets/commitments/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

3+
mod benchmarking;
34
#[cfg(test)]
45
mod tests;
56

6-
#[cfg(feature = "runtime-benchmarks")]
7-
mod benchmarking;
8-
97
pub mod types;
108
pub mod weights;
119

1210
pub use pallet::*;
11+
use subtensor_macros::freeze_struct;
1312
pub use types::*;
1413
pub use weights::WeightInfo;
1514

@@ -210,6 +209,7 @@ use {
210209
},
211210
};
212211

212+
#[freeze_struct("6a00398e14a8a984")]
213213
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
214214
pub struct CommitmentsSignedExtension<T: Config + Send + Sync + TypeInfo>(pub PhantomData<T>);
215215

@@ -235,7 +235,7 @@ where
235235
pub fn get_priority_vanilla() -> u64 {
236236
// Return high priority so that every extrinsic except set_weights function will
237237
// have a higher priority than the set_weights call
238-
u64::max_value()
238+
u64::MAX
239239
}
240240
}
241241

pallets/commitments/src/types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use sp_runtime::{
2929
RuntimeDebug,
3030
};
3131
use sp_std::{fmt::Debug, iter::once, prelude::*};
32+
use subtensor_macros::freeze_struct;
3233

3334
/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
3435
/// than 32-bytes then it will be truncated when encoding.
@@ -283,11 +284,12 @@ impl Default for Data {
283284
}
284285
}
285286

287+
#[freeze_struct("25c84048dcc90813")]
286288
#[derive(
287289
CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
288290
)]
289291
#[codec(mel_bound())]
290-
#[cfg_attr(test, derive(frame_support::DefaultNoBound))]
292+
#[derive(frame_support::DefaultNoBound)]
291293
#[scale_info(skip_type_params(FieldLimit))]
292294
pub struct CommitmentInfo<FieldLimit: Get<u32>> {
293295
pub fields: BoundedVec<Data, FieldLimit>,

pallets/registry/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
targets = ["x86_64-unknown-linux-gnu"]
1717

1818
[dependencies]
19+
subtensor-macros.workspace = true
1920
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
2021
"derive",
2122
"max-encoded-len",

pallets/registry/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#[cfg(test)]
44
mod tests;
55

6-
#[cfg(feature = "runtime-benchmarks")]
76
mod benchmarking;
87
pub mod types;
98
pub mod weights;

pallets/registry/src/types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use sp_runtime::{
3030
RuntimeDebug,
3131
};
3232
use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*};
33+
use subtensor_macros::freeze_struct;
3334

3435
/// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
3536
/// than 32-bytes then it will be truncated when encoding.
@@ -278,11 +279,12 @@ impl TypeInfo for IdentityFields {
278279
///
279280
/// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra
280281
/// fields in a backwards compatible way through a specialized `Decode` impl.
282+
#[freeze_struct("70b183c8753429f1")]
281283
#[derive(
282284
CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
283285
)]
284286
#[codec(mel_bound())]
285-
#[cfg_attr(test, derive(frame_support::DefaultNoBound))]
287+
#[derive(frame_support::DefaultNoBound)]
286288
#[scale_info(skip_type_params(FieldLimit))]
287289
pub struct IdentityInfo<FieldLimit: Get<u32>> {
288290
/// Additional fields of the identity that are not catered for with the struct's explicit

0 commit comments

Comments
 (0)