Skip to content

Commit

Permalink
Merge pull request #2755 from subspace/new-fp-host-func
Browse files Browse the repository at this point in the history
Introduce new host function for the stateless fraud proof
  • Loading branch information
NingLin-P committed May 15, 2024
2 parents ebd45c2 + ee979ea commit d159452
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 74 deletions.
49 changes: 47 additions & 2 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ use sp_domains_fraud_proof::fraud_proof::{
InvalidExtrinsicsRootProof, ValidBundleDigest,
};
use sp_domains_fraud_proof::{
DomainChainAllowlistUpdateExtrinsic, FraudProofExtension, FraudProofHostFunctions,
DomainChainAllowlistUpdateExtrinsic, DomainInherentExtrinsic, DomainInherentExtrinsicData,
DomainStorageKeyRequest, FraudProofExtension, FraudProofHostFunctions,
FraudProofVerificationInfoRequest, FraudProofVerificationInfoResponse, SetCodeExtrinsic,
StatelessDomainRuntimeCall,
};
use sp_runtime::traits::{
AccountIdConversion, BlakeTwo256, BlockNumberProvider, Hash as HashT, IdentityLookup, One,
Expand Down Expand Up @@ -442,6 +444,14 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension {
Some(H256::random())
}

fn derive_bundle_digest_v2(
&self,
_domain_runtime_code: Vec<u8>,
_bundle_body: Vec<OpaqueExtrinsic>,
) -> Option<H256> {
Some(H256::random())
}

fn execution_proof_check(
&self,
_domain_id: (u32, H256),
Expand All @@ -453,6 +463,41 @@ impl FraudProofHostFunctions for MockDomainFraudProofExtension {
) -> Option<Vec<u8>> {
None
}

fn check_extrinsics_in_single_context(
&self,
_domain_runtime_code: Vec<u8>,
_domain_block_id: (u32, H256),
_domain_block_state_root: H256,
_bundle_extrinsics: Vec<OpaqueExtrinsic>,
_encoded_proof: Vec<u8>,
) -> Option<Option<u32>> {
None
}

fn construct_domain_inherent_extrinsic(
&self,
_domain_runtime_code: Vec<u8>,
_domain_inherent_extrinsic_data: DomainInherentExtrinsicData,
) -> Option<DomainInherentExtrinsic> {
None
}

fn domain_storage_key(
&self,
_domain_runtime_code: Vec<u8>,
_req: DomainStorageKeyRequest,
) -> Option<Vec<u8>> {
None
}

fn domain_runtime_call(
&self,
_domain_runtime_code: Vec<u8>,
_call: StatelessDomainRuntimeCall,
) -> Option<bool> {
None
}
}

pub(crate) fn new_test_ext_with_extensions() -> sp_io::TestExternalities {
Expand Down Expand Up @@ -932,7 +977,7 @@ fn generate_invalid_block_fees_fraud_proof<T: Config>(
bad_receipt_hash: ReceiptHashFor<T>,
block_fees: sp_domains::BlockFees<BalanceOf<T>>,
) -> (FraudProofFor<T>, T::Hash) {
let storage_key = sp_domains_fraud_proof::fraud_proof::operator_block_fees_final_key();
let storage_key = sp_domains::operator_block_fees_final_key();
let mut root = T::Hash::default();
let mut mdb = PrefixedMemoryDB::<T::Hashing>::default();
{
Expand Down
9 changes: 0 additions & 9 deletions crates/sp-domains-fraud-proof/src/fraud_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,6 @@ impl<ReceiptHash: Copy> InvalidBlockFeesProof<ReceiptHash> {
}
}

//TODO: remove there key generations from here and instead use the fraud proof host function to fetch them

/// This is a representation of actual Block Fees storage in pallet-block-fees.
/// Any change in key or value there should be changed here accordingly.
pub fn operator_block_fees_final_key() -> Vec<u8> {
frame_support::storage::storage_prefix("BlockFees".as_ref(), "CollectedBlockFees".as_ref())
.to_vec()
}

/// Fraud proof for the valid bundles in `ExecutionReceipt::inboxed_bundles`
#[derive(Clone, Debug, Decode, Encode, Eq, PartialEq, TypeInfo)]
pub struct ValidBundleProof<ReceiptHash> {
Expand Down

0 comments on commit d159452

Please sign in to comment.