mempool,rpc: add removetx rpc method (#7047)

Addresses one of the concerns with #7041.

Provides a mechanism (via the RPC interface) to delete a single transaction, described by its hash, from the mempool. The method returns an error if the transaction cannot be found. Once the transaction is removed it remains in the cache and cannot be resubmitted until the cache is cleared or it expires from the cache.
This commit is contained in:
Sam Kleinman
2021-10-05 20:23:15 +00:00
committed by GitHub
parent 3ea81bfaa7
commit 851d2e3bde
24 changed files with 137 additions and 78 deletions
+8
View File
@@ -315,6 +315,14 @@ func (c *baseRPCClient) CheckTx(ctx context.Context, tx types.Tx) (*coretypes.Re
return result, nil
}
func (c *baseRPCClient) RemoveTx(ctx context.Context, txKey types.TxKey) error {
_, err := c.caller.Call(ctx, "remove_tx", map[string]interface{}{"tx_key": txKey}, nil)
if err != nil {
return err
}
return nil
}
func (c *baseRPCClient) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error) {
result := new(coretypes.ResultNetInfo)
_, err := c.caller.Call(ctx, "net_info", map[string]interface{}{}, result)
+1
View File
@@ -146,6 +146,7 @@ type MempoolClient interface {
UnconfirmedTxs(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error)
NumUnconfirmedTxs(context.Context) (*coretypes.ResultUnconfirmedTxs, error)
CheckTx(context.Context, types.Tx) (*coretypes.ResultCheckTx, error)
RemoveTx(context.Context, types.TxKey) error
}
// EvidenceClient is used for submitting an evidence of the malicious
+4
View File
@@ -116,6 +116,10 @@ func (c *Local) CheckTx(ctx context.Context, tx types.Tx) (*coretypes.ResultChec
return c.env.CheckTx(c.ctx, tx)
}
func (c *Local) RemoveTx(ctx context.Context, txKey types.TxKey) error {
return c.env.Mempool.RemoveTxByKey(txKey)
}
func (c *Local) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo, error) {
return c.env.NetInfo(c.ctx)
}
+25
View File
@@ -237,6 +237,31 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/remove_tx:
get:
summary: Removes a transaction from the mempool.
tags:
- TxKey
operationId: remove_tx
parameters:
- in: query
name: txKey
required: true
schema:
type: string
example: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
description: The transaction key
responses:
"200":
description: empty response.
"500":
description: empty error.
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
/subscribe:
get:
summary: Subscribe for events via WebSocket.