Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Revert "Compact proof. (#295)"
Browse files Browse the repository at this point in the history
This reverts commit d935b81.
  • Loading branch information
andresilva committed Jul 15, 2021
1 parent 4e51d32 commit 2a50fc1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 51 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 3 additions & 19 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_consensus::BlockStatus;
use sp_core::traits::SpawnNamed;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, Header as HeaderT, Zero},
traits::{Block as BlockT, Header as HeaderT, Zero},
};

use cumulus_client_consensus_common::ParachainConsensus;
Expand Down Expand Up @@ -225,19 +225,8 @@ where

let (header, extrinsics) = candidate.block.deconstruct();

let compact_proof = match candidate
.proof
.into_compact_proof::<HashFor<Block>>(last_head.state_root().clone())
{
Ok(proof) => proof,
Err(e) => {
tracing::error!(target: "cumulus-collator", "Failed to compact proof: {:?}", e);
return None;
}
};

// Create the parachain block data for the validators.
let b = ParachainBlockData::<Block>::new(header, extrinsics, compact_proof);
let b = ParachainBlockData::<Block>::new(header, extrinsics, candidate.proof);

tracing::debug!(
target: LOG_TARGET,
Expand Down Expand Up @@ -454,12 +443,7 @@ mod tests {
assert_eq!(1, *block.header().number());

// Ensure that we did not include `:code` in the proof.
let db = block
.storage_proof()
.to_storage_proof::<BlakeTwo256>(Some(header.state_root()))
.unwrap()
.0
.into_memory_db();
let db = block.storage_proof().clone().into_memory_db();

let backend =
sp_state_machine::new_in_mem::<BlakeTwo256>().update_backend(*header.state_root(), db);
Expand Down
2 changes: 2 additions & 0 deletions pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sp-externalities = { git = "https://github.com/paritytech/substrate", default-fe

# Other Dependencies
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"]}
hash-db = { version = "0.15.2", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
log = { version = "0.4.14", default-features = false }
environmental = { version = "1.1.2", default-features = false }
Expand All @@ -55,6 +56,7 @@ default = [ "std" ]
std = [
"serde",
"codec/std",
"hash-db/std",
"frame-support/std",
"pallet-balances/std",
"sp-core/std",
Expand Down
18 changes: 7 additions & 11 deletions pallets/parachain-system/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use sp_runtime::traits::{Block as BlockT, Extrinsic, HashFor, Header as HeaderT,
use sp_io::KillStorageResult;
use sp_std::prelude::*;

use hash_db::{HashDB, EMPTY_PREFIX};

use polkadot_parachain::primitives::{HeadData, ValidationParams, ValidationResult};

use codec::{Decode, Encode};
Expand Down Expand Up @@ -69,17 +71,11 @@ where
"Invalid parent hash",
);

// Uncompress
let mut db = MemoryDB::default();
let root = match sp_trie::decode_compact::<sp_trie::Layout<HashFor<B>>, _, _>(
&mut db,
storage_proof.iter_compact_encoded_nodes(),
Some(parent_head.state_root()),
) {
Ok(root) => root,
Err(_) => panic!("Compact proof decoding failure."),
};
sp_std::mem::drop(storage_proof);
let db = storage_proof.into_memory_db();
let root = parent_head.state_root().clone();
if !HashDB::<HashFor<B>, _>::contains(&db, &root, EMPTY_PREFIX) {
panic!("Witness data does not contain given storage root.");
}

let backend = sp_state_machine::TrieBackend::new(db, root);

Expand Down
16 changes: 5 additions & 11 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ pub struct ParachainBlockData<B: BlockT> {
/// The extrinsics of the parachain block.
extrinsics: sp_std::vec::Vec<B::Extrinsic>,
/// The data that is required to emulate the storage accesses executed by all extrinsics.
storage_proof: sp_trie::CompactProof,
storage_proof: sp_trie::StorageProof,
}

impl<B: BlockT> ParachainBlockData<B> {
/// Creates a new instance of `Self`.
pub fn new(
header: <B as BlockT>::Header,
extrinsics: sp_std::vec::Vec<<B as BlockT>::Extrinsic>,
storage_proof: sp_trie::CompactProof,
storage_proof: sp_trie::StorageProof,
) -> Self {
Self {
header,
Expand Down Expand Up @@ -232,19 +232,13 @@ impl<B: BlockT> ParachainBlockData<B> {
&self.extrinsics
}

/// Returns the [`CompactProof`](sp_trie::CompactProof).
pub fn storage_proof(&self) -> &sp_trie::CompactProof {
/// Returns the [`StorageProof`](sp_trie::StorageProof).
pub fn storage_proof(&self) -> &sp_trie::StorageProof {
&self.storage_proof
}

/// Deconstruct into the inner parts.
pub fn deconstruct(
self,
) -> (
B::Header,
sp_std::vec::Vec<B::Extrinsic>,
sp_trie::CompactProof,
) {
pub fn deconstruct(self) -> (B::Header, sp_std::vec::Vec<B::Extrinsic>, sp_trie::StorageProof) {
(self.header, self.extrinsics, self.storage_proof)
}
}
Expand Down
18 changes: 8 additions & 10 deletions test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use crate::{Backend, Client};
use cumulus_primitives_core::{ParachainBlockData, PersistedValidationData};
use cumulus_primitives_parachain_inherent::{ParachainInherentData, INHERENT_IDENTIFIER};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use cumulus_test_runtime::{Block, GetLastTimestamp, Hash, Header};
use cumulus_test_runtime::{Block, GetLastTimestamp, Hash};
use polkadot_primitives::v1::{BlockNumber as PBlockNumber, Hash as PHash};
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sp_api::ProvideRuntimeApi;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
traits::Block as BlockT,
};

/// An extension for the Cumulus test client to init a block builder.
Expand Down Expand Up @@ -167,16 +167,14 @@ pub trait BuildParachainBlockData {
}

impl<'a> BuildParachainBlockData for sc_block_builder::BlockBuilder<'a, Block, Client, Backend> {
fn build_parachain_block(self, parent_state_root: Hash) -> ParachainBlockData<Block> {
fn build_parachain_block(self, _parent_state_root: Hash) -> ParachainBlockData<Block> {
let built_block = self.build().expect("Builds the block");

let storage_proof = built_block
.proof
.expect("We enabled proof recording before.")
.into_compact_proof::<<Header as HeaderT>::Hashing>(parent_state_root)
.expect("Creates the compact proof");

let (header, extrinsics) = built_block.block.deconstruct();
ParachainBlockData::new(header, extrinsics, storage_proof)
ParachainBlockData::new(
header,
extrinsics,
built_block.proof.expect("We enabled proof recording before."),
)
}
}

0 comments on commit 2a50fc1

Please sign in to comment.