Skip to content

Commit

Permalink
Merge pull request #550 from opentensor/sam-add-freeze-layout-devnet
Browse files Browse the repository at this point in the history
[devnet companion] prevent accidental changes to storage structs
  • Loading branch information
sam0x17 committed Jun 19, 2024
2 parents 1a0d09f + 68ab335 commit 6000266
Show file tree
Hide file tree
Showing 40 changed files with 564 additions and 111 deletions.
18 changes: 0 additions & 18 deletions .cargo-husky/hooks/prepare-commit-msg

This file was deleted.

59 changes: 5 additions & 54 deletions .github/workflows/check-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -119,55 +119,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
os:
- ubuntu-latest
# - macos-latest
include:
- os: ubuntu-latest
# - os: macos-latest
env:
RELEASE_NAME: development
# RUSTFLAGS: -A warnings
RUSTV: ${{ matrix.rust-branch }}
RUST_BACKTRACE: full
RUST_BIN_DIR: target/${{ matrix.rust-target }}
SKIP_WASM_BUILD: 1
TARGET: ${{ matrix.rust-target }}
steps:
- name: Check-out repository under $GITHUB_WORKSPACE
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update &&
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler
- name: Install Rust ${{ matrix.rust-branch }}
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: ${{ matrix.rust-branch }}
components: rustfmt, clippy
profile: minimal

- name: Utilize Shared Rust Cache
uses: Swatinem/rust-cache@v2.2.1
with:
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}

- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

cargo-clippy-all-features:
name: cargo clippy --all-features
runs-on: SubtensorCI
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -208,15 +160,14 @@ jobs:

- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

# runs cargo test --workspace
cargo-test:
name: cargo test
runs-on: SubtensorCI
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -265,7 +216,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down Expand Up @@ -314,7 +265,7 @@ jobs:
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
- stable
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/devnet-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Tested on Devnet
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
branches: [main]
jobs:
check-labels:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/testnet-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Tested on Testnet
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
branches: [main]
jobs:
check-labels:
runs-on: ubuntu-latest
Expand Down
Empty file removed CITATION.cft
Empty file.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"pallets/commitments",
"pallets/subtensor",
"runtime",
"support/macros",
]
resolver = "2"

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

subtensor-macros = { path = "support/macros" }

frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0", default-features = false }
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0" }
frame-executive = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.10.0", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ COPY ./raw_testspec.json /subtensor/raw_testspec.json
COPY ./node /subtensor/node
COPY ./pallets /subtensor/pallets
COPY ./runtime /subtensor/runtime
COPY ./support /subtensor/support

# Update to nightly toolchain
# Copy our toolchain
COPY rust-toolchain.toml /subtensor/
RUN /subtensor/scripts/init.sh

Expand Down
4 changes: 2 additions & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct FullDeps<C, P, B> {
/// Grandpa block import setup.
pub grandpa: GrandpaDeps<B>,
/// Backend used by the node.
pub backend: Arc<B>,
pub _backend: Arc<B>,
}

/// Instantiate all full RPC extensions.
Expand Down Expand Up @@ -74,7 +74,7 @@ where
pool,
deny_unsafe,
grandpa,
backend: _,
_backend: _,
} = deps;

// Custom RPC methods for Paratensor
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
backend: rpc_backend.clone(),
_backend: rpc_backend.clone(),
};
crate::rpc::create_full(deps).map_err(Into::into)
},
Expand Down
1 change: 1 addition & 0 deletions pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
subtensor-macros.workspace = true
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
Expand Down
1 change: 0 additions & 1 deletion pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub use weights::WeightInfo;
use sp_runtime::DispatchError;
use sp_runtime::{traits::Member, RuntimeAppPublic};

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

#[deny(missing_docs)]
Expand Down
1 change: 1 addition & 0 deletions pallets/collective/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
subtensor-macros.workspace = true
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
"derive",
] }
Expand Down
2 changes: 2 additions & 0 deletions pallets/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ mod benchmarking;
pub mod weights;

pub use pallet::*;
use subtensor_macros::freeze_struct;
pub use weights::WeightInfo;

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

/// Info for keeping track of a motion being voted on.
#[freeze_struct("5959418cdb31993b")]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct Votes<AccountId, BlockNumber> {
/// The proposal's unique index.
Expand Down
1 change: 1 addition & 0 deletions pallets/commitments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
subtensor-macros.workspace = true
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
"max-encoded-len",
Expand Down
8 changes: 4 additions & 4 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod benchmarking;
#[cfg(test)]
mod tests;

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

pub mod types;
pub mod weights;

pub use pallet::*;
use subtensor_macros::freeze_struct;
pub use types::*;
pub use weights::WeightInfo;

Expand Down Expand Up @@ -210,6 +209,7 @@ use {
},
};

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

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

Expand Down
4 changes: 3 additions & 1 deletion pallets/commitments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use sp_runtime::{
RuntimeDebug,
};
use sp_std::{fmt::Debug, iter::once, prelude::*};
use subtensor_macros::freeze_struct;

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

#[freeze_struct("25c84048dcc90813")]
#[derive(
CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo,
)]
#[codec(mel_bound())]
#[cfg_attr(test, derive(frame_support::DefaultNoBound))]
#[derive(frame_support::DefaultNoBound)]
#[scale_info(skip_type_params(FieldLimit))]
pub struct CommitmentInfo<FieldLimit: Get<u32>> {
pub fields: BoundedVec<Data, FieldLimit>,
Expand Down
1 change: 1 addition & 0 deletions pallets/registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
subtensor-macros.workspace = true
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
"max-encoded-len",
Expand Down
1 change: 0 additions & 1 deletion pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[cfg(test)]
mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod types;
pub mod weights;
Expand Down
4 changes: 3 additions & 1 deletion pallets/registry/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use sp_runtime::{
RuntimeDebug,
};
use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*};
use subtensor_macros::freeze_struct;

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

0 comments on commit 6000266

Please sign in to comment.