Skip to content

Commit bb4b703

Browse files
feat: allow removing txns from pool via CLI/RPC (#1059)
* feat: allow removing txns from pool via CLI/RPC (#1041) * fix --------- Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
1 parent d226deb commit bb4b703

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

eth/api_backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
314314
return b.eth.txPool.Add([]*types.Transaction{signedTx}, true, false)[0]
315315
}
316316

317+
func (b *EthAPIBackend) RemoveTx(txHash common.Hash) {
318+
b.eth.txPool.RemoveTx(txHash, true, true)
319+
}
320+
317321
func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
318322
pending := b.eth.txPool.Pending(false)
319323
var txs types.Transactions

internal/ethapi/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ func (s *TxPoolAPI) Status() map[string]hexutil.Uint {
237237
}
238238
}
239239

240+
// RemoveTransactionByHash evicts a transaction from the pool.
241+
func (s *TxPoolAPI) RemoveTransactionByHash(ctx context.Context, hash common.Hash) {
242+
s.b.RemoveTx(hash)
243+
}
244+
240245
// Inspect retrieves the content of the transaction pool and flattens it into an
241246
// easily inspectable list.
242247
func (s *TxPoolAPI) Inspect() map[string]map[string]map[string]string {

internal/ethapi/api_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match
601601
func (b testBackend) StateAt(root common.Hash) (*state.StateDB, error) {
602602
return b.chain.StateAt(root)
603603
}
604+
func (b testBackend) RemoveTx(txHash common.Hash) {}
604605

605606
func TestEstimateGas(t *testing.T) {
606607
t.Parallel()

internal/ethapi/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type Backend interface {
7676

7777
// Transaction pool API
7878
SendTx(ctx context.Context, signedTx *types.Transaction) error
79+
RemoveTx(txHash common.Hash)
7980
GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
8081
GetPoolTransactions() (types.Transactions, error)
8182
GetPoolTransaction(txHash common.Hash) *types.Transaction

internal/ethapi/transaction_args_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,5 @@ func (b *backendMock) Engine() consensus.Engine { return nil }
362362
func (b *backendMock) StateAt(root common.Hash) (*state.StateDB, error) {
363363
return nil, nil
364364
}
365+
366+
func (b *backendMock) RemoveTx(txHash common.Hash) {}

internal/web3ext/web3ext.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,11 @@ web3._extend({
800800
call: 'txpool_contentFrom',
801801
params: 1,
802802
}),
803+
new web3._extend.Method({
804+
name: 'removeTransactionByHash',
805+
call: 'txpool_removeTransactionByHash',
806+
params: 1
807+
}),
803808
]
804809
});
805810
`

0 commit comments

Comments
 (0)