Skip to content

Conversation

hvanz
Copy link
Member

@hvanz hvanz commented May 27, 2024

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

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments
  • Title follows the Conventional Commits spec

@@ -276,7 +253,7 @@ func (memR *Reactor) broadcastTxRoutine(peer p2p.Peer) {
// NOTE: Transaction batching was disabled due to
// https://github.com/tendermint/tendermint/issues/5796

if !memR.isSender(memTx.tx.Key(), peer.ID()) {
if !memTx.isSender(peer.ID()) {
Copy link
Member Author

@hvanz hvanz May 28, 2024

Choose a reason for hiding this comment

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

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.

@@ -92,8 +87,6 @@ func NewCListMempool(
mp.cache = NopTxCache{}
}

proxyAppConn.SetResponseCallback(mp.globalCb)
Copy link
Member Author

@hvanz hvanz May 28, 2024

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are three structures with a callback:

  • proxyAppConn, implementing the Client interface, with a callback of type func(*types.Request, *types.Response). Before this PR, this callback was used only on CheckTx ABCI responses. It is set only once, during the creation of CListMempool.
  • ReqRes, with a callback of type func(*types.Response). This is more flexible because we can set it when CheckTxAsync returns 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 endpoints broadcast_tx_sync and broadcast_tx_commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

The globalCb callback was only used for Recheck responses.

I see there a case for CheckTx in addition to the one for ReCheckTx

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 useful explanation be somewhere in the form of a comment?

@hvanz hvanz self-assigned this May 28, 2024
@hvanz hvanz added the mempool label May 28, 2024
@hvanz hvanz changed the title fix(mempool): Move senders back from reactor to clist_mempool entries fix(mempool): Move senders from reactor back to CList entries May 28, 2024
@hvanz hvanz marked this pull request as ready for review May 28, 2024 13:49
@hvanz hvanz requested a review from a team as a code owner May 28, 2024 13:49
@hvanz hvanz requested a review from a team May 28, 2024 13:49
@hvanz hvanz marked this pull request as draft May 28, 2024 15:06
@hvanz hvanz added the wip Work in progress label May 28, 2024
@hvanz hvanz added backport-to-v1.x Tell Mergify to backport the PR to v1.x labels May 28, 2024
default:
// ignore other messages
// update metrics
mem.metrics.Size.Set(float64(mem.Size()))
Copy link
Member Author

Choose a reason for hiding this comment

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

Now, update metrics only when the mempool is modified.

@hvanz hvanz marked this pull request as ready for review May 29, 2024 07:20
@hvanz hvanz marked this pull request as draft May 29, 2024 07:54
Co-authored-by: Sergio Mena <sergio@informal.systems>
Copy link
Contributor

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@hvanz hvanz enabled auto-merge June 4, 2024 09:36
@hvanz hvanz added this pull request to the merge queue Jun 4, 2024
Merged via the queue into main with commit 26cb788 Jun 4, 2024
@hvanz hvanz deleted the hvanz/mempool-fix-senders-3084 branch June 4, 2024 09:43
mergify bot pushed a commit that referenced this pull request Jun 4, 2024
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
hvanz added a commit that referenced this pull request Jun 4, 2024
hvanz added a commit that referenced this pull request Jun 4, 2024
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>
hvanz added a commit that referenced this pull request Jun 4, 2024
#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>
andynog added a commit that referenced this pull request Jun 4, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jun 5, 2024
…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
mergify bot pushed a commit that referenced this pull request Jun 5, 2024
…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
hvanz added a commit that referenced this pull request Jun 5, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-v1.x Tell Mergify to backport the PR to v1.x mempool
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

mempool: tx could be sent back to sender
4 participants