mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-01 05:37:05 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -2,17 +2,16 @@ use beacon_chain::{
|
||||
test_utils::{AttestationStrategy, BlockStrategy},
|
||||
GossipVerifiedBlock, IntoGossipVerifiedBlockContents,
|
||||
};
|
||||
use eth2::types::{BroadcastValidation, PublishBlockRequest, SignedBeaconBlock};
|
||||
use eth2::reqwest::StatusCode;
|
||||
use eth2::types::{BroadcastValidation, PublishBlockRequest};
|
||||
use http_api::test_utils::InteractiveTester;
|
||||
use http_api::{publish_blinded_block, publish_block, reconstruct_block, ProvenancedBlock};
|
||||
use std::sync::Arc;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{Hash256, MainnetEthSpec, Slot};
|
||||
use types::{Epoch, EthSpec, ForkName, Hash256, MainnetEthSpec, Slot};
|
||||
use warp::Rejection;
|
||||
use warp_utils::reject::CustomBadRequest;
|
||||
|
||||
use eth2::reqwest::StatusCode;
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
/*
|
||||
@@ -64,7 +63,7 @@ pub async fn gossip_invalid() {
|
||||
|
||||
tester.harness.advance_slot();
|
||||
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) = tester
|
||||
let ((block, blobs), _) = tester
|
||||
.harness
|
||||
.make_block_with_modifier(chain_state_before, slot, |b| {
|
||||
*b.state_root_mut() = Hash256::zero();
|
||||
@@ -116,7 +115,7 @@ pub async fn gossip_partial_pass() {
|
||||
|
||||
tester.harness.advance_slot();
|
||||
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) = tester
|
||||
let ((block, blobs), _) = tester
|
||||
.harness
|
||||
.make_block_with_modifier(chain_state_before, slot, |b| {
|
||||
*b.state_root_mut() = Hash256::random()
|
||||
@@ -162,8 +161,7 @@ pub async fn gossip_full_pass() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) =
|
||||
tester.harness.make_block(state_a, slot_b).await;
|
||||
let ((block, blobs), _) = tester.harness.make_block(state_a, slot_b).await;
|
||||
|
||||
let response: Result<(), eth2::Error> = tester
|
||||
.client
|
||||
@@ -190,7 +188,10 @@ pub async fn gossip_full_pass_ssz() {
|
||||
// `validator_count // 32`.
|
||||
let validator_count = 64;
|
||||
let num_initial: u64 = 31;
|
||||
let tester = InteractiveTester::<E>::new(None, validator_count).await;
|
||||
// Deneb epoch set ahead of block slot, to test fork-based decoding
|
||||
let mut spec = ForkName::Capella.make_genesis_spec(MainnetEthSpec::default_spec());
|
||||
spec.deneb_fork_epoch = Some(Epoch::new(4));
|
||||
let tester = InteractiveTester::<E>::new(Some(spec), validator_count).await;
|
||||
|
||||
// Create some chain depth.
|
||||
tester.harness.advance_slot();
|
||||
@@ -250,7 +251,7 @@ pub async fn consensus_invalid() {
|
||||
|
||||
tester.harness.advance_slot();
|
||||
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) = tester
|
||||
let ((block, blobs), _) = tester
|
||||
.harness
|
||||
.make_block_with_modifier(chain_state_before, slot, |b| {
|
||||
*b.state_root_mut() = Hash256::zero();
|
||||
@@ -302,7 +303,7 @@ pub async fn consensus_gossip() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) = tester
|
||||
let ((block, blobs), _) = tester
|
||||
.harness
|
||||
.make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero())
|
||||
.await;
|
||||
@@ -416,8 +417,7 @@ pub async fn consensus_full_pass() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) =
|
||||
tester.harness.make_block(state_a, slot_b).await;
|
||||
let ((block, blobs), _) = tester.harness.make_block(state_a, slot_b).await;
|
||||
|
||||
let response: Result<(), eth2::Error> = tester
|
||||
.client
|
||||
@@ -463,7 +463,7 @@ pub async fn equivocation_invalid() {
|
||||
|
||||
tester.harness.advance_slot();
|
||||
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) = tester
|
||||
let ((block, blobs), _) = tester
|
||||
.harness
|
||||
.make_block_with_modifier(chain_state_before, slot, |b| {
|
||||
*b.state_root_mut() = Hash256::zero();
|
||||
@@ -516,10 +516,9 @@ pub async fn equivocation_consensus_early_equivocation() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block_a, blobs_a), state_after_a): ((SignedBeaconBlock<E>, _), _) =
|
||||
let ((block_a, blobs_a), state_after_a) =
|
||||
tester.harness.make_block(state_a.clone(), slot_b).await;
|
||||
let ((block_b, blobs_b), state_after_b): ((SignedBeaconBlock<E>, _), _) =
|
||||
tester.harness.make_block(state_a, slot_b).await;
|
||||
let ((block_b, blobs_b), state_after_b) = tester.harness.make_block(state_a, slot_b).await;
|
||||
|
||||
/* check for `make_block` curios */
|
||||
assert_eq!(block_a.state_root(), state_after_a.tree_hash_root());
|
||||
@@ -588,7 +587,7 @@ pub async fn equivocation_gossip() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) = tester
|
||||
let ((block, blobs), _) = tester
|
||||
.harness
|
||||
.make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero())
|
||||
.await;
|
||||
@@ -643,10 +642,9 @@ pub async fn equivocation_consensus_late_equivocation() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block_a, blobs_a), state_after_a): ((SignedBeaconBlock<E>, _), _) =
|
||||
let ((block_a, blobs_a), state_after_a) =
|
||||
tester.harness.make_block(state_a.clone(), slot_b).await;
|
||||
let ((block_b, blobs_b), state_after_b): ((SignedBeaconBlock<E>, _), _) =
|
||||
tester.harness.make_block(state_a, slot_b).await;
|
||||
let ((block_b, blobs_b), state_after_b) = tester.harness.make_block(state_a, slot_b).await;
|
||||
|
||||
/* check for `make_block` curios */
|
||||
assert_eq!(block_a.state_root(), state_after_a.tree_hash_root());
|
||||
@@ -714,8 +712,7 @@ pub async fn equivocation_full_pass() {
|
||||
let slot_b = slot_a + 1;
|
||||
|
||||
let state_a = tester.harness.get_current_state();
|
||||
let ((block, blobs), _): ((SignedBeaconBlock<E>, _), _) =
|
||||
tester.harness.make_block(state_a, slot_b).await;
|
||||
let ((block, blobs), _) = tester.harness.make_block(state_a, slot_b).await;
|
||||
|
||||
let response: Result<(), eth2::Error> = tester
|
||||
.client
|
||||
@@ -1267,6 +1264,7 @@ pub async fn blinded_equivocation_consensus_late_equivocation() {
|
||||
.make_blinded_block(state_a.clone(), slot_b)
|
||||
.await;
|
||||
let (block_b, state_after_b) = tester.harness.make_blinded_block(state_a, slot_b).await;
|
||||
let block_b = Arc::new(block_b);
|
||||
|
||||
/* check for `make_blinded_block` curios */
|
||||
assert_eq!(block_a.state_root(), state_after_a.tree_hash_root());
|
||||
@@ -1276,7 +1274,7 @@ pub async fn blinded_equivocation_consensus_late_equivocation() {
|
||||
let unblinded_block_a = reconstruct_block(
|
||||
tester.harness.chain.clone(),
|
||||
block_a.canonical_root(),
|
||||
block_a,
|
||||
Arc::new(block_a),
|
||||
test_logger.clone(),
|
||||
)
|
||||
.await
|
||||
@@ -1299,15 +1297,11 @@ pub async fn blinded_equivocation_consensus_late_equivocation() {
|
||||
ProvenancedBlock::Builder(b, _) => b,
|
||||
};
|
||||
|
||||
let gossip_block_b = GossipVerifiedBlock::new(
|
||||
Arc::new(inner_block_b.clone().deconstruct().0),
|
||||
&tester.harness.chain,
|
||||
);
|
||||
let gossip_block_b =
|
||||
GossipVerifiedBlock::new(inner_block_b.clone().deconstruct().0, &tester.harness.chain);
|
||||
assert!(gossip_block_b.is_ok());
|
||||
let gossip_block_a = GossipVerifiedBlock::new(
|
||||
Arc::new(inner_block_a.clone().deconstruct().0),
|
||||
&tester.harness.chain,
|
||||
);
|
||||
let gossip_block_a =
|
||||
GossipVerifiedBlock::new(inner_block_a.clone().deconstruct().0, &tester.harness.chain);
|
||||
assert!(gossip_block_a.is_err());
|
||||
|
||||
let channel = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
@@ -632,7 +632,7 @@ pub async fn proposer_boost_re_org_test(
|
||||
panic!("Should not be a blinded block");
|
||||
}
|
||||
};
|
||||
let block_c = harness.sign_beacon_block(unsigned_block_c, &state_b);
|
||||
let block_c = Arc::new(harness.sign_beacon_block(unsigned_block_c, &state_b));
|
||||
|
||||
if should_re_org {
|
||||
// Block C should build on A.
|
||||
|
||||
@@ -1587,6 +1587,39 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_get_blob_sidecars(self, use_indices: bool) -> Self {
|
||||
let block_id = BlockId(CoreBlockId::Finalized);
|
||||
let (block_root, _, _) = block_id.root(&self.chain).unwrap();
|
||||
let (block, _, _) = block_id.full_block(&self.chain).await.unwrap();
|
||||
let num_blobs = block.num_expected_blobs();
|
||||
let blob_indices = if use_indices {
|
||||
Some(
|
||||
(0..num_blobs.saturating_sub(1) as u64)
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let result = match self
|
||||
.client
|
||||
.get_blobs::<E>(CoreBlockId::Root(block_root), blob_indices.as_deref())
|
||||
.await
|
||||
{
|
||||
Ok(result) => result.unwrap().data,
|
||||
Err(e) => panic!("query failed incorrectly: {e:?}"),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
result.len(),
|
||||
blob_indices.map_or(num_blobs, |indices| indices.len())
|
||||
);
|
||||
let expected = block.slot();
|
||||
assert_eq!(result.get(0).unwrap().slot(), expected);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_blocks_attestations(self) -> Self {
|
||||
for block_id in self.interesting_block_ids() {
|
||||
let result = self
|
||||
@@ -2597,7 +2630,7 @@ impl ApiTester {
|
||||
|
||||
let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
let signed_block_contents =
|
||||
PublishBlockRequest::try_from(signed_block.clone()).unwrap();
|
||||
PublishBlockRequest::try_from(Arc::new(signed_block.clone())).unwrap();
|
||||
|
||||
self.client
|
||||
.post_beacon_blocks(&signed_block_contents)
|
||||
@@ -2670,8 +2703,8 @@ impl ApiTester {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
self.chain.head_beacon_block().as_ref(),
|
||||
signed_block_contents.signed_block()
|
||||
self.chain.head_beacon_block(),
|
||||
*signed_block_contents.signed_block()
|
||||
);
|
||||
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
@@ -2763,8 +2796,8 @@ impl ApiTester {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
self.chain.head_beacon_block().as_ref(),
|
||||
signed_block_contents.signed_block()
|
||||
self.chain.head_beacon_block(),
|
||||
*signed_block_contents.signed_block()
|
||||
);
|
||||
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
@@ -2994,7 +3027,7 @@ impl ApiTester {
|
||||
.data;
|
||||
|
||||
let signed_block = signed_block_contents.signed_block();
|
||||
assert_eq!(&head_block, signed_block);
|
||||
assert_eq!(head_block, **signed_block);
|
||||
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
}
|
||||
@@ -6291,6 +6324,27 @@ async fn builder_works_post_deneb() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn get_blob_sidecars() {
|
||||
let mut config = ApiTesterConfig {
|
||||
retain_historic_states: false,
|
||||
spec: E::default_spec(),
|
||||
};
|
||||
config.spec.altair_fork_epoch = Some(Epoch::new(0));
|
||||
config.spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||
config.spec.capella_fork_epoch = Some(Epoch::new(0));
|
||||
config.spec.deneb_fork_epoch = Some(Epoch::new(0));
|
||||
|
||||
ApiTester::new_from_config(config)
|
||||
.await
|
||||
.test_post_beacon_blocks_valid()
|
||||
.await
|
||||
.test_get_blob_sidecars(false)
|
||||
.await
|
||||
.test_get_blob_sidecars(true)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn post_validator_liveness_epoch() {
|
||||
ApiTester::new()
|
||||
|
||||
Reference in New Issue
Block a user