Skip to content

Commit

Permalink
Merge pull request #237 from ralexstokes/builder-subsidy-from-config
Browse files Browse the repository at this point in the history
Builder subsidy from config and refactor `RelaySet`
  • Loading branch information
ralexstokes authored May 3, 2024
2 parents 779a632 + 3cda0ed commit d402145
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 31 deletions.
8 changes: 4 additions & 4 deletions example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ wait_until_ms = 1000
# [optional] amount of value to bid as a fraction of the payload's revenue
# if missing, defaults to 1.0 (100%)
# validation: should be between [0, 1] inclusive.
bid_percent = 0.9
# [optional] amount to add to the bid on top of the payload's revenue,
# if missing, defaults to 0 wei
bid_percent = 1.0
# [optional] amount in wei to add to the bid on top of the payload's revenue,
# if missing, defaults to `mev_build_rs::payload::builder::DEFAULT_SUBSIDY_PAYMENT`
# currently sourced from the builder's wallet authoring the payment transaction
subsidy_wei = "0x0000000000000000000000000000000000000000000000000000000000000001"
subsidy_wei = "0x000000000000000000000000000000000000000000000000000000174876e800" # 100 Gwei
14 changes: 6 additions & 8 deletions mev-build-rs/src/auctioneer/auction_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use ethereum_consensus::primitives::{BlsPublicKey, Slot};
use mev_rs::{types::ProposerSchedule, Relay};
use mev_rs::types::ProposerSchedule;
use reth::primitives::Address;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::collections::{HashMap, HashSet};

pub type RelaySet = HashSet<Arc<Relay>>;
pub type RelayIndex = usize;
pub type RelaySet = HashSet<RelayIndex>;
pub type Proposals = HashMap<Proposer, RelaySet>;

#[derive(Debug, Clone, Default, Hash, PartialEq, Eq)]
Expand All @@ -30,7 +28,7 @@ impl AuctionSchedule {
self.schedule.get(&slot)
}

pub fn process(&mut self, relay: Arc<Relay>, schedule: &[ProposerSchedule]) -> Vec<Slot> {
pub fn process(&mut self, relay: RelayIndex, schedule: &[ProposerSchedule]) -> Vec<Slot> {
let mut slots = Vec::with_capacity(schedule.len());
for entry in schedule {
slots.push(entry.slot);
Expand All @@ -42,7 +40,7 @@ impl AuctionSchedule {
gas_limit: registration.gas_limit,
};
let relays = slot.entry(proposer).or_default();
relays.insert(relay.clone());
relays.insert(relay);
}
slots
}
Expand Down
30 changes: 19 additions & 11 deletions mev-build-rs/src/auctioneer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub struct Service<
clock: broadcast::Receiver<ClockMessage>,
builder: PayloadBuilderHandle<Engine>,
payload_store: PayloadStore<Engine>,
relays: Vec<Arc<Relay>>,
relays: Vec<Relay>,
config: Config,
context: Arc<Context>,
// TODO consolidate this somewhere...
Expand Down Expand Up @@ -155,10 +155,8 @@ impl<
context: Arc<Context>,
genesis_time: u64,
) -> Self {
let relays = parse_relay_endpoints(&config.relays)
.into_iter()
.map(|endpoint| Arc::new(Relay::from(endpoint)))
.collect::<Vec<_>>();
let relays =
parse_relay_endpoints(&config.relays).into_iter().map(Relay::from).collect::<Vec<_>>();

config.public_key = config.secret_key.public_key();

Expand All @@ -185,10 +183,12 @@ impl<
// and not block others at this interval
// TODO: batch updates to auction schedule
// TODO: consider fast data access once this stabilizes
for relay in self.relays.iter() {
// TODO: rework `auction_schedule` so there is no issue with confusing relays and their
// indices
for (relay_index, relay) in self.relays.iter().enumerate() {
match relay.get_proposal_schedule().await {
Ok(schedule) => {
let slots = self.auction_schedule.process(relay.clone(), &schedule);
let slots = self.auction_schedule.process(relay_index, &schedule);
info!(?slots, %relay, "processed proposer schedule");
}
Err(err) => {
Expand Down Expand Up @@ -354,11 +354,19 @@ impl<
&self.context,
) {
Ok(signed_submission) => {
let relays = &auction.relays;
// TODO: parallel dispatch
for relay in relays {
if let Err(err) = relay.submit_bid(&signed_submission).await {
warn!(%err, ?relay, slot = auction.slot, "could not submit payload");
for &relay_index in &auction.relays {
match self.relays.get(relay_index) {
Some(relay) => {
if let Err(err) = relay.submit_bid(&signed_submission).await {
warn!(%err, ?relay, slot = auction.slot, "could not submit payload");
}
}
None => {
// NOTE: this arm signals a violation of an internal invariant
// Please fix if you see this error
error!(relay_index, "could not dispatch to unknown relay");
}
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions mev-build-rs/src/payload/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub enum Error {
}

pub const BASE_TX_GAS_LIMIT: u64 = 21000;
// Default value in wei to add to payload payment, regardless of fees.
pub const DEFAULT_SUBSIDY_PAYMENT: u64 = 1337;

fn make_payment_transaction(
signer: &LocalWallet,
Expand Down Expand Up @@ -183,12 +185,24 @@ pub struct Inner {
pub signer: LocalWallet,
pub fee_recipient: Address,
pub chain_id: ChainId,
pub subsidy_wei: U256,
pub states: Mutex<HashMap<PayloadId, BundleStateWithReceipts>>,
}

impl PayloadBuilder {
pub fn new(signer: LocalWallet, fee_recipient: Address, chain_id: ChainId) -> Self {
let inner = Inner { signer, fee_recipient, chain_id, states: Default::default() };
pub fn new(
signer: LocalWallet,
fee_recipient: Address,
chain_id: ChainId,
subsidy_wei: Option<U256>,
) -> Self {
let inner = Inner {
signer,
fee_recipient,
chain_id,
subsidy_wei: subsidy_wei.unwrap_or_else(|| U256::from(DEFAULT_SUBSIDY_PAYMENT)),
states: Default::default(),
};
Self(Arc::new(inner))
}

Expand All @@ -199,7 +213,7 @@ impl PayloadBuilder {

fn determine_payment_amount(&self, fees: U256) -> U256 {
// TODO: remove temporary hardcoded subsidy
fees + U256::from(1337)
fees + self.subsidy_wei
}

pub fn finalize_payload<Client: StateProviderFactory>(
Expand Down
12 changes: 9 additions & 3 deletions mev-build-rs/src/payload/service_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reth::{
builder::{node::FullNodeTypes, BuilderContext},
cli::config::PayloadBuilderConfig,
payload::{PayloadBuilderHandle, PayloadBuilderService},
primitives::{Address, Bytes},
primitives::{Address, Bytes, U256},
providers::CanonStateSubscriptions,
transaction_pool::TransactionPool,
};
Expand All @@ -26,6 +26,7 @@ pub struct PayloadServiceBuilder {
extra_data: Option<Bytes>,
signer: LocalWallet,
fee_recipient: Address,
subsidy_wei: Option<U256>,
}

impl TryFrom<&Config> for PayloadServiceBuilder {
Expand All @@ -34,7 +35,12 @@ impl TryFrom<&Config> for PayloadServiceBuilder {
fn try_from(value: &Config) -> Result<Self, Self::Error> {
let signer = signer_from_mnemonic(&value.execution_mnemonic)?;
let fee_recipient = value.fee_recipient.unwrap_or_else(|| signer.address());
Ok(Self { extra_data: value.extra_data.clone(), signer, fee_recipient })
Ok(Self {
extra_data: value.extra_data.clone(),
signer,
fee_recipient,
subsidy_wei: value.subsidy_wei,
})
}
}

Expand Down Expand Up @@ -71,7 +77,7 @@ where
ctx.task_executor().clone(),
payload_job_config,
ctx.chain_spec().clone(),
PayloadBuilder::new(self.signer, self.fee_recipient, chain_id),
PayloadBuilder::new(self.signer, self.fee_recipient, chain_id, self.subsidy_wei),
);

let (payload_service, payload_builder) =
Expand Down
10 changes: 8 additions & 2 deletions mev-build-rs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use reth::{
api::EngineTypes,
builder::{NodeBuilder, WithLaunchContext},
payload::{EthBuiltPayload, PayloadBuilderHandle},
primitives::{Address, Bytes, NamedChain},
primitives::{Address, Bytes, NamedChain, U256},
tasks::TaskExecutor,
};
use reth_db::DatabaseEnv;
Expand All @@ -39,6 +39,9 @@ pub struct BuilderConfig {
pub genesis_time: Option<u64>,
pub extra_data: Option<Bytes>,
pub execution_mnemonic: String,
// NOTE: This is a temporary field to route the same data from the `BidderConfig`
// to the builder. Will be removed once we have communications set up from bidder to builder.
pub subsidy_wei: Option<U256>,
}

#[derive(Deserialize, Debug, Default, Clone)]
Expand Down Expand Up @@ -108,8 +111,11 @@ fn custom_network_from_config_directory(path: PathBuf) -> Network {
pub async fn launch(
node_builder: WithLaunchContext<NodeBuilder<Arc<DatabaseEnv>>>,
custom_chain_config_directory: Option<PathBuf>,
config: Config,
mut config: Config,
) -> eyre::Result<()> {
// NOTE: temporary shim
// TODO: remove once bidder can talk to builder
config.builder.subsidy_wei = config.bidder.subsidy_wei;
let payload_builder = PayloadServiceBuilder::try_from(&config.builder)?;

let handle = node_builder
Expand Down

0 comments on commit d402145

Please sign in to comment.