github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/transaction.go (about)

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