github.com/koko1123/flow-go-1@v0.29.6/fvm/transaction.go (about) 1 package fvm 2 3 import ( 4 "github.com/koko1123/flow-go-1/fvm/derived" 5 "github.com/koko1123/flow-go-1/fvm/errors" 6 "github.com/koko1123/flow-go-1/fvm/meter" 7 "github.com/koko1123/flow-go-1/fvm/state" 8 "github.com/koko1123/flow-go-1/model/flow" 9 ) 10 11 // TODO(patrick): pass in initial snapshot time when we start supporting 12 // speculative pre-processing / execution. 13 func Transaction(tx *flow.TransactionBody, txIndex uint32) *TransactionProcedure { 14 return &TransactionProcedure{ 15 ID: tx.ID(), 16 Transaction: tx, 17 InitialSnapshotTxIndex: txIndex, 18 TxIndex: txIndex, 19 ComputationIntensities: make(meter.MeteredComputationIntensities), 20 } 21 } 22 23 type TransactionProcedure struct { 24 ID flow.Identifier 25 Transaction *flow.TransactionBody 26 InitialSnapshotTxIndex uint32 27 TxIndex uint32 28 29 Logs []string 30 Events []flow.Event 31 ServiceEvents []flow.Event 32 ComputationUsed uint64 33 ComputationIntensities meter.MeteredComputationIntensities 34 MemoryEstimate uint64 35 Err errors.CodedError 36 } 37 38 func (proc *TransactionProcedure) NewExecutor( 39 ctx Context, 40 txnState *state.TransactionState, 41 derivedTxnData *derived.DerivedTransactionData, 42 ) ProcedureExecutor { 43 return newTransactionExecutor(ctx, proc, txnState, derivedTxnData) 44 } 45 46 func (proc *TransactionProcedure) ComputationLimit(ctx Context) uint64 { 47 // TODO for BFT (enforce max computation limit, already checked by collection nodes) 48 // TODO replace tx.Gas with individual limits for computation and memory 49 50 // decide computation limit 51 computationLimit := proc.Transaction.GasLimit 52 // if the computation limit is set to zero by user, fallback to the gas limit set by the context 53 if computationLimit == 0 { 54 computationLimit = ctx.ComputationLimit 55 // if the context computation limit is also zero, fallback to the default computation limit 56 if computationLimit == 0 { 57 computationLimit = DefaultComputationLimit 58 } 59 } 60 return computationLimit 61 } 62 63 func (proc *TransactionProcedure) MemoryLimit(ctx Context) uint64 { 64 // TODO for BFT (enforce max memory limit, already checked by collection nodes) 65 // TODO let user select a lower limit for memory (when its part of fees) 66 67 memoryLimit := ctx.MemoryLimit // TODO use the one set by tx 68 // if the context memory limit is also zero, fallback to the default memory limit 69 if memoryLimit == 0 { 70 memoryLimit = DefaultMemoryLimit 71 } 72 return memoryLimit 73 } 74 75 func (proc *TransactionProcedure) ShouldDisableMemoryAndInteractionLimits( 76 ctx Context, 77 ) bool { 78 return ctx.DisableMemoryAndInteractionLimits || 79 proc.Transaction.Payer == ctx.Chain.ServiceAddress() 80 } 81 82 func (TransactionProcedure) Type() ProcedureType { 83 return TransactionProcedureType 84 } 85 86 func (proc *TransactionProcedure) InitialSnapshotTime() derived.LogicalTime { 87 return derived.LogicalTime(proc.InitialSnapshotTxIndex) 88 } 89 90 func (proc *TransactionProcedure) ExecutionTime() derived.LogicalTime { 91 return derived.LogicalTime(proc.TxIndex) 92 }