mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-01 05:37:05 +00:00
merge conflicts
This commit is contained in:
@@ -21,12 +21,13 @@ use types::{
|
||||
Blob, ChainSpec, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadBellatrix,
|
||||
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadEip7805,
|
||||
ExecutionPayloadElectra, ExecutionPayloadFulu, ExecutionPayloadHeader, FixedBytesExtended,
|
||||
ForkName, Hash256, Transaction, Transactions, Uint256,
|
||||
ForkName, Hash256, KzgProofs, Transaction, Transactions, Uint256,
|
||||
};
|
||||
|
||||
use super::DEFAULT_TERMINAL_BLOCK;
|
||||
|
||||
const TEST_BLOB_BUNDLE: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle.ssz");
|
||||
const TEST_BLOB_BUNDLE_V2: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle_v2.ssz");
|
||||
|
||||
pub const DEFAULT_GAS_LIMIT: u64 = 30_000_000;
|
||||
const GAS_USED: u64 = DEFAULT_GAS_LIMIT - 1;
|
||||
@@ -722,15 +723,13 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
},
|
||||
};
|
||||
|
||||
if execution_payload.fork_name().deneb_enabled() {
|
||||
let fork_name = execution_payload.fork_name();
|
||||
if fork_name.deneb_enabled() {
|
||||
// get random number between 0 and Max Blobs
|
||||
let mut rng = self.rng.lock();
|
||||
let max_blobs = self
|
||||
.spec
|
||||
.max_blobs_per_block_by_fork(execution_payload.fork_name())
|
||||
as usize;
|
||||
let max_blobs = self.spec.max_blobs_per_block_by_fork(fork_name) as usize;
|
||||
let num_blobs = rng.gen::<usize>() % (max_blobs + 1);
|
||||
let (bundle, transactions) = generate_blobs(num_blobs)?;
|
||||
let (bundle, transactions) = generate_blobs(num_blobs, fork_name)?;
|
||||
for tx in Vec::from(transactions) {
|
||||
execution_payload
|
||||
.transactions_mut()
|
||||
@@ -746,7 +745,8 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_test_blobs_bundle<E: EthSpec>() -> Result<(KzgCommitment, KzgProof, Blob<E>), String> {
|
||||
pub fn load_test_blobs_bundle_v1<E: EthSpec>() -> Result<(KzgCommitment, KzgProof, Blob<E>), String>
|
||||
{
|
||||
let BlobsBundle::<E> {
|
||||
commitments,
|
||||
proofs,
|
||||
@@ -770,32 +770,56 @@ pub fn load_test_blobs_bundle<E: EthSpec>() -> Result<(KzgCommitment, KzgProof,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn load_test_blobs_bundle_v2<E: EthSpec>(
|
||||
) -> Result<(KzgCommitment, KzgProofs<E>, Blob<E>), String> {
|
||||
let BlobsBundle::<E> {
|
||||
commitments,
|
||||
proofs,
|
||||
blobs,
|
||||
} = BlobsBundle::from_ssz_bytes(TEST_BLOB_BUNDLE_V2)
|
||||
.map_err(|e| format!("Unable to decode ssz: {:?}", e))?;
|
||||
|
||||
Ok((
|
||||
commitments
|
||||
.first()
|
||||
.cloned()
|
||||
.ok_or("commitment missing in test bundle")?,
|
||||
// there's only one blob in the test bundle, hence we take all the cell proofs here.
|
||||
proofs,
|
||||
blobs
|
||||
.first()
|
||||
.cloned()
|
||||
.ok_or("blob missing in test bundle")?,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn generate_blobs<E: EthSpec>(
|
||||
n_blobs: usize,
|
||||
fork_name: ForkName,
|
||||
) -> Result<(BlobsBundle<E>, Transactions<E>), String> {
|
||||
let (kzg_commitment, kzg_proof, blob) = load_test_blobs_bundle::<E>()?;
|
||||
let tx = static_valid_tx::<E>()
|
||||
.map_err(|e| format!("error creating valid tx SSZ bytes: {:?}", e))?;
|
||||
let transactions = vec![tx; n_blobs];
|
||||
|
||||
let mut bundle = BlobsBundle::<E>::default();
|
||||
let mut transactions = vec![];
|
||||
|
||||
for blob_index in 0..n_blobs {
|
||||
let tx = static_valid_tx::<E>()
|
||||
.map_err(|e| format!("error creating valid tx SSZ bytes: {:?}", e))?;
|
||||
|
||||
transactions.push(tx);
|
||||
bundle
|
||||
.blobs
|
||||
.push(blob.clone())
|
||||
.map_err(|_| format!("blobs are full, blob index: {:?}", blob_index))?;
|
||||
bundle
|
||||
.commitments
|
||||
.push(kzg_commitment)
|
||||
.map_err(|_| format!("blobs are full, blob index: {:?}", blob_index))?;
|
||||
bundle
|
||||
.proofs
|
||||
.push(kzg_proof)
|
||||
.map_err(|_| format!("blobs are full, blob index: {:?}", blob_index))?;
|
||||
}
|
||||
let bundle = if fork_name.fulu_enabled() {
|
||||
let (kzg_commitment, kzg_proofs, blob) = load_test_blobs_bundle_v2::<E>()?;
|
||||
BlobsBundle {
|
||||
commitments: vec![kzg_commitment; n_blobs].into(),
|
||||
proofs: vec![kzg_proofs.to_vec(); n_blobs]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
blobs: vec![blob; n_blobs].into(),
|
||||
}
|
||||
} else {
|
||||
let (kzg_commitment, kzg_proof, blob) = load_test_blobs_bundle_v1::<E>()?;
|
||||
BlobsBundle {
|
||||
commitments: vec![kzg_commitment; n_blobs].into(),
|
||||
proofs: vec![kzg_proof; n_blobs].into(),
|
||||
blobs: vec![blob; n_blobs].into(),
|
||||
}
|
||||
};
|
||||
|
||||
Ok((bundle, transactions.into()))
|
||||
}
|
||||
@@ -936,7 +960,7 @@ pub fn generate_pow_block(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use kzg::{trusted_setup::get_trusted_setup, TrustedSetup};
|
||||
use kzg::{trusted_setup::get_trusted_setup, Bytes48, CellRef, KzgBlobRef, TrustedSetup};
|
||||
use types::{MainnetEthSpec, MinimalEthSpec};
|
||||
|
||||
#[test]
|
||||
@@ -1006,20 +1030,28 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_test_blobs() {
|
||||
fn valid_test_blobs_bundle_v1() {
|
||||
assert!(
|
||||
validate_blob::<MainnetEthSpec>().is_ok(),
|
||||
validate_blob_bundle_v1::<MainnetEthSpec>().is_ok(),
|
||||
"Mainnet preset test blobs bundle should contain valid proofs"
|
||||
);
|
||||
assert!(
|
||||
validate_blob::<MinimalEthSpec>().is_ok(),
|
||||
validate_blob_bundle_v1::<MinimalEthSpec>().is_ok(),
|
||||
"Minimal preset test blobs bundle should contain valid proofs"
|
||||
);
|
||||
}
|
||||
|
||||
fn validate_blob<E: EthSpec>() -> Result<(), String> {
|
||||
#[test]
|
||||
fn valid_test_blobs_bundle_v2() {
|
||||
validate_blob_bundle_v2::<MainnetEthSpec>()
|
||||
.expect("Mainnet preset test blobs bundle v2 should contain valid proofs");
|
||||
validate_blob_bundle_v2::<MinimalEthSpec>()
|
||||
.expect("Minimal preset test blobs bundle v2 should contain valid proofs");
|
||||
}
|
||||
|
||||
fn validate_blob_bundle_v1<E: EthSpec>() -> Result<(), String> {
|
||||
let kzg = load_kzg()?;
|
||||
let (kzg_commitment, kzg_proof, blob) = load_test_blobs_bundle::<E>()?;
|
||||
let (kzg_commitment, kzg_proof, blob) = load_test_blobs_bundle_v1::<E>()?;
|
||||
let kzg_blob = kzg::Blob::from_bytes(blob.as_ref())
|
||||
.map(Box::new)
|
||||
.map_err(|e| format!("Error converting blob to kzg blob: {e:?}"))?;
|
||||
@@ -1027,6 +1059,26 @@ mod test {
|
||||
.map_err(|e| format!("Invalid blobs bundle: {e:?}"))
|
||||
}
|
||||
|
||||
fn validate_blob_bundle_v2<E: EthSpec>() -> Result<(), String> {
|
||||
let kzg = load_kzg()?;
|
||||
let (kzg_commitments, kzg_proofs, cells) =
|
||||
load_test_blobs_bundle_v2::<E>().map(|(commitment, proofs, blob)| {
|
||||
let kzg_blob: KzgBlobRef = blob.as_ref().try_into().unwrap();
|
||||
(
|
||||
vec![Bytes48::from(commitment); proofs.len()],
|
||||
proofs.into_iter().map(|p| p.into()).collect::<Vec<_>>(),
|
||||
kzg.compute_cells(kzg_blob).unwrap(),
|
||||
)
|
||||
})?;
|
||||
let (cell_indices, cell_refs): (Vec<u64>, Vec<CellRef>) = cells
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(cell_idx, cell)| (cell_idx as u64, CellRef::try_from(cell.as_ref()).unwrap()))
|
||||
.unzip();
|
||||
kzg.verify_cell_proof_batch(&cell_refs, &kzg_proofs, cell_indices, &kzg_commitments)
|
||||
.map_err(|e| format!("Invalid blobs bundle: {e:?}"))
|
||||
}
|
||||
|
||||
fn load_kzg() -> Result<Kzg, String> {
|
||||
let trusted_setup: TrustedSetup =
|
||||
serde_json::from_reader(get_trusted_setup().as_slice())
|
||||
|
||||
Binary file not shown.
@@ -424,9 +424,8 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
== ForkName::Fulu
|
||||
&& (method == ENGINE_GET_PAYLOAD_V1
|
||||
|| method == ENGINE_GET_PAYLOAD_V2
|
||||
|| method == ENGINE_GET_PAYLOAD_V3)
|
||||
// TODO(fulu): Uncomment this once v5 method is ready for Fulu
|
||||
// || method == ENGINE_GET_PAYLOAD_V4)
|
||||
|| method == ENGINE_GET_PAYLOAD_V3
|
||||
|| method == ENGINE_GET_PAYLOAD_V4)
|
||||
{
|
||||
return Err((
|
||||
format!("{} called after Fulu fork!", method),
|
||||
@@ -492,22 +491,6 @@ pub async fn handle_rpc<E: EthSpec>(
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
// TODO(fulu): remove this once we switch to v5 method
|
||||
JsonExecutionPayload::V5(execution_payload) => {
|
||||
serde_json::to_value(JsonGetPayloadResponseV5 {
|
||||
execution_payload,
|
||||
block_value: Uint256::from(DEFAULT_MOCK_EL_PAYLOAD_VALUE_WEI),
|
||||
blobs_bundle: maybe_blobs
|
||||
.ok_or((
|
||||
"No blobs returned despite V5 Payload".to_string(),
|
||||
GENERIC_ERROR_CODE,
|
||||
))?
|
||||
.into(),
|
||||
should_override_builder: false,
|
||||
execution_requests: Default::default(),
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}),
|
||||
ENGINE_GET_PAYLOAD_V5 => Ok(match JsonExecutionPayload::from(response) {
|
||||
|
||||
@@ -574,7 +574,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.map_err(|_| "incorrect payload variant".to_string())?
|
||||
.into(),
|
||||
blob_kzg_commitments: maybe_blobs_bundle
|
||||
.map(|b| b.commitments)
|
||||
.map(|b| b.commitments.clone())
|
||||
.unwrap_or_default(),
|
||||
value: self.get_bid_value(value),
|
||||
pubkey: self.builder_sk.public_key().compress(),
|
||||
@@ -598,7 +598,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.map_err(|_| "incorrect payload variant".to_string())?
|
||||
.into(),
|
||||
blob_kzg_commitments: maybe_blobs_bundle
|
||||
.map(|b| b.commitments)
|
||||
.map(|b| b.commitments.clone())
|
||||
.unwrap_or_default(),
|
||||
value: self.get_bid_value(value),
|
||||
pubkey: self.builder_sk.public_key().compress(),
|
||||
@@ -610,7 +610,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.map_err(|_| "incorrect payload variant".to_string())?
|
||||
.into(),
|
||||
blob_kzg_commitments: maybe_blobs_bundle
|
||||
.map(|b| b.commitments)
|
||||
.map(|b| b.commitments.clone())
|
||||
.unwrap_or_default(),
|
||||
value: self.get_bid_value(value),
|
||||
pubkey: self.builder_sk.public_key().compress(),
|
||||
@@ -783,7 +783,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.await
|
||||
.map_err(|_| "couldn't get head".to_string())?
|
||||
.ok_or_else(|| "missing head block".to_string())?
|
||||
.data;
|
||||
.into_data();
|
||||
|
||||
let head_block_root = head_block_root.unwrap_or(head.canonical_root());
|
||||
|
||||
@@ -801,7 +801,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.await
|
||||
.map_err(|_| "couldn't get finalized block".to_string())?
|
||||
.ok_or_else(|| "missing finalized block".to_string())?
|
||||
.data
|
||||
.data()
|
||||
.message()
|
||||
.body()
|
||||
.execution_payload()
|
||||
@@ -814,7 +814,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.await
|
||||
.map_err(|_| "couldn't get justified block".to_string())?
|
||||
.ok_or_else(|| "missing justified block".to_string())?
|
||||
.data
|
||||
.data()
|
||||
.message()
|
||||
.body()
|
||||
.execution_payload()
|
||||
@@ -855,7 +855,7 @@ impl<E: EthSpec> MockBuilder<E> {
|
||||
.await
|
||||
.map_err(|_| "couldn't get state".to_string())?
|
||||
.ok_or_else(|| "missing state".to_string())?
|
||||
.data;
|
||||
.into_data();
|
||||
|
||||
let prev_randao = head_state
|
||||
.get_randao_mix(head_state.current_epoch())
|
||||
@@ -1022,7 +1022,7 @@ pub fn serve<E: EthSpec>(
|
||||
.await
|
||||
.map_err(|e| warp::reject::custom(Custom(e)))?;
|
||||
let resp: ForkVersionedResponse<_> = ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
version: fork_name,
|
||||
metadata: Default::default(),
|
||||
data: payload,
|
||||
};
|
||||
@@ -1082,7 +1082,7 @@ pub fn serve<E: EthSpec>(
|
||||
),
|
||||
eth2::types::Accept::Json | eth2::types::Accept::Any => {
|
||||
let resp: ForkVersionedResponse<_> = ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
version: fork_name,
|
||||
metadata: Default::default(),
|
||||
data: signed_bid,
|
||||
};
|
||||
|
||||
@@ -58,6 +58,7 @@ pub const DEFAULT_ENGINE_CAPABILITIES: EngineCapabilities = EngineCapabilities {
|
||||
get_payload_v5: true,
|
||||
get_client_version_v1: true,
|
||||
get_blobs_v1: true,
|
||||
get_blobs_v2: true,
|
||||
get_inclusion_list_v1: true,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user