mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Compact proof. (#295)
* compact, need to be made optional and look into/compress child trie roots/state. * proto with child trie support * Missing set_offchain_storage overload. * right name * Ignore offchain indexing in validation function. * patch trie-db * decompress from iter * use compressed proof * remove wasm blob from proof (no inject plugged yet) * change lock * update trie * change in toml * Revert "change in toml" This reverts commit e588583b79e1a64e2a54157b40968aa6b586fbbe. * use patch to branches * i * i:wq * switch branch * ii * ok, needed to patch the runtime by putting substrate patch in polkadot project. * test passing with this conf * actual lazy code fetch * patch issue * Code reorg * restore commented tests. * update deps. * remove polka patch * fixes * remove patch * revert cargo.lock * cargo update -p sp-trie polkadot-service * fix collator test (using parent state root). * Update pallets/parachain-system/src/validate_block/implementation.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove encode_witness test function. * Update pallets/parachain-system/src/validate_block/implementation.rs * Fix compilation Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
Generated
+231
-231
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,7 @@ use sp_consensus::BlockStatus;
|
|||||||
use sp_core::traits::SpawnNamed;
|
use sp_core::traits::SpawnNamed;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
generic::BlockId,
|
generic::BlockId,
|
||||||
traits::{Block as BlockT, Header as HeaderT, Zero},
|
traits::{Block as BlockT, Header as HeaderT, Zero, HashFor},
|
||||||
};
|
};
|
||||||
|
|
||||||
use cumulus_client_consensus_common::ParachainConsensus;
|
use cumulus_client_consensus_common::ParachainConsensus;
|
||||||
@@ -225,8 +225,19 @@ where
|
|||||||
|
|
||||||
let (header, extrinsics) = candidate.block.deconstruct();
|
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.
|
// Create the parachain block data for the validators.
|
||||||
let b = ParachainBlockData::<Block>::new(header, extrinsics, candidate.proof);
|
let b = ParachainBlockData::<Block>::new(header, extrinsics, compact_proof);
|
||||||
|
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
target: LOG_TARGET,
|
target: LOG_TARGET,
|
||||||
@@ -440,7 +451,10 @@ mod tests {
|
|||||||
assert_eq!(1, *block.header().number());
|
assert_eq!(1, *block.header().number());
|
||||||
|
|
||||||
// Ensure that we did not include `:code` in the proof.
|
// Ensure that we did not include `:code` in the proof.
|
||||||
let db = block.storage_proof().clone().into_memory_db();
|
let db = block.storage_proof()
|
||||||
|
.to_storage_proof::<BlakeTwo256>(Some(header.state_root()))
|
||||||
|
.unwrap().0
|
||||||
|
.into_memory_db();
|
||||||
|
|
||||||
let backend =
|
let backend =
|
||||||
sp_state_machine::new_in_mem::<BlakeTwo256>().update_backend(*header.state_root(), db);
|
sp_state_machine::new_in_mem::<BlakeTwo256>().update_backend(*header.state_root(), db);
|
||||||
|
|||||||
@@ -138,9 +138,10 @@ where
|
|||||||
P::Signature: TryFrom<Vec<u8>> + Hash + Member + Encode + Decode,
|
P::Signature: TryFrom<Vec<u8>> + Hash + Member + Encode + Decode,
|
||||||
{
|
{
|
||||||
let worker =
|
let worker =
|
||||||
sc_consensus_aura::build_aura_worker::<P, _, _, _, _, _, _, _>(BuildAuraWorkerParams {
|
sc_consensus_aura::build_aura_worker::<P, _, _, _, _, _, _, _, _>(BuildAuraWorkerParams {
|
||||||
client: para_client,
|
client: para_client,
|
||||||
block_import: ParachainBlockImport::new(block_import),
|
block_import: ParachainBlockImport::new(block_import),
|
||||||
|
justification_sync_link: (),
|
||||||
proposer_factory,
|
proposer_factory,
|
||||||
sync_oracle,
|
sync_oracle,
|
||||||
force_authoring,
|
force_authoring,
|
||||||
|
|||||||
@@ -65,11 +65,17 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>, PSC: crate::Config>(
|
|||||||
"Invalid parent hash",
|
"Invalid parent hash",
|
||||||
);
|
);
|
||||||
|
|
||||||
let db = storage_proof.into_memory_db();
|
// Uncompress
|
||||||
let root = parent_head.state_root().clone();
|
let mut db = MemoryDB::default();
|
||||||
if !HashDB::<HashFor<B>, _>::contains(&db, &root, EMPTY_PREFIX) {
|
let root = match sp_trie::decode_compact::<sp_trie::Layout<HashFor<B>>, _, _>(
|
||||||
panic!("Witness data does not contain given storage root.");
|
&mut db,
|
||||||
}
|
storage_proof.iter_compact_encoded_nodes(),
|
||||||
|
Some(parent_head.state_root()),
|
||||||
|
) {
|
||||||
|
Ok(root) => root,
|
||||||
|
Err(_) => panic!("Compact proof decoding failure."),
|
||||||
|
};
|
||||||
|
|
||||||
let backend = sp_state_machine::TrieBackend::new(db, root);
|
let backend = sp_state_machine::TrieBackend::new(db, root);
|
||||||
let mut overlay = sp_state_machine::OverlayedChanges::default();
|
let mut overlay = sp_state_machine::OverlayedChanges::default();
|
||||||
let mut cache = Default::default();
|
let mut cache = Default::default();
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ fn create_test_client() -> (Client, LongestChain) {
|
|||||||
|
|
||||||
struct TestBlockData {
|
struct TestBlockData {
|
||||||
block: Block,
|
block: Block,
|
||||||
witness: sp_trie::StorageProof,
|
witness: sp_trie::CompactProof,
|
||||||
validation_data: PersistedValidationData,
|
validation_data: PersistedValidationData,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,11 +114,15 @@ fn build_block_with_witness(
|
|||||||
|
|
||||||
let built_block = builder.build().expect("Creates block");
|
let built_block = builder.build().expect("Creates block");
|
||||||
|
|
||||||
|
let witness = built_block
|
||||||
|
.proof
|
||||||
|
.expect("We enabled proof recording before.")
|
||||||
|
.into_compact_proof::<<Header as HeaderT>::Hashing>(*parent_head.state_root())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
TestBlockData {
|
TestBlockData {
|
||||||
block: built_block.block,
|
block: built_block.block,
|
||||||
witness: built_block
|
witness,
|
||||||
.proof
|
|
||||||
.expect("We enabled proof recording before."),
|
|
||||||
validation_data,
|
validation_data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ pub struct ParachainBlockData<B: BlockT> {
|
|||||||
/// The extrinsics of the parachain block.
|
/// The extrinsics of the parachain block.
|
||||||
extrinsics: sp_std::vec::Vec<B::Extrinsic>,
|
extrinsics: sp_std::vec::Vec<B::Extrinsic>,
|
||||||
/// The data that is required to emulate the storage accesses executed by all extrinsics.
|
/// The data that is required to emulate the storage accesses executed by all extrinsics.
|
||||||
storage_proof: sp_trie::StorageProof,
|
storage_proof: sp_trie::CompactProof,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BlockT> ParachainBlockData<B> {
|
impl<B: BlockT> ParachainBlockData<B> {
|
||||||
@@ -206,7 +206,7 @@ impl<B: BlockT> ParachainBlockData<B> {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
header: <B as BlockT>::Header,
|
header: <B as BlockT>::Header,
|
||||||
extrinsics: sp_std::vec::Vec<<B as BlockT>::Extrinsic>,
|
extrinsics: sp_std::vec::Vec<<B as BlockT>::Extrinsic>,
|
||||||
storage_proof: sp_trie::StorageProof,
|
storage_proof: sp_trie::CompactProof,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
header,
|
header,
|
||||||
@@ -235,13 +235,13 @@ impl<B: BlockT> ParachainBlockData<B> {
|
|||||||
&self.extrinsics
|
&self.extrinsics
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`StorageProof`](sp_trie::StorageProof).
|
/// Returns the [`CompactProof`](sp_trie::CompactProof).
|
||||||
pub fn storage_proof(&self) -> &sp_trie::StorageProof {
|
pub fn storage_proof(&self) -> &sp_trie::CompactProof {
|
||||||
&self.storage_proof
|
&self.storage_proof
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deconstruct into the inner parts.
|
/// Deconstruct into the inner parts.
|
||||||
pub fn deconstruct(self) -> (B::Header, sp_std::vec::Vec<B::Extrinsic>, sp_trie::StorageProof) {
|
pub fn deconstruct(self) -> (B::Header, sp_std::vec::Vec<B::Extrinsic>, sp_trie::CompactProof) {
|
||||||
(self.header, self.extrinsics, self.storage_proof)
|
(self.header, self.extrinsics, self.storage_proof)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user