Skip to content

Commit

Permalink
refactor: handle missing proposer in bid opening
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkaufmann committed Sep 7, 2023
1 parent f923c42 commit 842b869
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion mev-build-rs/src/mempool_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ impl BlindedBlockProvider for Builder {
signed_block: &mut SignedBlindedBeaconBlock,
) -> Result<ExecutionPayload, Error> {
let slot = signed_block.slot();
let public_key = self.proposer_scheduler.get_proposer_for(slot)?;
let public_key =
self.proposer_scheduler.get_proposer_for(slot).ok_or(Error::MissingProposer(slot))?;
signed_block.verify_signature(&public_key, self.genesis_validators_root, &self.context)?;

let parent_hash = signed_block.parent_hash();
Expand Down
4 changes: 3 additions & 1 deletion mev-rs/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::types::BidRequest;
use beacon_api_client::Error as ApiError;
use ethereum_consensus::{
primitives::{BlsPublicKey, ExecutionAddress, Hash32},
primitives::{BlsPublicKey, ExecutionAddress, Hash32, Slot},
state_transition::Error as ConsensusError,
};
use thiserror::Error;
Expand All @@ -16,6 +16,8 @@ pub enum Error {
NoBids,
#[error("could not find relay with outstanding bid to accept")]
MissingOpenBid,
#[error("could not find proposer for slot {0}")]
MissingProposer(Slot),
#[error("could not register with any relay")]
CouldNotRegister,
#[error("no preferences found for validator with public key {0}")]
Expand Down
6 changes: 2 additions & 4 deletions mev-rs/src/proposer_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("missing proposer for the requested slot {0}")]
MissingProposer(Slot),
#[error("api error: {0}")]
Api(#[from] ApiError),
}
Expand Down Expand Up @@ -48,8 +46,8 @@ impl ProposerScheduler {
Ok(duties)
}

pub fn get_proposer_for(&self, slot: Slot) -> Result<BlsPublicKey, Error> {
pub fn get_proposer_for(&self, slot: Slot) -> Option<BlsPublicKey> {
let state = self.state.lock();
state.proposer_schedule.get(&slot).cloned().ok_or_else(|| Error::MissingProposer(slot))
state.proposer_schedule.get(&slot).cloned()
}
}

0 comments on commit 842b869

Please sign in to comment.