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

publish blobs to beacon node #31

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
144 changes: 133 additions & 11 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use ethereum_consensus::{
primitives::{BlsPublicKey, Slot},
serde::as_str,
};
use helix_beacon_client::BeaconClientTrait;
use helix_beacon_client::{beacon_client::BeaconClient, BeaconClientTrait};
use reqwest::Error;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::channel;

use helix_common::api::{
use helix_common::{api::{
builder_api::BuilderGetValidatorsResponseEntry, proposer_api::ValidatorRegistrationInfo,
};
}, BeaconClientConfig};
use url::Url;

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct BuilderGetValidatorsResponseEntryExternal {
Expand Down Expand Up @@ -119,9 +120,10 @@ async fn run() {
];

let helix_register_endpoint = "http://localhost:4040/eth/v1/builder/validators";
let beacon_client = helix_beacon_client::beacon_client::BeaconClient::from_endpoint_str(
"http://localhost:5052",
);
let beacon_client = BeaconClient::from_config(BeaconClientConfig{
url: Url::parse("http://localhost:5052").unwrap(),
gossip_blobs_enabled: false,
});

let (head_event_sender, mut head_event_receiver) =
tokio::sync::broadcast::channel::<helix_beacon_client::types::HeadEventData>(100);
Expand Down
52 changes: 51 additions & 1 deletion crates/api/src/proposer/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use helix_common::{
api::{
builder_api::BuilderGetValidatorsResponseEntry,
proposer_api::{GetPayloadResponse, ValidatorRegistrationInfo},
}, chain_info::{ChainInfo, Network}, signed_proposal::VersionedSignedProposal, try_execution_header_from_payload, validator_preferences, versioned_payload::PayloadAndBlobs, BidRequest, Filtering, GetHeaderTrace, GetPayloadTrace, RegisterValidatorsTrace, ValidatorPreferences
}, beacon_api::PublishBlobsRequest, chain_info::{ChainInfo, Network}, deneb::{BlobSidecars, BuildBlobSidecarError}, signed_proposal::VersionedSignedProposal, try_execution_header_from_payload, validator_preferences, versioned_payload::PayloadAndBlobs, BidRequest, Filtering, GetHeaderTrace, GetPayloadTrace, RegisterValidatorsTrace, ValidatorPreferences
};
use helix_database::DatabaseService;
use helix_datastore::{error::AuctioneerError, Auctioneer};
Expand Down Expand Up @@ -169,6 +169,7 @@ where
filtering: proposer_api.validator_preferences.filtering,
trusted_builders: proposer_api.validator_preferences.trusted_builders.clone(),
header_delay: proposer_api.validator_preferences.header_delay,
gossip_blobs: proposer_api.validator_preferences.gossip_blobs,
};


Expand Down Expand Up @@ -203,6 +204,10 @@ where
if let Some(header_delay) = preferences.header_delay {
validator_preferences.header_delay = header_delay;
}

if let Some(gossip_blobs) = preferences.gossip_blobs {
validator_preferences.gossip_blobs = gossip_blobs;
}
}

let request_id = Uuid::new_v4();
Expand Down Expand Up @@ -650,6 +655,19 @@ where
};
let payload = Arc::new(versioned_payload);

if self.validator_preferences.gossip_blobs || !matches!(self.chain_info.network, Network::Mainnet) {
info!(?request_id, "gossip blobs: about to gossip blobs");
let self_clone = self.clone();
let unblinded_payload_clone = unblinded_payload.clone();
let req_id = *request_id;
tokio::spawn(async move {
self_clone.gossip_blobs(unblinded_payload_clone, req_id).await;
});
} else {
info!(?request_id, "gossip blobs: bug")
}


let is_trusted_proposer = self.is_trusted_proposer(&proposer_public_key).await?;

// Publish and validate payload with multi-beacon-client
Expand Down Expand Up @@ -996,6 +1014,38 @@ where
}
}

/// If there are blobs in the unblinded payload, this function will send them directly to the
/// beacon chain to be propagated async to the full block.
async fn gossip_blobs(
&self,
unblinded_payload: Arc<VersionedSignedProposal>,
request_id: Uuid,
) {
let blob_sidecars = match BlobSidecars::try_from_unblinded_payload(unblinded_payload.clone()) {
Ok(blob_sidecars) => blob_sidecars,
Err(err) => {
match err {
BuildBlobSidecarError::NoBlobsInPayload | BuildBlobSidecarError::PayloadVersionBeforeBlobs=> {}
error => {
error!(%request_id, ?error, "gossip blobs: failed to build blob sidecars for async gossiping");
}
}
return;
}
};

info!(%request_id, "gossip blobs: successfully built blob sidecars for request. Gossiping async..");

// Send blob sidecars to beacon clients.
let publish_blob_request = PublishBlobsRequest {
blob_sidecars,
beacon_root: unblinded_payload.beacon_block().message().parent_root().clone(),
};
if let Err(error) = self.multi_beacon_client.publish_blobs(publish_blob_request).await {
error!(%request_id, ?error, "gossip blobs: failed to gossip blob sidecars");
}
}

/// This function should be run as a seperate async task.
/// Will process new gossiped messages from
async fn process_gossiped_info(&self, mut recveiver: Receiver<GossipedMessage>) {
Expand Down
2 changes: 2 additions & 0 deletions crates/api/src/proposer/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@ pub struct PreferencesHeader {

/// Allows validators to express a preference for whether a delay should be applied to get headers or not.
pub header_delay: Option<bool>,

pub gossip_blobs: Option<bool>,
}
Loading
Loading