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

Commit 4219b3a

Browse files
cmichiathei
andauthored
Allow specifying immediate finalize for manual-seal (#12106)
Co-authored-by: Alexander Theißen <[email protected]>
1 parent d0214e7 commit 4219b3a

File tree

1 file changed

+54
-0
lines changed
  • client/consensus/manual-seal/src

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,60 @@ pub async fn run_instant_seal<B, BI, CB, E, C, TP, SC, CIDP, P>(
247247
.await
248248
}
249249

250+
/// Runs the background authorship task for the instant seal engine.
251+
/// instant-seal creates a new block for every transaction imported into
252+
/// the transaction pool.
253+
///
254+
/// This function will finalize the block immediately as well. If you don't
255+
/// want this behavior use `run_instant_seal` instead.
256+
pub async fn run_instant_seal_and_finalize<B, BI, CB, E, C, TP, SC, CIDP, P>(
257+
InstantSealParams {
258+
block_import,
259+
env,
260+
client,
261+
pool,
262+
select_chain,
263+
consensus_data_provider,
264+
create_inherent_data_providers,
265+
}: InstantSealParams<B, BI, E, C, TP, SC, CIDP, P>,
266+
) where
267+
B: BlockT + 'static,
268+
BI: BlockImport<B, Error = sp_consensus::Error, Transaction = sp_api::TransactionFor<C, B>>
269+
+ Send
270+
+ Sync
271+
+ 'static,
272+
C: HeaderBackend<B> + Finalizer<B, CB> + ProvideRuntimeApi<B> + 'static,
273+
CB: ClientBackend<B> + 'static,
274+
E: Environment<B> + 'static,
275+
E::Proposer: Proposer<B, Proof = P, Transaction = TransactionFor<C, B>>,
276+
SC: SelectChain<B> + 'static,
277+
TransactionFor<C, B>: 'static,
278+
TP: TransactionPool<Block = B>,
279+
CIDP: CreateInherentDataProviders<B, ()>,
280+
P: Send + Sync + 'static,
281+
{
282+
// Creates and finalizes blocks as soon as transactions are imported
283+
// into the transaction pool.
284+
let commands_stream = pool.import_notification_stream().map(|_| EngineCommand::SealNewBlock {
285+
create_empty: false,
286+
finalize: true,
287+
parent_hash: None,
288+
sender: None,
289+
});
290+
291+
run_manual_seal(ManualSealParams {
292+
block_import,
293+
env,
294+
client,
295+
pool,
296+
commands_stream,
297+
select_chain,
298+
consensus_data_provider,
299+
create_inherent_data_providers,
300+
})
301+
.await
302+
}
303+
250304
#[cfg(test)]
251305
mod tests {
252306
use super::*;

0 commit comments

Comments
 (0)