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

feat(mempool): backport Lanes and DOG from upstream #5

Merged
merged 14 commits into from
Mar 15, 2025

Conversation

hvanz
Copy link
Collaborator

@hvanz hvanz commented Mar 12, 2025

I cherry-picked the relevant commits for Lanes and DOG from cometbft/cometbft's main branch. These commits were mostly unchanged.

When it's ready to be merged, remember to do "Rebase and Merge"!

hvanz and others added 14 commits March 5, 2025 11:55
…etbft#3659)

Required for cometbft#3658

---

- [ ] 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

---------

Co-authored-by: Andy Nogueira <[email protected]>
<!--

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

-->

---

- [ ] 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

---------

Co-authored-by: Anton Kaliaev <[email protected]>
…#3700)

Fixes cometbft#3694

This PR replaces:
```
type CListMempool struct {
	txsBytes atomic.Int64 // total size of mempool, in bytes
        ...
	txs    *clist.CList
	txsMap sync.Map
        ...
}
```
by
```
type CListMempool struct {
        ...
	txsMtx   cmtsync.RWMutex
	txs      *clist.CList                    // concurrent linked-list of valid txs
	txsMap   map[types.TxKey]*clist.CElement // for quick access to txs
	txsBytes int64                           // total size of mempool, in bytes
        ...
}
```
The new `txsMtx` mutex is used every time the variables `txs`, `txsMap`,
and `txsBytes` are accessed.

---

- [ ] Tests written/updated
- [x] 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

---------

Co-authored-by: Andy Nogueira <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…4117)

Closes cometbft#4120
- [Allow different lanes to the same
priority](cometbft@7360365)
- [Limits on lane
capacities](cometbft@2de8f07)
…4229)

There are reports of some test failing because of non-existing lanes
(eg.
https://github.com/cometbft/cometbft/actions/runs/11121278617/job/30900042983)

This PR always initialises mempools in tests with lane information
fetched from the app.
As per the title.

---

- [ ] 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

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Closes cometbft#4138 

Formatted file:
[docs/guides/app-dev/mempool-lanes.md](https://github.com/cometbft/cometbft/blob/hvanz/docs-guides-lanes-4138/docs/guides/app-dev/mempool-lanes.md)

---------

Co-authored-by: Jasmina Malicevic <[email protected]>
Co-authored-by: Anton Kaliaev <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Sergio Mena <[email protected]>
Contributes to cometbft#4318

The DOG spec is based on Flood's spec (cometbft#4477)


[README.md](https://github.com/cometbft/cometbft/tree/hvanz/flood-spec-4318/spec/mempool/gossip/)

---------

Co-authored-by: Andy Nogueira <[email protected]>
Co-authored-by: Daniel <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Solves cometbft#4318

Based on cometbft#4476 


[README.md](https://github.com/cometbft/cometbft/tree/hvanz/dog-spec-4318/spec/mempool/gossip)

---------

Co-authored-by: Andy Nogueira <[email protected]>
Co-authored-by: Daniel <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ometbft#4555)

Closes cometbft#4558

The bulk of the work is in one file: `mempool/reactor.go`.

Each commit is a self-contained addition to the code:
- [add new proto messages HaveTx and
ResetRoute](cometbft@e236427)
- [add
config](cometbft@bca343a)
- [add
MempoolControlChannel](cometbft@cb65e15)
- [add GetSenders method to Mempool interface, and Senders to Entry
interface](cometbft@d73f263)
- [add router to mempool
reactor](cometbft@fb38f14)
- [add redundancy controller to mempool
reactor](cometbft@f91be43)
- [add metrics DisabledRoutes and
Redundancy](cometbft@28b14f1)
- [add changelog
file](cometbft@4677722)

---

- [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

---------

Co-authored-by: Jasmina Malicevic <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…t#4646)

A mistake in the tests got merged with the PR merging the DOG protocol
into main.

`TestDOGDisabledRoutes` was put asleep for 100s instead of 100ms. 

---

#### 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
The test should be able now to catch the error introduced by
cometbft#3657.

----

To see how it would break, please checkout the branch
`cason/test-nobroadcastsender`, then:

```
$ cd mempool
$ go test -v -run TestReactorNoBroadcastToSender
```

And wait it to fail, after 2 minutes. You are going to see the busy-loop
around, logs entries starting with `Skipping tx`, forever for the same
transaction.

Important: the test unit only works in the traditional mempool design,
without lanes. We should consider adding a variant of it that should
also pass when lanes are considered.

---

- [x] 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

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@hvanz hvanz requested review from nmarcetic and maxim-inj March 12, 2025 07:45
@hvanz hvanz self-assigned this Mar 12, 2025
Copy link

coderabbitai bot commented Mar 12, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nmarcetic
Copy link
Member

LGTM!

// NewPersistentApplication creates a new application using the goleveldb database engine.
func NewPersistentApplication(dbDir string) *Application {
// newDB creates a DB engine for persisting the application state.
func newDB(dbDir string) *dbm.PebbleDB {
Copy link
Member

@nmarcetic nmarcetic Mar 13, 2025

Choose a reason for hiding this comment

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

leveldb is still supported in v1? Pebble is just defult in newly generated configs?
Btw do you have any benchmarks or anything that you could share regarding decision to move to pebble as default storage.

Copy link
Collaborator Author

@hvanz hvanz Mar 14, 2025

Choose a reason for hiding this comment

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

Only pebble is supported but it's still possible to use any database: https://github.com/cometbft/cometbft/blob/main/UPGRADING.md#db-changes

Some of the reasons for this decision are here (from 2023) and more recently here.

Copy link
Member

Choose a reason for hiding this comment

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

@hvanz Does that mean we only need to use the goleveldb build flag with v1, without requiring any custom implementation (e.g., DB interface modifications, DefaultDBProvider overrides, etc.)?

We’re currently evaluating Pebble, but migrating would be a major effort. We’d prefer to avoid mixing implementations for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, ignore my previous message. Those changes are not in v1.0.1. You would only need to set db_backend = "goleveldb". See here: https://github.com/InjectiveLabs/cometbft/blob/hvanz/v1.0.1%2Blanes%2Bdog/docs/references/config/config.toml.md#db_backend

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also there is a document we wrote as Upgrading guidelines to v1.0 which might have some other helpful insights.

Copy link
Collaborator

Choose a reason for hiding this comment

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

leveldb is still supported in v1? Pebble is just defult in newly generated configs? Btw do you have any benchmarks or anything that you could share regarding decision to move to pebble as default storage.

@nmarcetic We tested Pebble when exploring changing the database key layout and pruning + compaction.

We had reports from other teams about Pebble's superiors performance compared to goleveldb. More than that golevelDB is not maintained anymore.

In our local tests, our app was not really storage bound but the numbers we got from multiple runs indicated Pebble was slightly better:
https://github.com/cometbft/cometbft/blob/main/docs/references/storage/README.md#pebble vs . https://github.com/cometbft/cometbft/blob/main/docs/references/storage/README.md#local-1node .

The dealbreaker was the fact that Pebble is able to actually compact data without us intructing it to.
Namely, for golevelDB , in v1.x you now have an explicit call to db.Compact when you prune. This will now actually delete the files on disk (unlike before where pruning was not doing this). Pebble does not need that call.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @jmalicevic @hvanz

Btw we also have the same results from benchmarking Leveldb vs. PebbleDB: lower CPU, RAM, and IO utilization and faster read/write (mostly reads due to improved caching).

@maxim-inj maxim-inj merged commit e9e4c8a into v1.x-inj Mar 15, 2025
22 checks passed
@maxim-inj maxim-inj deleted the hvanz/v1.0.1+lanes+dog branch March 15, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants