Skip to content

Latest commit

聽

History

History
71 lines (50 loc) 路 2.73 KB

CUSTOM-ALGORITHM.md

File metadata and controls

71 lines (50 loc) 路 2.73 KB

Test another rbuilder algorithm

This is an optional extension for researchers. It keeps the devnet, captured block, parent state, and order flow fixed while replacing or adding one rbuilder algorithm.

馃敊 back to the README

Change parameters without changing Rust

Start from configs/rbuilder/custom-algo.example.toml.tmpl. It demonstrates another ordering-builder configuration and the upstream parallel builder. Select it for both live and replay configs in .env:

RBUILDER_CONFIG_TEMPLATE=custom-algo.example.toml.tmpl
RBUILDER_BACKTEST_TEMPLATE=custom-algo.example.toml.tmpl
RBUILDER_LIVE_BUILDERS='["mgp-ordering","mp-ordering","mgp-deadline","parallel"]'

Then recreate rbuilder and replay a candidate:

docker compose up -d --force-recreate rbuilder
make candidates
make backtest BLOCK=81 \
  BUILDERS="mgp-ordering mp-ordering parallel default mgp-deadline"

Replace 81 with a height printed by make candidates.

Add new Rust code in an rbuilder fork

  1. Fork hackingdecentralized/rbuilder and create a branch from the artifact's pinned Boost+ commit:
git clone https://github.com/<YOUR-ACCOUNT>/rbuilder.git
cd rbuilder
git switch -c my-algorithm db8e5b57f7d3d086131eb9f48502fde85763fae6
  1. Implement BlockBuildingAlgorithm, add a variant to SpecificBuilderConfig, and wire that variant into the live builder and/or backtest dispatch. Commit and push the result.

  2. Copy configs/rbuilder/custom-algo.example.toml.tmpl to a new file in the same directory. Add a [[builders]] entry for my-algo, and add its name to the top-level backtest_builders list. Add it to RBUILDER_LIVE_BUILDERS only if the fork implements the live dispatch too.

  3. Point this artifact at the exact pushed revision in .env:

RBUILDER_REPO=https://github.com/<YOUR-ACCOUNT>/rbuilder.git
RBUILDER_COMMIT=<FULL_40_CHARACTER_COMMIT>
RBUILDER_CONFIG_TEMPLATE=my-algo.toml.tmpl
RBUILDER_BACKTEST_TEMPLATE=my-algo.toml.tmpl
  1. Build and verify the image metadata before running it:
make rebuild
docker image inspect "$(docker compose images -q rbuilder)" \
   --format 'source={{index .Config.Labels "org.opencontainers.image.source"}} revision={{index .Config.Labels "org.opencontainers.image.revision"}}'
make up
make smoke-test
  1. Compare the new algorithm on exactly the same replay input:
make candidates
make backtest BLOCK=81 \
   BUILDERS="mgp-ordering mp-ordering parallel default my-algo"

Replace 81 with a height printed by make candidates.

The command must print one result for every requested builder. Compare block profit, used orders, gas, failures, and execution time; the winner is allowed to vary by block.