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

fix(sidecar): local blob building #152

Merged
merged 10 commits into from
Jul 22, 2024
2 changes: 1 addition & 1 deletion bolt-sidecar/src/api/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ where
meta: Default::default(),
};

tracing::info!(elapsed = ?start.elapsed(), %hash, number, "Returning locally built header");
tracing::info!(elapsed = ?start.elapsed(), %hash, number, ?versioned_bid, "Returning locally built header");
Ok(Json(versioned_bid))
}

Expand Down
9 changes: 6 additions & 3 deletions bolt-sidecar/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy_primitives::U256;
use blst::min_pk::SecretKey;
use ethereum_consensus::{
crypto::PublicKey,
crypto::{KzgCommitment, PublicKey},
deneb::mainnet::ExecutionPayloadHeader,
ssz::prelude::{List, MerkleizationError},
};
Expand Down Expand Up @@ -102,6 +102,7 @@ impl LocalBuilder {
) -> Result<(), BuilderError> {
let transactions = template.as_signed_transactions();
let blobs_bundle = template.as_blobs_bundle();
let kzg_commitments = blobs_bundle.commitments.clone();

// 1. build a fallback payload with the given transactions, on top of
// the current head of the chain
Expand Down Expand Up @@ -132,7 +133,7 @@ impl LocalBuilder {
);

// 3. sign the bid with the local builder's BLS key
let signed_bid = self.create_signed_builder_bid(value, eth_header)?;
let signed_bid = self.create_signed_builder_bid(value, eth_header, kzg_commitments)?;

// 4. prepare a get_payload response for when the beacon node will ask for it
let Some(get_payload_res) =
Expand Down Expand Up @@ -165,14 +166,16 @@ impl LocalBuilder {
&self,
value: U256,
header: ExecutionPayloadHeader,
blob_kzg_commitments: Vec<KzgCommitment>,
) -> Result<SignedBuilderBid, BuilderError> {
// compat: convert from blst to ethereum consensus types
let pubkey = self.secret_key.sk_to_pk().to_bytes();
let consensus_pubkey = PublicKey::try_from(pubkey.as_slice()).expect("valid pubkey bytes");
let blob_kzg_commitments = List::try_from(blob_kzg_commitments).expect("valid list");

let message = BuilderBid {
header,
blob_kzg_commitments: List::default(),
blob_kzg_commitments,
public_key: consensus_pubkey,
value,
};
Expand Down
10 changes: 7 additions & 3 deletions bolt-sidecar/src/builder/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl FallbackPayloadBuilder {
pub struct Context {
extra_data: Bytes,
base_fee: u64,
blob_gas_used: u64,
excess_blob_gas: u64,
prev_randao: B256,
fee_recipient: Address,
Expand All @@ -91,7 +92,6 @@ pub struct Hints {
pub gas_used: Option<u64>,
pub receipts_root: Option<B256>,
pub logs_bloom: Option<Bloom>,
pub blob_gas_used: Option<u64>,
pub state_root: Option<B256>,
pub block_hash: Option<B256>,
}
Expand Down Expand Up @@ -173,8 +173,13 @@ impl FallbackPayloadBuilder {
latest_block.header.blob_gas_used.unwrap_or_default(),
) as u64;

let blob_gas_used = transactions
.iter()
.fold(0, |acc, tx| acc + tx.blob_gas_used().unwrap_or_default());

let ctx = Context {
base_fee,
blob_gas_used,
excess_blob_gas,
parent_beacon_block_root,
prev_randao,
Expand Down Expand Up @@ -359,7 +364,6 @@ pub(crate) fn build_header_with_hints_and_context(
let gas_used = hints.gas_used.unwrap_or_default();
let receipts_root = hints.receipts_root.unwrap_or_default();
let logs_bloom = hints.logs_bloom.unwrap_or_default();
let blob_gas_used = hints.blob_gas_used.unwrap_or_default();
let state_root = hints.state_root.unwrap_or_default();

Header {
Expand All @@ -379,7 +383,7 @@ pub(crate) fn build_header_with_hints_and_context(
mix_hash: context.prev_randao,
nonce: BEACON_NONCE,
base_fee_per_gas: Some(context.base_fee),
blob_gas_used: Some(blob_gas_used),
blob_gas_used: Some(context.blob_gas_used),
excess_blob_gas: Some(context.excess_blob_gas),
parent_beacon_block_root: Some(context.parent_beacon_block_root),
extra_data: context.extra_data.clone(),
Expand Down
8 changes: 5 additions & 3 deletions bolt-spammer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub fn generate_random_tx() -> TransactionRequest {

/// Generate random transaction with blob (eip4844)
pub fn generate_random_blob_tx() -> TransactionRequest {
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Blobs are fun!");
let random_bytes = thread_rng().gen::<[u8; 32]>();
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(random_bytes.as_slice());
let sidecar: BlobTransactionSidecar = sidecar.build().unwrap();

let dead_address = Address::from_str(DEAD_ADDRESS).unwrap();
Expand All @@ -35,10 +36,11 @@ pub fn generate_random_blob_tx() -> TransactionRequest {
.with_chain_id(KURTOSIS_CHAIN_ID)
.with_value(U256::from(100))
.with_max_fee_per_blob_gas(100u128)
.max_fee_per_gas(100u128)
.max_priority_fee_per_gas(50u128)
.max_fee_per_gas(NOICE_GAS_PRICE)
.max_priority_fee_per_gas(NOICE_GAS_PRICE / 10)
.with_gas_limit(1_000_000u128)
.with_blob_sidecar(sidecar)
.with_input(random_bytes)
}

pub fn prepare_rpc_request(method: &str, params: Vec<Value>) -> Value {
Expand Down
Loading