Skip to content

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Jul 5, 2024
2 parents 3b22d52 + 882ce81 commit dadf117
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 112 deletions.
96 changes: 21 additions & 75 deletions .github/workflows/bench.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Benchmarks

on:
workflow_dispatch:
pull_request:
push:
branches: [develop]
Expand All @@ -16,7 +15,6 @@ jobs:
- stable
env:
PR_NUMBER: ${{ github.event.number }}
BENCH_AGAINST_BASE: 1
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -40,84 +38,32 @@ jobs:
run: |
source scripts/ci/env-vars.sh
echo "HEAD_SHA: ${HEAD_SHA}"
echo "HEAD_SHA_SHORT: ${HEAD_SHA_SHORT}"
echo "BASE_SHA: ${BASE_SHA}"
echo "BASE_SHA_SHORT: ${BASE_SHA_SHORT}"
# Keep important variables around for the upload workflow that comes afterwards
fn_vars="vars.txt"
echo "PR_NUMBER=${PR_NUMBER}" >> $fn_vars
echo "HEAD_SHA=${HEAD_SHA}" >> $fn_vars
echo "HEAD_SHA_SHORT=${HEAD_SHA_SHORT}" >> $fn_vars
echo "BASE_SHA=${BASE_SHA}" >> $fn_vars
echo "BASE_SHA_SHORT=${BASE_SHA_SHORT}" >> $fn_vars
cat $fn_vars
echo "HEAD_SHA=${HEAD_SHA}" >> "$GITHUB_OUTPUT"
echo "HEAD_SHA_SHORT=${HEAD_SHA_SHORT}" >> "$GITHUB_OUTPUT"
echo "BASE_SHA=${BASE_SHA}" >> "$GITHUB_OUTPUT"
echo "BASE_SHA_SHORT=${BASE_SHA_SHORT}" >> "$GITHUB_OUTPUT"
# S3 upload directory, depending if it includes a comparison or not
if [ "$HEAD_SHA" == "$BASE_SHA" ]; then
# No comparison (i.e. running on a branch like develop directly)
S3_UPLOAD_DIR="benchmark/${HEAD_SHA_SHORT}"
else
# Comparison (i.e. running on a PR)
S3_UPLOAD_DIR="benchmark/${HEAD_SHA_SHORT}-${BASE_SHA_SHORT}"
fi
echo "S3_UPLOAD_DIR: ${S3_UPLOAD_DIR}"
echo "S3_UPLOAD_DIR=${S3_UPLOAD_DIR}" >> "$GITHUB_OUTPUT"
echo "S3_UPLOAD_DIR=${S3_UPLOAD_DIR}" >> "$GITHUB_ENV"
#
# RUN BENCHMARKS (and upload the report)
#
# RUN BENCHMARKS
- run: make bench-in-ci

# Upload as artifact first
- name: Upload report as artifact
uses: actions/[email protected]
with:
name: benchmark-report
path: target/benchmark-in-ci/benchmark-report/

- name: Zip the report and add to folder (for S3 upload)
working-directory: target/benchmark-in-ci
- name: Zip the report
run: |
zip_fn="report.zip"
zip -r $zip_fn benchmark-report
mv $zip_fn benchmark-report/
cp vars.txt target/benchmark-in-ci/benchmark-report/
# Upload S3 (using https://github.com/shallwefootball/upload-s3-action)
- name: Upload report to S3
uses: shallwefootball/s3-upload-action@master
id: S3
with:
aws_key_id: ${{secrets.AWS_KEY_ID}}
aws_secret_access_key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: flashbots-rbuilder-ci-stats
source_dir: target/benchmark-in-ci/benchmark-report
destination_dir: ${{ steps.vars.outputs.S3_UPLOAD_DIR }}
cd target/benchmark-in-ci
zip -r benchmark-report.zip benchmark-report
mv benchmark-report.zip ../../
#
# POST SUMMARY (to PR comment and CI job summary)
#
- name: Add summary to CI job summary
run: |
BENCH_URL="https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/${{steps.S3.outputs.object_key}}/report/index.html"
sed -i "s|__BENCH_URL__|${BENCH_URL}|" target/benchmark-in-ci/benchmark-summary.md
sed -i "s|__BENCH_URL__|${BENCH_URL}|" target/benchmark-in-ci/benchmark-pr-comment.md
cat target/benchmark-in-ci/benchmark-summary.md >> $GITHUB_STEP_SUMMARY
# https://github.com/peter-evans/find-comment
- name: Find previous PR comment
uses: peter-evans/find-comment@v3
if: github.event_name == 'pull_request'
id: fc
- name: Upload report as artifact
uses: actions/upload-artifact@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Benchmark results
name: benchmark-report.zip
path: benchmark-report.zip

# https://github.com/peter-evans/create-or-update-comment
- name: Create or update PR comment
uses: peter-evans/create-or-update-comment@v4
if: github.event_name == 'pull_request'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body-path: target/benchmark-in-ci/benchmark-pr-comment.md
- name: Add details to CI job summary
run: |
cat target/benchmark-in-ci/benchmark-report/benchmark-summary.md >> $GITHUB_STEP_SUMMARY
86 changes: 86 additions & 0 deletions .github/workflows/bench_upload_for_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Benchmark upload

#
# This workflow runs after every benchmark, to upload the report to S3.
#
# It is its own workflow, because PRs can contain malicious code and run in a context with secrets..
#
# See also https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
#

on:
workflow_run:
workflows: ["Benchmarks"]
types:
- completed

jobs:
upload:
name: Upload benchmark report
runs-on: warp-ubuntu-latest-x64-16x
if: github.event.workflow_run.conclusion == 'success'
steps:
# https://github.com/actions/download-artifact
- uses: actions/download-artifact@v4
with:
name: benchmark-report.zip
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}

- name: Extract report
run: |
unzip benchmark-report.zip
ls -alh benchmark-report/
- name: Prepare variables
id: prepare
run: |
cat benchmark-report/vars.txt
source benchmark-report/vars.txt
S3_UPLOAD_DIR="benchmark/${HEAD_SHA_SHORT}-${BASE_SHA_SHORT}"
echo "S3_UPLOAD_DIR=${S3_UPLOAD_DIR}" >> "$GITHUB_OUTPUT"
echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
# Upload S3 (using https://github.com/shallwefootball/upload-s3-action)
- name: Upload to S3
uses: shallwefootball/s3-upload-action@master
id: S3
with:
aws_key_id: ${{secrets.AWS_KEY_ID}}
aws_secret_access_key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws_bucket: flashbots-rbuilder-ci-stats
source_dir: benchmark-report
destination_dir: ${{ steps.prepare.outputs.S3_UPLOAD_DIR }}

#
# POST SUMMARY (to PR comment and CI job summary)
#
- name: Add summary to CI job summary
run: |
BENCH_URL="https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/${{steps.S3.outputs.object_key}}/report/index.html"
sed -i "s|__BENCH_URL__|${BENCH_URL}|" benchmark-report/benchmark-pr-comment.md
cat benchmark-report/benchmark-pr-comment.md
cat benchmark-report/benchmark-pr-comment.md >> $GITHUB_STEP_SUMMARY
cat benchmark-report/benchmark-summary.md >> $GITHUB_STEP_SUMMARY
# https://github.com/peter-evans/find-comment
- name: Find previous PR comment
if: steps.prepare.outputs.PR_NUMBER != ''
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ steps.prepare.outputs.PR_NUMBER }}
comment-author: 'github-actions[bot]'
body-includes: Benchmark results

# https://github.com/peter-evans/create-or-update-comment
- name: Create or update PR comment
if: steps.prepare.outputs.PR_NUMBER != ''
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.prepare.outputs.PR_NUMBER }}
edit-mode: replace
body-path: benchmark-report/benchmark-pr-comment.md
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
/mev-test-contract/out
/target
/scripts/benchmark-results.*
/test/
/test/

# editors
.code
.idea
74 changes: 57 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# rbuilder

[![CI status](https://github.com/flashbots/rbuilder/workflows/Checks/badge.svg)](https://github.com/flashbots/rbuilder/actions/workflows/checks.yaml)
[![Telegram Chat](https://img.shields.io/endpoint?color=neon&logo=telegram&label=Chat&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fflashbots_rbuilder)](https://t.me/flashbots_rbuilder)
[![GitHub Release](https://img.shields.io/github/v/release/flashbots/rbuilder?label=Release)](https://github.com/flashbots/rbuilder/releases)

rbuilder is an open-source, blazingly fast, cutting edge implementation of a Ethereum MEV-Boost block builder written in Rust.
It is designed to provide a delightful developer experience, enabling community members to contribute and researchers to use rbuilder to study block building.
#### Features:
- **Multiple algorithms**: build Ethereum blocks by sorting for either effective gas price `mev_gas_price` or total profit `max_profit`

#### Features
- **Multiple algorithms**: Can be upgraded to handle several block building algorithms. The included algorithm builds blocks by sorting the orders by either effective gas price or total profit and then trying (they might fail!) to execute them to create the block. For more details see [ordering_builder.rs](crates/rbuilder/src/building/builders/ordering_builder.rs)
- **Backtesting**: support for quick and easy backtesting on mempool transactions and other data
- **Bundle merging**: bundles that target transactions which have already been included in a pending block can be dropped if they are marked in `reverting_tx_hashes`.
- **Smart nonce management**: identifies and smartly handles nonce dependencies between bundles and transactions
Expand Down Expand Up @@ -30,7 +36,7 @@ To run rbuilder you need:
* Reth node for state. (`reth_datadir`)
* Reth node must expose ipc interface for mempool tx subscription (`el_node_ipc_path`).
* CL node that triggers new payload events (it must be additionally configured to trigger payload event every single time)
* Source of bundles that sends `eth_sendBundle`, `mev_sendBundle`, `eth_sendRawTransaction` as JSON rpc calls. (`incoming_bundles_server_port`)
* Source of bundles that sends `eth_sendBundle`, `mev_sendBundle`, `eth_sendRawTransaction` as JSON rpc calls. (`jsonrpc_server_port`)
(by default rbuilder will take raw txs from the reth node mempool)
* Relays so submit to (`relays`)
* Alternatively it can submit to the block validation API if run in the dry run mode (`dry_run`, `dry_run_validation_url`)
Expand All @@ -43,27 +49,42 @@ Additionally, you can:

Running:
1. Prepare config file based on the `config-live-example.toml`
2. Run `builder run PATH_TO_CONFIG_FILE`
2. Run `rbuilder run PATH_TO_CONFIG_FILE`

### Benchmarking

rbuilder has a solid initial benchmarking setup (based on [Criterion.rs](https://github.com/bheisler/criterion.rs)).

- Benchmarks are located in [`crates/rbuilder/benches`](./crates/rbuilder/benches/). We'd love to add more meaningful benchmarks there!
- All PRs receive a [benchmark report like this](https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/benchmark/17c379a-24c50ff/report/index.html).
- All PRs receive a [benchmark report like this](https://flashbots-rbuilder-ci-stats.s3.us-east-2.amazonaws.com/benchmark/3b22d52-f468712/report/index.html).
- You can run benchmarks with `make bench` and open the Criterion-generated report with `make bench-report-open`.
Benchmarks also run on every PR.
- The rbuilder benchmark report is based on the Criterion-generated one, and prettifies it with custom templates. It's produced by
[`scripts/ci/benchmark-in-ci.sh`](./scripts/ci/benchmark-in-ci.sh).
- Let us know about further improvement ideas!
- Benchmarks are located in [`crates/rbuilder/benches`](./crates/rbuilder/benches/). We'd love to add more meaningful benchmarks there!
- Let us know about further improvement ideas and additional relevant benchmarks.


---

## Release Stability and Development Process

### Other executables
rbuilder is running in production at Flashbots since Q1 2024, and is reasonably stable. It is under active (and sometimes heavy) development, as we are constantly adding new features and improvements.

* `misc-relay-slot` shows info about winning bid for the block
* `debug-bench-machine` tests execution performance
* `debug-order-input` observe input of the bundles and transactions
* `debug-order-sim` observe simulation of the bundles and transactions
* `debug-slot-data-generation` shows new payload jobs coming from CL with attached data from relays.
We encourage users to choose the version that best fits their needs: the latest stable release for production use, or the `develop` branch for those who want to test the latest features and are comfortable with potential instability.

### Develop Branch
The `develop` branch is our main integration branch for ongoing development:
- We frequently merge pull requests into this branch.
- While we strive for quality, the `develop` branch may occasionally be unstable.
- There are no guarantees that code in this branch is fully tested or production-ready.

### Stable Releases
For users seeking stability:
- We recommend using the latest tagged release.
- Each release undergoes thorough testing in production environments before publication.
- Tagged releases offer a higher level of reliability and are suitable for production use.
- You can find the stable releases at [github.com/flashbots/rbuilder/releases](https://github.com/flashbots/rbuilder/releases)

### Release Cadence

We plan to cut a stable release at least once a month, but this may vary depending on the volume of changes and the stability of the codebase. To get notified, watch the repository, and you'll get an email notification on new releases.

---

Expand Down Expand Up @@ -99,6 +120,25 @@ See [`SECURITY.md`](./SECURITY.md)

## Acknowledgements

None of this would have been possible without having a fast and efficient Ethereum node, so big shoutout to the [Reth](https://github.com/paradigmxyz/reth) team.
Big shoutout to the [Reth](https://github.com/paradigmxyz/reth) team for building a kick-ass Ethereum node.


---

## Various notes

`make build` builds a bunch of additional binaries:


| Binary | Description |
| --------------------------- | ----------------------------------------------------------------------------------------------------- |
| `rbuilder` | Live block builder |
| `backtest-build-block` | Run backtests for a single block |
| `backtest-build-range` | Run backtests for a range of block |
| `backtest-fetch` | Download data for backtesting |
| `dummy-builder` | Simple sample builder to show how to plugin a custom `BlockBuildingSink` and `BlockBuildingAlgorithm` |
| `misc-relays-slot` | Shows info about winning bid for the block |
| `debug-bench-machine` | Tests execution performance |
| `debug-order-input` | Observe input of the bundles and transactions |
| `debug-order-sim` | Observe simulation of the bundles and transactions |
| `debug-slot-data-generator` | Shows new payload jobs coming from CL with attached data from relays. |
2 changes: 0 additions & 2 deletions config-backtest-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ backtest_fetch_eth_rpc_parallel = 400
backtest_fetch_output_file = "~/.rbuilder/backtest/main.sqlite"
backtest_fetch_mempool_data_dir = "~/.rbuilder/mempool-data"

#flashbots_db = "postgres://USER:PASSWORD@HOST:5432" # todo: delete before open sourcing

sbundle_mergeabe_signers = []

backtest_builders = ["mp-ordering", "mgp-ordering"]
Expand Down
8 changes: 7 additions & 1 deletion crates/rbuilder/src/building/builders/ordering_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
//! This builder just inserts orders in some order discarding everything that failed
//! Implementation of BlockBuildingAlgorithm that sorts the SimulatedOrders by some criteria.
//! After sorting it starts from an empty block and tries to add the SimulatedOrders one by one keeping on the block only the successful ones.
//! If a SimulatedOrder gives less profit than the value it gave on the top of block simulation is considered as failed (ExecutionError::LowerInsertedValue)
//! but it can be later reused.
//! The described algorithm is ran continuously adding new SimulatedOrders (they arrive on real time!) on each iteration until we run out of time (slot ends).
//! Sorting criteria are described on [`Sorting`].
//! For some more details see [`OrderingBuilderConfig`]
use crate::{
building::{
block_orders_from_sim_orders,
Expand Down
Loading

0 comments on commit dadf117

Please sign in to comment.