Skip to content

Commit

Permalink
feat: allow removing txns from pool via CLI/RPC (#1059)
Browse files Browse the repository at this point in the history
* feat: allow removing txns from pool via CLI/RPC (#1041)

* fix

---------

Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
  • Loading branch information
0xmountaintop and omerfirmak authored Oct 9, 2024
1 parent d226deb commit bb4b703
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
return b.eth.txPool.Add([]*types.Transaction{signedTx}, true, false)[0]
}

func (b *EthAPIBackend) RemoveTx(txHash common.Hash) {
b.eth.txPool.RemoveTx(txHash, true, true)
}

func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
pending := b.eth.txPool.Pending(false)
var txs types.Transactions
Expand Down
5 changes: 5 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ func (s *TxPoolAPI) Status() map[string]hexutil.Uint {
}
}

// RemoveTransactionByHash evicts a transaction from the pool.
func (s *TxPoolAPI) 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 *TxPoolAPI) Inspect() map[string]map[string]map[string]string {
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match
func (b testBackend) StateAt(root common.Hash) (*state.StateDB, error) {
return b.chain.StateAt(root)
}
func (b testBackend) RemoveTx(txHash common.Hash) {}

func TestEstimateGas(t *testing.T) {
t.Parallel()
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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
Expand Down
2 changes: 2 additions & 0 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,5 @@ func (b *backendMock) Engine() consensus.Engine { return nil }
func (b *backendMock) StateAt(root common.Hash) (*state.StateDB, error) {
return nil, nil
}

func (b *backendMock) RemoveTx(txHash common.Hash) {}
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,11 @@ web3._extend({
call: 'txpool_contentFrom',
params: 1,
}),
new web3._extend.Method({
name: 'removeTransactionByHash',
call: 'txpool_removeTransactionByHash',
params: 1
}),
]
});
`
Expand Down

0 comments on commit bb4b703

Please sign in to comment.