mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
Refactor validate_block (#2069)
* Refactor `validate_block` This pull request changes the `validate_block` implementation. One of the key changes are that we free data structures as early as possible. The memory while validating the block is scarce and we need to give as much as possible to the actual execution of the block. Besides that the pr moves the validation of the `validation_data` into the `validate_block` implementation completely instead of using this machinery with putting the data into some global variable that would then be read while executing the block. There are also some new docs to explain the internals of `validate_block`. * No clone wars!! * Integrate more feedback * FMT * Delay the header encoding
This commit is contained in:
@@ -114,11 +114,20 @@ pub fn register_validate_block(input: proc_macro::TokenStream) -> proc_macro::To
|
||||
use super::*;
|
||||
|
||||
#[no_mangle]
|
||||
unsafe fn validate_block(arguments: *const u8, arguments_len: usize) -> u64 {
|
||||
let params = #crate_::validate_block::polkadot_parachain::load_params(
|
||||
arguments,
|
||||
arguments_len,
|
||||
unsafe fn validate_block(arguments: *mut u8, arguments_len: usize) -> u64 {
|
||||
// We convert the `arguments` into a boxed slice and then into `Bytes`.
|
||||
let args = #crate_::validate_block::sp_std::boxed::Box::from_raw(
|
||||
#crate_::validate_block::sp_std::slice::from_raw_parts_mut(
|
||||
arguments,
|
||||
arguments_len,
|
||||
)
|
||||
);
|
||||
let args = #crate_::validate_block::bytes::Bytes::from(args);
|
||||
|
||||
// Then we decode from these bytes the `MemoryOptimizedValidationParams`.
|
||||
let params = #crate_::validate_block::decode_from_bytes::<
|
||||
#crate_::validate_block::MemoryOptimizedValidationParams
|
||||
>(args).expect("Invalid arguments to `validate_block`.");
|
||||
|
||||
let res = #crate_::validate_block::implementation::validate_block::<
|
||||
<#runtime as #crate_::validate_block::GetRuntimeBlockType>::RuntimeBlock,
|
||||
|
||||
Reference in New Issue
Block a user