diff --git a/access/validator.go b/access/validator.go index f85881c3414..1fcdc2e8878 100644 --- a/access/validator.go +++ b/access/validator.go @@ -4,6 +4,9 @@ import ( "errors" "fmt" + "github.com/onflow/flow-go/fvm/environment" + "github.com/onflow/flow-go/fvm/tracing" + "github.com/onflow/cadence/runtime/parser" "github.com/onflow/crypto" @@ -159,6 +162,11 @@ func (v *TransactionValidator) Validate(tx *flow.TransactionBody) (err error) { return err } + err = v.checkSufficientFlowAmountToPayForTransaction(tx) + if err != nil { + return err + } + // TODO replace checkSignatureFormat by verifying the account/payer signatures return nil @@ -346,6 +354,19 @@ func (v *TransactionValidator) checkSignatureFormat(tx *flow.TransactionBody) er return nil } +func (v *TransactionValidator) checkSufficientFlowAmountToPayForTransaction(tx *flow.TransactionBody) error { + tracer := tracing.NewMockTracerSpan() + systemContracts := environment.NewSystemContracts( + v.chain, + tracer, + environment.NewProgramLogger(tracer, environment.DefaultProgramLoggerParams()), + environment.NewRuntime(environment.DefaultRuntimeParams()), + ) + + _, err := systemContracts.CheckPayerBalanceAndGetMaxTxFees(tx.Payer, tx.InclusionEffort(), tx.GasLimit) + return err +} + func remove(s []string, r string) []string { for i, v := range s { if v == r {