Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: linning <linningde25@gmail.com>
  • Loading branch information
NingLin-P committed Oct 22, 2023
1 parent 5f4bced commit 6ec6f04
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 44 deletions.
22 changes: 10 additions & 12 deletions crates/sp-domains-fraud-proof/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_blockchain::HeaderBackend;
use sp_core::traits::{CodeExecutor, FetchRuntimeCode, RuntimeCode};
use sp_core::H256;
use sp_domains::{DomainId, DomainsApi};
use sp_runtime::traits::{BlakeTwo256, Header as HeaderT, NumberFor};
use sp_runtime::traits::{Header as HeaderT, NumberFor};
use sp_runtime::OpaqueExtrinsic;
use sp_std::vec::Vec;
use sp_trie::StorageProof;
Expand Down Expand Up @@ -214,7 +214,7 @@ where
Block: BlockT,
Block::Hash: From<H256>,
DomainBlock: BlockT,
DomainBlock::Hash: From<H256>,
DomainBlock::Hash: Into<H256> + From<H256>,
Client: BlockBackend<Block> + HeaderBackend<Block> + ProvideRuntimeApi<Block>,
Client::Api: DomainsApi<Block, NumberFor<DomainBlock>, DomainBlock::Hash>,
Executor: CodeExecutor + RuntimeVersionOf,
Expand Down Expand Up @@ -266,14 +266,6 @@ where
domain_id: DomainId,
bundle_body: Vec<OpaqueExtrinsic>,
) -> Option<H256> {
let domain_runtime_code = {
let consensus_block_hash = consensus_block_hash.into();
self.consensus_client
.runtime_api()
.domain_runtime_code(consensus_block_hash, domain_id)
.ok()??
};

let mut extrinsics = Vec::with_capacity(bundle_body.len());
for opaque_extrinsic in bundle_body {
let ext = <<DomainBlock as BlockT>::Extrinsic>::decode(
Expand All @@ -283,6 +275,7 @@ where
extrinsics.push(ext);
}

let domain_runtime_code = self.get_domain_runtime_code(consensus_block_hash, domain_id)?;
let domain_runtime_api_light =
RuntimeApiLight::new(self.executor.clone(), domain_runtime_code.into());

Expand All @@ -295,10 +288,15 @@ where
)
.ok()?
.into_iter()
.map(|(signer, tx)| (signer, BlakeTwo256::hash_of(&tx)))
.map(|(signer, tx)| {
(
signer,
<DomainBlock::Header as HeaderT>::Hashing::hash_of(&tx),
)
})
.collect();

Some(BlakeTwo256::hash_of(&ext_signers))
Some(<DomainBlock::Header as HeaderT>::Hashing::hash_of(&ext_signers).into())
}

fn execution_proof_check(
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 @@ -16,7 +16,6 @@

//! Subspace fraud proof primitives for consensus chain.
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(associated_type_bounds)]

pub mod fraud_proof;
#[cfg(feature = "std")]
Expand Down
3 changes: 2 additions & 1 deletion crates/sp-domains-fraud-proof/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ pub fn verify_valid_bundle_fraud_proof<CBlock, DomainNumber, DomainHash, Balance
fraud_proof: &ValidBundleProof,
) -> Result<(), VerificationError>
where
CBlock: BlockT<Hash: Into<H256>>,
CBlock: BlockT,
CBlock::Hash: Into<H256>,
{
let ValidBundleProof {
domain_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
Block: BlockT,
Block::Hash: From<H256>,
DomainBlock: BlockT,
DomainBlock::Hash: From<H256>,
DomainBlock::Hash: Into<H256> + From<H256>,
Client: BlockBackend<Block>
+ HeaderBackend<Block>
+ ProvideRuntimeApi<Block>
Expand Down
13 changes: 10 additions & 3 deletions domains/client/block-preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ use runtime_api::TimestampExtrinsicConstructor;
use sc_client_api::BlockBackend;
use sp_api::{HashT, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_core::H256;
use sp_domains::extrinsics::deduplicate_and_shuffle_extrinsics;
use sp_domains::{
DomainId, DomainsApi, ExecutionReceipt, InboxedBundle, InvalidBundleType, OpaqueBundle,
OpaqueBundles, ReceiptValidity,
};
use sp_messenger::MessengerApi;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, NumberFor};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use std::collections::VecDeque;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down Expand Up @@ -118,6 +119,7 @@ impl<Block, CBlock, Client, CClient, RuntimeApi, ReceiptValidator>
DomainBlockPreprocessor<Block, CBlock, Client, CClient, RuntimeApi, ReceiptValidator>
where
Block: BlockT,
Block::Hash: Into<H256>,
CBlock: BlockT,
CBlock::Hash: From<Block::Hash>,
NumberFor<CBlock>: From<NumberFor<Block>>,
Expand Down Expand Up @@ -226,10 +228,15 @@ where
};
let bundle_digest: Vec<_> = extrinsics
.iter()
.map(|(signer, tx)| (signer.clone(), BlakeTwo256::hash_of(tx)))
.map(|(signer, tx)| {
(
signer.clone(),
<Block::Header as HeaderT>::Hashing::hash_of(tx),
)
})
.collect();
inboxed_bundles.push(InboxedBundle::valid(
BlakeTwo256::hash_of(&bundle_digest),
<Block::Header as HeaderT>::Hashing::hash_of(&bundle_digest).into(),
extrinsic_root,
));
valid_extrinsics.extend(extrinsics);
Expand Down
14 changes: 6 additions & 8 deletions domains/client/domain-operator/src/domain_block_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sp_core::traits::CodeExecutor;
use sp_core::H256;
use sp_domains::merkle_tree::MerkleTree;
use sp_domains::{BundleValidity, DomainId, DomainsApi, ExecutionReceipt};
use sp_domains_fraud_proof::fraud_proof::FraudProof;
use sp_domains_fraud_proof::fraud_proof::{FraudProof, ValidBundleProof};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, One, Zero};
use sp_runtime::Digest;
use std::cmp::Ordering;
Expand Down Expand Up @@ -970,13 +970,11 @@ where
bundle_index,
..
} => match mismatch_type {
BundleMismatchType::Valid => self
.fraud_proof_generator
.generate_bad_valid_bundle_proof::<ParentChainBlock>(
self.domain_id,
local_receipt.hash(),
bundle_index,
),
BundleMismatchType::Valid => FraudProof::ValidBundle(ValidBundleProof {
domain_id: self.domain_id,
bad_receipt_hash: local_receipt.hash(),
bundle_index,
}),
_ => self
.fraud_proof_generator
.generate_invalid_bundle_field_proof::<ParentChainBlock>(
Expand Down
18 changes: 1 addition & 17 deletions domains/client/domain-operator/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sp_domains_fraud_proof::fraud_proof::{
ExecutionPhase, ExtrinsicDigest, FraudProof, InvalidBundlesFraudProof,
InvalidDomainBlockHashProof, InvalidExtrinsicsRootProof, InvalidStateTransitionProof,
InvalidTotalRewardsProof, MissingInvalidBundleEntryFraudProof,
ValidAsInvalidBundleEntryFraudProof, ValidBundleDigest, ValidBundleProof,
ValidAsInvalidBundleEntryFraudProof, ValidBundleDigest,
};
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, HashingFor, Header as HeaderT, NumberFor};
use sp_runtime::{Digest, DigestItem};
Expand Down Expand Up @@ -101,22 +101,6 @@ where
}
}

pub fn generate_bad_valid_bundle_proof<PCB>(
&self,
domain_id: DomainId,
bad_receipt_hash: H256,
bundle_index: u32,
) -> FraudProof<NumberFor<PCB>, PCB::Hash>
where
PCB: BlockT,
{
FraudProof::ValidBundle(ValidBundleProof {
domain_id,
bad_receipt_hash,
bundle_index,
})
}

pub(crate) fn generate_invalid_total_rewards_proof<PCB>(
&self,
domain_id: DomainId,
Expand Down
2 changes: 1 addition & 1 deletion test/subspace-test-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ where
Block: BlockT,
Block::Hash: From<H256>,
DomainBlock: BlockT,
DomainBlock::Hash: From<H256>,
DomainBlock::Hash: Into<H256> + From<H256>,
Client: BlockBackend<Block> + HeaderBackend<Block> + ProvideRuntimeApi<Block> + 'static,
Client::Api: DomainsApi<Block, NumberFor<DomainBlock>, DomainBlock::Hash>,
Executor: CodeExecutor + sc_executor::RuntimeVersionOf,
Expand Down

0 comments on commit 6ec6f04

Please sign in to comment.