@@ -111,6 +111,7 @@ type blockComputer struct {
111111 tracer module.Tracer
112112 log zerolog.Logger
113113 systemTxn * flow.TransactionBody
114+ processCallbackTxn * flow.TransactionBody
114115 committer ViewCommitter
115116 executionDataProvider provider.Provider
116117 signer module.Local
@@ -184,6 +185,8 @@ func NewBlockComputer(
184185 return nil , fmt .Errorf ("could not build system chunk transaction: %w" , err )
185186 }
186187
188+ processCallbackTxn := blueprints .ProcessCallbacksTransaction (vmCtx .Chain )
189+
187190 return & blockComputer {
188191 vm : vm ,
189192 vmCtx : vmCtx ,
@@ -193,6 +196,7 @@ func NewBlockComputer(
193196 tracer : tracer ,
194197 log : logger ,
195198 systemTxn : systemTxn ,
199+ processCallbackTxn : processCallbackTxn ,
196200 committer : committer ,
197201 executionDataProvider : executionDataProvider ,
198202 signer : signer ,
@@ -241,8 +245,11 @@ func (e *blockComputer) queueUserTransactions(
241245 blockId flow.Identifier ,
242246 blockHeader * flow.Header ,
243247 rawCollections []* entity.CompleteCollection ,
244- requestQueue chan TransactionRequest ,
245- ) {
248+ userTxCount int ,
249+ ) chan TransactionRequest {
250+ txQueue := make (chan TransactionRequest , userTxCount )
251+ defer close (txQueue )
252+
246253 txnIndex := uint32 (0 )
247254 blockIdStr := blockId .String ()
248255
@@ -270,7 +277,7 @@ func (e *blockComputer) queueUserTransactions(
270277 }
271278
272279 for i , txnBody := range collection .Transactions {
273- requestQueue <- newTransactionRequest (
280+ txQueue <- newTransactionRequest (
274281 collectionInfo ,
275282 collectionCtx ,
276283 collectionLogger ,
@@ -280,6 +287,8 @@ func (e *blockComputer) queueUserTransactions(
280287 txnIndex += 1
281288 }
282289 }
290+
291+ return txQueue
283292}
284293
285294func (e * blockComputer ) queueSystemTransactions (
@@ -288,16 +297,18 @@ func (e *blockComputer) queueSystemTransactions(
288297 systemColection collectionInfo ,
289298 systemTxn * flow.TransactionBody ,
290299 executeCallbackTxs []* flow.TransactionBody ,
291- requestQueue chan TransactionRequest ,
292300 txnIndex uint32 ,
293301 systemLogger zerolog.Logger ,
294- ) {
302+ ) chan TransactionRequest {
295303 allTxs := append (executeCallbackTxs , systemTxn )
296304 // add execute callback transactions to the system collection info along to existing process transaction
297305 systemTxs := systemColection .CompleteCollection .Transactions
298306 systemColection .CompleteCollection .Transactions = append (systemTxs , allTxs ... )
299307 systemLogger = systemLogger .With ().Uint32 ("num_txs" , uint32 (len (systemTxs ))).Logger ()
300308
309+ txQueue := make (chan TransactionRequest , len (allTxs ))
310+ defer close (txQueue )
311+
301312 for i , txBody := range allTxs {
302313 last := i == len (allTxs )- 1
303314 ctx := callbackCtx
@@ -306,7 +317,7 @@ func (e *blockComputer) queueSystemTransactions(
306317 ctx = systemChunkCtx
307318 }
308319
309- requestQueue <- newTransactionRequest (
320+ txQueue <- newTransactionRequest (
310321 systemColection ,
311322 ctx ,
312323 systemLogger ,
@@ -317,6 +328,8 @@ func (e *blockComputer) queueSystemTransactions(
317328
318329 txnIndex ++
319330 }
331+
332+ return txQueue
320333}
321334
322335func (e * blockComputer ) executeBlock (
@@ -415,17 +428,13 @@ func (e *blockComputer) executeUserTransactions(
415428 rawCollections []* entity.CompleteCollection ,
416429 userTxCount int ,
417430) {
418- txQueue := make (chan TransactionRequest , userTxCount )
419-
420- e .queueUserTransactions (
431+ txQueue := e .queueUserTransactions (
421432 block .ID (),
422433 block .Block .Header ,
423434 rawCollections ,
424- txQueue ,
435+ userTxCount ,
425436 )
426437
427- close (txQueue )
428-
429438 e .executeQueue (blockSpan , database , txQueue )
430439}
431440
@@ -479,10 +488,9 @@ func (e *blockComputer) executeSystemTransactions(
479488 }
480489
481490 var callbackTxs []* flow.TransactionBody
482- var err error
483491
484492 if e .vmCtx .ScheduleCallbacksEnabled {
485- callbackTxs , err = e .executeProcessCallback (
493+ callbacks , updatedTxnIndex , err : = e .executeProcessCallback (
486494 callbackCtx ,
487495 systemCollectionInfo ,
488496 database ,
@@ -494,25 +502,20 @@ func (e *blockComputer) executeSystemTransactions(
494502 return err
495503 }
496504
497- txIndex ++
505+ callbackTxs = callbacks
506+ txIndex = updatedTxnIndex
498507 }
499508
500- // queue size for callback transactions + 1 system transaction (process callback already executed)
501- txQueue := make (chan TransactionRequest , len (callbackTxs )+ 1 )
502-
503- e .queueSystemTransactions (
509+ txQueue := e .queueSystemTransactions (
504510 callbackCtx ,
505511 systemChunkCtx ,
506512 systemCollectionInfo ,
507513 e .systemTxn ,
508514 callbackTxs ,
509- txQueue ,
510515 txIndex ,
511516 systemLogger ,
512517 )
513518
514- close (txQueue )
515-
516519 e .executeQueue (blockSpan , database , txQueue )
517520
518521 return nil
@@ -549,28 +552,28 @@ func (e *blockComputer) executeProcessCallback(
549552 blockSpan otelTrace.Span ,
550553 txnIndex uint32 ,
551554 systemLogger zerolog.Logger ,
552- ) ([]* flow.TransactionBody , error ) {
553- processTxn := blueprints .ProcessCallbacksTransaction (e .vmCtx .Chain )
554-
555+ ) ([]* flow.TransactionBody , uint32 , error ) {
555556 // add process callback transaction to the system collection info
556- systemCollectionInfo .CompleteCollection .Transactions = append (systemCollectionInfo .CompleteCollection .Transactions , processTxn )
557+ systemCollectionInfo .CompleteCollection .Transactions = append (systemCollectionInfo .CompleteCollection .Transactions , e . processCallbackTxn )
557558
558559 request := newTransactionRequest (
559560 systemCollectionInfo ,
560561 systemCtx ,
561562 systemLogger ,
562563 txnIndex ,
563- processTxn ,
564+ e . processCallbackTxn ,
564565 false )
565566
567+ txnIndex ++
568+
566569 txn , err := e .executeTransactionInternal (blockSpan , database , request , 0 )
567570 if err != nil {
568571 snapshotTime := logical .Time (0 )
569572 if txn != nil {
570573 snapshotTime = txn .SnapshotTime ()
571574 }
572575
573- return nil , fmt .Errorf (
576+ return nil , 0 , fmt .Errorf (
574577 "failed to execute %s transaction %v (%d@%d) for block %s at height %v: %w" ,
575578 "system" ,
576579 request .txnIdStr ,
@@ -582,13 +585,18 @@ func (e *blockComputer) executeProcessCallback(
582585 }
583586
584587 if txn .Output ().Err != nil {
585- return nil , fmt .Errorf (
588+ return nil , 0 , fmt .Errorf (
586589 "process callback transaction %s error: %v" ,
587590 request .txnIdStr ,
588591 txn .Output ().Err )
589592 }
590593
591- return blueprints .ExecuteCallbacksTransactions (e .vmCtx .Chain , txn .Output ().Events )
594+ callbackTxs , err := blueprints .ExecuteCallbacksTransactions (e .vmCtx .Chain , txn .Output ().Events )
595+ if err != nil {
596+ return nil , 0 , err
597+ }
598+
599+ return callbackTxs , txnIndex , nil
592600}
593601
594602func (e * blockComputer ) executeTransactions (
0 commit comments