-
Notifications
You must be signed in to change notification settings - Fork 178
/
transaction.go
83 lines (71 loc) · 2.3 KB
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package fvm
import (
"github.com/onflow/flow-go/fvm/storage"
"github.com/onflow/flow-go/fvm/storage/logical"
"github.com/onflow/flow-go/model/flow"
)
func Transaction(
txn *flow.TransactionBody,
txnIndex uint32,
) *TransactionProcedure {
return NewTransaction(txn.ID(), txnIndex, txn)
}
func NewTransaction(
txnId flow.Identifier,
txnIndex uint32,
txnBody *flow.TransactionBody,
) *TransactionProcedure {
return &TransactionProcedure{
ID: txnId,
Transaction: txnBody,
TxIndex: txnIndex,
}
}
type TransactionProcedure struct {
ID flow.Identifier
Transaction *flow.TransactionBody
TxIndex uint32
}
func (proc *TransactionProcedure) NewExecutor(
ctx Context,
txnState storage.TransactionPreparer,
) ProcedureExecutor {
return newTransactionExecutor(ctx, proc, txnState)
}
func (proc *TransactionProcedure) ComputationLimit(ctx Context) uint64 {
// TODO for BFT (enforce max computation limit, already checked by collection nodes)
// TODO replace tx.Gas with individual limits for computation and memory
// decide computation limit
computationLimit := proc.Transaction.GasLimit
// if the computation limit is set to zero by user, fallback to the gas limit set by the context
if computationLimit == 0 {
computationLimit = ctx.ComputationLimit
// if the context computation limit is also zero, fallback to the default computation limit
if computationLimit == 0 {
computationLimit = DefaultComputationLimit
}
}
return computationLimit
}
func (proc *TransactionProcedure) MemoryLimit(ctx Context) uint64 {
// TODO for BFT (enforce max memory limit, already checked by collection nodes)
// TODO let user select a lower limit for memory (when its part of fees)
memoryLimit := ctx.MemoryLimit // TODO use the one set by tx
// if the context memory limit is also zero, fallback to the default memory limit
if memoryLimit == 0 {
memoryLimit = DefaultMemoryLimit
}
return memoryLimit
}
func (proc *TransactionProcedure) ShouldDisableMemoryAndInteractionLimits(
ctx Context,
) bool {
return ctx.DisableMemoryAndInteractionLimits ||
proc.Transaction.Payer == ctx.Chain.ServiceAddress()
}
func (TransactionProcedure) Type() ProcedureType {
return TransactionProcedureType
}
func (proc *TransactionProcedure) ExecutionTime() logical.Time {
return logical.Time(proc.TxIndex)
}