Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow reverted tx to be added to the pool #1744

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
64 changes: 64 additions & 0 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/pool/pgpoolstorage"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Revert"
"github.com/0xPolygonHermez/zkevm-node/test/dbutils"
"github.com/0xPolygonHermez/zkevm-node/test/operations"
"github.com/0xPolygonHermez/zkevm-node/test/testutils"
Expand Down Expand Up @@ -1131,3 +1132,66 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) {
assert.Equal(t, pool.TxStatusPending, txs[0].Status)
}
}

func Test_AddRevertedTx(t *testing.T) {
initOrResetDB()

stateSqlDB, err := db.NewSQLDB(stateDBCfg)
if err != nil {
t.Error(err)
}
defer stateSqlDB.Close() //nolint:gosec,errcheck

st := newState(stateSqlDB)

genesisBlock := state.Block{
BlockNumber: 0,
BlockHash: state.ZeroHash,
ParentHash: state.ZeroHash,
ReceivedAt: time.Now(),
}
ctx := context.Background()
dbTx, err := st.BeginStateTransaction(ctx)
require.NoError(t, err)
_, err = st.SetGenesis(ctx, genesisBlock, genesis, dbTx)
require.NoError(t, err)
require.NoError(t, dbTx.Commit(ctx))

s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg)
if err != nil {
t.Error(err)
}
cfg := pool.Config{
FreeClaimGasLimit: 150000,
}
p := pool.NewPool(cfg, s, st, common.Address{}, chainID.Uint64())

privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x"))
require.NoError(t, err)

auth, err := bind.NewKeyedTransactorWithChainID(privateKey, chainID)
require.NoError(t, err)

// insert transaction
revertScData, err := hex.DecodeHex(Revert.RevertBin)
require.NoError(t, err)
tx := types.NewTx(&types.LegacyTx{
Nonce: uint64(0),
Gas: uint64(1000000),
GasPrice: big.NewInt(10),
Data: revertScData,
})
signedTx, err := auth.Signer(auth.From, tx)
require.NoError(t, err)

err = p.AddTx(ctx, *signedTx)
require.NoError(t, err)

txs, err := p.GetPendingTxs(ctx, false, 0)
require.NoError(t, err)
assert.Equal(t, 1, len(txs))

for i := 0; i < 1; i++ {
assert.Equal(t, pool.TxStatusPending, txs[0].Status)
}
}
7 changes: 6 additions & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,12 @@ func (s *State) PreProcessTransaction(ctx context.Context, tx *types.Transaction
return nil, err
}

return s.internalProcessUnsignedTransaction(ctx, tx, sender, &lastL2BlockNumber, false, &nonce, dbTx)
response, err := s.internalProcessUnsignedTransaction(ctx, tx, sender, &lastL2BlockNumber, false, &nonce, dbTx)
if err != nil && !errors.Is(err, runtime.ErrExecutionReverted) {
return nil, err
}

return response, nil
}

// ProcessUnsignedTransaction processes the given unsigned transaction.
Expand Down