Skip to content

Commit a79dd40

Browse files
committed
coinbase bugfix from flashbots#215
1 parent d35dd3c commit a79dd40

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

crates/rbuilder/src/backtest/backtest_build_block.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use ahash::HashMap;
99
use alloy_primitives::utils::format_ether;
1010
use alloy_rpc_client::RpcClient;
11+
use rand::rngs::OsRng;
12+
use revm_primitives::hex;
13+
use secp256k1::SecretKey;
1114
use url::Url;
1215

1316
use crate::{
@@ -26,7 +29,7 @@ use crate::{
2629
utils::timestamp_as_u64,
2730
};
2831
use clap::Parser;
29-
use std::path::PathBuf;
32+
use std::{env, path::PathBuf};
3033

3134
#[derive(Parser, Debug)]
3235
struct Cli {
@@ -106,6 +109,10 @@ where
106109
print_onchain_block_data(tx_sim_results, &orders, &block_data);
107110
}
108111

112+
if let Err(_) = config.base_config().coinbase_signer() {
113+
add_env_coinbase_signer();
114+
}
115+
109116
let BacktestBlockInput {
110117
ctx, sim_orders, ..
111118
} = backtest_prepare_ctx_for_block(
@@ -406,3 +413,17 @@ fn print_onchain_block_data(
406413
}
407414
}
408415
}
416+
417+
// Generate a random private key
418+
fn generate_private_key() -> String {
419+
let mut rng = OsRng;
420+
let secret_key = SecretKey::new(&mut rng);
421+
let hex_secret_key = hex::encode(secret_key.secret_bytes());
422+
hex_secret_key
423+
}
424+
425+
// Add COINBASE_SECRET_KEY as an environment variable during runtime
426+
fn add_env_coinbase_signer() {
427+
let private_key = generate_private_key();
428+
env::set_var("COINBASE_SECRET_KEY", private_key);
429+
}

crates/rbuilder/src/live_builder/base_config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ use alloy_primitives::{Address, B256};
1212
use eyre::{eyre, Context};
1313
use jsonrpsee::RpcModule;
1414
use lazy_static::lazy_static;
15+
use rand::rngs::OsRng;
1516
use reth::chainspec::chain_value_parser;
1617
use reth_chainspec::ChainSpec;
1718
use reth_db::DatabaseEnv;
1819
use reth_node_api::NodeTypesWithDBAdapter;
1920
use reth_node_ethereum::EthereumNode;
2021
use reth_primitives::StaticFileSegment;
2122
use reth_provider::{HeaderProvider, StateProviderFactory, StaticFileProviderFactory};
23+
use secp256k1::SecretKey;
2224
use serde::{Deserialize, Deserializer};
2325
use serde_with::{serde_as, DeserializeAs};
2426
use sqlx::PgPool;

0 commit comments

Comments
 (0)