From cd4536ed60ffd3028e8c84db3ef2932d8b890549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Faruk=20Irmak?= Date: Mon, 16 Sep 2024 13:56:11 +0300 Subject: [PATCH] feat: allow removing txns from pool via CLI/RPC (#1041) --- eth/api_backend.go | 4 ++++ internal/ethapi/api.go | 5 +++++ internal/ethapi/backend.go | 1 + internal/web3ext/web3ext.go | 5 +++++ params/version.go | 2 +- 5 files changed, 16 insertions(+), 1 deletion(-) 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 34cce5e6f0ec..f29d8e8680b7 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -227,6 +227,11 @@ func (s *PublicTxPoolAPI) Status() map[string]hexutil.Uint { } } +// RemoveTransactionByHash evicts a transaction from the pool. +func (s *PublicTxPoolAPI) RemoveTransactionByHash(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..2967a849b1a1 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: 'removeTransactionByHash', + call: 'txpool_removeTransactionByHash', + params: 1 + }), ] }); ` diff --git a/params/version.go b/params/version.go index 3916379abda9..7f4b7c582248 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 14 // Patch version component of the current release + VersionPatch = 15 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )