Fix some compilation errors in tests
This commit is contained in:
parent
6771954c5f
commit
d4aedab21f
@ -912,19 +912,19 @@ pub async fn blinded_gossip_full_pass_ssz() {
|
|||||||
let slot_b = slot_a + 1;
|
let slot_b = slot_a + 1;
|
||||||
|
|
||||||
let state_a = tester.harness.get_current_state();
|
let state_a = tester.harness.get_current_state();
|
||||||
let ((block, _), _): ((SignedBlindedBeaconBlock<E>, _), _) =
|
let (block_contents_tuple, _) = tester.harness.make_blinded_block(state_a, slot_b).await;
|
||||||
tester.harness.make_blinded_block(state_a, slot_b).await;
|
let block_contents = block_contents_tuple.into();
|
||||||
|
|
||||||
let response: Result<(), eth2::Error> = tester
|
let response: Result<(), eth2::Error> = tester
|
||||||
.client
|
.client
|
||||||
.post_beacon_blinded_blocks_v2_ssz(&block, validation_level)
|
.post_beacon_blinded_blocks_v2_ssz(&block_contents, validation_level)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
assert!(response.is_ok());
|
assert!(response.is_ok());
|
||||||
assert!(tester
|
assert!(tester
|
||||||
.harness
|
.harness
|
||||||
.chain
|
.chain
|
||||||
.block_is_known_to_fork_choice(&block.canonical_root()));
|
.block_is_known_to_fork_choice(&block_contents.signed_block().canonical_root()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This test checks that a block that is **invalid** from a gossip perspective gets rejected when using `broadcast_validation=consensus`.
|
/// This test checks that a block that is **invalid** from a gossip perspective gets rejected when using `broadcast_validation=consensus`.
|
||||||
|
@ -2656,13 +2656,10 @@ impl ApiTester {
|
|||||||
.get_validator_blinded_blocks::<E, Payload>(slot, &randao_reveal, None)
|
.get_validator_blinded_blocks::<E, Payload>(slot, &randao_reveal, None)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.data
|
.data;
|
||||||
.deconstruct()
|
|
||||||
.0;
|
|
||||||
|
|
||||||
let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
|
||||||
let signed_block_contents =
|
let signed_block_contents =
|
||||||
SignedBlockContents::<E, Payload>::Block(signed_block.clone());
|
block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||||
|
|
||||||
self.client
|
self.client
|
||||||
.post_beacon_blinded_blocks(&signed_block_contents)
|
.post_beacon_blinded_blocks(&signed_block_contents)
|
||||||
@ -2670,6 +2667,7 @@ impl ApiTester {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// This converts the generic `Payload` to a concrete type for comparison.
|
// 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());
|
let head_block = SignedBeaconBlock::from(signed_block.clone());
|
||||||
assert_eq!(head_block, signed_block);
|
assert_eq!(head_block, signed_block);
|
||||||
|
|
||||||
@ -2715,23 +2713,23 @@ impl ApiTester {
|
|||||||
sk.sign(message).into()
|
sk.sign(message).into()
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = self
|
let block_contents = self
|
||||||
.client
|
.client
|
||||||
.get_validator_blinded_blocks::<E, Payload>(slot, &randao_reveal, None)
|
.get_validator_blinded_blocks::<E, Payload>(slot, &randao_reveal, None)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.data
|
.data;
|
||||||
.deconstruct()
|
|
||||||
.0;
|
|
||||||
|
|
||||||
let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
let signed_block_contents =
|
||||||
|
block_contents.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||||
|
|
||||||
self.client
|
self.client
|
||||||
.post_beacon_blinded_blocks_ssz(&signed_block)
|
.post_beacon_blinded_blocks_ssz(&signed_block_contents)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// This converts the generic `Payload` to a concrete type for comparison.
|
// 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());
|
let head_block = SignedBeaconBlock::from(signed_block.clone());
|
||||||
assert_eq!(head_block, signed_block);
|
assert_eq!(head_block, signed_block);
|
||||||
|
|
||||||
|
@ -751,7 +751,7 @@ impl BeaconNodeHttpClient {
|
|||||||
/// Returns `Ok(None)` on a 404 error.
|
/// Returns `Ok(None)` on a 404 error.
|
||||||
pub async fn post_beacon_blinded_blocks_ssz<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
pub async fn post_beacon_blinded_blocks_ssz<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||||
&self,
|
&self,
|
||||||
block: &SignedBlindedBlockContents<T>,
|
block: &SignedBlockContents<T, Payload>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut path = self.eth_path(V1)?;
|
let mut path = self.eth_path(V1)?;
|
||||||
|
|
||||||
|
@ -1431,6 +1431,26 @@ impl<T: EthSpec, Payload: AbstractExecPayload<T>> BlockContents<T, Payload> {
|
|||||||
BlockContents::Block(block) => (block, None),
|
BlockContents::Block(block) => (block, None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Signs `self`, producing a `SignedBlockContents`.
|
||||||
|
pub fn sign(
|
||||||
|
self,
|
||||||
|
secret_key: &SecretKey,
|
||||||
|
fork: &Fork,
|
||||||
|
genesis_validators_root: Hash256,
|
||||||
|
spec: &ChainSpec,
|
||||||
|
) -> SignedBlockContents<T, Payload> {
|
||||||
|
let (block, maybe_blobs) = self.deconstruct();
|
||||||
|
let signed_block = block.sign(secret_key, fork, genesis_validators_root, spec);
|
||||||
|
let signed_blobs = maybe_blobs.map(|blobs| {
|
||||||
|
blobs
|
||||||
|
.into_iter()
|
||||||
|
.map(|blob| blob.sign(secret_key, fork, genesis_validators_root, spec))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into()
|
||||||
|
});
|
||||||
|
SignedBlockContents::new(signed_block, signed_blobs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
|
impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use crate::{Blob, ChainSpec, Domain, EthSpec, Fork, Hash256, SignedBlobSidecar, SignedRoot, Slot};
|
use crate::{Blob, EthSpec, Hash256, SignedRoot, Slot};
|
||||||
use bls::SecretKey;
|
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use kzg::{Kzg, KzgCommitment, KzgPreset, KzgProof};
|
use kzg::{Kzg, KzgCommitment, KzgPreset, KzgProof};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
@ -10,7 +9,6 @@ use ssz_derive::{Decode, Encode};
|
|||||||
use ssz_types::{FixedVector, VariableList};
|
use ssz_types::{FixedVector, VariableList};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use test_random_derive::TestRandom;
|
use test_random_derive::TestRandom;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
@ -171,31 +169,6 @@ impl<T: EthSpec> BlobSidecar<T> {
|
|||||||
// Fixed part
|
// Fixed part
|
||||||
Self::empty().as_ssz_bytes().len()
|
Self::empty().as_ssz_bytes().len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is mostly not used except for in testing
|
|
||||||
pub fn sign(
|
|
||||||
self: Arc<Self>,
|
|
||||||
secret_key: &SecretKey,
|
|
||||||
fork: &Fork,
|
|
||||||
genesis_validators_root: Hash256,
|
|
||||||
spec: &ChainSpec,
|
|
||||||
) -> SignedBlobSidecar<T> {
|
|
||||||
let signing_epoch = self.slot.epoch(T::slots_per_epoch());
|
|
||||||
let domain = spec.get_domain(
|
|
||||||
signing_epoch,
|
|
||||||
Domain::BlobSidecar,
|
|
||||||
fork,
|
|
||||||
genesis_validators_root,
|
|
||||||
);
|
|
||||||
let message = self.signing_root(domain);
|
|
||||||
let signature = secret_key.sign(message);
|
|
||||||
|
|
||||||
SignedBlobSidecar {
|
|
||||||
message: self,
|
|
||||||
signature,
|
|
||||||
_phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
@ -2,14 +2,17 @@ use crate::beacon_block_body::KzgCommitments;
|
|||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use crate::{
|
use crate::{
|
||||||
AbstractExecPayload, BeaconBlock, BlindedBlobSidecar, BlindedBlobSidecarList, BlobRootsList,
|
AbstractExecPayload, BeaconBlock, BlindedBlobSidecar, BlindedBlobSidecarList, BlobRootsList,
|
||||||
BlobSidecar, BlobSidecarList, BlobsList, EthSpec, SidecarList, SignedRoot, Slot,
|
BlobSidecar, BlobSidecarList, BlobsList, ChainSpec, Domain, EthSpec, Fork, Hash256,
|
||||||
|
SidecarList, SignedRoot, SignedSidecar, Slot,
|
||||||
};
|
};
|
||||||
|
use bls::SecretKey;
|
||||||
use kzg::KzgProof;
|
use kzg::KzgProof;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use ssz::{Decode, Encode};
|
use ssz::{Decode, Encode};
|
||||||
use ssz_types::VariableList;
|
use ssz_types::VariableList;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
|
|
||||||
@ -29,13 +32,40 @@ pub trait Sidecar<E: EthSpec>:
|
|||||||
+ for<'a> arbitrary::Arbitrary<'a>
|
+ for<'a> arbitrary::Arbitrary<'a>
|
||||||
{
|
{
|
||||||
type BlobItems: BlobItems<E>;
|
type BlobItems: BlobItems<E>;
|
||||||
|
|
||||||
fn slot(&self) -> Slot;
|
fn slot(&self) -> Slot;
|
||||||
|
|
||||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||||
blob_items: Self::BlobItems,
|
blob_items: Self::BlobItems,
|
||||||
block: &BeaconBlock<E, Payload>,
|
block: &BeaconBlock<E, Payload>,
|
||||||
expected_kzg_commitments: &KzgCommitments<E>,
|
expected_kzg_commitments: &KzgCommitments<E>,
|
||||||
kzg_proofs: Vec<KzgProof>,
|
kzg_proofs: Vec<KzgProof>,
|
||||||
) -> Result<SidecarList<E, Self>, String>;
|
) -> Result<SidecarList<E, Self>, String>;
|
||||||
|
|
||||||
|
// this is mostly not used except for in testing
|
||||||
|
fn sign(
|
||||||
|
self: Arc<Self>,
|
||||||
|
secret_key: &SecretKey,
|
||||||
|
fork: &Fork,
|
||||||
|
genesis_validators_root: Hash256,
|
||||||
|
spec: &ChainSpec,
|
||||||
|
) -> SignedSidecar<E, Self> {
|
||||||
|
let signing_epoch = self.slot().epoch(E::slots_per_epoch());
|
||||||
|
let domain = spec.get_domain(
|
||||||
|
signing_epoch,
|
||||||
|
Domain::BlobSidecar,
|
||||||
|
fork,
|
||||||
|
genesis_validators_root,
|
||||||
|
);
|
||||||
|
let message = self.signing_root(domain);
|
||||||
|
let signature = secret_key.sign(message);
|
||||||
|
|
||||||
|
SignedSidecar {
|
||||||
|
message: self,
|
||||||
|
signature,
|
||||||
|
_phantom: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BlobItems<T: EthSpec>: Sync + Send + Sized {
|
pub trait BlobItems<T: EthSpec>: Sync + Send + Sized {
|
||||||
|
Loading…
Reference in New Issue
Block a user