mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 13:24:44 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -21,6 +21,8 @@ use types::{
|
||||
MainnetEthSpec, MinimalEthSpec, ProposerPreparationData, Slot,
|
||||
};
|
||||
|
||||
use eth2::types::ForkVersionedBeaconBlockType::{Blinded, Full};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
// Test that the deposit_contract endpoint returns the correct chain_id and address.
|
||||
@@ -617,13 +619,18 @@ pub async fn proposer_boost_re_org_test(
|
||||
let randao_reveal = harness
|
||||
.sign_randao_reveal(&state_b, proposer_index, slot_c)
|
||||
.into();
|
||||
let unsigned_block_contents_c = tester
|
||||
let unsigned_block_type = tester
|
||||
.client
|
||||
.get_validator_blocks(slot_c, &randao_reveal, None)
|
||||
.get_validator_blocks_v3::<E>(slot_c, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data;
|
||||
let (unsigned_block_c, block_c_blobs) = unsigned_block_contents_c.deconstruct();
|
||||
.unwrap();
|
||||
|
||||
let (unsigned_block_c, block_c_blobs) = match unsigned_block_type {
|
||||
Full(unsigned_block_contents_c) => unsigned_block_contents_c.data.deconstruct(),
|
||||
Blinded(_) => {
|
||||
panic!("Should not be a blinded block");
|
||||
}
|
||||
};
|
||||
let block_c = harness.sign_beacon_block(unsigned_block_c, &state_b);
|
||||
|
||||
if should_re_org {
|
||||
|
||||
@@ -2604,6 +2604,98 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_block_production_v3_ssz(self) -> Self {
|
||||
let fork = self.chain.canonical_head.cached_head().head_fork();
|
||||
let genesis_validators_root = self.chain.genesis_validators_root;
|
||||
|
||||
for _ in 0..E::slots_per_epoch() * 3 {
|
||||
let slot = self.chain.slot().unwrap();
|
||||
let epoch = self.chain.epoch().unwrap();
|
||||
|
||||
let proposer_pubkey_bytes = self
|
||||
.client
|
||||
.get_validator_duties_proposer(epoch)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_iter()
|
||||
.find(|duty| duty.slot == slot)
|
||||
.map(|duty| duty.pubkey)
|
||||
.unwrap();
|
||||
let proposer_pubkey = (&proposer_pubkey_bytes).try_into().unwrap();
|
||||
|
||||
let sk = self
|
||||
.validator_keypairs()
|
||||
.iter()
|
||||
.find(|kp| kp.pk == proposer_pubkey)
|
||||
.map(|kp| kp.sk.clone())
|
||||
.unwrap();
|
||||
|
||||
let randao_reveal = {
|
||||
let domain = self.chain.spec.get_domain(
|
||||
epoch,
|
||||
Domain::Randao,
|
||||
&fork,
|
||||
genesis_validators_root,
|
||||
);
|
||||
let message = epoch.signing_root(domain);
|
||||
sk.sign(message).into()
|
||||
};
|
||||
|
||||
let (fork_version_response_bytes, is_blinded_payload) = self
|
||||
.client
|
||||
.get_validator_blocks_v3_ssz::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if is_blinded_payload {
|
||||
let block_contents = <BlockContents<E, BlindedPayload<E>>>::from_ssz_bytes(
|
||||
&fork_version_response_bytes.unwrap(),
|
||||
&self.chain.spec,
|
||||
)
|
||||
.expect("block contents bytes can be decoded");
|
||||
|
||||
let signed_block_contents =
|
||||
block_contents.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(&signed_block_contents)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// This converts the generic `Payload` to a concrete type for comparison.
|
||||
let signed_block = signed_block_contents.deconstruct().0;
|
||||
let head_block = SignedBeaconBlock::from(signed_block.clone());
|
||||
assert_eq!(head_block, signed_block);
|
||||
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
} else {
|
||||
let block_contents = <BlockContents<E, FullPayload<E>>>::from_ssz_bytes(
|
||||
&fork_version_response_bytes.unwrap(),
|
||||
&self.chain.spec,
|
||||
)
|
||||
.expect("block contents bytes can be decoded");
|
||||
|
||||
let signed_block_contents =
|
||||
block_contents.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks_ssz(&signed_block_contents)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
self.chain.head_beacon_block().as_ref(),
|
||||
signed_block_contents.signed_block()
|
||||
);
|
||||
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_block_production_no_verify_randao(self) -> Self {
|
||||
for _ in 0..E::slots_per_epoch() {
|
||||
let slot = self.chain.slot().unwrap();
|
||||
@@ -3544,7 +3636,6 @@ impl ApiTester {
|
||||
.cached_head()
|
||||
.head_random()
|
||||
.unwrap();
|
||||
|
||||
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
|
||||
|
||||
let payload: BlindedPayload<E> = self
|
||||
@@ -4586,8 +4677,7 @@ impl ApiTester {
|
||||
assert_eq!(withdrawal_response.finalized, Some(false));
|
||||
assert_eq!(withdrawal_response.data, expected_withdrawals.to_vec());
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
Err(_) => {
|
||||
panic!("query failed incorrectly");
|
||||
}
|
||||
}
|
||||
@@ -5055,6 +5145,20 @@ async fn block_production_ssz_with_skip_slots() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn block_production_ssz_v3() {
|
||||
ApiTester::new().await.test_block_production_v3_ssz().await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn block_production_v3_ssz_with_skip_slots() {
|
||||
ApiTester::new()
|
||||
.await
|
||||
.skip_slots(E::slots_per_epoch() * 2)
|
||||
.test_block_production_v3_ssz()
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn blinded_block_production_full_payload_premerge() {
|
||||
ApiTester::new()
|
||||
|
||||
Reference in New Issue
Block a user