mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
Switch to StorageProof (#160)
This commit is contained in:
@@ -324,7 +324,7 @@ where
|
|||||||
let b = ParachainBlockData::<Block>::new(
|
let b = ParachainBlockData::<Block>::new(
|
||||||
header.clone(),
|
header.clone(),
|
||||||
extrinsics,
|
extrinsics,
|
||||||
proof.iter_nodes().collect(),
|
proof,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut block_import_params = BlockImportParams::new(BlockOrigin::Own, header);
|
let mut block_import_params = BlockImportParams::new(BlockOrigin::Own, header);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use sp_runtime::traits::Block as BlockT;
|
use sp_runtime::traits::Block as BlockT;
|
||||||
use sp_std::vec::Vec;
|
use sp_std::vec::Vec;
|
||||||
|
use sp_trie::StorageProof;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@@ -29,9 +30,6 @@ pub use sp_std::slice;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod validate_block;
|
pub mod validate_block;
|
||||||
|
|
||||||
/// The witness data type.
|
|
||||||
type WitnessData = Vec<Vec<u8>>;
|
|
||||||
|
|
||||||
/// The parachain block that is created on a collator and validated by a validator.
|
/// The parachain block that is created on a collator and validated by a validator.
|
||||||
#[derive(Encode, Decode)]
|
#[derive(Encode, Decode)]
|
||||||
pub struct ParachainBlockData<B: BlockT> {
|
pub struct ParachainBlockData<B: BlockT> {
|
||||||
@@ -40,19 +38,19 @@ pub struct ParachainBlockData<B: BlockT> {
|
|||||||
/// The extrinsics of the parachain block without the `PolkadotInherent`.
|
/// The extrinsics of the parachain block without the `PolkadotInherent`.
|
||||||
extrinsics: Vec<<B as BlockT>::Extrinsic>,
|
extrinsics: Vec<<B as BlockT>::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.
|
||||||
witness_data: WitnessData,
|
storage_proof: StorageProof,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BlockT> ParachainBlockData<B> {
|
impl<B: BlockT> ParachainBlockData<B> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
header: <B as BlockT>::Header,
|
header: <B as BlockT>::Header,
|
||||||
extrinsics: Vec<<B as BlockT>::Extrinsic>,
|
extrinsics: Vec<<B as BlockT>::Extrinsic>,
|
||||||
witness_data: WitnessData,
|
storage_proof: StorageProof,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
header,
|
header,
|
||||||
extrinsics,
|
extrinsics,
|
||||||
witness_data,
|
storage_proof,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
//! The actual implementation of the validate block functionality.
|
//! The actual implementation of the validate block functionality.
|
||||||
|
|
||||||
use crate::WitnessData;
|
|
||||||
use frame_executive::ExecuteBlock;
|
use frame_executive::ExecuteBlock;
|
||||||
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
|
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
|
||||||
|
|
||||||
use sp_std::{boxed::Box, vec::Vec};
|
use sp_std::{boxed::Box, vec::Vec};
|
||||||
use sp_trie::{delta_trie_root, read_trie_value, Layout, MemoryDB};
|
use sp_trie::{delta_trie_root, read_trie_value, Layout, MemoryDB, StorageProof};
|
||||||
|
|
||||||
use hash_db::{HashDB, EMPTY_PREFIX};
|
use hash_db::{HashDB, EMPTY_PREFIX};
|
||||||
|
|
||||||
@@ -117,7 +116,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
|
|||||||
let validation_function_params = (¶ms).into();
|
let validation_function_params = (¶ms).into();
|
||||||
|
|
||||||
let storage_inner = WitnessStorage::<B>::new(
|
let storage_inner = WitnessStorage::<B>::new(
|
||||||
block_data.witness_data,
|
block_data.storage_proof,
|
||||||
parent_head.state_root().clone(),
|
parent_head.state_root().clone(),
|
||||||
validation_function_params,
|
validation_function_params,
|
||||||
)
|
)
|
||||||
@@ -181,14 +180,11 @@ impl<B: BlockT> WitnessStorage<B> {
|
|||||||
///
|
///
|
||||||
/// Returns an error if given storage root was not found in the witness data.
|
/// Returns an error if given storage root was not found in the witness data.
|
||||||
fn new(
|
fn new(
|
||||||
data: WitnessData,
|
storage_proof: StorageProof,
|
||||||
storage_root: B::Hash,
|
storage_root: B::Hash,
|
||||||
params: ValidationFunctionParams,
|
params: ValidationFunctionParams,
|
||||||
) -> Result<Self, &'static str> {
|
) -> Result<Self, &'static str> {
|
||||||
let mut db = MemoryDB::default();
|
let mut db = storage_proof.into_memory_db();
|
||||||
data.into_iter().for_each(|i| {
|
|
||||||
db.insert(EMPTY_PREFIX, &i);
|
|
||||||
});
|
|
||||||
|
|
||||||
if !HashDB::contains(&db, &storage_root, EMPTY_PREFIX) {
|
if !HashDB::contains(&db, &storage_root, EMPTY_PREFIX) {
|
||||||
return Err("Witness data does not contain given storage root.");
|
return Err("Witness data does not contain given storage root.");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{ParachainBlockData, WitnessData};
|
use crate::ParachainBlockData;
|
||||||
|
|
||||||
use parachain::primitives::{BlockData, HeadData, ValidationParams, ValidationResult};
|
use parachain::primitives::{BlockData, HeadData, ValidationParams, ValidationResult};
|
||||||
use sc_block_builder::BlockBuilderProvider;
|
use sc_block_builder::BlockBuilderProvider;
|
||||||
@@ -114,7 +114,7 @@ fn create_test_client() -> (Client, LongestChain) {
|
|||||||
fn build_block_with_proof(
|
fn build_block_with_proof(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
|
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
|
||||||
) -> (Block, WitnessData) {
|
) -> (Block, sp_trie::StorageProof) {
|
||||||
let block_id = BlockId::Hash(client.info().best_hash);
|
let block_id = BlockId::Hash(client.info().best_hash);
|
||||||
let mut builder = client
|
let mut builder = client
|
||||||
.new_block_at(&block_id, Default::default(), true)
|
.new_block_at(&block_id, Default::default(), true)
|
||||||
@@ -131,8 +131,6 @@ fn build_block_with_proof(
|
|||||||
built_block
|
built_block
|
||||||
.proof
|
.proof
|
||||||
.expect("We enabled proof recording before.")
|
.expect("We enabled proof recording before.")
|
||||||
.iter_nodes()
|
|
||||||
.collect(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user