mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Switch to StorageProof (#160)
This commit is contained in:
@@ -324,7 +324,7 @@ where
|
||||
let b = ParachainBlockData::<Block>::new(
|
||||
header.clone(),
|
||||
extrinsics,
|
||||
proof.iter_nodes().collect(),
|
||||
proof,
|
||||
);
|
||||
|
||||
let mut block_import_params = BlockImportParams::new(BlockOrigin::Own, header);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
use codec::{Decode, Encode};
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_std::vec::Vec;
|
||||
use sp_trie::StorageProof;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[doc(hidden)]
|
||||
@@ -29,9 +30,6 @@ pub use sp_std::slice;
|
||||
#[macro_use]
|
||||
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.
|
||||
#[derive(Encode, Decode)]
|
||||
pub struct ParachainBlockData<B: BlockT> {
|
||||
@@ -40,19 +38,19 @@ pub struct ParachainBlockData<B: BlockT> {
|
||||
/// The extrinsics of the parachain block without the `PolkadotInherent`.
|
||||
extrinsics: Vec<<B as BlockT>::Extrinsic>,
|
||||
/// 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> {
|
||||
pub fn new(
|
||||
header: <B as BlockT>::Header,
|
||||
extrinsics: Vec<<B as BlockT>::Extrinsic>,
|
||||
witness_data: WitnessData,
|
||||
storage_proof: StorageProof,
|
||||
) -> Self {
|
||||
Self {
|
||||
header,
|
||||
extrinsics,
|
||||
witness_data,
|
||||
storage_proof,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
//! The actual implementation of the validate block functionality.
|
||||
|
||||
use crate::WitnessData;
|
||||
use frame_executive::ExecuteBlock;
|
||||
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
|
||||
|
||||
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};
|
||||
|
||||
@@ -117,7 +116,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
|
||||
let validation_function_params = (¶ms).into();
|
||||
|
||||
let storage_inner = WitnessStorage::<B>::new(
|
||||
block_data.witness_data,
|
||||
block_data.storage_proof,
|
||||
parent_head.state_root().clone(),
|
||||
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.
|
||||
fn new(
|
||||
data: WitnessData,
|
||||
storage_proof: StorageProof,
|
||||
storage_root: B::Hash,
|
||||
params: ValidationFunctionParams,
|
||||
) -> Result<Self, &'static str> {
|
||||
let mut db = MemoryDB::default();
|
||||
data.into_iter().for_each(|i| {
|
||||
db.insert(EMPTY_PREFIX, &i);
|
||||
});
|
||||
let mut db = storage_proof.into_memory_db();
|
||||
|
||||
if !HashDB::contains(&db, &storage_root, EMPTY_PREFIX) {
|
||||
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
|
||||
// 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 sc_block_builder::BlockBuilderProvider;
|
||||
@@ -114,7 +114,7 @@ fn create_test_client() -> (Client, LongestChain) {
|
||||
fn build_block_with_proof(
|
||||
client: &Client,
|
||||
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
|
||||
) -> (Block, WitnessData) {
|
||||
) -> (Block, sp_trie::StorageProof) {
|
||||
let block_id = BlockId::Hash(client.info().best_hash);
|
||||
let mut builder = client
|
||||
.new_block_at(&block_id, Default::default(), true)
|
||||
@@ -131,8 +131,6 @@ fn build_block_with_proof(
|
||||
built_block
|
||||
.proof
|
||||
.expect("We enabled proof recording before.")
|
||||
.iter_nodes()
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user