Skip to content

Commit 0562459

Browse files
add transaction type enum
1 parent 475f2e1 commit 0562459

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

engine/execution/computation/computer/computer.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ type collectionInfo struct {
4040
*entity.CompleteCollection
4141
}
4242

43+
type ComputerTransactionType uint
44+
45+
const (
46+
ComputerTransactionTypeUser ComputerTransactionType = iota
47+
ComputerTransactionTypeSystem
48+
ComputerTransactionTypeScheduled
49+
)
50+
4351
type TransactionRequest struct {
4452
collectionInfo
4553

@@ -48,8 +56,7 @@ type TransactionRequest struct {
4856

4957
txnIndex uint32
5058

51-
isScheduledTransaction bool
52-
isSystemTransaction bool
59+
transactionType ComputerTransactionType
5360
lastTransactionInCollection bool
5461

5562
ctx fvm.Context
@@ -62,8 +69,7 @@ func newTransactionRequest(
6269
collectionLogger zerolog.Logger,
6370
txnIndex uint32,
6471
txnBody *flow.TransactionBody,
65-
isScheduledTransaction bool,
66-
isSystemTransaction bool,
72+
transactionType ComputerTransactionType,
6773
lastTransactionInCollection bool,
6874
) TransactionRequest {
6975
txnId := txnBody.ID()
@@ -85,8 +91,7 @@ func newTransactionRequest(
8591
txnId,
8692
txnIndex,
8793
txnBody),
88-
isScheduledTransaction: isScheduledTransaction,
89-
isSystemTransaction: isSystemTransaction,
94+
transactionType: transactionType,
9095
lastTransactionInCollection: lastTransactionInCollection,
9196
}
9297
}
@@ -299,8 +304,7 @@ func (e *blockComputer) queueUserTransactions(
299304
collectionLogger,
300305
txnIndex,
301306
txnBody,
302-
false,
303-
false,
307+
ComputerTransactionTypeUser,
304308
i == len(collection.Collection.Transactions)-1,
305309
)
306310
txnIndex += 1
@@ -340,8 +344,7 @@ func (e *blockComputer) queueSystemTransactions(
340344
scheduledTxLogger,
341345
txnIndex,
342346
txBody,
343-
true,
344-
false,
347+
ComputerTransactionTypeScheduled,
345348
false,
346349
)
347350

@@ -354,8 +357,7 @@ func (e *blockComputer) queueSystemTransactions(
354357
systemTxLogger,
355358
txnIndex,
356359
systemTxn,
357-
false,
358-
true,
360+
ComputerTransactionTypeSystem,
359361
true,
360362
)
361363

@@ -631,8 +633,7 @@ func (e *blockComputer) executeProcessCallback(
631633
callbackLogger,
632634
txnIndex,
633635
e.processCallbackTxn,
634-
false,
635-
true,
636+
ComputerTransactionTypeSystem,
636637
false)
637638

638639
txnIndex++
@@ -733,7 +734,7 @@ func (e *blockComputer) executeTransaction(
733734
attempt)
734735
if err != nil {
735736
prefix := ""
736-
if request.isSystemTransaction {
737+
if request.transactionType == ComputerTransactionTypeSystem {
737738
prefix = "system "
738739
}
739740

engine/execution/computation/computer/result_collector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (collector *resultCollector) processTransactionResult(
240240
Logger()
241241
logger.Info().Msg("transaction execution failed")
242242

243-
if txn.isSystemTransaction {
243+
if txn.transactionType == ComputerTransactionTypeSystem {
244244
// This log is used as the data source for an alert on grafana.
245245
// The critical_error field must not be changed without adding
246246
// the corresponding changes in grafana.
@@ -311,8 +311,8 @@ func (collector *resultCollector) handleTransactionExecutionMetrics(
311311
ComputationIntensities: output.ComputationIntensities,
312312
NumberOfTxnConflictRetries: numConflictRetries,
313313
Failed: output.Err != nil,
314-
ScheduledTransaction: txn.isScheduledTransaction,
315-
SystemTransaction: txn.isSystemTransaction,
314+
ScheduledTransaction: txn.transactionType == ComputerTransactionTypeScheduled,
315+
SystemTransaction: txn.transactionType == ComputerTransactionTypeSystem,
316316
}
317317
for _, entry := range txnExecutionSnapshot.UpdatedRegisters() {
318318
transactionExecutionStats.NumberOfBytesWrittenToRegisters += len(entry.Value)

engine/execution/computation/computer/transaction_coordinator_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ func (db *testCoordinator) newTransaction(txnIndex uint32) (
122122
zerolog.Nop(),
123123
txnIndex,
124124
&flow.TransactionBody{},
125-
false,
126-
false,
125+
ComputerTransactionTypeUser,
127126
false),
128127
0)
129128
}

utils/unittest/fvm.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,13 @@ import (
55

66
"github.com/stretchr/testify/require"
77

8-
"github.com/onflow/flow-go/fvm/systemcontracts"
98
"github.com/onflow/flow-go/model/flow"
109
)
1110

12-
func IsServiceEvent(event flow.Event, chainID flow.ChainID) bool {
13-
serviceEvents := systemcontracts.ServiceEventsForChain(chainID)
14-
for _, serviceEvent := range serviceEvents.All() {
15-
if serviceEvent.EventType() == event.Type {
16-
return true
17-
}
18-
}
19-
return false
20-
}
21-
2211
// EnsureEventsIndexSeq checks if values of given event index sequence are monotonically increasing.
2312
func EnsureEventsIndexSeq(t *testing.T, events []flow.Event, chainID flow.ChainID) {
2413
expectedEventIndex := uint32(0)
2514
for _, event := range events {
26-
if expectedEventIndex != event.EventIndex {
27-
require.Equal(t, expectedEventIndex, event.EventIndex)
28-
}
2915
require.Equal(t, expectedEventIndex, event.EventIndex)
3016
expectedEventIndex++
3117
}

0 commit comments

Comments
 (0)