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

Commit 2a50fc1

Browse files
committed
Revert "Compact proof. (#295)"
This reverts commit d935b81.
1 parent 4e51d32 commit 2a50fc1

File tree

6 files changed

+26
-51
lines changed

6 files changed

+26
-51
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/collator/src/lib.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use sp_consensus::BlockStatus;
2525
use sp_core::traits::SpawnNamed;
2626
use sp_runtime::{
2727
generic::BlockId,
28-
traits::{Block as BlockT, HashFor, Header as HeaderT, Zero},
28+
traits::{Block as BlockT, Header as HeaderT, Zero},
2929
};
3030

3131
use cumulus_client_consensus_common::ParachainConsensus;
@@ -225,19 +225,8 @@ where
225225

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

228-
let compact_proof = match candidate
229-
.proof
230-
.into_compact_proof::<HashFor<Block>>(last_head.state_root().clone())
231-
{
232-
Ok(proof) => proof,
233-
Err(e) => {
234-
tracing::error!(target: "cumulus-collator", "Failed to compact proof: {:?}", e);
235-
return None;
236-
}
237-
};
238-
239228
// Create the parachain block data for the validators.
240-
let b = ParachainBlockData::<Block>::new(header, extrinsics, compact_proof);
229+
let b = ParachainBlockData::<Block>::new(header, extrinsics, candidate.proof);
241230

242231
tracing::debug!(
243232
target: LOG_TARGET,
@@ -454,12 +443,7 @@ mod tests {
454443
assert_eq!(1, *block.header().number());
455444

456445
// Ensure that we did not include `:code` in the proof.
457-
let db = block
458-
.storage_proof()
459-
.to_storage_proof::<BlakeTwo256>(Some(header.state_root()))
460-
.unwrap()
461-
.0
462-
.into_memory_db();
446+
let db = block.storage_proof().clone().into_memory_db();
463447

464448
let backend =
465449
sp_state_machine::new_in_mem::<BlakeTwo256>().update_backend(*header.state_root(), db);

pallets/parachain-system/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sp-externalities = { git = "https://github.com/paritytech/substrate", default-fe
3131

3232
# Other Dependencies
3333
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"]}
34+
hash-db = { version = "0.15.2", default-features = false }
3435
serde = { version = "1.0.101", optional = true, features = ["derive"] }
3536
log = { version = "0.4.14", default-features = false }
3637
environmental = { version = "1.1.2", default-features = false }
@@ -55,6 +56,7 @@ default = [ "std" ]
5556
std = [
5657
"serde",
5758
"codec/std",
59+
"hash-db/std",
5860
"frame-support/std",
5961
"pallet-balances/std",
6062
"sp-core/std",

pallets/parachain-system/src/validate_block/implementation.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use sp_runtime::traits::{Block as BlockT, Extrinsic, HashFor, Header as HeaderT,
2222
use sp_io::KillStorageResult;
2323
use sp_std::prelude::*;
2424

25+
use hash_db::{HashDB, EMPTY_PREFIX};
26+
2527
use polkadot_parachain::primitives::{HeadData, ValidationParams, ValidationResult};
2628

2729
use codec::{Decode, Encode};
@@ -69,17 +71,11 @@ where
6971
"Invalid parent hash",
7072
);
7173

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

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

primitives/core/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ pub struct ParachainBlockData<B: BlockT> {
195195
/// The extrinsics of the parachain block.
196196
extrinsics: sp_std::vec::Vec<B::Extrinsic>,
197197
/// The data that is required to emulate the storage accesses executed by all extrinsics.
198-
storage_proof: sp_trie::CompactProof,
198+
storage_proof: sp_trie::StorageProof,
199199
}
200200

201201
impl<B: BlockT> ParachainBlockData<B> {
202202
/// Creates a new instance of `Self`.
203203
pub fn new(
204204
header: <B as BlockT>::Header,
205205
extrinsics: sp_std::vec::Vec<<B as BlockT>::Extrinsic>,
206-
storage_proof: sp_trie::CompactProof,
206+
storage_proof: sp_trie::StorageProof,
207207
) -> Self {
208208
Self {
209209
header,
@@ -232,19 +232,13 @@ impl<B: BlockT> ParachainBlockData<B> {
232232
&self.extrinsics
233233
}
234234

235-
/// Returns the [`CompactProof`](sp_trie::CompactProof).
236-
pub fn storage_proof(&self) -> &sp_trie::CompactProof {
235+
/// Returns the [`StorageProof`](sp_trie::StorageProof).
236+
pub fn storage_proof(&self) -> &sp_trie::StorageProof {
237237
&self.storage_proof
238238
}
239239

240240
/// Deconstruct into the inner parts.
241-
pub fn deconstruct(
242-
self,
243-
) -> (
244-
B::Header,
245-
sp_std::vec::Vec<B::Extrinsic>,
246-
sp_trie::CompactProof,
247-
) {
241+
pub fn deconstruct(self) -> (B::Header, sp_std::vec::Vec<B::Extrinsic>, sp_trie::StorageProof) {
248242
(self.header, self.extrinsics, self.storage_proof)
249243
}
250244
}

test/client/src/block_builder.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ use crate::{Backend, Client};
1818
use cumulus_primitives_core::{ParachainBlockData, PersistedValidationData};
1919
use cumulus_primitives_parachain_inherent::{ParachainInherentData, INHERENT_IDENTIFIER};
2020
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
21-
use cumulus_test_runtime::{Block, GetLastTimestamp, Hash, Header};
21+
use cumulus_test_runtime::{Block, GetLastTimestamp, Hash};
2222
use polkadot_primitives::v1::{BlockNumber as PBlockNumber, Hash as PHash};
2323
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
2424
use sp_api::ProvideRuntimeApi;
2525
use sp_runtime::{
2626
generic::BlockId,
27-
traits::{Block as BlockT, Header as HeaderT},
27+
traits::Block as BlockT,
2828
};
2929

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

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

173-
let storage_proof = built_block
174-
.proof
175-
.expect("We enabled proof recording before.")
176-
.into_compact_proof::<<Header as HeaderT>::Hashing>(parent_state_root)
177-
.expect("Creates the compact proof");
178-
179173
let (header, extrinsics) = built_block.block.deconstruct();
180-
ParachainBlockData::new(header, extrinsics, storage_proof)
174+
ParachainBlockData::new(
175+
header,
176+
extrinsics,
177+
built_block.proof.expect("We enabled proof recording before."),
178+
)
181179
}
182180
}

0 commit comments

Comments
 (0)