Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion models/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@ import (
"github.com/onflow/cadence"
"github.com/onflow/flow-go/fvm/evm/types"
"github.com/onflow/go-ethereum/common"
"github.com/onflow/go-ethereum/core/txpool"
gethTypes "github.com/onflow/go-ethereum/core/types"
)

const (
// txSlotSize is used to calculate how many data slots a single transaction
// takes up based on its size. The slots are used as DoS protection, ensuring
// that validating a new transaction remains a constant operation (in reality
// O(maxslots), where max slots are 4 currently).
TxSlotSize = 32 * 1024

// txMaxSize is the maximum size a single transaction can have. This field has
// non-trivial consequences: larger transactions are significantly harder and
// more expensive to propagate; larger transactions also take more resources
// to validate whether they fit into the pool or not.
TxMaxSize = 4 * TxSlotSize // 128KB
)

type Transaction interface {
Hash() common.Hash
RawSignatureValues() (v *big.Int, r *big.Int, s *big.Int)
Expand Down Expand Up @@ -204,7 +219,12 @@ func UnmarshalTransaction(value []byte) (Transaction, error) {
return TransactionCall{Transaction: tx}, nil
}

func ValidateTransaction(tx *gethTypes.Transaction) error {
func ValidateTransaction(
tx *gethTypes.Transaction,
head *gethTypes.Header,
signer gethTypes.Signer,
opts *txpool.ValidationOptions,
) error {
txDataLen := len(tx.Data())

// Contract creation doesn't validate call data, handle first
Expand Down Expand Up @@ -255,5 +275,9 @@ func ValidateTransaction(tx *gethTypes.Transaction) error {
}
}

if err := txpool.ValidateTransaction(tx, head, signer, opts); err != nil {
return err
}

return nil
}
Loading