From 574592d1cff483718463da84273e4c42f616fa79 Mon Sep 17 00:00:00 2001 From: Cem Eliguzel <cemeliguzel@gmail.com> Date: Wed, 23 Aug 2023 15:06:50 +0300 Subject: [PATCH] return proof size on manually created blocks (for tests only) (#14650) * return proof size on manually created blocks (for tests only) * Fix the build error in the test --------- Co-authored-by: librelois <c@elo.tf> --- .../client/consensus/manual-seal/src/lib.rs | 18 +++++++++++------- .../client/consensus/manual-seal/src/rpc.rs | 2 ++ .../consensus/manual-seal/src/seal_block.rs | 10 +++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/substrate/client/consensus/manual-seal/src/lib.rs b/substrate/client/consensus/manual-seal/src/lib.rs index c3b891b84e8..1e5db966e66 100644 --- a/substrate/client/consensus/manual-seal/src/lib.rs +++ b/substrate/client/consensus/manual-seal/src/lib.rs @@ -173,7 +173,7 @@ pub async fn run_manual_seal<B, BI, CB, E, C, TP, SC, CS, CIDP, P>( SC: SelectChain<B> + 'static, TP: TransactionPool<Block = B>, CIDP: CreateInherentDataProviders<B, ()>, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { while let Some(command) = commands_stream.next().await { match command { @@ -231,7 +231,7 @@ pub async fn run_instant_seal<B, BI, CB, E, C, TP, SC, CIDP, P>( SC: SelectChain<B> + 'static, TP: TransactionPool<Block = B>, CIDP: CreateInherentDataProviders<B, ()>, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { // instant-seal creates blocks as soon as transactions are imported // into the transaction pool. @@ -281,7 +281,7 @@ pub async fn run_instant_seal_and_finalize<B, BI, CB, E, C, TP, SC, CIDP, P>( SC: SelectChain<B> + 'static, TP: TransactionPool<Block = B>, CIDP: CreateInherentDataProviders<B, ()>, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { // Creates and finalizes blocks as soon as transactions are imported // into the transaction pool. @@ -459,7 +459,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true, - } + }, + proof_size: 0 } ); // assert that there's a new block in the db. @@ -549,7 +550,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true, - } + }, + proof_size: created_block.proof_size } ); // assert that there's a new block in the db. @@ -625,7 +627,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true, - } + }, + proof_size: 0 } ); // assert that there's a new block in the db. @@ -711,7 +714,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true - } + }, + proof_size: 0 } ); diff --git a/substrate/client/consensus/manual-seal/src/rpc.rs b/substrate/client/consensus/manual-seal/src/rpc.rs index 85abcdc0857..c0b3af69bed 100644 --- a/substrate/client/consensus/manual-seal/src/rpc.rs +++ b/substrate/client/consensus/manual-seal/src/rpc.rs @@ -97,6 +97,8 @@ pub struct CreatedBlock<Hash> { pub hash: Hash, /// some extra details about the import operation pub aux: ImportedAux, + /// uncompacted storage proof size (zero mean that there is no proof) + pub proof_size: usize, } impl<Hash> ManualSeal<Hash> { diff --git a/substrate/client/consensus/manual-seal/src/seal_block.rs b/substrate/client/consensus/manual-seal/src/seal_block.rs index 4b6230c3efc..716e889ec03 100644 --- a/substrate/client/consensus/manual-seal/src/seal_block.rs +++ b/substrate/client/consensus/manual-seal/src/seal_block.rs @@ -83,7 +83,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>( TP: TransactionPool<Block = B>, SC: SelectChain<B>, CIDP: CreateInherentDataProviders<B, ()>, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { let future = async { if pool.status().ready == 0 && !create_empty { @@ -131,6 +131,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>( let (header, body) = proposal.block.deconstruct(); let proof = proposal.proof; + let proof_size = proof.encoded_size(); let mut params = BlockImportParams::new(BlockOrigin::Own, header.clone()); params.body = Some(body); params.finalized = finalize; @@ -149,8 +150,11 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>( post_header.digest_mut().logs.extend(params.post_digests.iter().cloned()); match block_import.import_block(params).await? { - ImportResult::Imported(aux) => - Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&post_header), aux }), + ImportResult::Imported(aux) => Ok(CreatedBlock { + hash: <B as BlockT>::Header::hash(&post_header), + aux, + proof_size, + }), other => Err(other.into()), } }; -- GitLab