Skip to content

Commit

Permalink
Merge pull request #7 from quilt/aa_tx_ordering
Browse files Browse the repository at this point in the history
Aa tx ordering
  • Loading branch information
villanuevawill authored Jun 11, 2020
2 parents 64ad2c4 + ea087ff commit afc79d2
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 67 deletions.
8 changes: 4 additions & 4 deletions core/aa_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func setupBlockchain(blockGasLimit uint64) *BlockChain {
func testValidate(blockchain *BlockChain, statedb *state.StateDB, transaction *types.Transaction, validationGasLimit uint64, expectedErr error, t *testing.T) {
var (
snapshotRevisionId = statedb.Snapshot()
context = NewEVMContext(types.AADummyMessage, blockchain.CurrentHeader(), blockchain, &common.Address{})
context = NewEVMContext(types.AAEntryMessage, blockchain.CurrentHeader(), blockchain, &common.Address{})
vmenv = vm.NewEVM(context, statedb, blockchain.Config(), vm.Config{PaygasMode: vm.PaygasHalt})
err = Validate(transaction, types.HomesteadSigner{}, vmenv, validationGasLimit)
)
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestInvalidEVMConfig(t *testing.T) {
blockchain = setupBlockchain(10000000)
statedb, _ = blockchain.State()

context = NewEVMContext(types.AADummyMessage, blockchain.CurrentHeader(), blockchain, &common.Address{})
context = NewEVMContext(types.AAEntryMessage, blockchain.CurrentHeader(), blockchain, &common.Address{})
vmenv = vm.NewEVM(context, statedb, blockchain.Config(), vm.Config{})

tx = &types.Transaction{}
Expand All @@ -153,13 +153,13 @@ func TestMalformedTransaction(t *testing.T) {
blockchain = setupBlockchain(10000000)
statedb, _ = blockchain.State()

context = NewEVMContext(types.AADummyMessage, blockchain.CurrentHeader(), blockchain, &common.Address{})
context = NewEVMContext(types.AAEntryMessage, blockchain.CurrentHeader(), blockchain, &common.Address{})
vmenv = vm.NewEVM(context, statedb, blockchain.Config(), vm.Config{PaygasMode: vm.PaygasHalt})

key, _ = crypto.GenerateKey()
tx = pricedTransaction(0, 100000, big.NewInt(0), key)
err = Validate(tx, types.HomesteadSigner{}, vmenv, 400000)
expectedErr = ErrMalformedTransaction
expectedErr = ErrMalformedAATransaction
)
if err != expectedErr {
t.Error("\n\texpected:", expectedErr, "\n\tgot:", err)
Expand Down
7 changes: 4 additions & 3 deletions core/transaction_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package core

import (
"errors"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)

var (
ErrIncorrectAAConfig = errors.New("incorrect AA config for EVM")
ErrMalformedTransaction = errors.New("AA transaction malformed")
ErrIncorrectAAConfig = errors.New("incorrect AA config for EVM")
ErrMalformedAATransaction = errors.New("AA transaction malformed")
)

func Validate(tx *types.Transaction, s types.Signer, evm *vm.EVM, gasLimit uint64) error {
Expand All @@ -39,7 +40,7 @@ func Validate(tx *types.Transaction, s types.Signer, evm *vm.EVM, gasLimit uint6
if err != nil {
return err
} else if !msg.IsAA() {
return ErrMalformedTransaction
return ErrMalformedAATransaction
}
msg.SetGas(gasLimit)
gp := new(GasPool).AddGas(gasLimit)
Expand Down
4 changes: 3 additions & 1 deletion core/tx_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,17 @@ type txList struct {

costcap *big.Int // Price of the highest costing transaction (reset only if exceeds balance)
gascap uint64 // Gas limit of the highest spending transaction (reset only if exceeds block limit)
isAA bool
}

// newTxList create a new transaction list for maintaining nonce-indexable fast,
// gapped, sortable transaction lists.
func newTxList(strict bool) *txList {
func newTxList(strict bool, isAA bool) *txList {
return &txList{
strict: strict,
txs: newTxSortedMap(),
costcap: new(big.Int),
isAA: isAA,
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/tx_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestStrictTxListAdd(t *testing.T) {
txs[i] = transaction(uint64(i), 0, key)
}
// Insert the transactions in a random order
list := newTxList(true)
list := newTxList(true, false)
for _, v := range rand.Perm(len(txs)) {
list.Add(txs[v], DefaultTxPoolConfig.PriceBump)
}
Expand Down
Loading

0 comments on commit afc79d2

Please sign in to comment.