Skip to content

Commit

Permalink
Filter txpool: new ethereum#1
Browse files Browse the repository at this point in the history
  • Loading branch information
ntminh611 committed Feb 23, 2023
1 parent 86ec7a4 commit 971842e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,20 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return nil
}

var dexs = map[common.Address]string{
common.HexToAddress("0x7a250d5630b4cf539739df2c5dacb4c659f2488d"): "Uni v2",
common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45"): "Uni v3",
common.HexToAddress("0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B"): "Universal",
common.HexToAddress("0x7a250d5630b4cf539739df2c5dacb4c659f2488d"): "1inchv4",
common.HexToAddress("0x1111111254fb6c44bAC0beD2854e76F90643097d"): "1inchv5",
common.HexToAddress("0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"): "Sushi",
}

func isDex(addr common.Address) (b bool) {
_, b = dexs[addr]
return
}

// add validates a transaction and inserts it into the non-executable queue for later
// pending promotion and execution. If the transaction is a replacement for an already
// pending or queued one, it overwrites the previous transaction if its price is higher.
Expand All @@ -663,9 +677,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err error) {
// If the transaction is already known, discard it
hash := tx.Hash()
if tx.To() == nil || (*tx.To() != common.HexToAddress("0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D") &&
*tx.To() != common.HexToAddress("0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45") &&
*tx.To() != common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88")) {
if !local && (tx.To() == nil || !isDex(*tx.To())) {
log.Trace("Deo phai uniswap", "hash", hash)
knownTxMeter.Mark(1)
return false, ErrAlreadyKnown
Expand Down

0 comments on commit 971842e

Please sign in to comment.