From 8baf5cfd386818358616d39ebd7b7f2b6977cb54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Fri, 13 Sep 2024 15:19:28 +0300 Subject: [PATCH] feat: allow removing txns from pool via CLI/RPC --- eth/api_backend.go | 4 ++++ internal/ethapi/api.go | 5 +++++ internal/ethapi/backend.go | 1 + internal/web3ext/web3ext.go | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/eth/api_backend.go b/eth/api_backend.go index cae5e28efb79..5aee374c3c66 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -266,6 +266,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) return b.eth.txPool.AddLocal(signedTx) } +func (b *EthAPIBackend) RemoveTx(txHash common.Hash) { + b.eth.txPool.RemoveTx(txHash, true) +} + func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) { pending := b.eth.txPool.Pending(false) var txs types.Transactions diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 67bf83af6bfc..9b11f4d31223 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -227,6 +227,11 @@ func (s *PublicTxPoolAPI) Status() map[string]hexutil.Uint { } } +// Remove evicts a transaction from the pool. +func (s *PublicTxPoolAPI) Remove(ctx context.Context, hash common.Hash) { + s.b.RemoveTx(hash) +} + // Inspect retrieves the content of the transaction pool and flattens it into an // easily inspectable list. func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string { diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index b2be3ae41a0a..45d595edd51c 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -75,6 +75,7 @@ type Backend interface { // Transaction pool API SendTx(ctx context.Context, signedTx *types.Transaction) error + RemoveTx(txHash common.Hash) GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) GetPoolTransactions() (types.Transactions, error) GetPoolTransaction(txHash common.Hash) *types.Transaction diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 023c13687144..1198edf17747 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -772,6 +772,11 @@ web3._extend({ call: 'txpool_contentFrom', params: 1, }), + new web3._extend.Method({ + name: 'remove', + call: 'txpool_remove', + params: 1 + }), ] }); `