Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1631c8e

Browse files
rimbilibrelois
andauthored
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 <[email protected]>
1 parent a732a9a commit 1631c8e

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

client/consensus/manual-seal/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub async fn run_manual_seal<B, BI, CB, E, C, TP, SC, CS, CIDP, P>(
173173
SC: SelectChain<B> + 'static,
174174
TP: TransactionPool<Block = B>,
175175
CIDP: CreateInherentDataProviders<B, ()>,
176-
P: Send + Sync + 'static,
176+
P: codec::Encode + Send + Sync + 'static,
177177
{
178178
while let Some(command) = commands_stream.next().await {
179179
match command {
@@ -231,7 +231,7 @@ pub async fn run_instant_seal<B, BI, CB, E, C, TP, SC, CIDP, P>(
231231
SC: SelectChain<B> + 'static,
232232
TP: TransactionPool<Block = B>,
233233
CIDP: CreateInherentDataProviders<B, ()>,
234-
P: Send + Sync + 'static,
234+
P: codec::Encode + Send + Sync + 'static,
235235
{
236236
// instant-seal creates blocks as soon as transactions are imported
237237
// 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>(
281281
SC: SelectChain<B> + 'static,
282282
TP: TransactionPool<Block = B>,
283283
CIDP: CreateInherentDataProviders<B, ()>,
284-
P: Send + Sync + 'static,
284+
P: codec::Encode + Send + Sync + 'static,
285285
{
286286
// Creates and finalizes blocks as soon as transactions are imported
287287
// into the transaction pool.
@@ -459,7 +459,8 @@ mod tests {
459459
needs_justification: false,
460460
bad_justification: false,
461461
is_new_best: true,
462-
}
462+
},
463+
proof_size: 0
463464
}
464465
);
465466
// assert that there's a new block in the db.
@@ -549,7 +550,8 @@ mod tests {
549550
needs_justification: false,
550551
bad_justification: false,
551552
is_new_best: true,
552-
}
553+
},
554+
proof_size: created_block.proof_size
553555
}
554556
);
555557
// assert that there's a new block in the db.
@@ -625,7 +627,8 @@ mod tests {
625627
needs_justification: false,
626628
bad_justification: false,
627629
is_new_best: true,
628-
}
630+
},
631+
proof_size: 0
629632
}
630633
);
631634
// assert that there's a new block in the db.
@@ -711,7 +714,8 @@ mod tests {
711714
needs_justification: false,
712715
bad_justification: false,
713716
is_new_best: true
714-
}
717+
},
718+
proof_size: 0
715719
}
716720
);
717721

client/consensus/manual-seal/src/rpc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub struct CreatedBlock<Hash> {
9797
pub hash: Hash,
9898
/// some extra details about the import operation
9999
pub aux: ImportedAux,
100+
/// uncompacted storage proof size (zero mean that there is no proof)
101+
pub proof_size: usize,
100102
}
101103

102104
impl<Hash> ManualSeal<Hash> {

client/consensus/manual-seal/src/seal_block.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
8383
TP: TransactionPool<Block = B>,
8484
SC: SelectChain<B>,
8585
CIDP: CreateInherentDataProviders<B, ()>,
86-
P: Send + Sync + 'static,
86+
P: codec::Encode + Send + Sync + 'static,
8787
{
8888
let future = async {
8989
if pool.status().ready == 0 && !create_empty {
@@ -131,6 +131,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
131131

132132
let (header, body) = proposal.block.deconstruct();
133133
let proof = proposal.proof;
134+
let proof_size = proof.encoded_size();
134135
let mut params = BlockImportParams::new(BlockOrigin::Own, header.clone());
135136
params.body = Some(body);
136137
params.finalized = finalize;
@@ -149,8 +150,11 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP, P>(
149150
post_header.digest_mut().logs.extend(params.post_digests.iter().cloned());
150151

151152
match block_import.import_block(params).await? {
152-
ImportResult::Imported(aux) =>
153-
Ok(CreatedBlock { hash: <B as BlockT>::Header::hash(&post_header), aux }),
153+
ImportResult::Imported(aux) => Ok(CreatedBlock {
154+
hash: <B as BlockT>::Header::hash(&post_header),
155+
aux,
156+
proof_size,
157+
}),
154158
other => Err(other.into()),
155159
}
156160
};

0 commit comments

Comments
 (0)