Skip to content

Commit

Permalink
Fixed da BlockImport validation (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToufeeqP authored Jan 31, 2024
1 parent aac4398 commit f9a6b6b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions node/src/da_block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use sc_consensus::{
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_consensus::{BlockOrigin, Error as ConsensusError};
use sp_core::H256;
use sp_runtime::traits::Block as BlockT;

#[derive(Constructor)]
Expand All @@ -51,7 +52,7 @@ impl<BE, C, I: Clone> Clone for BlockImport<BE, C, I> {
#[async_trait::async_trait]
impl<B, BE, C, I> BlockImportT<B> for BlockImport<BE, C, I>
where
B: BlockT<Extrinsic = OpaqueExtrinsic, Header = DaHeader>,
B: BlockT<Extrinsic = OpaqueExtrinsic, Header = DaHeader, Hash = H256>,
BE: Backend<B>,
I: BlockImportT<B> + Clone + Send + Sync,
I::Error: Into<ConsensusError>,
Expand Down Expand Up @@ -82,7 +83,7 @@ where

let extrinsics = block.body.as_ref().unwrap_or(&vec![]).clone();

let best_hash = self.client.info().best_hash;
let parent_hash = <B as BlockT>::Hash::from(block.header.parent_hash);
let extension = &block.header.extension.clone();

let (block_number, import_block_hash) = (block.header.number, block.post_hash());
Expand All @@ -98,7 +99,7 @@ where

let success = build_data_root_and_extension(
self,
best_hash,
parent_hash,
import_block_hash,
extrinsics,
extension,
Expand Down Expand Up @@ -133,7 +134,7 @@ where

fn build_data_root_and_extension<B, BE, C, I>(
block_import: &BlockImport<BE, C, I>,
best_hash: <B as BlockT>::Hash,
parent_hash: <B as BlockT>::Hash,
import_block_hash: <B as BlockT>::Hash,
extrinsics: Vec<OpaqueExtrinsic>,
extension: &avail_core::header::HeaderExtension,
Expand Down Expand Up @@ -166,13 +167,19 @@ where
let data_root = block_import
.client
.runtime_api()
.build_data_root(best_hash, extrinsics.clone())
.build_data_root(parent_hash, extrinsics.clone())
.map_err(|e| ClientImport(format!("Data root cannot be calculated: {e:?}")))?;

block_import
.client
.runtime_api()
.build_extension(best_hash, extrinsics, data_root, block_length, block_number)
.build_extension(
parent_hash,
extrinsics,
data_root,
block_length,
block_number,
)
.map_err(|e| ClientImport(format!("Build extension fails due to: {e:?}")))?
},
_ => {
Expand All @@ -198,14 +205,14 @@ where
let data_root = block_import
.client
.runtime_api()
.build_data_root_v2(best_hash, successful_extrinsics.clone())
.build_data_root_v2(parent_hash, successful_extrinsics.clone())
.map_err(|e| ClientImport(format!("Data root cannot be calculated: {e:?}")))?;

block_import
.client
.runtime_api()
.build_versioned_extension(
best_hash,
parent_hash,
successful_extrinsics,
data_root,
block_length,
Expand Down

2 comments on commit f9a6b6b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f9a6b6b Previous: 33f7951 Ratio
commitment_builder/32 4328912423 ns/iter (± 120337078) 4325417137 ns/iter (± 81695432) 1.00
commitment_builder/64 4313612716 ns/iter (± 58335116) 4343451680 ns/iter (± 92231152) 0.99
commitment_builder/128 4968354638 ns/iter (± 188709804) 4647446215 ns/iter (± 137494514) 1.07
commitment_builder/256 2430965284 ns/iter (± 64152567) 2367397557 ns/iter (± 42776582) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f9a6b6b Previous: 909af7f Ratio
commitment_builder_32 Instructions 43507375676 ops (± 0) 43503093041 ops (± 0) 1.00
commitment_builder_32 L1 Accesses 53519318169 ops (± 0) 53514815042 ops (± 0) 1.00
commitment_builder_32 L2 Accesses 730522 ops (± 0) 700403 ops (± 0) 1.04
commitment_builder_32 RAM Accesses 92150 ops (± 0) 89904 ops (± 0) 1.02
commitment_builder_32 Estimated Cycles 53526196029 ops (± 0) 53521463697 ops (± 0) 1.00
commitment_builder_64 Instructions 41976513171 ops (± 0) 41972869826 ops (± 0) 1.00
commitment_builder_64 L1 Accesses 51411518019 ops (± 0) 51407870438 ops (± 0) 1.00
commitment_builder_64 L2 Accesses 869747 ops (± 0) 893120 ops (± 0) 0.97
commitment_builder_64 RAM Accesses 190536 ops (± 0) 191298 ops (± 0) 1.00
commitment_builder_64 Estimated Cycles 51422535514 ops (± 0) 51419031468 ops (± 0) 1.00
commitment_builder_128 Instructions 54208190662 ops (± 0) 54204175550 ops (± 0) 1.00
commitment_builder_128 L1 Accesses 68306061500 ops (± 0) 68301951624 ops (± 0) 1.00
commitment_builder_128 L2 Accesses 1299971 ops (± 0) 1258510 ops (± 0) 1.03
commitment_builder_128 RAM Accesses 243643 ops (± 0) 242507 ops (± 0) 1.00
commitment_builder_128 Estimated Cycles 68321088860 ops (± 0) 68316731919 ops (± 0) 1.00
commitment_builder_256 Instructions 31760370633 ops (± 0) 31758548180 ops (± 0) 1.00
commitment_builder_256 L1 Accesses 40835156440 ops (± 0) 40833274463 ops (± 0) 1.00
commitment_builder_256 L2 Accesses 6797717 ops (± 0) 6788005 ops (± 0) 1.00
commitment_builder_256 RAM Accesses 253721 ops (± 0) 239352 ops (± 0) 1.06
commitment_builder_256 Estimated Cycles 40878025260 ops (± 0) 40875591808 ops (± 0) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.