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

[WIP] Stream best blocks to the relay instead of pushing them #277

Draft
wants to merge 27 commits into
base: develop
Choose a base branch
from

Conversation

SkandaBhat
Copy link

@SkandaBhat SkandaBhat commented Dec 11, 2024

📝 Summary

  1. Use a block store that keeps track of the single best block at all times and streams it to any subscriber: https://github.com/SkandaBhat/rbuilder/blob/82f3d829ad4e9787847c66cb9cc157d22bad57dc/crates/rbuilder/src/building/builders/best_block_store.rs. Also added tests for both the store and tracker.

  2. added a helper function on Block that helps keep the comparing logic more readable: https://github.com/flashbots/rbuilder/compare/develop...SkandaBhat:best-block-store?expand=1#diff-3349e9f2b5d24a3da06ac[…]1334cc81518f9090a131c9dR47. This is used in best_block_store

  3. In relay_submit, we now subscribe to best_block_store and process best blocks as and when they arrive. BlockBuildingSink and BlockBuildingSinkFactory is not needed anymore here and we now call RelayCoordinator: https://github.com/flashbots/rbuilder/compare/develop...SkandaBhat:best-block-store?expand=1#diff-1ab827716722c4d9c2be8[…]19983e2a53a4c54b2553bf3cf0

  4. In bid maker, we call try_and_update on the tracker, which checks if the block is better than the global best block, and if so, updates it on the global best block store: https://github.com/flashbots/rbuilder/compare/develop...SkandaBhat:best-block-store?expand=1#diff-be9eab4716937ef12a623[…]dfb88b7571d7f82e54c23eR131

  5. UnfinishedBlockBuildingSink and UnfinishedBlockBuildingSinkFactory can be decoupled from BlockSealingBidder and the Sink can be entirely removed in favour of the new architecture, making the end to end process simpler.

💡 Motivation and Context

We have a push-based architecture for block building right now, where each builder runs a building algorithm and pushes blocks to a Sink, which sorts the blocks and submits the best block in a loop. This causes unnecessary flooding of the sink with low value blocks and additional overhead for the sink to sort every block it receives.

We can instead have a global best block store that stores a single best block at all times, and stream updates to any subscriber. This way, the relay sink can react immediately to updates from the store, and the builders can push best blocks only when they have a block that has a higher bid value than the global best block, thereby keeping the channel only for new best blocks found.

Overview

  1. Builders report strictly best blocks to a Global Best Block Store
  2. The sink subscribes to the Global Best Block Store
  3. The sink processes updates(new blocks) to the Global Best Block Store on-demand
  4. Builders subscribe to the Global Best Block Store and stores new best blocks whenever they arrive

✅ I have completed the following steps:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

@SkandaBhat SkandaBhat changed the title Stream best blocks to the relay instead of pushing them [WIP] Stream best blocks to the relay instead of pushing them Dec 11, 2024
Copy link

Benchmark results for 6446e08

Report: https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/benchmark/6446e08-16290b6/report/index.html

Date (UTC) 2024-12-13T09:57:25+00:00
Commit 6446e089e874beaeea353f1838d545f9bea4388a
Base SHA 16290b62a7b1a7693b04589ce403013bee09b20b

Significant changes

Benchmark Mean Status
MEV-Boost SubmitBlock serialization/JSON encoding -35.40% Performance has improved.

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.

1 participant