Skip to content

Commit

Permalink
Merge branch 'main' into bump-trivy-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DaMandal0rian authored Dec 21, 2024
2 parents 7cf1343 + cdc769b commit 7fde491
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 208 deletions.
39 changes: 24 additions & 15 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# Order matters
# below ones takes precedence over the upper ones
# Order matters: entries that are further down override any entries above them

# Global owners
* @nazar-pc @rg3l3dr

/crates @nazar-pc @rg3l3dr
/crates/pallet-* @nazar-pc @rg3l3dr @vedhavyas @NingLin-P
/crates/sp-* @nazar-pc @rg3l3dr @vedhavyas @NingLin-P
/crates/subspace-archiving @shamil-gadelshin @nazar-pc @rg3l3dr
/crates/subspace-farmer @nazar-pc @shamil-gadelshin @rg3l3dr
/crates/subspace-networking @shamil-gadelshin @nazar-pc @rg3l3dr
/crates/subspace-runtime* @vedhavyas @nazar-pc @rg3l3dr
/crates/subspace-node @NingLin-P @nazar-pc @rg3l3dr @vedhavyas
/crates/substrate @nazar-pc @rg3l3dr
/domains @vedhavyas @NingLin-P @nazar-pc @rg3l3dr
/.github/workflows @nazar-pc
/crates/pallet-* @NingLin-P @vedhavyas
/crates/pallet-subspace @NingLin-P @vedhavyas @nazar-pc
/crates/sc-consensus-* @nazar-pc
/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
/crates/subspace-core-primitives @nazar-pc
/crates/subspace-erasure-coding @nazar-pc
/crates/subspace-farmer* @nazar-pc @shamil-gadelshin
/crates/subspace-networking @nazar-pc @shamil-gadelshin
/crates/subspace-proof-* @nazar-pc
/crates/subspace-rpc-primitives @nazar-pc
/crates/subspace-runtime* @vedhavyas @nazar-pc
/crates/subspace-service @nazar-pc
/crates/subspace-node @NingLin-P @vedhavyas @nazar-pc
/crates/subspace-verification @nazar-pc
/docker @nazar-pc
/domains @NingLin-P @vedhavyas
/shared/subspace-kzg @nazar-pc
/shared/subspace-proof-* @nazar-pc
/Cargo.toml @nazar-pc
1 change: 0 additions & 1 deletion Cargo.lock

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

56 changes: 49 additions & 7 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,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::weights::WeightInfo;
#[cfg(not(feature = "runtime-benchmarks"))]
use crate::DomainHashingFor;
Expand All @@ -222,7 +223,7 @@ mod pallet {
use frame_support::pallet_prelude::*;
use frame_support::traits::fungible::{Inspect, InspectHold, Mutate, MutateHold};
use frame_support::traits::tokens::Preservation;
use frame_support::traits::Randomness as RandomnessT;
use frame_support::traits::{Randomness as RandomnessT, Time};
use frame_support::weights::Weight;
use frame_support::{Identity, PalletError};
use frame_system::pallet_prelude::*;
Expand All @@ -246,8 +247,8 @@ mod pallet {
use sp_std::collections::btree_set::BTreeSet;
use sp_std::fmt::Debug;
use sp_subspace_mmr::MmrProofVerifier;
use subspace_core_primitives::U256;
use subspace_runtime_primitives::StorageFee;
use subspace_core_primitives::{Randomness, U256};
use subspace_runtime_primitives::{Balance, StorageFee};

#[pallet::config]
pub trait Config: frame_system::Config<Hash: Into<H256>> {
Expand Down Expand Up @@ -389,6 +390,9 @@ mod pallet {
/// Storage fee interface used to deal with bundle storage fee
type StorageFee: StorageFee<BalanceOf<Self>>;

/// The block timestamp
type BlockTimestamp: Time;

/// The block slot
type BlockSlot: BlockSlot<Self>;

Expand Down Expand Up @@ -1850,6 +1854,10 @@ mod pallet {
}
}

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

#[pallet::hooks]
// TODO: proper benchmark
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
Expand Down Expand Up @@ -1894,10 +1902,44 @@ mod pallet {
}
}

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

Weight::zero()
}

fn on_finalize(_: BlockNumberFor<T>) {
// If this consensus block will derive any domain block, gather the necessary storage for potential fraud proof usage
if SuccessfulBundles::<T>::iter_keys().count() > 0
|| DomainRuntimeUpgrades::<T>::exists()
{
let extrinsics_shuffling_seed = Randomness::from(
Into::<H256>::into(Self::extrinsics_shuffling_seed()).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");

// 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 invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
extrinsics_shuffling_seed,
timestamp,
consensus_transaction_byte_fee,
};

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

let _ = LastEpochStakingDistribution::<T>::clear(u32::MAX, None);
let _ = NewAddedHeadReceipt::<T>::clear(u32::MAX, None);
}
Expand Down Expand Up @@ -2717,8 +2759,8 @@ impl<T: Config> Pallet<T> {
}

pub fn extrinsics_shuffling_seed() -> T::Hash {
let seed = DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT;
let (randomness, _) = T::Randomness::random(seed);
let subject = DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT;
let (randomness, _) = T::Randomness::random(subject);
randomness
}

Expand Down Expand Up @@ -2889,9 +2931,9 @@ impl<T: Config> Pallet<T> {
parent_receipt.consensus_block_number
};

let is_domain_runtime_updraded = current_runtime_obj.updated_at >= at;
let is_domain_runtime_upgraded = current_runtime_obj.updated_at >= at;

let mut runtime_obj = match (is_domain_runtime_updraded, maybe_domain_runtime_code_at) {
let mut runtime_obj = match (is_domain_runtime_upgraded, maybe_domain_runtime_code_at) {
// The domain runtime is upgraded since `at`, the domain runtime code in `at` is not available
// so `domain_runtime_code_proof` must be provided
(true, None) => return Err(FraudProofError::DomainRuntimeCodeProofNotFound),
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl pallet_domains::Config for Test {
type Randomness = MockRandomness;
type PalletId = DomainsPalletId;
type StorageFee = DummyStorageFee;
type BlockTimestamp = pallet_timestamp::Pallet<Test>;
type BlockSlot = DummyBlockSlot;
type DomainsTransfersTracker = MockDomainsTransfersTracker;
type MaxInitialDomainAccounts = MaxInitialDomainAccounts;
Expand Down
4 changes: 0 additions & 4 deletions crates/pallet-transaction-fees/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ where
}
}

pub fn transaction_byte_fee_storage_key() -> Vec<u8> {
TransactionByteFee::<T>::hashed_key().to_vec()
}

pub fn calculate_transaction_byte_fee() -> BalanceOf<T> {
let credit_supply = T::CreditSupply::get();

Expand Down
7 changes: 4 additions & 3 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,10 @@ where
continue;
};

let last_archived_block = client
.block(last_archived_block_hash)?
.expect("Last archived block must always be retrievable; qed");
let Some(last_archived_block) = client.block(last_archived_block_hash)? else {
// This block data was already pruned (but the headers weren't)
continue;
};

// If we're starting mapping creation at this block, return its mappings.
let block_object_mappings = if create_object_mappings {
Expand Down
6 changes: 5 additions & 1 deletion crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,11 @@ pub struct InvalidExtrinsicsRootProof {
/// Valid Bundle digests
pub valid_bundle_digests: Vec<ValidBundleDigest>,

/// The storage proof used during verification
/// The combined storage proofs used during verification
pub invalid_inherent_extrinsic_proofs: InvalidInherentExtrinsicDataProof,

/// The individual storage proofs used during verification
// TODO: combine these proofs into `InvalidInherentExtrinsicDataProof`
pub invalid_inherent_extrinsic_proof: InvalidInherentExtrinsicProof,

/// Optional sudo extrinsic call storage proof
Expand Down
2 changes: 0 additions & 2 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ where
domain_inherent_extrinsic_data: DomainInherentExtrinsicData,
) -> Option<DomainInherentExtrinsic> {
let DomainInherentExtrinsicData {
// Used by caller
block_randomness: _,
timestamp,
maybe_domain_runtime_upgrade,
consensus_transaction_byte_fee,
Expand Down
5 changes: 2 additions & 3 deletions crates/sp-domains-fraud-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidity};
use sp_runtime::OpaqueExtrinsic;
use sp_runtime_interface::pass_by;
use sp_runtime_interface::pass_by::PassBy;
use subspace_core_primitives::{Randomness, U256};
use subspace_core_primitives::U256;
use subspace_runtime_primitives::{Balance, Moment};

/// Custom invalid validity code for the extrinsics in pallet-domains.
Expand Down Expand Up @@ -108,7 +108,6 @@ pub enum DomainChainAllowlistUpdateExtrinsic {

#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
pub struct DomainInherentExtrinsicData {
pub block_randomness: Randomness,
pub timestamp: Moment,
pub maybe_domain_runtime_upgrade: Option<Vec<u8>>,
pub consensus_transaction_byte_fee: Balance,
Expand Down Expand Up @@ -161,7 +160,7 @@ sp_api::decl_runtime_apis! {
/// Submit the fraud proof via an unsigned extrinsic.
fn submit_fraud_proof_unsigned(fraud_proof: FraudProof<NumberFor<Block>, Block::Hash, DomainHeader, H256>);

/// Reture the storage key used in fraud proof
/// Return the storage key used in fraud proof
fn fraud_proof_storage_key(req: FraudProofStorageKeyRequest<NumberFor<Block>>) -> Vec<u8>;
}
}
Loading

0 comments on commit 7fde491

Please sign in to comment.