From c6e97407fda69c22868c04fa6e3f6ceaaa5aa60f Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 18:06:09 +0800 Subject: [PATCH 1/7] Remove 3h compatibility code for domain inherent extrinsic order Signed-off-by: linning --- domains/client/block-builder/src/lib.rs | 23 +++---------------- .../src/domain_block_processor.rs | 11 --------- .../client/domain-operator/src/fraud_proof.rs | 4 +--- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/domains/client/block-builder/src/lib.rs b/domains/client/block-builder/src/lib.rs index 7c81ba4c47..a3d7fb8c84 100644 --- a/domains/client/block-builder/src/lib.rs +++ b/domains/client/block-builder/src/lib.rs @@ -158,7 +158,6 @@ where backend: &'a B, mut extrinsics: VecDeque, maybe_inherent_data: Option, - is_gemini_3h: bool, ) -> Result { let header = ::new( parent_number + One::one(), @@ -181,25 +180,9 @@ where if let Some(inherent_data) = maybe_inherent_data { let inherent_extrinsics = Self::create_inherents(parent_hash, &api, inherent_data)?; - // TODO: This is used to keep compatible with gemini-3h, remove before next network - // - // HACK: ideally, any network should maintain the inherent extrinsic order to keep consistency - // with the order in the fraud proof verification side, but in gemini-3h, the domain inherent - // extrinsic order is changed in the ER that derived from the consensus block #168431, we have - // to follow this change in the client side to ensure every domain node that sync from genesis - // will produce the same ER and hence can successfully submit ER to exend the previous ER. - let maintain_runtime_inherent_extrinsic_order = - !is_gemini_3h || parent_number >= 168430u32.into(); - - if maintain_runtime_inherent_extrinsic_order { - // reverse and push the inherents so that order is maintained - for inherent_extrinsic in inherent_extrinsics.into_iter().rev() { - extrinsics.push_front(inherent_extrinsic) - } - } else { - for inherent_extrinsic in inherent_extrinsics { - extrinsics.push_front(inherent_extrinsic) - } + // reverse and push the inherents so that order is maintained + for inherent_extrinsic in inherent_extrinsics.into_iter().rev() { + extrinsics.push_front(inherent_extrinsic) } } diff --git a/domains/client/domain-operator/src/domain_block_processor.rs b/domains/client/domain-operator/src/domain_block_processor.rs index 67f18650f5..a04220610d 100644 --- a/domains/client/domain-operator/src/domain_block_processor.rs +++ b/domains/client/domain-operator/src/domain_block_processor.rs @@ -28,7 +28,6 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, One, Zer use sp_runtime::{Digest, Saturating}; use std::cmp::Ordering; use std::collections::VecDeque; -use std::str::FromStr; use std::sync::Arc; struct DomainBlockBuildResult @@ -423,15 +422,6 @@ where inherent_digests: Digest, inherent_data: sp_inherents::InherentData, ) -> Result, sp_blockchain::Error> { - // TODO: This is used to keep compatible with gemini-3h, remove before next network - let is_gemini_3h = self.consensus_client.info().genesis_hash - == FromStr::from_str( - // The genesis hash of gemini-3h - "0c121c75f4ef450f40619e1fca9d1e8e7fbabc42c895bc4790801e85d5a91c34", - ) - .map_err(|_| ()) - .expect("parsing consensus block hash should success"); - let block_builder = BlockBuilder::new( &*self.client, parent_hash, @@ -441,7 +431,6 @@ where &*self.backend, extrinsics, Some(inherent_data), - is_gemini_3h, )?; let BuiltBlock { diff --git a/domains/client/domain-operator/src/fraud_proof.rs b/domains/client/domain-operator/src/fraud_proof.rs index 0d72ceb7ab..0a6d3d3b41 100644 --- a/domains/client/domain-operator/src/fraud_proof.rs +++ b/domains/client/domain-operator/src/fraud_proof.rs @@ -238,10 +238,8 @@ where extrinsics.into(), // NOTE: the inherent extrinsic is already contained in the above `extrinsics`, which // is getting from the block body, thus it is okay to pass `maybe_inherent_data` as - // `None` and `is_gemini_3h` as `false`, the latter is only used when `maybe_inherent_data` - // is `Some`. + // `None`. None, - false, )?; let (storage_changes, call_data) = match &execution_phase { From 50c562162fb3736c148de5014970469333f77837 Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 18:06:45 +0800 Subject: [PATCH 2/7] Remove unused mmr digest Signed-off-by: linning --- crates/pallet-subspace-mmr/src/lib.rs | 8 +------- crates/sp-subspace-mmr/src/lib.rs | 29 +-------------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/crates/pallet-subspace-mmr/src/lib.rs b/crates/pallet-subspace-mmr/src/lib.rs index 54fa0c601a..581d5d10a4 100644 --- a/crates/pallet-subspace-mmr/src/lib.rs +++ b/crates/pallet-subspace-mmr/src/lib.rs @@ -22,9 +22,8 @@ pub use pallet::*; use sp_core::Get; use sp_mmr_primitives::{LeafDataProvider, OnNewRoot}; use sp_runtime::traits::{CheckedSub, One}; -use sp_runtime::DigestItem; use sp_subspace_mmr::subspace_mmr_runtime_interface::get_mmr_leaf_data; -use sp_subspace_mmr::{LeafDataV0, MmrDigest, MmrLeaf}; +use sp_subspace_mmr::{LeafDataV0, MmrLeaf}; #[frame_support::pallet] mod pallet { @@ -56,11 +55,6 @@ mod pallet { impl OnNewRoot for Pallet { fn on_new_root(root: &T::MmrRootHash) { - // TODO: this digest is not used remove it before next network reset but keep it - // as is for now to keep compatible with gemini-3h. - let digest = DigestItem::new_mmr_root(*root); - >::deposit_log(digest); - let block_number = frame_system::Pallet::::block_number(); >::insert(block_number, *root); if let Some(to_prune) = block_number.checked_sub(&T::MmrRootHashCount::get().into()) { diff --git a/crates/sp-subspace-mmr/src/lib.rs b/crates/sp-subspace-mmr/src/lib.rs index 2822cf1a0e..4d8e65f996 100644 --- a/crates/sp-subspace-mmr/src/lib.rs +++ b/crates/sp-subspace-mmr/src/lib.rs @@ -29,11 +29,9 @@ pub use runtime_interface::{domain_mmr_runtime_interface, subspace_mmr_runtime_i #[cfg(not(feature = "std"))] extern crate alloc; -use codec::{Codec, Decode, Encode}; +use codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_mmr_primitives::{EncodableOpaqueLeaf, LeafProof as MmrProof}; -use sp_runtime::generic::OpaqueDigestItemId; -use sp_runtime::DigestItem; /// MMR leaf structure #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] @@ -67,31 +65,6 @@ pub struct LeafDataV0 { pub extrinsics_root: Hash, } -/// MMR specific digest item. -#[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] -pub enum MmrDigestItem { - NewMmrRoot(MmrRootHash), -} - -/// MMR specific digest items interface. -pub trait MmrDigest { - fn new_mmr_root(root: MmrRootHash) -> Self; - fn as_new_mmr_root(&self) -> Option; -} - -impl MmrDigest for DigestItem { - fn new_mmr_root(root: MmrRootHash) -> Self { - DigestItem::Other(MmrDigestItem::NewMmrRoot(root).encode()) - } - - fn as_new_mmr_root(&self) -> Option { - match self.try_to::>(OpaqueDigestItemId::Other) { - Some(MmrDigestItem::NewMmrRoot(root)) => Some(root), - _ => None, - } - } -} - /// Consensus chain MMR leaf and its Proof at specific block. /// /// The verifier is not required to contains any the MMR offchain data but this proof From f0656780467cefe079e11495499f55c20ef39de3 Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 18:18:21 +0800 Subject: [PATCH 3/7] Remove the unused ProofOfElection::consensus_block_hash field Signed-off-by: linning --- crates/pallet-domains/src/lib.rs | 2 +- .../sp-domains/src/bundle_producer_election.rs | 4 ++-- crates/sp-domains/src/lib.rs | 17 +++++------------ .../src/bundle_producer_election_solver.rs | 3 +-- .../src/domain_bundle_proposer.rs | 2 +- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 87140ba169..5472a8a00e 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -2240,7 +2240,7 @@ impl Pallet { fn validate_eligibility( to_sign: &[u8], signature: &OperatorSignature, - proof_of_election: &ProofOfElection, + proof_of_election: &ProofOfElection, domain_config: &DomainConfig>, pre_dispatch: bool, ) -> Result<(), BundleError> { diff --git a/crates/sp-domains/src/bundle_producer_election.rs b/crates/sp-domains/src/bundle_producer_election.rs index 78fac33e0b..2a79af2c16 100644 --- a/crates/sp-domains/src/bundle_producer_election.rs +++ b/crates/sp-domains/src/bundle_producer_election.rs @@ -82,10 +82,10 @@ pub(crate) fn verify_vrf_signature( Ok(()) } -pub fn check_proof_of_election( +pub fn check_proof_of_election( operator_signing_key: &OperatorPublicKey, bundle_slot_probability: (u64, u64), - proof_of_election: &ProofOfElection, + proof_of_election: &ProofOfElection, operator_stake: StakeWeight, total_domain_stake: StakeWeight, ) -> Result<(), ProofOfElectionError> { diff --git a/crates/sp-domains/src/lib.rs b/crates/sp-domains/src/lib.rs index 6b9e614a6d..2fb9c582d5 100644 --- a/crates/sp-domains/src/lib.rs +++ b/crates/sp-domains/src/lib.rs @@ -342,7 +342,7 @@ pub const INITIAL_DOMAIN_TX_RANGE: u64 = 3; #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] pub struct BundleHeader { /// Proof of bundle producer election. - pub proof_of_election: ProofOfElection, + pub proof_of_election: ProofOfElection, /// Execution receipt that should extend the receipt chain or add confirmations /// to the head receipt. pub receipt: ExecutionReceipt< @@ -712,7 +712,7 @@ impl< } #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] -pub struct ProofOfElection { +pub struct ProofOfElection { /// Domain id. pub domain_id: DomainId, /// The slot number. @@ -723,15 +723,9 @@ pub struct ProofOfElection { pub vrf_signature: VrfSignature, /// Operator index in the OperatorRegistry. pub operator_id: OperatorId, - /// TODO: this field is only used in the bundle equivocation FP which is removed, - /// also this field is problematic see - /// so remove this field before next network - /// - /// Consensus block hash at which proof of election was derived. - pub consensus_block_hash: CHash, } -impl ProofOfElection { +impl ProofOfElection { pub fn verify_vrf_signature( &self, operator_signing_key: &OperatorPublicKey, @@ -760,7 +754,7 @@ impl ProofOfElection { } } -impl ProofOfElection { +impl ProofOfElection { #[cfg(any(feature = "std", feature = "runtime-benchmarks"))] pub fn dummy(domain_id: DomainId, operator_id: OperatorId) -> Self { let output_bytes = sp_std::vec![0u8; VrfPreOutput::max_encoded_len()]; @@ -775,7 +769,6 @@ impl ProofOfElection { proof_of_time: PotOutput::default(), vrf_signature, operator_id, - consensus_block_hash: Default::default(), } } } @@ -785,7 +778,7 @@ impl ProofOfElection { #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] pub struct SingletonReceipt { /// Proof of receipt producer election. - pub proof_of_election: ProofOfElection, + pub proof_of_election: ProofOfElection, /// The receipt to submit pub receipt: ExecutionReceipt< Number, diff --git a/domains/client/domain-operator/src/bundle_producer_election_solver.rs b/domains/client/domain-operator/src/bundle_producer_election_solver.rs index 5a5338014c..7c3bf0c083 100644 --- a/domains/client/domain-operator/src/bundle_producer_election_solver.rs +++ b/domains/client/domain-operator/src/bundle_producer_election_solver.rs @@ -55,7 +55,7 @@ where domain_id: DomainId, operator_id: OperatorId, proof_of_time: PotOutput, - ) -> sp_blockchain::Result, OperatorPublicKey)>> { + ) -> sp_blockchain::Result> { let BundleProducerElectionParams { total_domain_stake, bundle_slot_probability, @@ -102,7 +102,6 @@ where proof_of_time, vrf_signature, operator_id, - consensus_block_hash, }; return Ok(Some((proof_of_election, operator_signing_key))); } diff --git a/domains/client/domain-operator/src/domain_bundle_proposer.rs b/domains/client/domain-operator/src/domain_bundle_proposer.rs index 13b3861d50..28964f2dd0 100644 --- a/domains/client/domain-operator/src/domain_bundle_proposer.rs +++ b/domains/client/domain-operator/src/domain_bundle_proposer.rs @@ -122,7 +122,7 @@ where pub(crate) async fn propose_bundle_at( &mut self, - proof_of_election: ProofOfElection, + proof_of_election: ProofOfElection, tx_range: U256, operator_id: OperatorId, receipt: ExecutionReceiptFor, From fdab249fae4ae224abe30a47b533b36384c39949 Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 20:06:08 +0800 Subject: [PATCH 4/7] Remove deprecated fraud proof verification host function Signed-off-by: linning --- .../src/host_functions.rs | 488 +----------------- crates/sp-domains-fraud-proof/src/lib.rs | 246 +-------- .../src/runtime_interface.rs | 59 +-- 3 files changed, 6 insertions(+), 787 deletions(-) diff --git a/crates/sp-domains-fraud-proof/src/host_functions.rs b/crates/sp-domains-fraud-proof/src/host_functions.rs index 474dc1744d..eede593383 100644 --- a/crates/sp-domains-fraud-proof/src/host_functions.rs +++ b/crates/sp-domains-fraud-proof/src/host_functions.rs @@ -2,14 +2,12 @@ extern crate alloc; use crate::{ - DomainChainAllowlistUpdateExtrinsic, DomainInherentExtrinsic, DomainInherentExtrinsicData, - DomainStorageKeyRequest, FraudProofVerificationInfoRequest, FraudProofVerificationInfoResponse, - SetCodeExtrinsic, StatelessDomainRuntimeCall, StorageKeyRequest, + DomainInherentExtrinsic, DomainInherentExtrinsicData, DomainStorageKeyRequest, + StatelessDomainRuntimeCall, }; #[cfg(not(feature = "std"))] use alloc::vec::Vec; use codec::{Codec, Decode, Encode}; -use domain_block_preprocessor::inherents::extract_domain_runtime_upgrade_code; use domain_block_preprocessor::stateless_runtime::StatelessRuntime; use domain_runtime_primitives::{ BlockNumber, CheckExtrinsicsValidityError, CHECK_EXTRINSICS_AND_DO_PRE_DISPATCH_METHOD_NAME, @@ -22,8 +20,7 @@ use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode}; use sp_core::H256; -use sp_domains::bundle_producer_election::BundleProducerElectionParams; -use sp_domains::{BundleProducerElectionApi, DomainId, DomainsApi, OperatorId}; +use sp_domains::{BundleProducerElectionApi, DomainsApi}; use sp_externalities::Extensions; use sp_messenger::MessengerApi; use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, NumberFor}; @@ -34,7 +31,6 @@ use sp_weights::Weight; use std::borrow::Cow; use std::marker::PhantomData; use std::sync::Arc; -use subspace_core_primitives::{Randomness, U256}; use subspace_runtime_primitives::Balance; struct DomainRuntimeCodeFetcher(Vec); @@ -47,24 +43,8 @@ impl FetchRuntimeCode for DomainRuntimeCodeFetcher { /// Trait to query and verify Domains Fraud proof. pub trait FraudProofHostFunctions: Send + Sync { - /// Returns the required verification info for the runtime to verify the Fraud proof. - fn get_fraud_proof_verification_info( - &self, - consensus_block_hash: H256, - fraud_proof_verification_req: FraudProofVerificationInfoRequest, - ) -> Option; - /// Derive the bundle digest for the given bundle body. - // TODO: remove before the new network fn derive_bundle_digest( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - bundle_body: Vec, - ) -> Option; - - /// Derive the bundle digest for the given bundle body. - fn derive_bundle_digest_v2( &self, domain_runtime_code: Vec, bundle_body: Vec, @@ -160,327 +140,6 @@ impl } } -// TODO: Revisit the host function implementation once we decide best strategy to structure them. -impl - FraudProofHostFunctionsImpl -where - Block: BlockT, - Block::Hash: From, - DomainBlock: BlockT, - DomainBlock::Hash: From + Into, - Client: BlockBackend + HeaderBackend + ProvideRuntimeApi, - Client::Api: DomainsApi - + BundleProducerElectionApi - + MessengerApi, Block::Hash>, - Executor: CodeExecutor + RuntimeVersionOf, - EFC: Fn(Arc, Arc) -> Box> + Send + Sync, -{ - fn get_block_randomness(&self, consensus_block_hash: H256) -> Option { - let runtime_api = self.consensus_client.runtime_api(); - let consensus_block_hash = consensus_block_hash.into(); - runtime_api - .extrinsics_shuffling_seed(consensus_block_hash) - .ok() - } - - fn derive_domain_timestamp_extrinsic( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - ) -> Option> { - let runtime_api = self.consensus_client.runtime_api(); - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let timestamp = runtime_api.timestamp(consensus_block_hash.into()).ok()?; - - let domain_stateless_runtime = StatelessRuntime::::new( - self.domain_executor.clone(), - runtime_code.into(), - ); - - domain_stateless_runtime - .construct_timestamp_extrinsic(timestamp) - .ok() - .map(|ext| ext.encode()) - } - - fn derive_domain_chain_allowlist_update_extrinsic( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - ) -> Option> { - let runtime_api = self.consensus_client.runtime_api(); - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let updates = runtime_api - .domain_chains_allowlist_update(consensus_block_hash.into(), domain_id) - .ok()??; - - let domain_stateless_runtime = StatelessRuntime::::new( - self.domain_executor.clone(), - runtime_code.into(), - ); - - domain_stateless_runtime - .construct_domain_update_chain_allowlist_extrinsic(updates) - .ok() - .map(|ext| ext.encode()) - } - - fn derive_consensus_chain_byte_fee_extrinsic( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - ) -> Option> { - let runtime_api = self.consensus_client.runtime_api(); - let consensus_chain_byte_fee = runtime_api - .consensus_chain_byte_fee(consensus_block_hash.into()) - .ok()?; - - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let domain_stateless_runtime = StatelessRuntime::::new( - self.domain_executor.clone(), - runtime_code.into(), - ); - - domain_stateless_runtime - .construct_consensus_chain_byte_fee_extrinsic(consensus_chain_byte_fee) - .ok() - .map(|ext| ext.encode()) - } - - fn get_domain_bundle_body( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - bundle_index: u32, - ) -> Option> { - let consensus_block_hash = consensus_block_hash.into(); - let consensus_extrinsics = self - .consensus_client - .block_body(consensus_block_hash) - .ok()??; - let mut bundles = self - .consensus_client - .runtime_api() - .extract_successful_bundles(consensus_block_hash, domain_id, consensus_extrinsics) - .ok()?; - - if bundle_index < bundles.len() as u32 { - Some(bundles.swap_remove(bundle_index as usize).extrinsics) - } else { - None - } - } - - fn derive_domain_set_code_extrinsic( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - ) -> Option { - let maybe_upgraded_runtime = extract_domain_runtime_upgrade_code::<_, _, DomainBlock>( - &self.consensus_client, - consensus_block_hash.into(), - domain_id, - ) - .ok() - .flatten(); - - if let Some(upgraded_runtime) = maybe_upgraded_runtime { - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let domain_stateless_runtime = StatelessRuntime::::new( - self.domain_executor.clone(), - runtime_code.into(), - ); - - domain_stateless_runtime - .construct_set_code_extrinsic(upgraded_runtime) - .ok() - .map(|ext| SetCodeExtrinsic::EncodedExtrinsic(ext.encode())) - } else { - Some(SetCodeExtrinsic::None) - } - } - - fn get_domain_runtime_code( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - ) -> Option> { - let runtime_api = self.consensus_client.runtime_api(); - // Use the parent hash to get the actual used domain runtime code - // TODO: update once we can get the actual used domain runtime code by `consensus_block_hash` - let consensus_block_header = self - .consensus_client - .header(consensus_block_hash.into()) - .ok() - .flatten()?; - runtime_api - .domain_runtime_code(*consensus_block_header.parent_hash(), domain_id) - .ok() - .flatten() - } - - fn is_tx_in_range( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - opaque_extrinsic: OpaqueExtrinsic, - bundle_index: u32, - ) -> Option { - let runtime_api = self.consensus_client.runtime_api(); - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let consensus_block_hash = consensus_block_hash.into(); - let domain_tx_range = runtime_api - .domain_tx_range(consensus_block_hash, domain_id) - .ok()?; - - let consensus_extrinsics = self - .consensus_client - .block_body(consensus_block_hash) - .ok()??; - let bundles = self - .consensus_client - .runtime_api() - .extract_successful_bundles(consensus_block_hash, domain_id, consensus_extrinsics) - .ok()?; - - let bundle = bundles.get(bundle_index as usize)?; - let bundle_vrf_hash = - U256::from_be_bytes(*bundle.sealed_header.header.proof_of_election.vrf_hash()); - - self.domain_runtime_call( - runtime_code, - StatelessDomainRuntimeCall::IsTxInRange { - opaque_extrinsic, - bundle_vrf_hash, - domain_tx_range, - }, - ) - } - - fn is_inherent_extrinsic( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - opaque_extrinsic: OpaqueExtrinsic, - ) -> Option { - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - self.domain_runtime_call( - runtime_code, - StatelessDomainRuntimeCall::IsInherentExtrinsic(opaque_extrinsic), - ) - } - - fn is_valid_xdm( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - opaque_extrinsic: OpaqueExtrinsic, - ) -> Option { - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let mut domain_stateless_runtime = StatelessRuntime::::new( - self.domain_executor.clone(), - runtime_code.into(), - ); - let extension_factory = (self.domain_extensions_factory_creator)( - self.consensus_client.clone(), - self.domain_executor.clone(), - ); - domain_stateless_runtime.set_extension_factory(extension_factory); - - let consensus_api = self.consensus_client.runtime_api(); - let domain_initial_state = consensus_api - .domain_instance_data(consensus_block_hash.into(), domain_id) - .expect("Runtime Api must not fail. This is unrecoverable error")? - .0 - .raw_genesis - .into_storage(); - domain_stateless_runtime.set_storage(domain_initial_state); - - let encoded_extrinsic = opaque_extrinsic.encode(); - let extrinsic = DomainBlock::Extrinsic::decode(&mut encoded_extrinsic.as_slice()).ok()?; - domain_stateless_runtime - .is_xdm_mmr_proof_valid(&extrinsic) - .expect("Runtime api must not fail. This is an unrecoverable error") - } - - fn is_decodable_extrinsic( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - opaque_extrinsic: OpaqueExtrinsic, - ) -> Option { - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - self.domain_runtime_call( - runtime_code, - StatelessDomainRuntimeCall::IsDecodableExtrinsic(opaque_extrinsic), - ) - } - - fn storage_key( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - req: StorageKeyRequest, - ) -> Option> { - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - let domain_stateless_runtime = StatelessRuntime::::new( - self.domain_executor.clone(), - runtime_code.into(), - ); - Some( - match req { - StorageKeyRequest::Transfers => domain_stateless_runtime.transfers_storage_key(), - } - .expect("Domain Runtime Api should not fail. There is no recovery from this; qed."), - ) - } - - fn get_domain_election_params( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - ) -> Option> { - let runtime_api = self.consensus_client.runtime_api(); - let consensus_block_hash = consensus_block_hash.into(); - let election_params = runtime_api - .bundle_producer_election_params(consensus_block_hash, domain_id) - .ok()??; - Some(election_params) - } - - fn get_operator_stake( - &self, - consensus_block_hash: H256, - operator_id: OperatorId, - ) -> Option { - let runtime_api = self.consensus_client.runtime_api(); - let consensus_block_hash = consensus_block_hash.into(); - let (_, operator_stake) = runtime_api - .operator(consensus_block_hash, operator_id) - .ok()??; - Some(operator_stake) - } - - fn check_extrinsics_in_single_context_v1( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - domain_block_id: (BlockNumber, H256), - domain_block_state_root: H256, - bundle_extrinsics: Vec, - storage_proof: StorageProof, - ) -> Option> { - let runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - self.check_extrinsics_in_single_context( - runtime_code, - domain_block_id, - domain_block_state_root, - bundle_extrinsics, - storage_proof.encode(), - ) - } -} - impl FraudProofHostFunctions for FraudProofHostFunctionsImpl where @@ -496,148 +155,7 @@ where Executor: CodeExecutor + RuntimeVersionOf, EFC: Fn(Arc, Arc) -> Box> + Send + Sync, { - fn get_fraud_proof_verification_info( - &self, - consensus_block_hash: H256, - fraud_proof_verification_req: FraudProofVerificationInfoRequest, - ) -> Option { - match fraud_proof_verification_req { - FraudProofVerificationInfoRequest::BlockRandomness => self - .get_block_randomness(consensus_block_hash) - .map(|block_randomness| { - FraudProofVerificationInfoResponse::BlockRandomness(block_randomness) - }), - FraudProofVerificationInfoRequest::DomainTimestampExtrinsic(domain_id) => self - .derive_domain_timestamp_extrinsic(consensus_block_hash, domain_id) - .map(|domain_timestamp_extrinsic| { - FraudProofVerificationInfoResponse::DomainTimestampExtrinsic( - domain_timestamp_extrinsic, - ) - }), - FraudProofVerificationInfoRequest::ConsensusChainByteFeeExtrinsic(domain_id) => self - .derive_consensus_chain_byte_fee_extrinsic(consensus_block_hash, domain_id) - .map(|consensus_chain_byte_fee_extrinsic| { - FraudProofVerificationInfoResponse::ConsensusChainByteFeeExtrinsic( - consensus_chain_byte_fee_extrinsic, - ) - }), - FraudProofVerificationInfoRequest::DomainBundleBody { - domain_id, - bundle_index, - } => self - .get_domain_bundle_body(consensus_block_hash, domain_id, bundle_index) - .map(|domain_bundle_body| { - FraudProofVerificationInfoResponse::DomainBundleBody(domain_bundle_body) - }), - FraudProofVerificationInfoRequest::DomainRuntimeCode(domain_id) => self - .get_domain_runtime_code(consensus_block_hash, domain_id) - .map(|domain_runtime_code| { - FraudProofVerificationInfoResponse::DomainRuntimeCode(domain_runtime_code) - }), - FraudProofVerificationInfoRequest::DomainSetCodeExtrinsic(domain_id) => self - .derive_domain_set_code_extrinsic(consensus_block_hash, domain_id) - .map(|maybe_domain_set_code_extrinsic| { - FraudProofVerificationInfoResponse::DomainSetCodeExtrinsic( - maybe_domain_set_code_extrinsic, - ) - }), - FraudProofVerificationInfoRequest::TxRangeCheck { - domain_id, - opaque_extrinsic, - bundle_index, - } => self - .is_tx_in_range( - consensus_block_hash, - domain_id, - opaque_extrinsic, - bundle_index, - ) - .map(|is_tx_in_range| { - FraudProofVerificationInfoResponse::TxRangeCheck(is_tx_in_range) - }), - FraudProofVerificationInfoRequest::InherentExtrinsicCheck { - domain_id, - opaque_extrinsic, - } => self - .is_inherent_extrinsic(consensus_block_hash, domain_id, opaque_extrinsic) - .map(|is_inherent| { - FraudProofVerificationInfoResponse::InherentExtrinsicCheck(is_inherent) - }), - FraudProofVerificationInfoRequest::ExtrinsicDecodableCheck { - domain_id, - opaque_extrinsic, - } => self - .is_decodable_extrinsic(consensus_block_hash, domain_id, opaque_extrinsic) - .map(|is_decodable| { - FraudProofVerificationInfoResponse::ExtrinsicDecodableCheck(is_decodable) - }), - FraudProofVerificationInfoRequest::DomainElectionParams { domain_id } => self - .get_domain_election_params(consensus_block_hash, domain_id) - .map(|domain_election_params| { - FraudProofVerificationInfoResponse::DomainElectionParams { - domain_total_stake: domain_election_params.total_domain_stake, - bundle_slot_probability: domain_election_params.bundle_slot_probability, - } - }), - FraudProofVerificationInfoRequest::OperatorStake { operator_id } => self - .get_operator_stake(consensus_block_hash, operator_id) - .map(|operator_stake| { - FraudProofVerificationInfoResponse::OperatorStake(operator_stake) - }), - FraudProofVerificationInfoRequest::CheckExtrinsicsInSingleContext { - domain_id, - domain_block_number, - domain_block_hash, - domain_block_state_root, - extrinsics, - storage_proof, - } => self - .check_extrinsics_in_single_context_v1( - consensus_block_hash, - domain_id, - (domain_block_number, domain_block_hash), - domain_block_state_root, - extrinsics, - storage_proof, - ) - .map(FraudProofVerificationInfoResponse::CheckExtrinsicsInSingleContext), - FraudProofVerificationInfoRequest::StorageKey { domain_id, req } => { - Some(FraudProofVerificationInfoResponse::StorageKey( - self.storage_key(consensus_block_hash, domain_id, req), - )) - } - FraudProofVerificationInfoRequest::XDMValidationCheck { - domain_id, - opaque_extrinsic, - } => Some(FraudProofVerificationInfoResponse::XDMValidationCheck( - self.is_valid_xdm(consensus_block_hash, domain_id, opaque_extrinsic), - )), - FraudProofVerificationInfoRequest::DomainChainsAllowlistUpdateExtrinsic(domain_id) => { - Some( - FraudProofVerificationInfoResponse::DomainChainAllowlistUpdateExtrinsic( - self.derive_domain_chain_allowlist_update_extrinsic( - consensus_block_hash, - domain_id, - ) - .map(DomainChainAllowlistUpdateExtrinsic::EncodedExtrinsic) - .unwrap_or(DomainChainAllowlistUpdateExtrinsic::None), - ), - ) - } - } - } - fn derive_bundle_digest( - &self, - consensus_block_hash: H256, - domain_id: DomainId, - bundle_body: Vec, - ) -> Option { - let domain_runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?; - self.derive_bundle_digest_v2(domain_runtime_code, bundle_body) - } - - fn derive_bundle_digest_v2( &self, domain_runtime_code: Vec, bundle_body: Vec, diff --git a/crates/sp-domains-fraud-proof/src/lib.rs b/crates/sp-domains-fraud-proof/src/lib.rs index a1c2c3ec84..f061c28796 100644 --- a/crates/sp-domains-fraud-proof/src/lib.rs +++ b/crates/sp-domains-fraud-proof/src/lib.rs @@ -48,14 +48,13 @@ pub use runtime_interface::fraud_proof_runtime_interface; pub use runtime_interface::fraud_proof_runtime_interface::HostFunctions; use scale_info::TypeInfo; use sp_core::H256; -use sp_domains::{DomainAllowlistUpdates, DomainId, OperatorId}; +use sp_domains::DomainAllowlistUpdates; use sp_runtime::traits::{Header as HeaderT, NumberFor}; 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 sp_trie::StorageProof; -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. @@ -89,82 +88,6 @@ pub enum StorageKeyRequest { Transfers, } -/// Request type to fetch required verification information for fraud proof through Host function. -#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] -pub enum FraudProofVerificationInfoRequest { - /// Block randomness at a given consensus block hash. - BlockRandomness, - /// Domain timestamp extrinsic using the timestamp at a given consensus block hash. - DomainTimestampExtrinsic(DomainId), - /// Domain `set_consensus_chain_byte_fee` extrinsic using the `consensus_chain_byte_fee` at a given - /// consensus block hash. - ConsensusChainByteFeeExtrinsic(DomainId), - /// Domains `update_domain_chain_allowlist` extrinsic at a given consensus block hash. - DomainChainsAllowlistUpdateExtrinsic(DomainId), - /// The body of domain bundle included in a given consensus block at a given index - DomainBundleBody { - domain_id: DomainId, - bundle_index: u32, - }, - /// The domain runtime code - DomainRuntimeCode(DomainId), - /// Domain set_code extrinsic if there is a runtime upgrade at a given consensus block hash. - DomainSetCodeExtrinsic(DomainId), - /// Request to check if particular extrinsic is in range for (domain, bundle) pair at given domain block - TxRangeCheck { - domain_id: DomainId, - /// Index of the bundle in which the extrinsic exists - bundle_index: u32, - /// Extrinsic for which we need to check the range - opaque_extrinsic: OpaqueExtrinsic, - }, - /// Request to check if particular extrinsic is an inherent extrinsic - InherentExtrinsicCheck { - domain_id: DomainId, - /// Extrinsic for which we need to if it is inherent or not. - opaque_extrinsic: OpaqueExtrinsic, - }, - /// Request to check if the domain extrinsic is decodable or not. - ExtrinsicDecodableCheck { - domain_id: DomainId, - /// Extrinsic for which we need to if it is decodable or not. - opaque_extrinsic: OpaqueExtrinsic, - }, - /// Request to check if the XDM is valid - XDMValidationCheck { - domain_id: DomainId, - /// Encoded XDM extrinsic that needs to be validated. - opaque_extrinsic: OpaqueExtrinsic, - }, - /// Request to get Domain election params. - DomainElectionParams { domain_id: DomainId }, - /// Request to get Operator stake. - OperatorStake { operator_id: OperatorId }, - /// Request to check extrinsics in single context - CheckExtrinsicsInSingleContext { - domain_id: DomainId, - /// Domain block number from ER - domain_block_number: u32, - /// Domain block hash from ER - domain_block_hash: H256, - /// Domain block state root from ER - domain_block_state_root: H256, - /// Extrinsics which we want to check in single context - extrinsics: Vec, - /// Storage proof for the keys used in validating the extrinsic - storage_proof: StorageProof, - }, - /// Request to fetch a specific storage key - StorageKey { - domain_id: DomainId, - req: StorageKeyRequest, - }, -} - -impl PassBy for FraudProofVerificationInfoRequest { - type PassBy = pass_by::Codec; -} - /// Type that maybe holds an encoded set_code extrinsic with upgraded runtime #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] pub enum SetCodeExtrinsic { @@ -183,171 +106,6 @@ pub enum DomainChainAllowlistUpdateExtrinsic { EncodedExtrinsic(Vec), } -/// Response holds required verification information for fraud proof from Host function. -#[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] -pub enum FraudProofVerificationInfoResponse { - /// Block randomness fetched from consensus state at a specific block hash. - BlockRandomness(Randomness), - /// Encoded domain timestamp extrinsic using the timestamp from consensus state at a specific block hash. - DomainTimestampExtrinsic(Vec), - /// Encoded domain `set_consensus_chain_byte_fee` extrinsic using the `consensus_chain_byte_fee` at a - /// given consensus block hash. - ConsensusChainByteFeeExtrinsic(Vec), - /// Domain block body fetch from a specific consensus block body - DomainBundleBody(Vec), - /// The domain runtime code - DomainRuntimeCode(Vec), - /// Encoded domain set_code extrinsic if there is a runtime upgrade at given consensus block hash. - DomainSetCodeExtrinsic(SetCodeExtrinsic), - /// Encoded domain update_chain_allowlist extrinsic if there are any updates on consensus chain - /// for this domain at a specific consensus hash. - DomainChainAllowlistUpdateExtrinsic(DomainChainAllowlistUpdateExtrinsic), - /// If particular extrinsic is in range for (domain, bundle) pair at given domain block - TxRangeCheck(bool), - /// If the particular extrinsic provided is either inherent or not. - InherentExtrinsicCheck(bool), - /// If the particular xdm extrinsic is valid or not. - /// Returns None if extrinsic is not an XDM - XDMValidationCheck(Option), - /// If the domain extrinsic is decodable or not. - ExtrinsicDecodableCheck(bool), - /// Domain's total stake at a given Consensus hash. - DomainElectionParams { - domain_total_stake: Balance, - bundle_slot_probability: (u64, u64), - }, - /// Operators Stake at a given Consensus hash. - OperatorStake(Balance), - /// Result of check extrinsics in single context - CheckExtrinsicsInSingleContext(Option), - /// Result of the storage key request - StorageKey(Option>), -} - -impl FraudProofVerificationInfoResponse { - pub fn into_block_randomness(self) -> Option { - match self { - Self::BlockRandomness(randomness) => Some(randomness), - _ => None, - } - } - - pub fn into_domain_timestamp_extrinsic(self) -> Option> { - match self { - Self::DomainTimestampExtrinsic(timestamp_extrinsic) => Some(timestamp_extrinsic), - _ => None, - } - } - - pub fn into_consensus_chain_byte_fee_extrinsic(self) -> Option> { - match self { - Self::ConsensusChainByteFeeExtrinsic(ext) => Some(ext), - _ => None, - } - } - - pub fn into_domain_runtime_code(self) -> Option> { - match self { - Self::DomainRuntimeCode(c) => Some(c), - _ => None, - } - } - - pub fn into_domain_set_code_extrinsic(self) -> SetCodeExtrinsic { - match self { - FraudProofVerificationInfoResponse::DomainSetCodeExtrinsic( - maybe_set_code_extrinsic, - ) => maybe_set_code_extrinsic, - _ => SetCodeExtrinsic::None, - } - } - - pub fn into_domain_chain_allowlist_update_extrinsic( - self, - ) -> DomainChainAllowlistUpdateExtrinsic { - match self { - FraudProofVerificationInfoResponse::DomainChainAllowlistUpdateExtrinsic( - allowlist_update_extrinsic, - ) => allowlist_update_extrinsic, - _ => DomainChainAllowlistUpdateExtrinsic::None, - } - } - - pub fn into_tx_range_check(self) -> Option { - match self { - FraudProofVerificationInfoResponse::TxRangeCheck(is_tx_in_range) => { - Some(is_tx_in_range) - } - _ => None, - } - } - - pub fn into_bundle_body(self) -> Option> { - match self { - Self::DomainBundleBody(bb) => Some(bb), - _ => None, - } - } - - pub fn into_inherent_extrinsic_check(self) -> Option { - match self { - FraudProofVerificationInfoResponse::InherentExtrinsicCheck(is_inherent) => { - Some(is_inherent) - } - _ => None, - } - } - - pub fn into_xdm_validation_check(self) -> Option { - match self { - FraudProofVerificationInfoResponse::XDMValidationCheck(maybe_valid) => maybe_valid, - _ => None, - } - } - - pub fn into_extrinsic_decodable_check(self) -> Option { - match self { - FraudProofVerificationInfoResponse::ExtrinsicDecodableCheck(is_decodable) => { - Some(is_decodable) - } - _ => None, - } - } - - pub fn into_domain_election_params(self) -> Option<(Balance, (u64, u64))> { - match self { - FraudProofVerificationInfoResponse::DomainElectionParams { - domain_total_stake, - bundle_slot_probability, - } => Some((domain_total_stake, bundle_slot_probability)), - _ => None, - } - } - - pub fn into_operator_stake(self) -> Option { - match self { - FraudProofVerificationInfoResponse::OperatorStake(stake) => Some(stake), - _ => None, - } - } - - pub fn into_single_context_extrinsic_check(self) -> Option> { - match self { - FraudProofVerificationInfoResponse::CheckExtrinsicsInSingleContext(result) => { - Some(result) - } - _ => None, - } - } - - pub fn into_storage_key(self) -> Option> { - match self { - FraudProofVerificationInfoResponse::StorageKey(result) => result, - _ => None, - } - } -} - #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)] pub struct DomainInherentExtrinsicData { pub timestamp: Moment, diff --git a/crates/sp-domains-fraud-proof/src/runtime_interface.rs b/crates/sp-domains-fraud-proof/src/runtime_interface.rs index 1d97cc30ab..4a85e8970e 100644 --- a/crates/sp-domains-fraud-proof/src/runtime_interface.rs +++ b/crates/sp-domains-fraud-proof/src/runtime_interface.rs @@ -5,14 +5,12 @@ extern crate alloc; use crate::FraudProofExtension; use crate::{ DomainInherentExtrinsic, DomainInherentExtrinsicData, DomainStorageKeyRequest, - FraudProofVerificationInfoRequest, FraudProofVerificationInfoResponse, StatelessDomainRuntimeCall, }; #[cfg(not(feature = "std"))] use alloc::vec::Vec; use domain_runtime_primitives::BlockNumber; use sp_core::H256; -use sp_domains::DomainId; #[cfg(feature = "std")] use sp_externalities::ExternalitiesExt; use sp_runtime::OpaqueExtrinsic; @@ -22,32 +20,7 @@ use sp_weights::Weight; /// Domain fraud proof related runtime interface #[runtime_interface] pub trait FraudProofRuntimeInterface { - /// Returns required fraud proof verification information to the runtime through host function. - fn get_fraud_proof_verification_info( - &mut self, - consensus_block_hash: H256, - fraud_proof_verification_req: FraudProofVerificationInfoRequest, - ) -> Option { - self.extension::() - .expect("No `FraudProofExtension` associated for the current context!") - .get_fraud_proof_verification_info(consensus_block_hash, fraud_proof_verification_req) - } - /// Derive the bundle digest for the given bundle body. - #[version(1)] - fn derive_bundle_digest( - &mut self, - consensus_block_hash: H256, - domain_id: DomainId, - bundle_body: Vec, - ) -> Option { - self.extension::() - .expect("No `FraudProofExtension` associated for the current context!") - .derive_bundle_digest(consensus_block_hash, domain_id, bundle_body) - } - - /// Derive the bundle digest for the given bundle body. - #[version(2)] fn derive_bundle_digest( &mut self, domain_runtime_code: Vec, @@ -55,34 +28,10 @@ pub trait FraudProofRuntimeInterface { ) -> Option { self.extension::() .expect("No `FraudProofExtension` associated for the current context!") - .derive_bundle_digest_v2(domain_runtime_code, bundle_body) - } - - /// Check the execution proof - // TODO: remove before the new network - #[version(1)] - fn execution_proof_check( - &mut self, - pre_state_root: H256, - encoded_proof: Vec, - execution_method: &str, - call_data: &[u8], - domain_runtime_code: Vec, - ) -> Option> { - self.extension::() - .expect("No `FraudProofExtension` associated for the current context!") - .execution_proof_check( - (Default::default(), Default::default()), - pre_state_root, - encoded_proof, - execution_method, - call_data, - domain_runtime_code, - ) + .derive_bundle_digest(domain_runtime_code, bundle_body) } /// Check the execution proof with also included domain block id. - #[version(2)] fn execution_proof_check( &mut self, domain_block_id: (BlockNumber, H256), @@ -104,7 +53,6 @@ pub trait FraudProofRuntimeInterface { ) } - #[version(1)] fn check_extrinsics_in_single_context( &mut self, domain_runtime_code: Vec, @@ -124,7 +72,6 @@ pub trait FraudProofRuntimeInterface { ) } - #[version(1)] fn construct_domain_inherent_extrinsic( &mut self, domain_runtime_code: Vec, @@ -138,7 +85,6 @@ pub trait FraudProofRuntimeInterface { ) } - #[version(1)] fn domain_storage_key( &mut self, domain_runtime_code: Vec, @@ -149,7 +95,6 @@ pub trait FraudProofRuntimeInterface { .domain_storage_key(domain_runtime_code, req) } - #[version(1)] fn domain_runtime_call( &mut self, domain_runtime_code: Vec, @@ -160,7 +105,6 @@ pub trait FraudProofRuntimeInterface { .domain_runtime_call(domain_runtime_code, call) } - #[version(1)] fn bundle_weight( &mut self, domain_runtime_code: Vec, @@ -171,7 +115,6 @@ pub trait FraudProofRuntimeInterface { .bundle_weight(domain_runtime_code, bundle_body) } - #[version(1)] fn extract_xdm_mmr_proof( &mut self, domain_runtime_code: Vec, From a2d0c57fb07a5a825bbc364476047eef51d3336f Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 20:15:53 +0800 Subject: [PATCH 5/7] Fix typo, rename field/variable, remove codec(skip) Signed-off-by: linning --- crates/pallet-domains/src/staking.rs | 15 +++++++-------- crates/sp-domains/src/lib.rs | 6 +----- crates/subspace-fake-runtime-api/src/lib.rs | 2 +- crates/subspace-runtime/src/lib.rs | 2 +- .../domain-operator/src/domain_block_processor.rs | 7 +++---- domains/client/domain-operator/src/fraud_proof.rs | 2 +- test/subspace-test-runtime/src/lib.rs | 2 +- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/crates/pallet-domains/src/staking.rs b/crates/pallet-domains/src/staking.rs index d169163e32..6c45f3fa84 100644 --- a/crates/pallet-domains/src/staking.rs +++ b/crates/pallet-domains/src/staking.rs @@ -191,8 +191,7 @@ pub struct Operator { /// The status of the operator, it may be stale due to the `OperatorStatus::PendingSlash` is /// not assigned to this field directly, thus MUST use the `status()` method to query the status /// instead. - /// TODO: update the filed to `_status` to avoid accidental access in next network reset - status: OperatorStatus, + _status: OperatorStatus, /// Total deposits during the previous epoch pub deposits_in_epoch: Balance, /// Total withdrew shares during the previous epoch @@ -203,17 +202,17 @@ pub struct Operator { impl Operator { pub fn status(&self, operator_id: OperatorId) -> &OperatorStatus { - if matches!(self.status, OperatorStatus::Slashed) { + if matches!(self._status, OperatorStatus::Slashed) { &OperatorStatus::Slashed } else if Pallet::::is_operator_pending_to_slash(self.current_domain_id, operator_id) { &OperatorStatus::PendingSlash } else { - &self.status + &self._status } } pub fn update_status(&mut self, new_status: OperatorStatus) { - self.status = new_status; + self._status = new_status; } } @@ -233,7 +232,7 @@ impl Operator( current_total_stake: Zero::zero(), current_epoch_rewards: Zero::zero(), current_total_shares: Zero::zero(), - status: OperatorStatus::Registered, + _status: OperatorStatus::Registered, // sum total deposits added during this epoch. deposits_in_epoch: new_deposit.staking, withdrawals_in_epoch: Zero::zero(), @@ -1681,7 +1680,7 @@ pub(crate) mod tests { current_total_stake: operator_stake, current_epoch_rewards: 0, current_total_shares: operator_stake, - status: OperatorStatus::Registered, + _status: OperatorStatus::Registered, deposits_in_epoch: 0, withdrawals_in_epoch: 0, total_storage_fee_deposit: operator_storage_fee_deposit, diff --git a/crates/sp-domains/src/lib.rs b/crates/sp-domains/src/lib.rs index 2fb9c582d5..34e254a684 100644 --- a/crates/sp-domains/src/lib.rs +++ b/crates/sp-domains/src/lib.rs @@ -280,8 +280,6 @@ pub struct BlockFees { /// Burned balances on domain chain pub burned_balance: Balance, /// Rewards for the chain. - // TODO: remove this before mainnet. Skipping to maintain compatibility with Gemini - #[codec(skip)] pub chain_rewards: BTreeMap, } @@ -1538,9 +1536,7 @@ sp_api::decl_runtime_apis! { fn storage_fund_account_balance(operator_id: OperatorId) -> Balance; /// Return if the domain runtime code is upgraded since `at` - // TODO: change from `is_domain_runtime_updraded_since` to `is_domain_runtime_upgraded_since` - // before next network - fn is_domain_runtime_updraded_since(domain_id: DomainId, at: NumberFor) -> Option; + fn is_domain_runtime_upgraded_since(domain_id: DomainId, at: NumberFor) -> Option; /// Return domain sudo call. fn domain_sudo_call(domain_id: DomainId) -> Option>; diff --git a/crates/subspace-fake-runtime-api/src/lib.rs b/crates/subspace-fake-runtime-api/src/lib.rs index 1e115e1562..41d2bf5d05 100644 --- a/crates/subspace-fake-runtime-api/src/lib.rs +++ b/crates/subspace-fake-runtime-api/src/lib.rs @@ -288,7 +288,7 @@ sp_api::impl_runtime_apis! { unreachable!() } - fn is_domain_runtime_updraded_since(_domain_id: DomainId, _at: NumberFor) -> Option { + fn is_domain_runtime_upgraded_since(_domain_id: DomainId, _at: NumberFor) -> Option { unreachable!() } diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index de80bbd2aa..2a16349c07 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -1364,7 +1364,7 @@ impl_runtime_apis! { Domains::storage_fund_account_balance(operator_id) } - fn is_domain_runtime_updraded_since(domain_id: DomainId, at: NumberFor) -> Option { + fn is_domain_runtime_upgraded_since(domain_id: DomainId, at: NumberFor) -> Option { Domains::is_domain_runtime_upgraded_since(domain_id, at) } diff --git a/domains/client/domain-operator/src/domain_block_processor.rs b/domains/client/domain-operator/src/domain_block_processor.rs index a04220610d..47453f9f15 100644 --- a/domains/client/domain-operator/src/domain_block_processor.rs +++ b/domains/client/domain-operator/src/domain_block_processor.rs @@ -746,8 +746,8 @@ where } if let Some(mismatched_receipts) = self.find_mismatch_receipt(consensus_block_hash)? { - let fraud_proof_v2 = self.generate_fraud_proof(mismatched_receipts)?; - tracing::info!("Submit fraud proof: {fraud_proof_v2:?}"); + let fraud_proof = self.generate_fraud_proof(mismatched_receipts)?; + tracing::info!("Submit fraud proof: {fraud_proof:?}"); let consensus_best_hash = self.consensus_client.info().best_hash; let mut consensus_runtime_api = self.consensus_client.runtime_api(); @@ -755,8 +755,7 @@ where self.consensus_offchain_tx_pool_factory .offchain_transaction_pool(consensus_best_hash), ); - consensus_runtime_api - .submit_fraud_proof_unsigned(consensus_best_hash, fraud_proof_v2)?; + consensus_runtime_api.submit_fraud_proof_unsigned(consensus_best_hash, fraud_proof)?; } Ok(()) diff --git a/domains/client/domain-operator/src/fraud_proof.rs b/domains/client/domain-operator/src/fraud_proof.rs index 0a6d3d3b41..3402e69735 100644 --- a/domains/client/domain-operator/src/fraud_proof.rs +++ b/domains/client/domain-operator/src/fraud_proof.rs @@ -178,7 +178,7 @@ where ) })?; let is_domain_runtime_upgraded_since = runtime_api - .is_domain_runtime_updraded_since(best_hash, domain_id, parent_consensus_number)? + .is_domain_runtime_upgraded_since(best_hash, domain_id, parent_consensus_number)? .ok_or_else(|| { sp_blockchain::Error::Application( "Failed to get domain runtime object".to_string().into(), diff --git a/test/subspace-test-runtime/src/lib.rs b/test/subspace-test-runtime/src/lib.rs index 5e11cd4efd..1ceb6e2011 100644 --- a/test/subspace-test-runtime/src/lib.rs +++ b/test/subspace-test-runtime/src/lib.rs @@ -1392,7 +1392,7 @@ impl_runtime_apis! { Domains::storage_fund_account_balance(operator_id) } - fn is_domain_runtime_updraded_since(domain_id: DomainId, at: NumberFor) -> Option { + fn is_domain_runtime_upgraded_since(domain_id: DomainId, at: NumberFor) -> Option { Domains::is_domain_runtime_upgraded_since(domain_id, at) } From d126368bc9c0b53695a3b0c7e08e30061c763a1f Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 20:21:13 +0800 Subject: [PATCH 6/7] Remove resolved TODOs Signed-off-by: linning --- crates/pallet-domains/src/lib.rs | 3 --- crates/pallet-domains/src/staking.rs | 1 - 2 files changed, 4 deletions(-) diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 5472a8a00e..83f70157d4 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -628,9 +628,6 @@ mod pallet { /// only store the consensus block hash for a domain /// if that consensus block contains bundle of the domain, the hash will be pruned when the ER /// that point to the consensus block is pruned. - /// - /// TODO: this storage is unbounded in some cases, see https://github.com/autonomys/subspace/issues/1673 - /// for more details, this will be fixed once https://github.com/autonomys/subspace/issues/1731 is implemented. #[pallet::storage] #[pallet::getter(fn consensus_block_info)] pub type ConsensusBlockHash = diff --git a/crates/pallet-domains/src/staking.rs b/crates/pallet-domains/src/staking.rs index 6c45f3fa84..61333249d9 100644 --- a/crates/pallet-domains/src/staking.rs +++ b/crates/pallet-domains/src/staking.rs @@ -125,7 +125,6 @@ pub(crate) struct Withdrawal { /// Total amount of storage fee on withdraw (including withdrawal in shares) pub(crate) total_storage_fee_withdrawal: Balance, /// Individual withdrawal amounts with their unlocking block for a given domain - // TODO: fixed number of withdrawal & uhlock all ready withdrawal at once pub(crate) withdrawals: VecDeque>, /// Withdrawal that was initiated by nominator and not converted to balance due to /// unfinished domain epoch. From 0b6eb1b194b574f7f7f87aeb8e69a40e2a47c658 Mon Sep 17 00:00:00 2001 From: linning Date: Thu, 26 Sep 2024 23:59:44 +0800 Subject: [PATCH 7/7] Rename Operator::_status to Operator::partial_status Signed-off-by: linning --- crates/pallet-domains/src/staking.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/pallet-domains/src/staking.rs b/crates/pallet-domains/src/staking.rs index 61333249d9..8f733e3643 100644 --- a/crates/pallet-domains/src/staking.rs +++ b/crates/pallet-domains/src/staking.rs @@ -190,7 +190,7 @@ pub struct Operator { /// The status of the operator, it may be stale due to the `OperatorStatus::PendingSlash` is /// not assigned to this field directly, thus MUST use the `status()` method to query the status /// instead. - _status: OperatorStatus, + partial_status: OperatorStatus, /// Total deposits during the previous epoch pub deposits_in_epoch: Balance, /// Total withdrew shares during the previous epoch @@ -201,17 +201,17 @@ pub struct Operator { impl Operator { pub fn status(&self, operator_id: OperatorId) -> &OperatorStatus { - if matches!(self._status, OperatorStatus::Slashed) { + if matches!(self.partial_status, OperatorStatus::Slashed) { &OperatorStatus::Slashed } else if Pallet::::is_operator_pending_to_slash(self.current_domain_id, operator_id) { &OperatorStatus::PendingSlash } else { - &self._status + &self.partial_status } } pub fn update_status(&mut self, new_status: OperatorStatus) { - self._status = new_status; + self.partial_status = new_status; } } @@ -231,7 +231,7 @@ impl Operator( current_total_stake: Zero::zero(), current_epoch_rewards: Zero::zero(), current_total_shares: Zero::zero(), - _status: OperatorStatus::Registered, + partial_status: OperatorStatus::Registered, // sum total deposits added during this epoch. deposits_in_epoch: new_deposit.staking, withdrawals_in_epoch: Zero::zero(), @@ -1679,7 +1679,7 @@ pub(crate) mod tests { current_total_stake: operator_stake, current_epoch_rewards: 0, current_total_shares: operator_stake, - _status: OperatorStatus::Registered, + partial_status: OperatorStatus::Registered, deposits_in_epoch: 0, withdrawals_in_epoch: 0, total_storage_fee_deposit: operator_storage_fee_deposit,