Skip to content

Commit

Permalink
Merge pull request #3066 from autonomys/remove-version-check
Browse files Browse the repository at this point in the history
Remove runtime version check
  • Loading branch information
NingLin-P authored Sep 26, 2024
2 parents fe71583 + 2683167 commit b341816
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 577 deletions.
14 changes: 3 additions & 11 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ use sp_consensus_subspace::WrappedPotOutput;
use sp_core::H256;
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
use sp_domains::{
DomainBlockLimit, DomainBundleLimit, DomainId, DomainInstanceData, ExecutionReceipt,
OpaqueBundle, OperatorId, OperatorPublicKey, OperatorSignature, ProofOfElection, RuntimeId,
SealedSingletonReceipt, DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT, EMPTY_EXTRINSIC_ROOT,
DomainBundleLimit, DomainId, DomainInstanceData, ExecutionReceipt, OpaqueBundle, OperatorId,
OperatorPublicKey, OperatorSignature, ProofOfElection, RuntimeId, SealedSingletonReceipt,
DOMAIN_EXTRINSICS_SHUFFLING_SEED_SUBJECT, EMPTY_EXTRINSIC_ROOT,
};
use sp_domains_fraud_proof::fraud_proof::{
DomainRuntimeCodeAt, FraudProof, FraudProofVariant, InvalidBlockFeesProof,
Expand Down Expand Up @@ -2689,14 +2689,6 @@ impl<T: Config> Pallet<T> {
.map(|er| (er.domain_block_number, er.domain_block_hash))
}

/// Returns the domain block limit of the given domain.
pub fn domain_block_limit(domain_id: DomainId) -> Option<DomainBlockLimit> {
DomainRegistry::<T>::get(domain_id).map(|domain_obj| DomainBlockLimit {
max_block_size: domain_obj.domain_config.max_block_size,
max_block_weight: domain_obj.domain_config.max_block_weight,
})
}

/// Returns the domain bundle limit of the given domain
pub fn domain_bundle_limit(
domain_id: DomainId,
Expand Down
1 change: 0 additions & 1 deletion crates/sp-domains-fraud-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ impl PassBy for StatelessDomainRuntimeCall {

sp_api::decl_runtime_apis! {
/// API necessary for fraud proof.
#[api_version(2)]
pub trait FraudProofApi<DomainHeader: HeaderT> {
/// Submit the fraud proof via an unsigned extrinsic.
fn submit_fraud_proof_unsigned(fraud_proof: FraudProof<NumberFor<Block>, Block::Hash, DomainHeader, H256>);
Expand Down
45 changes: 14 additions & 31 deletions crates/sp-domains-fraud-proof/src/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub struct DomainInherentExtrinsicDataProof {
pub dynamic_cost_of_storage_proof: DynamicCostOfStorageProof,
pub consensus_chain_byte_fee_proof: ConsensusTransactionByteFeeProof,
pub domain_chain_allowlist_proof: DomainChainsAllowlistUpdateStorageProof,
pub maybe_domain_sudo_call_proof: Option<DomainSudoCallStorageProof>,
pub domain_sudo_call_proof: DomainSudoCallStorageProof,
}

impl DomainInherentExtrinsicDataProof {
Expand All @@ -436,7 +436,6 @@ impl DomainInherentExtrinsicDataProof {
domain_id: DomainId,
block_hash: Block::Hash,
maybe_runtime_id: Option<RuntimeId>,
should_include_domain_sudo_call: bool,
) -> Result<Self, GenerationError> {
let timestamp_proof =
TimestampStorageProof::generate(proof_provider, block_hash, (), storage_key_provider)?;
Expand Down Expand Up @@ -465,28 +464,20 @@ impl DomainInherentExtrinsicDataProof {
storage_key_provider,
)?;

// Domain sudo call is optional since both Consensus and domain runtimes needs to have the functionality.
// If only consensus runtime is upgraded but not Domain, the storage proof will never contain the data
// Since sudo call extrinsic on Consensus will never go through.
// but it can still generate empty storage proof in this case
let maybe_domain_sudo_call_proof = if should_include_domain_sudo_call {
Some(DomainSudoCallStorageProof::generate(
proof_provider,
block_hash,
domain_id,
storage_key_provider,
)?)
} else {
None
};
let domain_sudo_call_proof = DomainSudoCallStorageProof::generate(
proof_provider,
block_hash,
domain_id,
storage_key_provider,
)?;

Ok(Self {
timestamp_proof,
maybe_domain_runtime_upgrade_proof,
dynamic_cost_of_storage_proof,
consensus_chain_byte_fee_proof,
domain_chain_allowlist_proof,
maybe_domain_sudo_call_proof,
domain_sudo_call_proof,
})
}

Expand Down Expand Up @@ -532,26 +523,18 @@ impl DomainInherentExtrinsicDataProof {
state_root,
)?;

let domain_sudo_call =
if let Some(domain_sudo_call_proof) = &self.maybe_domain_sudo_call_proof {
Some(
<DomainSudoCallStorageProof as BasicStorageProof<Block>>::verify::<SKP>(
domain_sudo_call_proof.clone(),
domain_id,
state_root,
)?,
)
} else {
None
};
let domain_sudo_call = <DomainSudoCallStorageProof as BasicStorageProof<Block>>::verify::<
SKP,
>(
self.domain_sudo_call_proof.clone(), domain_id, state_root
)?;

Ok(DomainInherentExtrinsicData {
timestamp,
maybe_domain_runtime_upgrade,
consensus_transaction_byte_fee,
domain_chain_allowlist,
maybe_sudo_runtime_call: domain_sudo_call
.and_then(|domain_sudo_call| domain_sudo_call.maybe_call),
maybe_sudo_runtime_call: domain_sudo_call.maybe_call,
})
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/sp-domains/src/core_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use subspace_runtime_primitives::Moment;

sp_api::decl_runtime_apis! {
/// Base API that every domain runtime must implement.
#[api_version(2)]
pub trait DomainCoreApi {
/// Extracts the optional signer per extrinsic.
fn extract_signer(
Expand Down
21 changes: 0 additions & 21 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,14 +1070,6 @@ pub struct DomainInstanceData {
pub raw_genesis: RawGenesis,
}

#[derive(Debug, Decode, Encode, TypeInfo, Clone)]
pub struct DomainBlockLimit {
/// The max block size for the domain.
pub max_block_size: u32,
/// The max block weight for the domain.
pub max_block_weight: Weight,
}

#[derive(Debug, Decode, Encode, TypeInfo, Clone)]
pub struct DomainBundleLimit {
/// The max bundle size for the domain.
Expand Down Expand Up @@ -1478,7 +1470,6 @@ impl<Balance> OnChainRewards<Balance> for () {

sp_api::decl_runtime_apis! {
/// API necessary for domains pallet.
#[api_version(6)]
pub trait DomainsApi<DomainHeader: HeaderT> {
/// Submits the transaction bundle via an unsigned extrinsic.
fn submit_bundle_unsigned(opaque_bundle: OpaqueBundle<NumberFor<Block>, Block::Hash, DomainHeader, Balance>);
Expand All @@ -1492,15 +1483,6 @@ sp_api::decl_runtime_apis! {
extrinsics: Vec<Block::Extrinsic>,
) -> OpaqueBundles<Block, DomainHeader, Balance>;

/// Extract bundle from the extrinsic if the extrinsic is `submit_bundle`.
fn extract_bundle(extrinsic: Block::Extrinsic) -> Option<OpaqueBundle<NumberFor<Block>, Block::Hash, DomainHeader, Balance>>;

/// Extract the execution receipt stored successfully from the given extrinsics.
fn extract_receipts(
domain_id: DomainId,
extrinsics: Vec<Block::Extrinsic>,
) -> Vec<ExecutionReceiptFor<DomainHeader, Block, Balance>>;

/// Generates a randomness seed for extrinsics shuffling.
fn extrinsics_shuffling_seed() -> Randomness;

Expand Down Expand Up @@ -1528,9 +1510,6 @@ sp_api::decl_runtime_apis! {
/// Returns the block number of oldest unconfirmed execution receipt.
fn oldest_unconfirmed_receipt_number(domain_id: DomainId) -> Option<HeaderNumberFor<DomainHeader>>;

/// Returns the domain block limit of the given domain.
fn domain_block_limit(domain_id: DomainId) -> Option<DomainBlockLimit>;

/// Returns the domain bundle limit of the given domain.
fn domain_bundle_limit(domain_id: DomainId) -> Option<DomainBundleLimit>;

Expand Down
21 changes: 2 additions & 19 deletions crates/subspace-fake-runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use sp_core::crypto::KeyTypeId;
use sp_core::{OpaqueMetadata, H256};
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
use sp_domains::{
DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor, OpaqueBundle,
OperatorId, OperatorPublicKey,
DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor, OperatorId,
OperatorPublicKey,
};
use sp_domains_fraud_proof::fraud_proof::FraudProof;
use sp_domains_fraud_proof::storage_proof::FraudProofStorageKeyRequest;
Expand Down Expand Up @@ -208,19 +208,6 @@ sp_api::impl_runtime_apis! {
unreachable!()
}

fn extract_bundle(
_extrinsic: <Block as BlockT>::Extrinsic
) -> Option<OpaqueBundle<NumberFor<Block>, <Block as BlockT>::Hash, DomainHeader, Balance>> {
unreachable!()
}

fn extract_receipts(
_domain_id: DomainId,
_extrinsics: Vec<<Block as BlockT>::Extrinsic>,
) -> Vec<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
unreachable!()
}

fn extrinsics_shuffling_seed() -> Randomness {
unreachable!()
}
Expand Down Expand Up @@ -257,10 +244,6 @@ sp_api::impl_runtime_apis! {
unreachable!()
}

fn domain_block_limit(_domain_id: DomainId) -> Option<sp_domains::DomainBlockLimit> {
unreachable!()
}

fn domain_bundle_limit(_domain_id: DomainId) -> Option<sp_domains::DomainBundleLimit> {
unreachable!()
}
Expand Down
14 changes: 0 additions & 14 deletions crates/subspace-runtime/src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{Balance, Block, Domains, RuntimeCall, UncheckedExtrinsic};
use alloc::vec::Vec;
use domain_runtime_primitives::opaque::Header as DomainHeader;
use sp_domains::DomainId;
use sp_runtime::traits::{Block as BlockT, NumberFor};

pub(crate) fn extract_successful_bundles(
domain_id: DomainId,
Expand All @@ -26,16 +25,3 @@ pub(crate) fn extract_successful_bundles(
})
.collect()
}

pub(crate) fn extract_bundle(
extrinsic: UncheckedExtrinsic,
) -> Option<
sp_domains::OpaqueBundle<NumberFor<Block>, <Block as BlockT>::Hash, DomainHeader, Balance>,
> {
match extrinsic.function {
RuntimeCall::Domains(pallet_domains::Call::submit_bundle { opaque_bundle }) => {
Some(opaque_bundle)
}
_ => None,
}
}
23 changes: 1 addition & 22 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ use sp_core::{ConstBool, OpaqueMetadata, H256};
use sp_domains::bundle_producer_election::BundleProducerElectionParams;
use sp_domains::{
ChannelId, DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor,
OpaqueBundle, OperatorId, OperatorPublicKey, DOMAIN_STORAGE_FEE_MULTIPLIER,
INITIAL_DOMAIN_TX_RANGE,
OperatorId, OperatorPublicKey, DOMAIN_STORAGE_FEE_MULTIPLIER, INITIAL_DOMAIN_TX_RANGE,
};
use sp_domains_fraud_proof::fraud_proof::FraudProof;
use sp_domains_fraud_proof::storage_proof::{
Expand Down Expand Up @@ -1279,22 +1278,6 @@ impl_runtime_apis! {
crate::domains::extract_successful_bundles(domain_id, extrinsics)
}

fn extract_bundle(
extrinsic: <Block as BlockT>::Extrinsic
) -> Option<OpaqueBundle<NumberFor<Block>, <Block as BlockT>::Hash, DomainHeader, Balance>> {
crate::domains::extract_bundle(extrinsic)
}

fn extract_receipts(
domain_id: DomainId,
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
) -> Vec<ExecutionReceiptFor<DomainHeader, Block, Balance>> {
crate::domains::extract_successful_bundles(domain_id, extrinsics)
.into_iter()
.map(|bundle| bundle.into_receipt())
.collect()
}

fn extrinsics_shuffling_seed() -> Randomness {
Randomness::from(Domains::extrinsics_shuffling_seed().to_fixed_bytes())
}
Expand Down Expand Up @@ -1331,10 +1314,6 @@ impl_runtime_apis! {
Domains::oldest_unconfirmed_receipt_number(domain_id)
}

fn domain_block_limit(domain_id: DomainId) -> Option<sp_domains::DomainBlockLimit> {
Domains::domain_block_limit(domain_id)
}

fn domain_bundle_limit(domain_id: DomainId) -> Option<sp_domains::DomainBundleLimit> {
Domains::domain_bundle_limit(domain_id).ok().flatten()
}
Expand Down
18 changes: 1 addition & 17 deletions crates/subspace-service/src/domains/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use parity_scale_codec::{Decode, Encode};
use sc_client_api::{BlockBackend, ProofProvider};
use sc_network::request_responses::{IncomingRequest, OutgoingResponse};
use sc_network::{NetworkBackend, PeerId};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_domains::{DomainId, DomainsApi, ExecutionReceiptFor};
use sp_domains_fraud_proof::FraudProofApi;
Expand Down Expand Up @@ -174,19 +174,6 @@ where
info.best_hash
};

let consensus_api_version = self
.client
.runtime_api()
.api_version::<dyn DomainsApi<Block, Block::Header>>(target_block_hash)
.map_err(sp_blockchain::Error::RuntimeApiError)?
.ok_or_else(|| HandleRequestError::ApiVersionNotSupported)?;

if consensus_api_version < 6 {
debug!("Incorrect API version to support the last confirmed block request: {consensus_api_version}");

return Err(HandleRequestError::ApiVersionNotSupported);
}

let last_confirmed_block_receipt = self
.client
.runtime_api()
Expand Down Expand Up @@ -245,9 +232,6 @@ enum HandleRequestError {
#[error("Failed to send response.")]
SendResponse,

#[error("Api version is not supported.")]
ApiVersionNotSupported,

#[error("Failed to decode request: {0}.")]
Decode(#[from] codec::Error),

Expand Down
15 changes: 1 addition & 14 deletions domains/client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,7 @@ where
api.record_proof();
}

let core_version = api
.api_version::<dyn Core<Block>>(parent_hash)?
.ok_or_else(|| Error::VersionInvalid("Core".to_string()))?;

if core_version >= 5 {
if api.initialize_block(parent_hash, &header).is_err() {
// TODO: Hack for Subspace fork caused by
// https://github.com/subspace/polkadot-sdk/commit/447bbc765020674614e9ac982163f7e11e5b03ea
// Replace with error propagation before next network
}
} else {
#[allow(deprecated)]
api.initialize_block_before_version_5(parent_hash, &header)?;
}
api.initialize_block(parent_hash, &header)?;

if let Some(inherent_data) = maybe_inherent_data {
let inherent_extrinsics = Self::create_inherents(parent_hash, &api, inherent_data)?;
Expand Down
Loading

0 comments on commit b341816

Please sign in to comment.