Skip to content

Commit

Permalink
Add check if tx payer has sufficient amount of flow to pay fee
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-malachyn committed May 30, 2024
1 parent b968034 commit 19d3d0d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions access/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 19d3d0d

Please sign in to comment.