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

updates to running reth in mev-build-rs #164

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 20 additions & 59 deletions book/mev-build-rs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,87 +23,46 @@ You can install the `mev-rs` binary, named `mev`, with the following steps:
```sh
git clone https://github.com/ralexstokes/mev-rs
cd mev-rs
cargo install --locked --path bin/mev
cargo install --locked --path bin/mev
```

> The builder has been verified as of this commit `bf3d41f026e9728233dd3e1c40e75c49b9ae00b3`. No guarantees about other states of the repository currently.
> The builder has been verified as of this commit `08973a298268a3ad5f5d2c247b69b47dbb7bf97f`. No guarantees about other states of the repository currently.

The `cargo install` command should place the `mev` binary under the default `.cargo/bin` folder which is also in your `PATH` following the suggested Rust installation process.

## Run the builder

Once installed, we are ready to run the builder.
### Configuration

### Syncing nodes

Before we can run the builder, we need to sync a CL and EL node pair on our target network.

The remainder of this document will assume we are building for the `sepolia` network.

> Repository has only been tested on the **Sepolia** network and there is no guarantee the builder works on other networks.

The builder requires a synced CL client like [Lighthouse](https://github.com/sigp/lighthouse/).
You can find instructions on [how to sync a `lighthouse` node here](https://lighthouse-book.sigmaprime.io).

> Repository has only been tested with **Lighthouse** and there is no guarantee other CLs will work.

Doing the initial/bulk sync from the `mev` builder should be possible, but has not been tested.

The recommended approach will be to run `reth` (ideally built from source at the same commit pinned in this repo) for the target network alongside the CL until the pair has reached the head of the chain.

Example commands utilizing [checkpoint sync following the Lighthouse book](https://lighthouse-book.sigmaprime.io/run_a_node.html) to do this:

1. Make the JWT secret (refer to the Lighthouse guide for more info).

2. [recommended] Obtain a checkpoint sync URL if you wish to use this sync mode.

3. Run `reth`:
```sh
reth --chain sepolia \
node \
--http \
--authrpc.jwtsecret $JWT_SECRET_FILE_PATH
````

4. Run `lighthouse`:
```sh
lighthouse --network sepolia \
bn \
--http \
--execution-endpoint http://localhost:8551 \
--execution-jwt $JWT_SECRET_FILE_PATH \
--disable-deposit-contract-sync \
--checkpoint-sync-url $CHECKPOINT_SYNC_PROVIDER
```

The pair should start syncing. Once the pair of nodes is fully synced you can stop `reth` and run the `mev` builder in its place.

> You should be able to skip this step [Syncing nodes](#syncing-nodes) and just proceed directly to running the CL and `mev` builder in the [next step](#run-the-builder-on-a-synced-chain), as the builder should also sync if needed.
> But note:
> 1) running the builder without having a synced database already has not been tested
> 2) the builder will wait anyway until the head of the chain has been synced
To run the `mev` builder, first you should make the appropriate configuration. You can make a local copy of `example.config.toml` to get started.

### Run the builder on a synced chain
First, you will need to construct a JWT secret for use in the Engine API. You can refer to [these instructions from the Lighthouse guide](https://lighthouse-book.sigmaprime.io/run_a_node.html#step-1-create-a-jwt-secret-file) to see how to do this.

To run the `mev` builder, first you should make the appropriate configuration. You can make a local copy of `example.config.toml` to get started.
Ensure the `network` key in the TOML matches the target network you wish to run the builder on. This network applies to any of the `mev-rs` tools
that consume this configuration. The remainder of this document (including examples below) will assume we are building for the `sepolia` network.

To configure the builder, you can edit the fields under the `[builder]` key of the TOML.
To configure the builder specifically, you can edit the fields under the `[builder]` key of the TOML.

Fields you should change:

* `execution_mnemonic`: update to a seed phrase of an ethereum wallet you control.
This wallet will be used to author payment transactions to the proposer and also is used as the source of funds for any subsidy value you wish to add to the block.
You can select a particular index (following BIP-39) by terminating the seed phrase with a `:N` and integer index `N`. Otherwise the builder will just use the first index from the key tree.
* `subsidy_gwei`: set this value to 0 if your execution layer address has no ETH in it; otherwise, the blocks will be invalid.
* `jwt_secret_path`: ensure this value matches the one used previously when doing the initial sync.
* `jwt_secret_path`: this path points to the JWT secret file created previously and is specific to your deployment.

### Launch

Once the configuration looks good, you can run the builder as follows alongside `lighthouse`.
Once the configuration looks good, you can run the builder as follows alongside `lighthouse`. If you are running from a fresh install or have fallen far enough behind
the tip of the chain, the CL and EL nodes will sync. To expedite syncing times, use of checkpoint sync is recommended. You can see more info in [this guide from the Lighthouse book](https://lighthouse-book.sigmaprime.io/run_a_node.html).

> `lighthouse` has some additional configuration from above to ensure the builder always receives head updates from the chain.
> Repository has only been tested on the **Sepolia** network and there is no guarantee the builder works on other networks.

> Repository has only been tested with **Lighthouse** and there is no guarantee other CLs will work.

1. Run `mev` with config file `config.toml`:
```sh
mev --network sepolia build config.toml
mev build config.toml
```

2. Run `lighthouse`:
Expand All @@ -119,10 +78,12 @@ Once the configuration looks good, you can run the builder as follows alongside
--suggested-fee-recipient $FEE_RECIPIENT
```

> NOTE: the builder will not be active until the local CL and EL are fully synced.

### Additional notes

* The `--suggested-fee-recipient` for `lighthouse` is ultimately not used, but currently required to run the node. Any valid address should do and it should not affect the builder.
* If you are seeing slow or lagging operation, you can try to adjust the preparation lookahead with the `--prepare-payload-lookahead` option on `lighthouse`.
* The builder has been tested on an AWS EC2 instance of `t3.xlarge` variety with a `512Gb` disk.
* You can control the logging level of `reth` and `mev` with the `RUST_LOG` environment variable.
For example, to silence the `reth` logs, you can run `mev` like `RUST_LOG=mev=info mev --network sepolia build config.toml`
For example, to silence the `reth` logs, you can run `mev` like `RUST_LOG=mev=info mev build config.toml`
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
outputs = { self, flake-utils, nixpkgs, rust-overlay, crane }:
let
overlays = [ (import rust-overlay) ];
pkgs-for-system = system: import nixpkgs { inherit system overlays; };
mev-rs = system:
let
pkgs = import nixpkgs { inherit system overlays; };
pkgs = pkgs-for-system system;
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
in
Expand All @@ -36,5 +37,9 @@

packages.x86_64-linux.mev-rs = mev-rs "x86_64-linux";
packages.x86_64-linux.default = self.packages.x86_64-linux.mev-rs;

devShells.x86_64-darwin.default = import ./shell.nix { pkgs = pkgs-for-system "x86_64-darwin"; };
devShells.aarch64-darwin.default = import ./shell.nix { pkgs = pkgs-for-system "aarch64-darwin"; };
devShells.x86_64-linux.default = import ./shell.nix { pkgs = pkgs-for-system "x86_64-linux"; };
};
}
9 changes: 7 additions & 2 deletions mev-build-rs/src/reth_builder/service_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ impl ServiceExt {
let network = &self.network;
let network_name = format!("{0}", network);

let mut params =
vec!["".into(), "--chain".into(), network_name.to_string(), "--http".into()];
let mut params = vec![
"".into(),
"--chain".into(),
network_name.to_string(),
"--full".into(),
"--http".into(),
];
if let Some(path) = self.config.jwt_secret_path.as_ref() {
params.push("--authrpc.jwtsecret".into());
params.push(path.clone());
Expand Down
5 changes: 5 additions & 0 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ in
};

config = {
network.firewall = lib.mkIf (cfg.enable == "build") {
allowedTCPPorts = [ 30303 ];
allowedUDPPorts = [ 30303 ];
};

environment.systemPackages = [
mev-rs
];
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mkShell {
] ++ lib.optionals pkgs.stdenv.isDarwin [
libiconv
darwin.apple_sdk.frameworks.CFNetwork
darwin.apple_sdk.frameworks.SystemConfiguration
] ++ [
just
mdbook
Expand Down