Skip to content

Commit 475f2e1

Browse files
Change system chunk logging
1 parent f58b0a2 commit 475f2e1

File tree

6 files changed

+61
-48
lines changed

6 files changed

+61
-48
lines changed

engine/execution/computation/computer/computer.go

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ type collectionInfo struct {
3838

3939
collectionIndex int
4040
*entity.CompleteCollection
41-
42-
isSystemTransaction bool
4341
}
4442

4543
type TransactionRequest struct {
@@ -50,6 +48,8 @@ type TransactionRequest struct {
5048

5149
txnIndex uint32
5250

51+
isScheduledTransaction bool
52+
isSystemTransaction bool
5353
lastTransactionInCollection bool
5454

5555
ctx fvm.Context
@@ -62,6 +62,8 @@ func newTransactionRequest(
6262
collectionLogger zerolog.Logger,
6363
txnIndex uint32,
6464
txnBody *flow.TransactionBody,
65+
isScheduledTransaction bool,
66+
isSystemTransaction bool,
6567
lastTransactionInCollection bool,
6668
) TransactionRequest {
6769
txnId := txnBody.ID()
@@ -83,6 +85,8 @@ func newTransactionRequest(
8385
txnId,
8486
txnIndex,
8587
txnBody),
88+
isScheduledTransaction: isScheduledTransaction,
89+
isSystemTransaction: isSystemTransaction,
8690
lastTransactionInCollection: lastTransactionInCollection,
8791
}
8892
}
@@ -281,12 +285,11 @@ func (e *blockComputer) queueUserTransactions(
281285
Logger()
282286

283287
collectionInfo := collectionInfo{
284-
blockId: blockId,
285-
blockIdStr: blockIdStr,
286-
blockHeight: blockHeader.Height,
287-
collectionIndex: idx,
288-
CompleteCollection: collection,
289-
isSystemTransaction: false,
288+
blockId: blockId,
289+
blockIdStr: blockIdStr,
290+
blockHeight: blockHeader.Height,
291+
collectionIndex: idx,
292+
CompleteCollection: collection,
290293
}
291294

292295
for i, txnBody := range collection.Collection.Transactions {
@@ -296,7 +299,10 @@ func (e *blockComputer) queueUserTransactions(
296299
collectionLogger,
297300
txnIndex,
298301
txnBody,
299-
i == len(collection.Collection.Transactions)-1)
302+
false,
303+
false,
304+
i == len(collection.Collection.Transactions)-1,
305+
)
300306
txnIndex += 1
301307
}
302308
}
@@ -307,49 +313,52 @@ func (e *blockComputer) queueUserTransactions(
307313
func (e *blockComputer) queueSystemTransactions(
308314
callbackCtx fvm.Context,
309315
systemChunkCtx fvm.Context,
310-
systemColection collectionInfo,
316+
systemCollection collectionInfo,
311317
systemTxn *flow.TransactionBody,
312318
executeCallbackTxs []*flow.TransactionBody,
313319
txnIndex uint32,
314320
systemLogger zerolog.Logger,
315321
) chan TransactionRequest {
316-
var logger zerolog.Logger
317322

318-
systemChunkTxLogger := systemLogger.With().
319-
Uint32("num_txs", uint32(len(systemColection.CompleteCollection.Collection.Transactions))).
323+
systemTxLogger := systemLogger.With().
324+
Uint32("num_txs", uint32(len(systemCollection.CompleteCollection.Collection.Transactions))).
325+
Bool("system_transaction", true).
320326
Logger()
321327

322-
scheduledTxLogger := systemChunkTxLogger.With().
328+
scheduledTxLogger := systemLogger.With().
329+
Uint32("num_txs", uint32(len(systemCollection.CompleteCollection.Collection.Transactions))).
323330
Bool("scheduled_transaction", true).
324-
Bool("critical_error", false).
325331
Logger()
326332

327-
allTxs := append(executeCallbackTxs, systemTxn)
328-
txQueue := make(chan TransactionRequest, len(allTxs))
333+
txQueue := make(chan TransactionRequest, len(executeCallbackTxs)+1)
329334
defer close(txQueue)
330335

331-
for i, txBody := range allTxs {
332-
systemChunkTx := i == len(allTxs)-1 // last tx in collection is system chunk
333-
ctx := callbackCtx
334-
logger = scheduledTxLogger
335-
336-
if systemChunkTx {
337-
ctx = systemChunkCtx
338-
logger = systemChunkTxLogger
339-
}
340-
336+
for _, txBody := range executeCallbackTxs {
341337
txQueue <- newTransactionRequest(
342-
systemColection,
343-
ctx,
344-
logger,
338+
systemCollection,
339+
callbackCtx,
340+
scheduledTxLogger,
345341
txnIndex,
346342
txBody,
347-
systemChunkTx,
343+
true,
344+
false,
345+
false,
348346
)
349347

350348
txnIndex++
351349
}
352350

351+
txQueue <- newTransactionRequest(
352+
systemCollection,
353+
systemChunkCtx,
354+
systemTxLogger,
355+
txnIndex,
356+
systemTxn,
357+
false,
358+
true,
359+
true,
360+
)
361+
353362
return txQueue
354363
}
355364

@@ -495,20 +504,17 @@ func (e *blockComputer) executeSystemTransactions(
495504
)
496505

497506
systemCollectionInfo := collectionInfo{
498-
blockId: block.BlockID(),
499-
blockIdStr: block.BlockID().String(),
500-
blockHeight: block.Block.Height,
501-
collectionIndex: userCollectionCount,
502-
CompleteCollection: nil, // We do not yet know all the scheduled callbacks, so postpone construction of the collection.
503-
isSystemTransaction: true,
507+
blockId: block.BlockID(),
508+
blockIdStr: block.BlockID().String(),
509+
blockHeight: block.Block.Height,
510+
collectionIndex: userCollectionCount,
511+
CompleteCollection: nil, // We do not yet know all the scheduled callbacks, so postpone construction of the collection.
504512
}
505513

506-
systemLogger := callbackCtx.Logger.With().
514+
systemChunkLogger := callbackCtx.Logger.With().
507515
Str("block_id", block.BlockID().String()).
508516
Uint64("height", block.Block.Height).
509517
Bool("system_chunk", true).
510-
Bool("system_transaction", true).
511-
Bool("critical_error", true).
512518
Int("num_collections", userCollectionCount).
513519
Logger()
514520

@@ -528,7 +534,7 @@ func (e *blockComputer) executeSystemTransactions(
528534
database,
529535
blockSpan,
530536
txIndex,
531-
systemLogger,
537+
systemChunkLogger,
532538
)
533539
if err != nil {
534540
return err
@@ -565,7 +571,7 @@ func (e *blockComputer) executeSystemTransactions(
565571
e.systemTxn,
566572
callbackTxs,
567573
txIndex,
568-
systemLogger,
574+
systemChunkLogger,
569575
)
570576

571577
e.executeQueue(blockSpan, database, txQueue)
@@ -616,7 +622,7 @@ func (e *blockComputer) executeProcessCallback(
616622
systemLogger zerolog.Logger,
617623
) ([]*flow.TransactionBody, uint32, error) {
618624
callbackLogger := systemLogger.With().
619-
Bool("scheduled_transaction", true).
625+
Bool("system_transaction", true).
620626
Logger()
621627

622628
request := newTransactionRequest(
@@ -625,6 +631,8 @@ func (e *blockComputer) executeProcessCallback(
625631
callbackLogger,
626632
txnIndex,
627633
e.processCallbackTxn,
634+
false,
635+
true,
628636
false)
629637

630638
txnIndex++

engine/execution/computation/computer/computer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
586586
assert.LessOrEqual(t, vm.CallCount(), (1+totalTransactionCount)/2*totalTransactionCount)
587587
})
588588

589+
// TODO: this test is flaky with a low probability of failing
589590
t.Run(
590591
"service events are emitted", func(t *testing.T) {
591592
execCtx := fvm.NewContext(
@@ -1510,7 +1511,7 @@ func testScheduledCallbackWithError(t *testing.T, chain flow.Chain, callbackEven
15101511
exemetrics.On("ExecutionTransactionExecuted",
15111512
mock.Anything,
15121513
mock.MatchedBy(func(arg module.TransactionExecutionResultStats) bool {
1513-
return !arg.Failed && arg.SystemTransaction
1514+
return !arg.Failed && (arg.SystemTransaction || arg.ScheduledTransaction)
15141515
}),
15151516
mock.Anything).
15161517
Return(nil).

engine/execution/computation/computer/result_collector.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,9 @@ func (collector *resultCollector) processTransactionResult(
242242

243243
if txn.isSystemTransaction {
244244
// This log is used as the data source for an alert on grafana.
245-
// The system_chunk_error field must not be changed without adding
245+
// The critical_error field must not be changed without adding
246246
// the corresponding changes in grafana.
247-
// https://github.com/dapperlabs/flow-internal/issues/1546
248247
logger.Error().
249-
Bool("system_chunk_error", true).
250-
Bool("system_transaction_error", true).
251248
Bool("critical_error", true).
252249
Msg("error executing system chunk transaction")
253250
}
@@ -314,6 +311,7 @@ func (collector *resultCollector) handleTransactionExecutionMetrics(
314311
ComputationIntensities: output.ComputationIntensities,
315312
NumberOfTxnConflictRetries: numConflictRetries,
316313
Failed: output.Err != nil,
314+
ScheduledTransaction: txn.isScheduledTransaction,
317315
SystemTransaction: txn.isSystemTransaction,
318316
}
319317
for _, entry := range txnExecutionSnapshot.UpdatedRegisters() {

engine/execution/computation/computer/transaction_coordinator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func (db *testCoordinator) newTransaction(txnIndex uint32) (
122122
zerolog.Nop(),
123123
txnIndex,
124124
&flow.TransactionBody{},
125+
false,
126+
false,
125127
false),
126128
0)
127129
}

module/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ type TransactionExecutionResultStats struct {
946946
ExecutionResultStats
947947
NumberOfTxnConflictRetries int
948948
Failed bool
949+
ScheduledTransaction bool
949950
SystemTransaction bool
950951
ComputationIntensities meter.MeteredComputationIntensities
951952
}

utils/unittest/fvm.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ func IsServiceEvent(event flow.Event, chainID flow.ChainID) bool {
2323
func EnsureEventsIndexSeq(t *testing.T, events []flow.Event, chainID flow.ChainID) {
2424
expectedEventIndex := uint32(0)
2525
for _, event := range events {
26+
if expectedEventIndex != event.EventIndex {
27+
require.Equal(t, expectedEventIndex, event.EventIndex)
28+
}
2629
require.Equal(t, expectedEventIndex, event.EventIndex)
2730
expectedEventIndex++
2831
}

0 commit comments

Comments
 (0)