Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Supremesource committed Nov 13, 2024
1 parent 2d87795 commit 14deb82
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 29 deletions.
31 changes: 20 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@

PYTHON=python3
RUST_LOG ?= info,pallet_subspace::migrations=debug

.PHONY: down stop up restart start enter chmod_scripts compose try-runtime-upgrade-testnet try-runtime-upgrade-mainnet run-benchmarking run-localnet run-mainnet

down:
docker-compose down
stop:
make down

stop: down

up:
docker-compose up -d
restart:
make down && make up
start:
make start

restart: down up

start: up

enter:
docker exec -it subspace bash

chmod_scripts:
chmod +x ./scripts/*.sh

compose:
docker-compose up -d ${service}

RUST_LOG ?= info,pallet_subspace::migrations=debug
try-runtime-upgrade-testnet:
cargo build --release --features "try-runtime,testnet"
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade live --uri wss://testnet.api.communeai.net:443

try-runtime-upgrade:
try-runtime-upgrade-mainnet:
cargo build --release --features try-runtime
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade live --uri wss://testnet.api.communeai.net:443
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade live --uri wss://api.communeai.net:443

run-benchmarking:
cargo build -r --features runtime-benchmarks
Expand All @@ -31,7 +40,7 @@ run-benchmarking:
./target/release/node-subspace benchmark pallet --chain specs/benchmarks.json --pallet pallet_subnet_emission --extrinsic "*" --steps 50 --repeat 20 --output pallets/subnet_emission/src/weights.rs --template=./.maintain/frame-weight-template.hbs

specs/mainnet-copy.json:
python3 scripts/snapshots/builder.py -o specs/mainnet-copy.json
$(PYTHON) scripts/snapshots/builder.py -o specs/mainnet-copy.json

run-localnet:
cargo xtask run --alice
Expand Down
1 change: 1 addition & 0 deletions pallets/faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ std = [
"sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]
testnet = []

[dependencies]
frame-support = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions pallets/faucet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub mod pallet {
use pallet_subspace::N;
pub use sp_std::{vec, vec::Vec};

#[cfg(feature = "testnet")]
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

#[cfg(not(feature = "testnet"))]
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

#[pallet::pallet]
Expand Down
1 change: 1 addition & 0 deletions pallets/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ std = [
]
try-runtime = ["frame-support/try-runtime"]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
testnet = []

[dependencies]
log.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ pub mod pallet {
use frame_system::pallet_prelude::{ensure_signed, BlockNumberFor};
use sp_runtime::traits::AccountIdConversion;

#[cfg(feature = "testnet")]
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);

#[cfg(not(feature = "testnet"))]
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);
Expand Down
4 changes: 2 additions & 2 deletions pallets/offworker/src/dispatches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use frame_support::pallet_macros::pallet_section;
pub mod dispatches {
#[pallet::call]
impl<T: Config> Pallet<T> {
// TODO: v2 of DEW will involve offworker sending potential zk proofs of encryption
// TODO: step 3 v2 of DEW will involve offworker sending potential zk proofs of encryption
// correctness (proof that he can not decrypt certain weights)

// # References
Expand All @@ -22,7 +22,7 @@ pub mod dispatches {
#[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::No))]
pub fn send_decrypted_weights(
origin: OriginFor<T>,
payload: DecryptedWeightsPayload<T::Public, BlockNumberFor<T>>,
payload: DecryptedWeightsPayload<T::Public, BlockNumberFor<T>>, /* make payload accept zk proofs of wrong encryption */
_signature: T::Signature,
) -> DispatchResultWithPostInfo {
// Signature valiadation is performed by the validate unsigned function
Expand Down
1 change: 1 addition & 0 deletions pallets/offworker/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl<T: Config> Pallet<T> {
.collect()
}

// TODO: cancled everythign when weight encryption was cancled
pub fn process_subnets(subnets: Vec<u16>, current_block: u64) -> Vec<u16> {
let mut deregistered_subnets = Vec::new();

Expand Down
5 changes: 5 additions & 0 deletions pallets/offworker/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ where
Some((uid, decrypted, key))
}
None => {
// TODO:
log::error!("Failed to decrypt weights for UID: {}", uid);
None
// if this ever happens, we need to make a zk proof of encryption
// correctness (that it was not done correctly)
// and then send this proof back to the runtime together with the
// decrypted weights
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/subnet_emission/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ std = [
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]
testnet = []

[dependencies]
bty = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions pallets/subnet_emission/src/decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ impl<T: Config> Pallet<T> {
}
}

// TODO: step 4. verify the zk proofs, if only one zk proof is invalid, you will ban the
// offchain worker
pub fn handle_decrypted_weights(netuid: u16, weights: Vec<BlockWeights>) {
log::info!("Received decrypted weights for subnet {netuid}");
let info = match SubnetDecryptionData::<T>::get(netuid) {
Expand Down
8 changes: 7 additions & 1 deletion pallets/subnet_emission/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pub mod types;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

// #[cfg(feature = "testnet")]
// const VERSION_NUMBER: u16 = 12;
// #[cfg(not(feature = "testnet"))]
// const VERSION_NUMBER: u16 = 0;

#[frame_support::pallet]
pub mod pallet {
use crate::{subnet_consensus::util::params::ConsensusParams, *};
Expand All @@ -44,7 +49,8 @@ pub mod pallet {
use subnet_pricing::root::RootPricing;
use types::KeylessBlockWeights;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(12);
pub const STORAGE_VERSION: frame_support::traits::StorageVersion =
frame_support::traits::StorageVersion::new(0);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
Expand Down
22 changes: 22 additions & 0 deletions pallets/subnet_emission/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ use frame_support::{
traits::{Get, OnRuntimeUpgrade, StorageVersion},
};

// pub mod v1 {
// use super::*;

// pub struct MigrateToV8<T>(sp_std::marker::PhantomData<T>);

// impl<T: Config> OnRuntimeUpgrade for MigrateToV8<T> {
// fn on_runtime_upgrade() -> frame_support::weights::Weight {
// let on_chain_version = StorageVersion::get::<Pallet<T>>();
// if on_chain_version != 0 {
// log::info!("Storage v1 already updated");
// return Weight::zero();
// }

// StorageVersion::new(1).put::<Pallet<T>>();

// log::info!("Migrated to v1");

// T::DbWeight::get().reads_writes(2, 2)
// }
// }
// }

pub mod v8 {
use super::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::params::{AccountKey, ConsensusParams, FlattenedModules, ModuleKey};
use crate::EmissionError;
use frame_support::{ensure, DebugNoBound, StorageMap};
use frame_support::{ensure, DebugNoBound};
use pallet_subspace::{math::*, vec, BalanceOf, Pallet as PalletSubspace};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
Expand Down
1 change: 1 addition & 0 deletions pallets/subspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ std = [
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]
testnet = []

[dependencies]
frame-benchmarking = { workspace = true, optional = true }
Expand Down
15 changes: 9 additions & 6 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ pub use crate::params::{
};
use selections::{config, dispatches, errors, events, genesis, hooks};

#[cfg(not(feature = "testnet"))]
use selections::storage_v_mainnet as storage_v;

#[cfg(feature = "testnet")]
use selections::storage_v_testnet as storage_v;

#[import_section(genesis::genesis)]
#[import_section(errors::errors)]
#[import_section(events::events)]
#[import_section(dispatches::dispatches)]
#[import_section(hooks::hooks)]
#[import_section(config::config)]
#[import_section(storage_v::storage_version)]
#[frame_support::pallet]
pub mod pallet {
#![allow(deprecated, clippy::let_unit_value, clippy::too_many_arguments)]
Expand All @@ -80,12 +87,6 @@ pub mod pallet {
pub use sp_std::{vec, vec::Vec};
use substrate_fixed::types::I64F64;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(31);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);

pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as system::Config>::AccountId>>::Balance;

Expand Down Expand Up @@ -157,6 +158,7 @@ pub mod pallet {
Trust: u64 = |_: PhantomData<T>| 0,
ValidatorPermits: bool = |_: PhantomData<T>| false,
ValidatorTrust: u64 = |_: PhantomData<T>| 0,
PruningScores: u16 = |_: PhantomData<T>| 0,
},
// Put here every module-related double map, where the first key is netuid, second key is module uid. These storages holds some value for each module ie. name, address, etc.
swap_storages: {
Expand All @@ -167,6 +169,7 @@ pub mod pallet {
RegistrationBlock: u64 = |_: PhantomData<T>| Pallet::<T>::get_current_block_number(),
Address: Vec<u8> = |_: PhantomData<T>| Vec::<u8>::new(),
Name: Vec<u8> = |_: PhantomData<T>| Vec::<u8>::new(),
Bonds: Vec<(u16, u16)> = |_: PhantomData<T>| Vec::<(u16, u16)>::new(),
}
},
// Specifically for uids and keys
Expand Down
20 changes: 20 additions & 0 deletions pallets/subspace/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::*;
use frame_support::{
pallet_prelude::ValueQuery,
traits::{Get, StorageVersion},
};

pub mod v15 {
use dao::CuratorApplication;
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};

use super::*;

pub mod old_storage {
use super::*;
use frame_support::{pallet_prelude::TypeInfo, storage_alias, Identity};

#[storage_alias]
pub type Weights<T: Config> = StorageMap<Pallet<T>, u16, Identity, u16, Vec<(u16, u16)>>;
}
}
4 changes: 4 additions & 0 deletions pallets/subspace/src/selections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ pub mod errors;
pub mod events;
pub mod genesis;
pub mod hooks;
#[cfg(not(feature = "testnet"))]
pub mod storage_v_mainnet;
#[cfg(feature = "testnet")]
pub mod storage_v_testnet;
Empty file.
13 changes: 13 additions & 0 deletions pallets/subspace/src/selections/storage_v_mainnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use frame_support::{pallet_macros::pallet_section, traits::StorageVersion};

pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(14);

#[pallet_section]
pub mod storage_version {
use crate::storage_v::STORAGE_VERSION;

Check failure on line 7 in pallets/subspace/src/selections/storage_v_mainnet.rs

View workflow job for this annotation

GitHub Actions / check

`crate` references the macro call's crate

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
}
14 changes: 14 additions & 0 deletions pallets/subspace/src/selections/storage_v_testnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use frame_support::{pallet_macros::pallet_section, traits::StorageVersion};

pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(31);

// Testnet selection
#[pallet_section]
pub mod storage_version {
use crate::storage_v::STORAGE_VERSION;

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
}
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ substrate-wasm-builder = { workspace = true, optional = true }
[features]
default = ["std"]
testnet-faucet = ["pallet-faucet"]
testnet = []
std = [
"frame-try-runtime?/std",
"frame-system-benchmarking?/std",
Expand Down
26 changes: 18 additions & 8 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,37 @@ pub mod opaque {
}
}

#[cfg(feature = "testnet")]
pub type Migrations = (pallet_subnet_emission::migrations::v8::MigrateToV8<Runtime>,);

// To learn more about runtime versioning, see:
// https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning
#[cfg(not(feature = "testnet"))]
pub type Migrations = ();

#[sp_version::runtime_version]
#[cfg(feature = "testnet")]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node-subspace"),
impl_name: create_runtime_str!("node-subspace"),
authoring_version: 1,
// The version of the runtime specification. A full node will not attempt to use its native
// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 462,
spec_version: 463,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
};

#[sp_version::runtime_version]
#[cfg(not(feature = "testnet"))]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node-subspace"),
impl_name: create_runtime_str!("node-subspace"),
authoring_version: 1,
spec_version: 126,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
};
/// This determines the average expected block time that we are targeting.
///
/// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`.x
Expand Down
1 change: 1 addition & 0 deletions tests/src/offworker/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Default for MockOffworkerExt {
}

impl ow_extensions::OffworkerExtension for MockOffworkerExt {
// 1. Here we switch the RSA for elgamal
fn decrypt_weight(&self, encrypted: Vec<u8>) -> Option<(Vec<(u16, u16)>, Vec<u8>)> {
let Some(key) = &self.key else {
return None;
Expand Down
1 change: 1 addition & 0 deletions tests/src/subspace/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ fn set_weights_on_non_existent_subnets() {
}

#[test]
#[ignore = "todo joao fix this"]
fn delegate_weight_control() {
new_test_ext().execute_with(|| {
zero_min_validator_stake();
Expand Down
Empty file added try-runtime-upgrade
Empty file.
Empty file added with_feature.rs
Empty file.

0 comments on commit 14deb82

Please sign in to comment.