Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix second segment offset in object retrieval, other minor cleanups #3367

Merged
merged 14 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions crates/pallet-domains/src/domain_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ pub struct DomainConfig<AccountId: Ord, Balance> {
pub operator_allow_list: OperatorAllowList<AccountId>,
// Initial balances for this domain.
pub initial_balances: Vec<(MultiAccountId, Balance)>,
/// Configurations for a specific type of domain runtime, for example, EVM.
pub domain_runtime_config: DomainRuntimeConfig,
}

/// Parameters of the `instantiate_domain` call, it is similar to `DomainConfig` except the `max_bundle_size/weight`
Expand All @@ -93,6 +91,9 @@ pub struct DomainConfigParams<AccountId: Ord, Balance> {
pub bundle_slot_probability: (u64, u64),
pub operator_allow_list: OperatorAllowList<AccountId>,
pub initial_balances: Vec<(MultiAccountId, Balance)>,
/// Configurations for a specific type of domain runtime, for example, EVM.
/// Currently these are all copied into `DomainObject.domain_runtime_info`, so they don't need
/// to be in `DomainConfig`.
pub domain_runtime_config: DomainRuntimeConfig,
}

Expand All @@ -106,7 +107,7 @@ pub fn into_domain_config<T: Config>(
bundle_slot_probability,
operator_allow_list,
initial_balances,
domain_runtime_config,
domain_runtime_config: _,
} = domain_config_params;

let DomainBundleLimit {
Expand All @@ -131,7 +132,6 @@ pub fn into_domain_config<T: Config>(
bundle_slot_probability,
operator_allow_list,
initial_balances,
domain_runtime_config,
})
}

Expand Down Expand Up @@ -244,6 +244,7 @@ pub(crate) fn do_instantiate_domain<T: Config>(
owner_account_id: T::AccountId,
created_at: BlockNumberFor<T>,
) -> Result<DomainId, Error> {
let domain_runtime_config = domain_config_params.domain_runtime_config.clone();
let domain_config = can_instantiate_domain::<T>(&owner_account_id, domain_config_params)?;

let domain_instantiation_deposit = T::DomainInstantiationDeposit::get();
Expand All @@ -257,23 +258,20 @@ pub(crate) fn do_instantiate_domain<T: Config>(
runtime_object
});

let domain_runtime_info = match (
runtime_obj.runtime_type,
&domain_config.domain_runtime_config,
) {
let domain_runtime_info = match (runtime_obj.runtime_type, domain_runtime_config) {
(RuntimeType::Evm, DomainRuntimeConfig::Evm(domain_runtime_config)) => {
let evm_chain_id = NextEVMChainId::<T>::get();
let next_evm_chain_id = evm_chain_id.checked_add(1).ok_or(Error::MaxEVMChainId)?;
NextEVMChainId::<T>::set(next_evm_chain_id);

DomainRuntimeInfo::Evm {
chain_id: evm_chain_id,
domain_runtime_config: domain_runtime_config.clone(),
domain_runtime_config,
}
}
(RuntimeType::AutoId, DomainRuntimeConfig::AutoId(domain_runtime_config)) => {
DomainRuntimeInfo::AutoId {
domain_runtime_config: domain_runtime_config.clone(),
domain_runtime_config,
}
}
_ => return Err(Error::InvalidConfigForRuntimeType),
Expand Down Expand Up @@ -795,8 +793,8 @@ mod tests {
);
assert_eq!(
domain_obj
.domain_config
.domain_runtime_config
.domain_runtime_info
.domain_runtime_config()
.initial_contract_creation_allow_list(),
Some(&PermissionedActionAllowedBy::Anyone),
"anyone should be allowed to create contracts by default"
Expand Down Expand Up @@ -834,8 +832,8 @@ mod tests {
);
assert_eq!(
domain_obj
.domain_config
.domain_runtime_config
.domain_runtime_info
.domain_runtime_config()
.initial_contract_creation_allow_list(),
Some(&PermissionedActionAllowedBy::Accounts(list)),
"empty list should work"
Expand Down Expand Up @@ -873,8 +871,8 @@ mod tests {
);
assert_eq!(
domain_obj
.domain_config
.domain_runtime_config
.domain_runtime_info
.domain_runtime_config()
.initial_contract_creation_allow_list(),
Some(&PermissionedActionAllowedBy::Accounts(list)),
"1 account list should work"
Expand Down Expand Up @@ -916,8 +914,8 @@ mod tests {
);
assert_eq!(
domain_obj
.domain_config
.domain_runtime_config
.domain_runtime_info
.domain_runtime_config()
.initial_contract_creation_allow_list(),
Some(&PermissionedActionAllowedBy::Accounts(list)),
"multi account list should work"
Expand Down
36 changes: 34 additions & 2 deletions crates/pallet-domains/src/runtime_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use sp_core::crypto::AccountId32;
use sp_core::Hasher;
use sp_domains::storage::{RawGenesis, StorageData, StorageKey};
use sp_domains::{
AutoIdDomainRuntimeConfig, DomainId, DomainsDigestItem, EvmDomainRuntimeConfig, RuntimeId,
RuntimeObject, RuntimeType,
AutoIdDomainRuntimeConfig, DomainId, DomainRuntimeConfig, DomainsDigestItem,
EvmDomainRuntimeConfig, RuntimeId, RuntimeObject, RuntimeType,
};
use sp_runtime::traits::{CheckedAdd, Get, Zero};
use sp_runtime::DigestItem;
Expand Down Expand Up @@ -68,6 +68,38 @@ impl Default for DomainRuntimeInfo {
}
}

impl DomainRuntimeInfo {
/// Returns the inner config as a `DomainRuntimeConfig`.
pub fn domain_runtime_config(&self) -> DomainRuntimeConfig {
match self {
Self::Evm {
domain_runtime_config,
..
} => DomainRuntimeConfig::Evm(domain_runtime_config.clone()),
Self::AutoId {
domain_runtime_config,
..
} => DomainRuntimeConfig::AutoId(domain_runtime_config.clone()),
}
}

/// If this is an EVM runtime, returns the chain id.
pub fn evm_chain_id(&self) -> Option<EVMChainId> {
match self {
Self::Evm { chain_id, .. } => Some(*chain_id),
_ => None,
}
}

pub fn is_evm(&self) -> bool {
matches!(self, Self::Evm { .. })
}

pub fn is_auto_id(&self) -> bool {
matches!(self, Self::AutoId { .. })
}
}

#[derive(TypeInfo, Debug, Encode, Decode, Clone, PartialEq, Eq)]
pub struct DomainRuntimeUpgradeEntry<Hash> {
// The consensus block hash at which the upgrade happened
Expand Down
2 changes: 0 additions & 2 deletions crates/pallet-domains/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,6 @@ pub(crate) mod tests {
bundle_slot_probability: (0, 0),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
domain_runtime_config: Default::default(),
};

let domain_obj = DomainObject {
Expand Down Expand Up @@ -1818,7 +1817,6 @@ pub(crate) mod tests {
bundle_slot_probability: (0, 0),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
domain_runtime_config: Default::default(),
};

let domain_obj = DomainObject {
Expand Down
1 change: 0 additions & 1 deletion crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ fn test_bundle_format_verification() {
bundle_slot_probability: (1, 1),
operator_allow_list: OperatorAllowList::Anyone,
initial_balances: Default::default(),
domain_runtime_config: Default::default(),
};
let domain_obj = DomainObject {
owner_account_id: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions crates/sc-consensus-subspace-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::sync::{Arc, Weak};
use std::time::Duration;
use subspace_archiving::archiver::NewArchivedSegment;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::objects::{GlobalObjectMapping, ObjectMappingResponse};
use subspace_core_primitives::objects::GlobalObjectMapping;
use subspace_core_primitives::pieces::{Piece, PieceIndex};
use subspace_core_primitives::segments::{HistorySize, SegmentHeader, SegmentIndex};
use subspace_core_primitives::solutions::Solution;
Expand All @@ -48,8 +48,8 @@ use subspace_farmer_components::FarmerProtocolInfo;
use subspace_kzg::Kzg;
use subspace_networking::libp2p::Multiaddr;
use subspace_rpc_primitives::{
FarmerAppInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse,
MAX_SEGMENT_HEADERS_PER_REQUEST,
FarmerAppInfo, ObjectMappingResponse, RewardSignatureResponse, RewardSigningInfo, SlotInfo,
SolutionResponse, MAX_SEGMENT_HEADERS_PER_REQUEST,
};
use tracing::{debug, error, warn};

Expand Down
3 changes: 1 addition & 2 deletions crates/sc-consensus-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
//!
//! All of the modules here are crucial for consensus, open each module for specific details.

#![feature(let_chains, try_blocks)]
#![feature(duration_constructors)]
#![feature(let_chains, try_blocks, duration_constructors)]
#![forbid(unsafe_code)]
#![warn(missing_docs)]

Expand Down
3 changes: 1 addition & 2 deletions crates/sp-domains-fraud-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#![allow(incomplete_features)]
// TODO: This feature is not actually used in this crate, but is added as a workaround for
// https://github.com/rust-lang/rust/issues/133199
#![feature(generic_const_exprs)]
#![feature(associated_type_defaults)]
#![feature(generic_const_exprs, associated_type_defaults)]

#[cfg(feature = "std")]
pub mod execution_prover;
Expand Down
15 changes: 0 additions & 15 deletions crates/subspace-core-primitives/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern crate alloc;

use crate::hashes::Blake3Hash;
use crate::pieces::PieceIndex;
use crate::BlockNumber;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use core::default::Default;
Expand Down Expand Up @@ -158,17 +157,3 @@ impl GlobalObjectMapping {
}
}
}

/// Response to object mapping subscription, including a block height.
/// Large responses are batched, so the block height can be repeated in different responses.
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct ObjectMappingResponse {
/// The block number that the object mapping is from.
pub block_number: BlockNumber,

/// The object mappings.
#[cfg_attr(feature = "serde", serde(flatten))]
pub objects: GlobalObjectMapping,
}
4 changes: 2 additions & 2 deletions crates/subspace-gateway/src/commands/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use std::sync::Arc;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::objects::ObjectMappingResponse;
use subspace_data_retrieval::object_fetcher::ObjectFetcher;
use subspace_data_retrieval::piece_getter::PieceGetter;
use subspace_rpc_primitives::ObjectMappingResponse;
use tracing::{debug, error, trace};

/// Parameters for the DSN object HTTP server.
Expand All @@ -22,7 +22,7 @@ where
/// Multiple hashes are separated by `+`.
async fn request_object_mapping(
endpoint: &str,
hashes: &Vec<Blake3Hash>,
hashes: &[Blake3Hash],
) -> anyhow::Result<ObjectMappingResponse> {
let client = reqwest::Client::new();
let hash_list = hashes.iter().map(hex::encode).collect::<Vec<_>>();
Expand Down
16 changes: 15 additions & 1 deletion crates/subspace-rpc-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use parity_scale_codec::{Decode, Encode, EncodeLike, Input, Output};
use serde::{Deserialize, Serialize};
use std::time::Duration;
use subspace_core_primitives::hashes::Blake3Hash;
use subspace_core_primitives::objects::GlobalObjectMapping;
use subspace_core_primitives::solutions::{RewardSignature, Solution, SolutionRange};
use subspace_core_primitives::{PublicKey, SlotNumber};
use subspace_core_primitives::{BlockNumber, PublicKey, SlotNumber};
use subspace_farmer_components::FarmerProtocolInfo;
use subspace_networking::libp2p::Multiaddr;

Expand Down Expand Up @@ -139,3 +140,16 @@ pub struct RewardSignatureResponse {
/// Pre-header or vote hash signature.
pub signature: Option<RewardSignature>,
}

/// Response to object mapping subscription, including a block height.
/// Large responses are batched, so the block height can be repeated in different responses.
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ObjectMappingResponse {
/// The block number that the object mapping is from.
pub block_number: BlockNumber,

/// The object mappings.
#[serde(flatten)]
pub objects: GlobalObjectMapping,
}
1 change: 1 addition & 0 deletions domains/client/domain-operator/src/domain_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ pub(super) async fn start_worker<
);
}
}
else => { break }
}
}
} else {
Expand Down
12 changes: 7 additions & 5 deletions domains/client/domain-operator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@
//! [`BlockBuilder`]: ../domain_block_builder/struct.BlockBuilder.html
//! [`FraudProof`]: ../sp_domains/struct.FraudProof.html

#![feature(array_windows)]
#![feature(box_into_inner)]
#![feature(duration_constructors)]
#![feature(extract_if)]
#![feature(assert_matches)]
#![feature(
array_windows,
box_into_inner,
duration_constructors,
extract_if,
assert_matches
)]

mod aux_schema;
mod bundle_processor;
Expand Down
Loading
Loading