@@ -27,6 +27,7 @@ import { IncomingMessagesService } from "../../../settlement/messages/IncomingMe
2727import { Tracer } from "../../../logging/Tracer" ;
2828import { trace } from "../../../logging/trace" ;
2929import { AsyncLinkedLeafStore } from "../../../state/async/AsyncLinkedLeafStore" ;
30+ import { ensureNotBusy } from "../../../helpers/BusyGuard" ;
3031
3132import { BlockProductionService } from "./BlockProductionService" ;
3233import { BlockResultService } from "./BlockResultService" ;
@@ -38,8 +39,6 @@ export interface BlockConfig {
3839
3940@sequencerModule ( )
4041export class BlockProducerModule extends SequencerModule < BlockConfig > {
41- private productionInProgress = false ;
42-
4342 public constructor (
4443 @inject ( "Mempool" ) private readonly mempool : Mempool ,
4544 @inject ( "IncomingMessagesService" , { isOptional : true } )
@@ -140,37 +139,25 @@ export class BlockProducerModule extends SequencerModule<BlockConfig> {
140139 return result ;
141140 }
142141
142+ @ensureNotBusy ( )
143143 public async tryProduceBlock ( ) : Promise < Block | undefined > {
144- if ( ! this . productionInProgress ) {
145- try {
146- const block = await this . produceBlock ( ) ;
147-
148- if ( block === undefined ) {
149- if ( ! this . allowEmptyBlock ( ) ) {
150- log . info ( "No transactions in mempool, skipping production" ) ;
151- } else {
152- log . error ( "Something wrong happened, skipping block" ) ;
153- }
154- return undefined ;
155- }
144+ const block = await this . produceBlock ( ) ;
156145
157- log . info (
158- `Produced block #${ block . height . toBigInt ( ) } (${ block . transactions . length } txs)`
159- ) ;
160- this . prettyPrintBlockContents ( block ) ;
161-
162- return block ;
163- } catch ( error : unknown ) {
164- if ( error instanceof Error ) {
165- throw error ;
166- } else {
167- log . error ( error ) ;
168- }
169- } finally {
170- this . productionInProgress = false ;
146+ if ( block === undefined ) {
147+ if ( ! this . allowEmptyBlock ( ) ) {
148+ log . info ( "No transactions in mempool, skipping production" ) ;
149+ } else {
150+ log . error ( "Something wrong happened, skipping block" ) ;
171151 }
152+ return undefined ;
172153 }
173- return undefined ;
154+
155+ log . info (
156+ `Produced block #${ block . height . toBigInt ( ) } (${ block . transactions . length } txs)`
157+ ) ;
158+ this . prettyPrintBlockContents ( block ) ;
159+
160+ return block ;
174161 }
175162
176163 // TODO Move to different service, to remove dependency on mempool and messagequeue
@@ -220,8 +207,6 @@ export class BlockProducerModule extends SequencerModule<BlockConfig> {
220207
221208 @trace ( "block" )
222209 private async produceBlock ( ) : Promise < Block | undefined > {
223- this . productionInProgress = true ;
224-
225210 const { txs, metadata } = await this . collectProductionData ( ) ;
226211
227212 // Skip production if no transactions are available for now
@@ -263,8 +248,6 @@ export class BlockProducerModule extends SequencerModule<BlockConfig> {
263248 ) ;
264249 }
265250
266- this . productionInProgress = false ;
267-
268251 return blockResult ?. block ;
269252 }
270253
0 commit comments