Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mempool,rpc: add removetx rpc method #7047

Merged
merged 19 commits into from Oct 5, 2021

Conversation

tychoish
Copy link
Contributor

@tychoish tychoish commented Oct 4, 2021

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.

Copy link
Contributor

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one minor comment. Love the cleanup!! thank you so much.

@adizere i think you and mircea were asking for something like this?

@@ -28,6 +28,7 @@ func (env *Environment) GetRoutes() RoutesMap {
"block_results": rpc.NewRPCFunc(env.BlockResults, "height", true),
"commit": rpc.NewRPCFunc(env.Commit, "height", true),
"check_tx": rpc.NewRPCFunc(env.CheckTx, "tx", true),
"remove_tx": rpc.NewRPCFunc(env.RemoveTx, "txkey,removeFromCache", false),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should try to avoid putting this on the public interface. Any one could potentially constantly remove all txs. Possibly group into the unsafe section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily see how that changes anything, as the unsafe section are just as available to users as the safe section

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unsafe section makes the operator aware they are turning it on. This change will expose functionality that could alter the nodes behaviour, that was my reasoning for suggesting unsafe.

I could crawl the network, find nodes and get a list of unconfirmed txs and remove all of them. If its a node that is a sentry or a validator it would clear the mempool. If we are fine exposing such behaviour, it should be documented somehow that this can cause problems.

@tychoish tychoish changed the title mempool,rpc: add removetxbykey rpc method mempool,rpc: add removetx rpc method Oct 4, 2021
types/mempool.go Outdated Show resolved Hide resolved
types/tx.go Show resolved Hide resolved
rpc/client/local/local.go Show resolved Hide resolved
internal/rpc/core/mempool.go Show resolved Hide resolved
@williambanfield
Copy link
Contributor

We should also add to the openapi docs as well.

@tychoish
Copy link
Contributor Author

tychoish commented Oct 4, 2021

@p4u and @mvdan it would be nice to see if this make sense to you and would help address some of your concerns!

Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an implementation standpoint this looks sound. I'd wait to get some response from users if there's anything else we may have missed. This will also require an update to the spec

internal/rpc/core/routes.go Outdated Show resolved Hide resolved
types/tx.go Show resolved Hide resolved
Copy link
Contributor

@adizere adizere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the code to understand the changes introduced by this PR, but my familiarity with tm-go is minimal. (Perhaps a PR description would be helpful in that regard.)

I have two questions to help me understand better the properties guaranteed by this new API:

  1. Suppose I call remove_tx(TxHashXYZ) on my full node. Is it possible that the transaction with key TxHashXYZ will re-enter the mempool of my full node if some peer of my full node broadcasts that tx?

  2. Related to question above: After calling remove_tx(TxHashXYZ) there's nothing preventing the call to broadcast_tx_sync(TxHashXYZ), right?

@@ -32,6 +32,10 @@ type Mempool interface {
// its validity and whether it should be added to the mempool.
CheckTx(ctx context.Context, tx types.Tx, callback func(*abci.Response), txInfo TxInfo) error

// RemoveTxByKey removes a transaction, identified by its key,
// from the mempool.
RemoveTxByKey(txKey types.TxKey) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a TxKey exactly, the same as hash? Ideally if we could remove the tx by hash that could be simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup it's the sha256 hash of the transaction

@cmwaters
Copy link
Contributor

cmwaters commented Oct 5, 2021

Hey @adizere. There is a fifo cache that can be used (see MempoolConfig.CacheSize) to stop removed transactions from re-entering the mempool via another node (or via BroadcastTx).

@tychoish tychoish added the S:automerge Automatically merge PR when requirements pass label Oct 5, 2021
types/mempool.go Outdated Show resolved Hide resolved
return nil
}

return errors.New("transaction not found")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this get a variable like the already-in-cache case? It seem like the kind of thing the caller might care to distinguish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I don't much see the point in distinguishing the error: there's no circumstance where removing a transaction would be retriable (perhaps eventually via the RPC, you might get a networking error that would make it worth retrying, but you'd want to be able to identify that that error is retriable? which seems/feels like an RPC feature.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but is the answer different for the "already in cache" case?

(Separately, and not related to this change, it seems like a mistake that we don't use the error code of the JSON-RPC response to communicate errors responsibly to the client)

@mergify mergify bot merged commit 851d2e3 into tendermint:master Oct 5, 2021
mergify bot pushed a commit that referenced this pull request Oct 5, 2021
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.

(cherry picked from commit 851d2e3)
tychoish added a commit that referenced this pull request Oct 5, 2021
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.

(cherry picked from commit 851d2e3)

Co-authored-by: Sam Kleinman <garen@tychoish.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S:automerge Automatically merge PR when requirements pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants