Skip to content

Commit

Permalink
Merge branch 'main' into storage_root_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhavyas committed Jan 24, 2025
2 parents 564c648 + bf75508 commit f4416f9
Show file tree
Hide file tree
Showing 133 changed files with 320 additions and 1,227 deletions.
8 changes: 4 additions & 4 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
/crates/sc-proof-of-time @nazar-pc
/crates/sp-* @NingLin-P @vedhavyas
/crates/sp-consensus-subspace @NingLin-P @vedhavyas @nazar-pc
/crates/subspace-archiving @nazar-pc @shamil-gadelshin @teor2345
/crates/subspace-archiving @nazar-pc @teor2345
/crates/subspace-core-primitives @nazar-pc
/crates/subspace-erasure-coding @nazar-pc
/crates/subspace-farmer* @nazar-pc @shamil-gadelshin
/crates/subspace-gateway-* @shamil-gadelshin @teor2345
/crates/subspace-networking @nazar-pc @shamil-gadelshin @teor2345
/crates/subspace-farmer* @nazar-pc
/crates/subspace-gateway-* @teor2345
/crates/subspace-networking @nazar-pc @teor2345
/crates/subspace-proof-* @nazar-pc
/crates/subspace-rpc-primitives @nazar-pc @teor2345
/crates/subspace-runtime* @vedhavyas @nazar-pc
Expand Down
36 changes: 5 additions & 31 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry
Expand Down Expand Up @@ -86,15 +86,15 @@ jobs:
if: runner.os == 'macOS'

- name: CUDA toolchain
uses: Jimver/cuda-toolkit@9b295696791d75d658d8de64c4a85097ad8abeaf # v0.2.16
uses: Jimver/cuda-toolkit@4bd727d5619dc6fa323b1e76c3aa5dca94f5ec6d # v0.2.19
with:
cuda: '12.4.1'
method: network
sub-packages: '["nvcc", "cudart"]'
if: runner.os == 'Linux' || runner.os == 'Windows'

- name: Configure ROCm cache (Windows)
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: rocm-cache
with:
path: C:\Program Files\AMD\ROCm
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
if: runner.os == 'Windows' && steps.rocm-cache.outputs.cache-hit != 'true'

- name: Configure cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry
Expand Down Expand Up @@ -155,32 +155,6 @@ jobs:
cargo -Zgitoxide -Zgit clippy --locked --all-targets --features rocm -- -D warnings
if: runner.os == 'Windows'

cargo-docs:
runs-on: ${{ fromJson(github.repository_owner == 'autonomys' && '["self-hosted", "ubuntu-22.04-x86-64"]' || '"ubuntu-22.04"') }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check Documentation
run: cargo -Zgitoxide -Zgit doc --locked --all --no-deps --lib
env:
RUSTDOCFLAGS: "-D rustdoc::broken-intra-doc-links -D rustdoc::private_intra_doc_links"

cargo-test:
strategy:
matrix:
Expand Down Expand Up @@ -223,7 +197,7 @@ jobs:
if: runner.os == 'macOS'

- name: Configure cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- main
pull_request:
workflow_dispatch:
merge_group:

concurrency:
group: rustdoc-${{ github.workflow }}-${{ github.ref }}
Expand All @@ -30,7 +33,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Configure cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry
Expand All @@ -40,21 +43,22 @@ jobs:
${{ runner.os }}-cargo-
- name: CUDA toolchain
uses: Jimver/cuda-toolkit@9b295696791d75d658d8de64c4a85097ad8abeaf # v0.2.16
uses: Jimver/cuda-toolkit@4bd727d5619dc6fa323b1e76c3aa5dca94f5ec6d # v0.2.19
with:
cuda: '12.4.1'
method: network
sub-packages: '["nvcc", "cudart"]'

# Build the rust crate docs
- name: Build Documentation
run: cargo -Zgitoxide -Zgit doc --all --no-deps --lib --features cuda
run: cargo -Zgitoxide -Zgit doc --locked --all --no-deps --lib --features cuda
env:
RUSTDOCFLAGS: "-Z unstable-options --enable-index-page"
RUSTDOCFLAGS: "-D rustdoc::broken-intra-doc-links -D rustdoc::private_intra_doc_links -Z unstable-options --enable-index-page"

- name: Deploy Docs
uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29 # v4.6.8
with:
branch: gh-pages
single-commit: true
folder: target/doc
if: ${{ github.event_name == 'push' }}
6 changes: 3 additions & 3 deletions .github/workflows/snapshot-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ jobs:
if: runner.os == 'macOS'

- name: CUDA toolchain
uses: Jimver/cuda-toolkit@9b295696791d75d658d8de64c4a85097ad8abeaf # v0.2.16
uses: Jimver/cuda-toolkit@4bd727d5619dc6fa323b1e76c3aa5dca94f5ec6d # v0.2.19
with:
cuda: '12.4.1'
method: network
sub-packages: '["nvcc", "cudart"]'
if: runner.os == 'Windows'

- name: Configure ROCm cache (Windows)
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
id: rocm-cache
with:
path: C:\Program Files\AMD\ROCm
Expand All @@ -215,7 +215,7 @@ jobs:
if: runner.os == 'Windows' && steps.rocm-cache.outputs.cache-hit != 'true'

- name: Configure cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cargo/registry
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-domains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pallet-domains"
version = "0.1.0"
authors = ["Subspace Labs <https://subspace.network>"]
edition = "2021"
license = "Apache-2.0"
license = "0BSD"
homepage = "https://subspace.network"
repository = "https://github.com/autonomys/subspace"
description = "Subspace domains pallet"
Expand Down
100 changes: 66 additions & 34 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
// Copyright (C) 2021 Subspace Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Pallet Domains
#![cfg_attr(not(feature = "std"), no_std)]
Expand Down Expand Up @@ -53,7 +38,7 @@ use frame_support::ensure;
use frame_support::pallet_prelude::StorageVersion;
use frame_support::traits::fungible::{Inspect, InspectHold};
use frame_support::traits::tokens::{Fortitude, Preservation};
use frame_support::traits::{Get, Randomness as RandomnessT};
use frame_support::traits::{Get, Randomness as RandomnessT, Time};
use frame_support::weights::Weight;
use frame_system::offchain::SubmitTransaction;
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -86,6 +71,7 @@ use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrProofVerifier};
pub use staking::OperatorConfig;
use subspace_core_primitives::pot::PotOutput;
use subspace_core_primitives::{BlockHash, SlotNumber, U256};
use subspace_runtime_primitives::{Balance, Moment, StorageFee};

/// Maximum number of nominators to slash within a give operator at a time.
pub const MAX_NOMINATORS_TO_SLASH: u32 = 10;
Expand Down Expand Up @@ -201,7 +187,7 @@ mod pallet {
#[cfg(not(feature = "runtime-benchmarks"))]
use crate::staking_epoch::do_slash_operator;
use crate::staking_epoch::{do_finalize_domain_current_epoch, Error as StakingEpochError};
use crate::storage_proof::InvalidInherentExtrinsicData;
use crate::storage_proof::InherentExtrinsicData;
use crate::weights::WeightInfo;
#[cfg(not(feature = "runtime-benchmarks"))]
use crate::DomainHashingFor;
Expand Down Expand Up @@ -248,10 +234,10 @@ mod pallet {
use sp_std::fmt::Debug;
use sp_subspace_mmr::MmrProofVerifier;
use subspace_core_primitives::{Randomness, U256};
use subspace_runtime_primitives::{Balance, StorageFee};
use subspace_runtime_primitives::StorageFee;

#[pallet::config]
pub trait Config: frame_system::Config<Hash: Into<H256>> {
pub trait Config: frame_system::Config<Hash: Into<H256> + From<H256>> {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

// TODO: `DomainHash` can be derived from `DomainHeader`, it is still needed just for
Expand Down Expand Up @@ -1856,7 +1842,7 @@ mod pallet {

/// Combined fraud proof data for the InvalidInherentExtrinsic fraud proof
#[pallet::storage]
pub type BlockInvalidInherentExtrinsicData<T> = StorageValue<_, InvalidInherentExtrinsicData>;
pub type BlockInherentExtrinsicData<T> = StorageValue<_, InherentExtrinsicData>;

#[pallet::hooks]
// TODO: proper benchmark
Expand Down Expand Up @@ -1907,7 +1893,7 @@ mod pallet {
}
}

BlockInvalidInherentExtrinsicData::<T>::kill();
BlockInherentExtrinsicData::<T>::kill();

Weight::zero()
}
Expand All @@ -1919,31 +1905,23 @@ mod pallet {
|| !DomainRuntimeUpgrades::<T>::get().is_empty()
{
let extrinsics_shuffling_seed = Randomness::from(
Into::<H256>::into(Self::extrinsics_shuffling_seed()).to_fixed_bytes(),
Into::<H256>::into(Self::extrinsics_shuffling_seed_value()).to_fixed_bytes(),
);

// There are no actual conversions here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
let timestamp = T::BlockTimestamp::now()
.try_into()
.map_err(|_| ())
.expect("Moment is the same type in both pallets; qed");
let transaction_byte_fee: Balance = T::StorageFee::transaction_byte_fee()
.try_into()
.map_err(|_| ())
.expect("Balance is the same type in both pallets; qed");
let timestamp = Self::timestamp_value();

// The value returned by the consensus_chain_byte_fee() runtime API
let consensus_transaction_byte_fee =
sp_domains::DOMAIN_STORAGE_FEE_MULTIPLIER * transaction_byte_fee;
let consensus_transaction_byte_fee = Self::consensus_transaction_byte_fee_value();

let invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
let inherent_extrinsic_data = InherentExtrinsicData {
extrinsics_shuffling_seed,
timestamp,
consensus_transaction_byte_fee,
};

BlockInvalidInherentExtrinsicData::<T>::set(Some(invalid_inherent_extrinsic_data));
BlockInherentExtrinsicData::<T>::set(Some(inherent_extrinsic_data));
}

let _ = LastEpochStakingDistribution::<T>::clear(u32::MAX, None);
Expand Down Expand Up @@ -2770,12 +2748,66 @@ impl<T: Config> Pallet<T> {
false
}

/// The external function used to access the extrinsics shuffling seed stored in
/// `BlockInherentExtrinsicData`.
pub fn extrinsics_shuffling_seed() -> T::Hash {
// Fall back to recalculating if it hasn't been stored yet.
BlockInherentExtrinsicData::<T>::get()
.map(|data| H256::from(*data.extrinsics_shuffling_seed).into())
.unwrap_or_else(|| Self::extrinsics_shuffling_seed_value())
}

/// The internal function used to calculate the extrinsics shuffling seed for storage into
/// `BlockInherentExtrinsicData`.
fn extrinsics_shuffling_seed_value() -> T::Hash {
let subject = DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT;
let (randomness, _) = T::Randomness::random(subject);
randomness
}

/// The external function used to access the timestamp stored in
/// `BlockInherentExtrinsicData`.
pub fn timestamp() -> Moment {
// Fall back to recalculating if it hasn't been stored yet.
BlockInherentExtrinsicData::<T>::get()
.map(|data| data.timestamp)
.unwrap_or_else(|| Self::timestamp_value())
}

/// The internal function used to access the timestamp for storage into
/// `BlockInherentExtrinsicData`.
fn timestamp_value() -> Moment {
// There are no actual conversions here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
T::BlockTimestamp::now()
.try_into()
.map_err(|_| ())
.expect("Moment is the same type in both pallets; qed")
}

/// The external function used to access the consensus transaction byte fee stored in
/// `BlockInherentExtrinsicData`.
/// This value is returned by the consensus_chain_byte_fee() runtime API
pub fn consensus_transaction_byte_fee() -> Balance {
// Fall back to recalculating if it hasn't been stored yet.
BlockInherentExtrinsicData::<T>::get()
.map(|data| data.consensus_transaction_byte_fee)
.unwrap_or_else(|| Self::consensus_transaction_byte_fee_value())
}

/// The internal function used to calculate the consensus transaction byte fee for storage into
/// `BlockInherentExtrinsicData`.
fn consensus_transaction_byte_fee_value() -> Balance {
// There are no actual conversions here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
let transaction_byte_fee: Balance = T::StorageFee::transaction_byte_fee()
.try_into()
.map_err(|_| ())
.expect("Balance is the same type in both pallets; qed");

sp_domains::DOMAIN_STORAGE_FEE_MULTIPLIER * transaction_byte_fee
}

pub fn execution_receipt(receipt_hash: ReceiptHashFor<T>) -> Option<ExecutionReceiptOf<T>> {
BlockTreeNodes::<T>::get(receipt_hash).map(|db| db.execution_receipt)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-rewards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pallet-rewards"
version = "0.1.0"
authors = ["Nazar Mokrynskyi <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
license = "0BSD"
homepage = "https://subspace.network"
repository = "https://github.com/autonomys/subspace"
description = "Pallet for issuing rewards to block producers"
Expand Down
15 changes: 0 additions & 15 deletions crates/pallet-rewards/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
// Copyright (C) 2021 Subspace Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Pallet for issuing rewards to block producers.
#![cfg_attr(not(feature = "std"), no_std)]
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-runtime-configs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "pallet-runtime-configs"
version = "0.1.0"
authors = ["Liu-Cheng Xu <[email protected]>"]
edition = "2021"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
license = "0BSD"
homepage = "https://subspace.network"
repository = "https://github.com/autonomys/subspace"
description = "Pallet for tweaking the runtime configs for multiple network"
Expand Down
Loading

0 comments on commit f4416f9

Please sign in to comment.