fix(mempool): Move senders from reactor back to CList entries#3131
fix(mempool): Move senders from reactor back to CList entries#3131
Conversation
| // https://github.com/tendermint/tendermint/issues/5796 | ||
|
|
||
| if !memR.isSender(memTx.tx.Key(), peer.ID()) { | ||
| if !memTx.isSender(peer.ID()) { |
There was a problem hiding this comment.
This is the main reason of this PR. When reading the transaction to gossip, the sender must be available immediately so the transaction is not sent back to it. By first storing the transaction in CList and then storing the sender in the reactor, a small delay was introduced during which the transaction has no sender.
| mp.cache = NopTxCache{} | ||
| } | ||
|
|
||
| proxyAppConn.SetResponseCallback(mp.globalCb) |
There was a problem hiding this comment.
The globalCb callback was only used for Recheck responses. Now the responses are simply handled by a callback in a ReqRes structure, right after calling CheckTxAsync during rechecking.
There was a problem hiding this comment.
There are three structures with a callback:
proxyAppConn, implementing theClientinterface, with a callback of typefunc(*types.Request, *types.Response). Before this PR, this callback was used only on CheckTx ABCI responses. It is set only once, during the creation ofCListMempool.ReqRes, with a callback of typefunc(*types.Response). This is more flexible because we can set it whenCheckTxAsyncreturns the request/response, allowing us to customise the function by passing extra information, such as the sender.- the external callback passed to
CListMempool.CheckTx, reintroduced in this PR, and invoked at the end of handling the CheckTx response. This is used for processing the response on the RPC endpointsbroadcast_tx_syncandbroadcast_tx_commit.
There was a problem hiding this comment.
The globalCb callback was only used for Recheck responses.
I see there a case for CheckTx in addition to the one for ReCheckTx
There was a problem hiding this comment.
Should this useful explanation be somewhere in the form of a comment?
| default: | ||
| // ignore other messages | ||
| // update metrics | ||
| mem.metrics.Size.Set(float64(mem.Size())) |
There was a problem hiding this comment.
Now, update metrics only when the mempool is modified.
Co-authored-by: Sergio Mena <sergio@informal.systems>
Closes #3084 This PR re-introduces the `TxInfo` parameter with sender information into the signature of `CheckTx` in the `Mempool` interface. The new signature is `CheckTx(tx types.Tx, sender p2p.ID) (*abcicli.ReqRes, error)`, instead of `CheckTx(tx types.Tx) (*abcicli.ReqRes, error)`. PR #1010 moved the senders from the CList mempool entries to the reactor. The reason for the changes in this PR is that storing the sender (in the reactor, through a callback) after storing the transaction (in the CList struct) introduces a small delay during which the transaction doesn't have a sender, allowing, in a few cases, the gossip routines to send back the transaction to the sender. Now the transaction and the (first) sender are stored together when the transaction is added to the mempool. Note that the changes in #1010 didn't reach `v0.38.x`, so this change will partially revert the mempool API in `main` and `v1.x`. For reviewers, please see the github comments on the code. <!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> --- #### PR checklist - [X] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [X] Updated relevant documentation (`docs/` or `spec/`) and code comments - [X] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec --------- Co-authored-by: Sergio Mena <sergio@informal.systems> (cherry picked from commit 26cb788) # Conflicts: # rpc/client/rpc_test.go # rpc/core/mempool.go
Closes #3084 This PR re-introduces the `TxInfo` parameter with sender information into the signature of `CheckTx` in the `Mempool` interface. The new signature is `CheckTx(tx types.Tx, sender p2p.ID) (*abcicli.ReqRes, error)`, instead of `CheckTx(tx types.Tx) (*abcicli.ReqRes, error)`. PR #1010 moved the senders from the CList mempool entries to the reactor. The reason for the changes in this PR is that storing the sender (in the reactor, through a callback) after storing the transaction (in the CList struct) introduces a small delay during which the transaction doesn't have a sender, allowing, in a few cases, the gossip routines to send back the transaction to the sender. Now the transaction and the (first) sender are stored together when the transaction is added to the mempool. Note that the changes in #1010 didn't reach `v0.38.x`, so this change will partially revert the mempool API in `main` and `v1.x`. For reviewers, please see the github comments on the code. <!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> --- - [X] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [X] Updated relevant documentation (`docs/` or `spec/`) and code comments - [X] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec --------- Co-authored-by: Sergio Mena <sergio@informal.systems>
#3131) (#3178) Closes #3084 This PR re-introduces the `TxInfo` parameter with sender information into the signature of `CheckTx` in the `Mempool` interface. The new signature is `CheckTx(tx types.Tx, sender p2p.ID) (*abcicli.ReqRes, error)`, instead of `CheckTx(tx types.Tx) (*abcicli.ReqRes, error)`. PR #1010 moved the senders from the CList mempool entries to the reactor. The reason for the changes in this PR is that storing the sender (in the reactor, through a callback) after storing the transaction (in the CList struct) introduces a small delay during which the transaction doesn't have a sender, allowing, in a few cases, the gossip routines to send back the transaction to the sender. Now the transaction and the (first) sender are stored together when the transaction is added to the mempool. Note that the changes in #1010 didn't reach `v0.38.x`, so this change will partially revert the mempool API in `main` and `v1.x`. For reviewers, please see the github comments on the code. --- #### PR checklist - [X] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [X] Updated relevant documentation (`docs/` or `spec/`) and code comments - [X] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #3131 done by [Mergify](https://mergify.com). --------- Co-authored-by: Hernán Vanzetto <15466498+hvanz@users.noreply.github.com> Co-authored-by: hvanz <hernan.vanzetto@gmail.com> Co-authored-by: Sergio Mena <sergio@informal.systems>
…ync/commit` (#3193) This PR fixes a race condition generated when calling `broadcast_tx_sync` and `broadcast_tx_commit`. When closing the context, we want to also close the goroutine waiting for the response with `reqRes.Wait()`. We don't need to do `reqRes.Done()` because there is a chance it may become negative; instead, we just let the ABCI client to do it. This bug was recently introduced by #3131. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
…ync/commit` (#3193) This PR fixes a race condition generated when calling `broadcast_tx_sync` and `broadcast_tx_commit`. When closing the context, we want to also close the goroutine waiting for the response with `reqRes.Wait()`. We don't need to do `reqRes.Done()` because there is a chance it may become negative; instead, we just let the ABCI client to do it. This bug was recently introduced by #3131. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit cd465c5) # Conflicts: # rpc/core/mempool.go
…ync/commit` (backport #3193) (#3194) This PR fixes a race condition generated when calling `broadcast_tx_sync` and `broadcast_tx_commit`. When closing the context, we want to also close the goroutine waiting for the response with `reqRes.Wait()`. We don't need to do `reqRes.Done()` because there is a chance it may become negative; instead, we just let the ABCI client to do it. This bug was recently introduced by #3131. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #3193 done by [Mergify](https://mergify.com). --------- Co-authored-by: Hernán Vanzetto <15466498+hvanz@users.noreply.github.com> Co-authored-by: hvanz <hernan.vanzetto@gmail.com>
Closes #3084
This PR re-introduces the
TxInfoparameter with sender information into the signature ofCheckTxin theMempoolinterface. The new signature isCheckTx(tx types.Tx, sender p2p.ID) (*abcicli.ReqRes, error), instead ofCheckTx(tx types.Tx) (*abcicli.ReqRes, error).PR #1010 moved the senders from the CList mempool entries to the reactor. The reason for the changes in this PR is that storing the sender (in the reactor, through a callback) after storing the transaction (in the CList struct) introduces a small delay during which the transaction doesn't have a sender, allowing, in a few cases, the gossip routines to send back the transaction to the sender. Now the transaction and the (first) sender are stored together when the transaction is added to the mempool.
Note that the changes in #1010 didn't reach
v0.38.x, so this change will partially revert the mempool API inmainandv1.x.For reviewers, please see the github comments on the code.
PR checklist
.changelog(we use unclog to manage our changelog)docs/orspec/) and code comments