fvm

package
v0.29.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: AGPL-3.0 Imports: 28 Imported by: 2

README

Flow Virtual Machine (FVM)

The Flow Virtual Machine (FVM) augments the Cadence runtime with the domain-specific functionality required by the Flow protocol.

Usage

Quickstart
import (
    "github.com/onflow/cadence/runtime"
    "github.com/onflow/flow-go/fvm"
    "github.com/onflow/flow-go/fvm/state"
    "github.com/onflow/flow-go/model/flow"
)

vm := fvm.NewVirtualMachine()

tx := flow.NewTransactionBody().
    SetScript([]byte(`transaction { execute { log("Hello, World!") } }`))

ctx := fvm.NewContext()
ledger := state.NewMapLedger()

txIndex := uint32(0)
txProc := fvm.Transaction(tx, txIndex)

err := vm.Run(ctx, txProc, ledger)
if err != nil {
  panic("fatal error during transaction procedure!")
}

fmt.Println(txProc.Logs[0]) // prints "Hello, World!"
Procedure

The FVM interacts with the Flow execution state by running atomic procedures against a shared ledger. A Procedure is an operation that can be applied to a Ledger.

Procedure Types
Transactions (Read/write)

A TransactionProcedure is an operation that mutates the ledger state.

A transaction procedure can be created from a flow.TransactionBody:

var tx flow.TransactionBody
var txIndex uint32

i := fvm.Transaction(tx, txIndex)

A transaction procedure has the following steps:

  1. Verify all transaction signatures against the current ledger state
  2. Validate and increment the proposal key sequence number
  3. Deduct transaction fee from the payer account
  4. Invoke transaction script with provided arguments and authorizers
Scripts (Read-only)

A ScriptProcedure is an operation that reads from the ledger state.

foo := fvm.Script([]byte(`fun main(): Int { return 42 }`))

A script can have optionally bound arguments:

script := fvm.Script([]byte(`fun main(x: Int): Int { x * 2 }`))

foo := script.WithArguments(argA)
bar := script.WithArguments(argB)
Contexts

The VM runs procedures inside of an execution context that defines the host functionality provided to the Cadence runtime. A Context instance is an immutable object, and any changes to a context must be made by spawning a new child context.

vm := fvm.New(runtime.NewInterpreterRuntime())

globalCtx := fvm.NewContext()

// create separate contexts for different blocks
block1Ctx := fvm.NewContextFromParent(globalCtx, fvm.WithBlockHeader(block1))
block2Ctx := fvm.NewContextFromParent(globalCtx, fvm.WithBlockHeader(block2))

// contexts can be safely used in parallel
go executeBlock(vm, block1Ctx)
go executeBlock(vm, block2Ctx)
Context Options

TODO: document context options

Design

The structure of the FVM package is intended to promote the following:

  • Determinism: the VM should be consistent and predictable, producing identical results given the same inputs.
  • Performance: the VM should expose functionality that allows the caller to exploit parallelism and pre-computation.
  • Flexibility: the VM should support a variety of use cases including not only execution and verification, but also developer tooling and network emulation.
Context

A Context is a reusable component that simply defines the parameters of an execution environment. For example, all transactions within the same block would share a common Context configured with the relevant block data.

Contexts can be arbitrarily nested. A child context inherits the parameters of its parent, but is free to override any parameters that it chooses.

HostEnvironment

A HostEnvironment is a short-lived component that is consumed by a procedure. A HostEnvironment is the interface through which the VM communicates with the Cadence runtime. The HostEnvironment provides information about the current Context and also collects logs, events and metrics emitted from the runtime.

Procedure Lifecycle

The diagram below illustrates the relationship between contexts, host environments and procedures. Multiple procedures can reuse the same context, each of which is supplied with a unique HostEnvironment instance.

fvm

TODO

  • Improve error handling
  • Create list of all missing test cases
  • Implement missing test cases
  • Documentation
    • Transaction validation (signatures, sequence numbers)
    • Fee payments
    • Address generation
    • Account management
    • Bootstrapping
    • Ledger usage

Open Questions

  • Currently the caller is responsible for providing the correct Ledger instance when running a procedure. When performing atomic operations in batches (i.e blocks or chunks), multiple ledgers are spawned in a hierarchy similar to that of multiple Context instances. Does it make sense for the fvm package to manage ledgers as well?

Documentation

Index

Constants

View Source
const (
	AccountKeyWeightThreshold = 1000

	DefaultComputationLimit   = 100_000 // 100K
	DefaultMemoryLimit        = math.MaxUint64
	DefaultMaxInteractionSize = 20_000_000 // ~20MB
)
View Source
const (
	BootstrapProcedureType   = ProcedureType("bootstrap")
	TransactionProcedureType = ProcedureType("transaction")
	ScriptProcedureType      = ProcedureType("script")
)

Variables

View Source
var (
	DefaultAccountCreationFee = mustParseUFix64(
		"account creation fee",
		"0.00100000")

	DefaultMinimumStorageReservation = mustParseUFix64(
		"minimum storage reservation",
		"0.00100000")

	DefaultStorageMBPerFLOW = mustParseUFix64(
		"storage mb per flow",
		"100.00000000")

	// DefaultTransactionFees are the default transaction fee parameters if
	// transaction fees are on. Surge factor is 1.0, inclusion effort cost is
	// 0.0001 (because the static inclusion effort is 1.0) and execution effort
	// cost is 0.0 because dynamic execution fees are off. If they are off
	// (which is the default behaviour) that means the transaction fees are 0.0.
	DefaultTransactionFees = BootstrapProcedureFeeParameters{
		SurgeFactor: mustParseUFix64("fee surge factor", "1.0"),
		InclusionEffortCost: mustParseUFix64(
			"fee inclusion effort cost",
			"0.00001"),
		ExecutionEffortCost: mustParseUFix64(
			"fee execution effort cost",
			"0.0"),
	}
)

Functions

func FlowTokenAddress

func FlowTokenAddress(chain flow.Chain) flow.Address

func FungibleTokenAddress

func FungibleTokenAddress(chain flow.Chain) flow.Address

func GetExecutionEffortWeights

func GetExecutionEffortWeights(
	env environment.Environment,
	service runtime.Address,
) (
	computationWeights meter.ExecutionEffortWeights,
	err error,
)

GetExecutionEffortWeights reads stored execution effort weights from the service account

func GetExecutionMemoryLimit

func GetExecutionMemoryLimit(
	env environment.Environment,
	service runtime.Address,
) (
	memoryLimit uint64,
	err error,
)

GetExecutionMemoryLimit reads the stored execution memory limit from the service account

func GetExecutionMemoryWeights

func GetExecutionMemoryWeights(
	env environment.Environment,
	service runtime.Address,
) (
	memoryWeights meter.ExecutionMemoryWeights,
	err error,
)

GetExecutionMemoryWeights reads stored execution memory weights from the service account

func NewTransactionEnvironment

func NewTransactionEnvironment(
	ctx Context,
	txnState *state.TransactionState,
	derivedTxnData environment.DerivedTransactionData,
	tx *flow.TransactionBody,
	txIndex uint32,
	traceSpan otelTrace.Span,
) environment.Environment

TODO(patrick): remove once https://github.com/onflow/flow-emulator/pull/242 is integrated into flow-go's integration test.

func Run

func Run(executor ProcedureExecutor) error

Types

type Blocks

type Blocks = environment.Blocks

TODO(patrick): rm after https://github.com/onflow/flow-emulator/pull/229 is merged and integrated.

func NewBlockFinder

func NewBlockFinder(storage storage.Headers) Blocks

TODO(patrick): rm after https://github.com/onflow/flow-emulator/pull/229 is merged and integrated.

type BootstrapAccountKeys

type BootstrapAccountKeys struct {
	ServiceAccountPublicKeys       []flow.AccountPublicKey
	FungibleTokenAccountPublicKeys []flow.AccountPublicKey
	FlowTokenAccountPublicKeys     []flow.AccountPublicKey
	FlowFeesAccountPublicKeys      []flow.AccountPublicKey
	NodeAccountPublicKeys          []flow.AccountPublicKey
}

type BootstrapParams

type BootstrapParams struct {
	// contains filtered or unexported fields
}

type BootstrapProcedure

type BootstrapProcedure struct {
	BootstrapParams
}

A BootstrapProcedure is an invokable that can be used to bootstrap the ledger state with the default accounts and contracts required by the Flow virtual machine.

func Bootstrap

func Bootstrap(
	serviceAccountPublicKey flow.AccountPublicKey,
	opts ...BootstrapProcedureOption,
) *BootstrapProcedure

Bootstrap returns a new BootstrapProcedure instance configured with the provided genesis parameters.

func (*BootstrapProcedure) ComputationLimit

func (proc *BootstrapProcedure) ComputationLimit(_ Context) uint64

func (*BootstrapProcedure) ExecutionTime

func (proc *BootstrapProcedure) ExecutionTime() derived.LogicalTime

func (*BootstrapProcedure) InitialSnapshotTime

func (proc *BootstrapProcedure) InitialSnapshotTime() derived.LogicalTime

func (*BootstrapProcedure) MemoryLimit

func (proc *BootstrapProcedure) MemoryLimit(_ Context) uint64

func (*BootstrapProcedure) NewExecutor

func (*BootstrapProcedure) ShouldDisableMemoryAndInteractionLimits

func (proc *BootstrapProcedure) ShouldDisableMemoryAndInteractionLimits(_ Context) bool

func (BootstrapProcedure) Type

type BootstrapProcedureFeeParameters

type BootstrapProcedureFeeParameters struct {
	SurgeFactor         cadence.UFix64
	InclusionEffortCost cadence.UFix64
	ExecutionEffortCost cadence.UFix64
}

type BootstrapProcedureOption

type BootstrapProcedureOption func(*BootstrapProcedure) *BootstrapProcedure

func WithAccountCreationFee

func WithAccountCreationFee(fee cadence.UFix64) BootstrapProcedureOption

func WithBootstrapAccountKeys

func WithBootstrapAccountKeys(keys BootstrapAccountKeys) BootstrapProcedureOption

WithBootstrapAccountKeys sets the public keys of the accounts that will be created during bootstrapping by default all accounts are created with the ServiceAccountPublicKey specified when calling `Bootstrap`.

func WithEpochConfig

func WithEpochConfig(epochConfig epochs.EpochConfig) BootstrapProcedureOption

func WithExecutionMemoryLimit

func WithExecutionMemoryLimit(limit uint64) BootstrapProcedureOption

func WithIdentities

func WithIdentities(identities flow.IdentityList) BootstrapProcedureOption

func WithInitialTokenSupply

func WithInitialTokenSupply(supply cadence.UFix64) BootstrapProcedureOption

func WithMinimumStorageReservation

func WithMinimumStorageReservation(reservation cadence.UFix64) BootstrapProcedureOption

func WithRestrictedAccountCreationEnabled

func WithRestrictedAccountCreationEnabled(enabled cadence.Bool) BootstrapProcedureOption

func WithRestrictedContractDeployment

func WithRestrictedContractDeployment(restricted *bool) BootstrapProcedureOption

func WithRootBlock

func WithRootBlock(rootBlock *flow.Header) BootstrapProcedureOption

func WithStorageMBPerFLOW

func WithStorageMBPerFLOW(ratio cadence.UFix64) BootstrapProcedureOption

type Context

type Context struct {
	// DisableMemoryAndInteractionLimits will override memory and interaction
	// limits and set them to MaxUint64, effectively disabling these limits.
	DisableMemoryAndInteractionLimits bool
	ComputationLimit                  uint64
	MemoryLimit                       uint64
	MaxStateKeySize                   uint64
	MaxStateValueSize                 uint64
	MaxStateInteractionSize           uint64

	TransactionExecutorParams

	DerivedBlockData *derived.DerivedBlockData

	tracing.TracerSpan

	environment.EnvironmentParams
}

A Context defines a set of execution parameters used by the virtual machine.

func NewContext

func NewContext(opts ...Option) Context

NewContext initializes a new execution context with the provided options.

func NewContextFromParent

func NewContextFromParent(parent Context, opts ...Option) Context

NewContextFromParent spawns a child execution context with the provided options.

type MeterParamOverridesComputer

type MeterParamOverridesComputer struct {
	// contains filtered or unexported fields
}

func NewMeterParamOverridesComputer

func NewMeterParamOverridesComputer(
	ctx Context,
	derivedTxnData *derived.DerivedTransactionData,
) MeterParamOverridesComputer

func (MeterParamOverridesComputer) Compute

func (computer MeterParamOverridesComputer) Compute(
	txnState *state.TransactionState,
	_ struct{},
) (
	derived.MeterParamOverrides,
	error,
)

type Option

type Option func(ctx Context) Context

An Option sets a configuration parameter for a virtual machine context.

func WithAccountKeyWeightThreshold

func WithAccountKeyWeightThreshold(threshold int) Option

WithAccountKeyWeightThreshold sets the key weight threshold used for authorization checks. If the threshold is a negative number, signature verification is skipped.

Note: This is set only by tests

func WithAccountStorageLimit

func WithAccountStorageLimit(enabled bool) Option

WithAccountStorageLimit enables or disables checking if account storage used is over its storage capacity

func WithAuthorizationChecksEnabled

func WithAuthorizationChecksEnabled(enabled bool) Option

WithAuthorizationCheckxEnabled enables or disables pre-execution authorization checks.

func WithBlockHeader

func WithBlockHeader(header *flow.Header) Option

WithBlockHeader sets the block header for a virtual machine context.

The VM uses the header to provide current block information to the Cadence runtime, as well as to seed the pseudorandom number generator.

func WithBlocks

func WithBlocks(blocks environment.Blocks) Option

WithBlocks sets the block storage provider for a virtual machine context.

The VM uses the block storage provider to provide historical block information to the Cadence runtime.

func WithCadenceLogging

func WithCadenceLogging(enabled bool) Option

WithCadenceLogging enables or disables Cadence logging for a virtual machine context.

func WithChain

func WithChain(chain flow.Chain) Option

WithChain sets the chain parameters for a virtual machine context.

func WithComputationLimit

func WithComputationLimit(limit uint64) Option

WithComputationLimit sets the computation limit for a virtual machine context.

func WithContractDeploymentRestricted

func WithContractDeploymentRestricted(enabled bool) Option

WithRestrictedContractDeployment enables or disables restricted contract deployment for a virtual machine context. Warning! this would be overridden with the flag stored on chain. this is just a fallback value

func WithContractRemovalRestricted

func WithContractRemovalRestricted(enabled bool) Option

WithRestrictContractRemoval enables or disables restricted contract removal for a virtual machine context. Warning! this would be overridden with the flag stored on chain. this is just a fallback value

func WithDerivedBlockData

func WithDerivedBlockData(derivedBlockData *derived.DerivedBlockData) Option

WithDerivedBlockData sets the derived data cache storage to be used by the transaction/script.

func WithEventCollectionSizeLimit

func WithEventCollectionSizeLimit(limit uint64) Option

WithEventCollectionSizeLimit sets the event collection byte size limit for a virtual machine context.

func WithEventEncoder

func WithEventEncoder(encoder environment.EventEncoder) Option

WithEventEncoder sets events encoder to be used for encoding events emitted during execution

func WithExtensiveTracing

func WithExtensiveTracing() Option

WithExtensiveTracing sets the extensive tracing

func WithGasLimit

func WithGasLimit(limit uint64) Option

WithGasLimit sets the computation limit for a virtual machine context. @depricated, please use WithComputationLimit instead.

func WithLogger

func WithLogger(logger zerolog.Logger) Option

WithLogger sets the context logger

func WithMaxStateInteractionSize

func WithMaxStateInteractionSize(limit uint64) Option

WithMaxStateInteractionSize sets the byte size limit for total interaction with ledger. this prevents attacks such as reading all large registers

func WithMaxStateKeySize

func WithMaxStateKeySize(limit uint64) Option

WithMaxStateKeySize sets the byte size limit for ledger keys

func WithMaxStateValueSize

func WithMaxStateValueSize(limit uint64) Option

WithMaxStateValueSize sets the byte size limit for ledger values

func WithMemoryAndInteractionLimitsDisabled

func WithMemoryAndInteractionLimitsDisabled() Option

WithMemoryAndInteractionLimitsDisabled will override memory and interaction limits and set them to MaxUint64, effectively disabling these limits.

func WithMemoryLimit

func WithMemoryLimit(limit uint64) Option

WithMemoryLimit sets the memory limit for a virtual machine context.

func WithMetricsReporter

func WithMetricsReporter(mr environment.MetricsReporter) Option

WithMetricsReporter sets the metrics collector for a virtual machine context.

A metrics collector is used to gather metrics reported by the Cadence runtime.

func WithRestrictedDeployment

func WithRestrictedDeployment(restricted bool) Option

@Depricated please use WithContractDeploymentRestricted instead of this this has been kept to reduce breaking change on the emulator, but would be removed at some point.

func WithReusableCadenceRuntimePool

func WithReusableCadenceRuntimePool(
	pool reusableRuntime.ReusableCadenceRuntimePool,
) Option

WithReusableCadenceRuntimePool set the (shared) RedusableCadenceRuntimePool use for creating the cadence runtime.

func WithSequenceNumberCheckAndIncrementEnabled

func WithSequenceNumberCheckAndIncrementEnabled(enabled bool) Option

WithSequenceNumberCheckAndIncrementEnabled enables or disables pre-execution sequence number check / increment.

func WithServiceAccount

func WithServiceAccount(enabled bool) Option

WithServiceAccount enables or disables calls to the Flow service account.

func WithServiceEventCollectionEnabled

func WithServiceEventCollectionEnabled() Option

WithServiceEventCollectionEnabled enables service event collection

func WithSpan

func WithSpan(span otelTrace.Span) Option

WithSpan sets the trace span for a virtual machine context.

func WithTracer

func WithTracer(tr module.Tracer) Option

WithTracer sets the tracer for a virtual machine context.

func WithTransactionBodyExecutionEnabled

func WithTransactionBodyExecutionEnabled(enabled bool) Option

WithTransactionBodyExecutionEnabled enables or disables the transaction body execution.

Note: This is disabled only by tests

func WithTransactionFeesEnabled

func WithTransactionFeesEnabled(enabled bool) Option

WithTransactionFeesEnabled enables or disables deduction of transaction fees

func WithTransactionProcessors

func WithTransactionProcessors(processors ...interface{}) Option

TODO(patrick): remove after emulator has been updated.

WithTransactionProcessors sets the transaction processors for a virtual machine context.

type Procedure

type Procedure interface {
	NewExecutor(
		ctx Context,
		txnState *state.TransactionState,
		derivedTxnData *derived.DerivedTransactionData,
	) ProcedureExecutor

	ComputationLimit(ctx Context) uint64
	MemoryLimit(ctx Context) uint64
	ShouldDisableMemoryAndInteractionLimits(ctx Context) bool

	Type() ProcedureType

	// The initial snapshot time is used as part of OCC validation to ensure
	// there are no read-write conflict amongst transactions.  Note that once
	// we start supporting parallel preprocessing/execution, a transaction may
	// operation on mutliple snapshots.
	//
	// For scripts, since they can only be executed after the block has been
	// executed, the initial snapshot time is EndOfBlockExecutionTime.
	InitialSnapshotTime() derived.LogicalTime

	// For transactions, the execution time is TxIndex.  For scripts, the
	// execution time is EndOfBlockExecutionTime.
	ExecutionTime() derived.LogicalTime
}

An Procedure is an operation (or set of operations) that reads or writes ledger state.

type ProcedureExecutor

type ProcedureExecutor interface {
	Preprocess() error
	Execute() error
	Cleanup()
}

type ProcedureType

type ProcedureType string

type ScriptProcedure

type ScriptProcedure struct {
	ID             flow.Identifier
	Script         []byte
	Arguments      [][]byte
	RequestContext context.Context
	Value          cadence.Value
	Logs           []string
	Events         []flow.Event
	GasUsed        uint64
	MemoryEstimate uint64
	Err            errors.CodedError
}

func NewScriptWithContextAndArgs

func NewScriptWithContextAndArgs(
	code []byte,
	reqContext context.Context,
	args ...[]byte,
) *ScriptProcedure

func Script

func Script(code []byte) *ScriptProcedure

func (*ScriptProcedure) ComputationLimit

func (proc *ScriptProcedure) ComputationLimit(ctx Context) uint64

func (*ScriptProcedure) ExecutionTime

func (proc *ScriptProcedure) ExecutionTime() derived.LogicalTime

func (*ScriptProcedure) InitialSnapshotTime

func (proc *ScriptProcedure) InitialSnapshotTime() derived.LogicalTime

func (*ScriptProcedure) MemoryLimit

func (proc *ScriptProcedure) MemoryLimit(ctx Context) uint64

func (*ScriptProcedure) NewExecutor

func (proc *ScriptProcedure) NewExecutor(
	ctx Context,
	txnState *state.TransactionState,
	derivedTxnData *derived.DerivedTransactionData,
) ProcedureExecutor

func (*ScriptProcedure) ShouldDisableMemoryAndInteractionLimits

func (proc *ScriptProcedure) ShouldDisableMemoryAndInteractionLimits(
	ctx Context,
) bool

func (ScriptProcedure) Type

func (*ScriptProcedure) WithArguments

func (proc *ScriptProcedure) WithArguments(args ...[]byte) *ScriptProcedure

func (*ScriptProcedure) WithRequestContext

func (proc *ScriptProcedure) WithRequestContext(
	reqContext context.Context,
) *ScriptProcedure

type TransactionExecutorParams

type TransactionExecutorParams struct {
	AuthorizationChecksEnabled bool

	SequenceNumberCheckAndIncrementEnabled bool

	// If AccountKeyWeightThreshold is set to a negative number, signature
	// verification is skipped during authorization checks.
	//
	// Note: This is set only by tests
	AccountKeyWeightThreshold int

	// Note: This is disabled only by tests
	TransactionBodyExecutionEnabled bool
}

func DefaultTransactionExecutorParams

func DefaultTransactionExecutorParams() TransactionExecutorParams

type TransactionInvoker

type TransactionInvoker struct {
}

TODO(patrick): rm once emulator is updated.

func NewTransactionInvoker

func NewTransactionInvoker() *TransactionInvoker

type TransactionPayerBalanceChecker

type TransactionPayerBalanceChecker struct{}

func (TransactionPayerBalanceChecker) CheckPayerBalanceAndReturnMaxFees

func (_ TransactionPayerBalanceChecker) CheckPayerBalanceAndReturnMaxFees(
	proc *TransactionProcedure,
	txnState *state.TransactionState,
	env environment.Environment,
) (uint64, error)

type TransactionProcedure

type TransactionProcedure struct {
	ID                     flow.Identifier
	Transaction            *flow.TransactionBody
	InitialSnapshotTxIndex uint32
	TxIndex                uint32

	Logs                   []string
	Events                 []flow.Event
	ServiceEvents          []flow.Event
	ComputationUsed        uint64
	ComputationIntensities meter.MeteredComputationIntensities
	MemoryEstimate         uint64
	Err                    errors.CodedError
}

func Transaction

func Transaction(tx *flow.TransactionBody, txIndex uint32) *TransactionProcedure

TODO(patrick): pass in initial snapshot time when we start supporting speculative pre-processing / execution.

func (*TransactionProcedure) ComputationLimit

func (proc *TransactionProcedure) ComputationLimit(ctx Context) uint64

func (*TransactionProcedure) ExecutionTime

func (proc *TransactionProcedure) ExecutionTime() derived.LogicalTime

func (*TransactionProcedure) InitialSnapshotTime

func (proc *TransactionProcedure) InitialSnapshotTime() derived.LogicalTime

func (*TransactionProcedure) MemoryLimit

func (proc *TransactionProcedure) MemoryLimit(ctx Context) uint64

func (*TransactionProcedure) NewExecutor

func (proc *TransactionProcedure) NewExecutor(
	ctx Context,
	txnState *state.TransactionState,
	derivedTxnData *derived.DerivedTransactionData,
) ProcedureExecutor

func (*TransactionProcedure) ShouldDisableMemoryAndInteractionLimits

func (proc *TransactionProcedure) ShouldDisableMemoryAndInteractionLimits(
	ctx Context,
) bool

func (TransactionProcedure) Type

type TransactionSequenceNumberChecker

type TransactionSequenceNumberChecker struct{}

func (TransactionSequenceNumberChecker) CheckAndIncrementSequenceNumber

func (c TransactionSequenceNumberChecker) CheckAndIncrementSequenceNumber(
	tracer tracing.TracerSpan,
	proc *TransactionProcedure,
	txnState *state.TransactionState,
) error

type TransactionStorageLimiter

type TransactionStorageLimiter struct{}

func (TransactionStorageLimiter) CheckStorageLimits

func (d TransactionStorageLimiter) CheckStorageLimits(
	env environment.Environment,
	addresses []flow.Address,
	payer flow.Address,
	maxTxFees uint64,
) error

CheckStorageLimits checks each account that had its storage written to during a transaction, that its storage used is less than its storage capacity. Storage used is an FVM register and is easily accessible. Storage capacity is calculated by the FlowStorageFees contract from the account's flow balance.

The payers balance is considered to be maxTxFees lower that its actual balance, due to the fact that the fee deduction step happens after the storage limit check.

type TransactionVerifier

type TransactionVerifier struct {
	VerificationConcurrency int
}

TransactionVerifier verifies the content of the transaction by checking accounts (authorizers, payer, proposer) are not frozen checking there is no double signature all signatures are valid all accounts provides enoguh weights

if KeyWeightThreshold is set to a negative number, signature verification is skipped

func (*TransactionVerifier) CheckAuthorization

func (v *TransactionVerifier) CheckAuthorization(
	tracer tracing.TracerSpan,
	proc *TransactionProcedure,
	txnState *state.TransactionState,
	keyWeightThreshold int,
) error

type VM

type VM interface {
	Run(Context, Procedure, state.View) error
	GetAccount(Context, flow.Address, state.View) (*flow.Account, error)
}

VM runs procedures

type VirtualMachine

type VirtualMachine struct {
}

A VirtualMachine augments the Cadence runtime with Flow host functionality.

func NewVirtualMachine

func NewVirtualMachine() *VirtualMachine

func (*VirtualMachine) GetAccount

func (vm *VirtualMachine) GetAccount(
	ctx Context,
	address flow.Address,
	v state.View,
) (
	*flow.Account,
	error,
)

GetAccount returns an account by address or an error if none exists.

func (*VirtualMachine) Run

func (vm *VirtualMachine) Run(
	ctx Context,
	proc Procedure,
	v state.View,
) error

Run runs a procedure against a ledger in the given context.

Directories

Path Synopsis
Package systemcontracts stores canonical address locations for all system smart contracts and service events.
Package systemcontracts stores canonical address locations for all system smart contracts and service events.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL