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

Update BlindedBlobsBundle SSZ and deserialize signed blinded block (Deneb) #124

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ members = ["bin/mev", "mev-boost-rs", "mev-relay-rs", "mev-build-rs", "mev-rs"]
default-members = ["bin/mev"]

[workspace.dependencies]
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "2bcb975" }
beacon-api-client = { git = "https://github.com/ralexstokes/beacon-api-client", rev = "d838d93" }
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "12508c1f9b0c8f4bf4c5e9b6d441e840c1b37fd9" }
ralexstokes marked this conversation as resolved.
Show resolved Hide resolved
beacon-api-client = { git = "https://github.com/ralexstokes/beacon-api-client", rev = "7f28993615fde52d563dd601a0511c34fe9b7c38" }
ssz_rs = "0.9.0"
10 changes: 8 additions & 2 deletions mev-boost-rs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
relay::{Relay, RelayEndpoint},
relay_mux::RelayMux,
};
use ethereum_consensus::state_transition::Context;
use ethereum_consensus::{clock::from_system_time, state_transition::Context};
use futures::StreamExt;
use mev_rs::{blinded_block_provider::Server as BlindedBlockProviderServer, Error, Network};
use serde::Deserialize;
Expand Down Expand Up @@ -69,7 +69,13 @@ impl Service {
let context =
if let Some(context) = context { context } else { Context::try_from(&network)? };
let relays = relays.into_iter().map(Relay::from);
let clock = context.clock(None);
let clock = match context.clock() {
jimmygchen marked this conversation as resolved.
Show resolved Hide resolved
Some(clock) => clock,
None => {
let genesis_time = context.genesis_time()?;
from_system_time(genesis_time, context.seconds_per_slot, context.slots_per_epoch)
}
};
let relay_mux = RelayMux::new(relays, context);

let relay_mux_clone = relay_mux.clone();
Expand Down
10 changes: 8 additions & 2 deletions mev-build-rs/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::mempool_builder::Builder;
use beacon_api_client::Client;
use ethereum_consensus::{crypto::SecretKey, state_transition::Context};
use ethereum_consensus::{clock::from_system_time, crypto::SecretKey, state_transition::Context};
use futures::StreamExt;
use mev_rs::{
blinded_block_provider::Server as BlindedBlockProviderServer,
Expand Down Expand Up @@ -72,7 +72,13 @@ impl Service {

let genesis_details = client.get_genesis_details().await?;
let genesis_validators_root = genesis_details.genesis_validators_root;
let clock = context.clock(Some(genesis_details.genesis_time));
let clock = match context.clock() {
jimmygchen marked this conversation as resolved.
Show resolved Hide resolved
Some(clock) => clock,
None => {
let genesis_time = context.genesis_time()?;
from_system_time(genesis_time, context.seconds_per_slot, context.slots_per_epoch)
}
};
let builder = Builder::new(
secret_key,
genesis_validators_root,
Expand Down
10 changes: 8 additions & 2 deletions mev-relay-rs/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::relay::Relay;
use beacon_api_client::mainnet::Client;
use ethereum_consensus::{crypto::SecretKey, state_transition::Context};
use ethereum_consensus::{clock::from_system_time, crypto::SecretKey, state_transition::Context};
use futures::StreamExt;
use mev_rs::{blinded_block_provider::Server as BlindedBlockProviderServer, Error, Network};
use serde::Deserialize;
Expand Down Expand Up @@ -58,7 +58,13 @@ impl Service {

let context =
if let Some(context) = context { context } else { Context::try_from(&network)? };
let clock = context.clock(None);
let clock = match context.clock() {
jimmygchen marked this conversation as resolved.
Show resolved Hide resolved
Some(clock) => clock,
None => {
let genesis_time = context.genesis_time()?;
from_system_time(genesis_time, context.seconds_per_slot, context.slots_per_epoch)
}
};
let context = Arc::new(context);
let genesis_details = beacon_node.get_genesis_details().await?;
let genesis_validators_root = genesis_details.genesis_validators_root;
Expand Down
22 changes: 14 additions & 8 deletions mev-rs/src/blinded_block_provider/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
blinded_block_provider::BlindedBlockProvider,
error::Error,
types::{
bellatrix, capella, BidRequest, ExecutionPayload, SignedBlindedBeaconBlock,
bellatrix, capella, deneb, BidRequest, ExecutionPayload, SignedBlindedBeaconBlock,
SignedBuilderBid, SignedValidatorRegistration,
},
};
Expand Down Expand Up @@ -49,13 +49,19 @@ async fn handle_open_bid<B: BlindedBlockProvider>(
State(builder): State<B>,
Json(block): Json<serde_json::Value>,
) -> Result<Json<VersionedValue<ExecutionPayload>>, Error> {
let maybe_capella_block = capella::SignedBlindedBeaconBlock::deserialize(&block);
let mut block = match maybe_capella_block {
Ok(block) => SignedBlindedBeaconBlock::Capella(block),
Err(err) => match bellatrix::SignedBlindedBeaconBlock::deserialize(block) {
Ok(block) => SignedBlindedBeaconBlock::Bellatrix(block),
Err(_) => return Err(ApiClientError::from(err).into()),
},
// TODO: Using the optional `Eth-Consensus-Version` header once clients have implemented it.
let mut block = if block["message"].is_null() {
deneb::SignedBlindedBlockAndBlobSidecars::deserialize(&block)
.map(SignedBlindedBeaconBlock::Deneb)
.map_err(ApiClientError::from)?
} else {
capella::SignedBlindedBeaconBlock::deserialize(&block)
.map(SignedBlindedBeaconBlock::Capella)
.or_else(|_| {
bellatrix::SignedBlindedBeaconBlock::deserialize(&block)
.map(SignedBlindedBeaconBlock::Bellatrix)
})
.map_err(ApiClientError::from)?
ralexstokes marked this conversation as resolved.
Show resolved Hide resolved
};

let payload = builder.open_bid(&mut block).await?;
Expand Down
14 changes: 7 additions & 7 deletions mev-rs/src/types/deneb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use ethereum_consensus::{builder::SignedValidatorRegistration, deneb::mainnet as spec};
use ethereum_consensus::{
deneb::mainnet::MAX_BLOBS_PER_BLOCK,
deneb::mainnet::{MAX_BLOBS_PER_BLOCK, MAX_BLOB_COMMITMENTS_PER_BLOCK},
kzg::{KzgCommitment, KzgProof},
primitives::{BlsPublicKey, BlsSignature, Root, U256},
};
Expand All @@ -26,9 +26,9 @@ pub struct BuilderBid {
#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlindedBlobsBundle {
pub commitments: List<KzgCommitment, MAX_BLOBS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOBS_PER_BLOCK>,
pub blob_roots: List<Root, MAX_BLOBS_PER_BLOCK>,
pub commitments: List<KzgCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
pub blob_roots: List<Root, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
Expand All @@ -48,9 +48,9 @@ pub struct SignedBlindedBlockAndBlobSidecars {
#[derive(Debug, Default, Clone, SimpleSerialize)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlobsBundle {
pub commitments: List<KzgCommitment, MAX_BLOBS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOBS_PER_BLOCK>,
pub blobs: List<Blob, MAX_BLOBS_PER_BLOCK>,
pub commitments: List<KzgCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
pub proofs: List<KzgProof, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
pub blobs: List<Blob, MAX_BLOB_COMMITMENTS_PER_BLOCK>,
}

#[derive(Debug, Default, Clone, SimpleSerialize)]
Expand Down