Skip to content

Commit

Permalink
Add a flag for always returning a max bid
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed Dec 20, 2024
1 parent cb9631d commit bfcbd77
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions beacon_node/execution_layer/src/test_utils/mock_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ pub struct MockBuilder<E: EthSpec> {
/// a valid block.
apply_operations: bool,
payload_id_cache: Arc<RwLock<HashMap<ExecutionBlockHash, PayloadParametersCloned>>>,
/// If set to `true`, sets the bid returned by `get_header` to Uint256::MAX
max_bid: bool,
/// A cache that stores the proposers index for a given epoch
proposers_cache: Arc<RwLock<HashMap<Epoch, Vec<ProposerData>>>>,
log: Logger,
Expand Down Expand Up @@ -304,6 +306,7 @@ impl<E: EthSpec> MockBuilder<E> {
BeaconNodeHttpClient::new(beacon_url, Timeouts::set_all(Duration::from_secs(1))),
true,
true,
false,
spec,
executor.log().clone(),
);
Expand All @@ -318,6 +321,7 @@ impl<E: EthSpec> MockBuilder<E> {
beacon_client: BeaconNodeHttpClient,
validate_pubkey: bool,
apply_operations: bool,
max_bid: bool,
spec: Arc<ChainSpec>,
log: Logger,
) -> Self {
Expand All @@ -335,6 +339,7 @@ impl<E: EthSpec> MockBuilder<E> {
payload_id_cache: Arc::new(RwLock::new(HashMap::new())),
proposers_cache: Arc::new(RwLock::new(HashMap::new())),
apply_operations,
max_bid,
genesis_time: None,
log,
}
Expand Down Expand Up @@ -496,11 +501,7 @@ impl<E: EthSpec> MockBuilder<E> {
blob_kzg_commitments: maybe_blobs_bundle
.map(|b| b.commitments)
.unwrap_or_default(),
value: if !self.apply_operations {
value
} else {
Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI)
},
value: self.get_bid_value(value),
pubkey: self.builder_sk.public_key().compress(),
execution_requests: maybe_requests.unwrap_or_default(),
}),
Expand All @@ -512,35 +513,23 @@ impl<E: EthSpec> MockBuilder<E> {
blob_kzg_commitments: maybe_blobs_bundle
.map(|b| b.commitments)
.unwrap_or_default(),
value: if !self.apply_operations {
value
} else {
Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI)
},
value: self.get_bid_value(value),
pubkey: self.builder_sk.public_key().compress(),
}),
ForkName::Capella => BuilderBid::Capella(BuilderBidCapella {
header: payload
.as_capella()
.map_err(|_| "incorrect payload variant".to_string())?
.into(),
value: if !self.apply_operations {
value
} else {
Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI)
},
value: self.get_bid_value(value),
pubkey: self.builder_sk.public_key().compress(),
}),
ForkName::Bellatrix => BuilderBid::Bellatrix(BuilderBidBellatrix {
header: payload
.as_bellatrix()
.map_err(|_| "incorrect payload variant".to_string())?
.into(),
value: if !self.apply_operations {
value
} else {
Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI)
},
value: self.get_bid_value(value),
pubkey: self.builder_sk.public_key().compress(),
}),
ForkName::Base | ForkName::Altair => return Err("invalid fork".to_string()),
Expand All @@ -566,6 +555,16 @@ impl<E: EthSpec> MockBuilder<E> {
self.spec.fork_name_at_slot::<E>(slot)
}

fn get_bid_value(&self, value: Uint256) -> Uint256 {
if self.max_bid {
Uint256::MAX
} else if !self.apply_operations {
value
} else {
Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI)
}
}

/// Prepare the execution layer for payload creation every slot for the correct
/// proposer index
pub async fn prepare_execution_layer(&self) -> Result<(), String> {
Expand Down

0 comments on commit bfcbd77

Please sign in to comment.