mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 20:02:43 +00:00
Merge branch 'expose-blst-internals' into into-anchor
# Conflicts: # Cargo.lock # Cargo.toml # account_manager/src/validator/create.rs # account_manager/src/validator/recover.rs # beacon_node/http_api/src/block_id.rs # beacon_node/http_api/src/lib.rs # consensus/types/src/payload.rs # validator_client/doppelganger_service/src/lib.rs # validator_client/http_metrics/Cargo.toml # validator_client/validator_services/src/preparation_service.rs
This commit is contained in:
@@ -41,7 +41,8 @@ use tree_hash::TreeHash;
|
||||
use types::application_domain::ApplicationDomain;
|
||||
use types::{
|
||||
attestation::AttestationBase, AggregateSignature, BitList, Domain, EthSpec, ExecutionBlockHash,
|
||||
Hash256, Keypair, MainnetEthSpec, RelativeEpoch, SelectionProof, SignedRoot, Slot,
|
||||
Hash256, Keypair, MainnetEthSpec, RelativeEpoch, SelectionProof, SignedRoot, SingleAttestation,
|
||||
Slot,
|
||||
};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
@@ -72,6 +73,7 @@ struct ApiTester {
|
||||
next_block: PublishBlockRequest<E>,
|
||||
reorg_block: PublishBlockRequest<E>,
|
||||
attestations: Vec<Attestation<E>>,
|
||||
single_attestations: Vec<SingleAttestation>,
|
||||
contribution_and_proofs: Vec<SignedContributionAndProof<E>>,
|
||||
attester_slashing: AttesterSlashing<E>,
|
||||
proposer_slashing: ProposerSlashing,
|
||||
@@ -204,6 +206,27 @@ impl ApiTester {
|
||||
"precondition: attestations for testing"
|
||||
);
|
||||
|
||||
let fork_name = harness
|
||||
.chain
|
||||
.spec
|
||||
.fork_name_at_slot::<E>(harness.chain.slot().unwrap());
|
||||
|
||||
let single_attestations = if fork_name.electra_enabled() {
|
||||
harness
|
||||
.get_single_attestations(
|
||||
&AttestationStrategy::AllValidators,
|
||||
&head.beacon_state,
|
||||
head_state_root,
|
||||
head.beacon_block_root,
|
||||
harness.chain.slot().unwrap(),
|
||||
)
|
||||
.into_iter()
|
||||
.flat_map(|vec| vec.into_iter().map(|(attestation, _subnet_id)| attestation))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
|
||||
let current_epoch = harness
|
||||
.chain
|
||||
.slot()
|
||||
@@ -295,6 +318,7 @@ impl ApiTester {
|
||||
next_block,
|
||||
reorg_block,
|
||||
attestations,
|
||||
single_attestations,
|
||||
contribution_and_proofs,
|
||||
attester_slashing,
|
||||
proposer_slashing,
|
||||
@@ -382,6 +406,7 @@ impl ApiTester {
|
||||
next_block,
|
||||
reorg_block,
|
||||
attestations,
|
||||
single_attestations: vec![],
|
||||
contribution_and_proofs: vec![],
|
||||
attester_slashing,
|
||||
proposer_slashing,
|
||||
@@ -1279,7 +1304,7 @@ impl ApiTester {
|
||||
.chain
|
||||
.block_root_at_slot(block.slot(), WhenSlotSkipped::None)
|
||||
.unwrap()
|
||||
.map_or(false, |canonical| block_root == canonical);
|
||||
.is_some_and(|canonical| block_root == canonical);
|
||||
|
||||
assert_eq!(result.canonical, canonical, "{:?}", block_id);
|
||||
assert_eq!(result.root, block_root, "{:?}", block_id);
|
||||
@@ -1801,13 +1826,16 @@ impl ApiTester {
|
||||
}
|
||||
|
||||
pub async fn test_post_beacon_pool_attestations_valid_v2(mut self) -> Self {
|
||||
if self.single_attestations.is_empty() {
|
||||
return self;
|
||||
}
|
||||
let fork_name = self
|
||||
.attestations
|
||||
.single_attestations
|
||||
.first()
|
||||
.map(|att| self.chain.spec.fork_name_at_slot::<E>(att.data().slot))
|
||||
.map(|att| self.chain.spec.fork_name_at_slot::<E>(att.data.slot))
|
||||
.unwrap();
|
||||
self.client
|
||||
.post_beacon_pool_attestations_v2(self.attestations.as_slice(), fork_name)
|
||||
.post_beacon_pool_attestations_v2(self.single_attestations.as_slice(), fork_name)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
@@ -1855,10 +1883,13 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
pub async fn test_post_beacon_pool_attestations_invalid_v2(mut self) -> Self {
|
||||
if self.single_attestations.is_empty() {
|
||||
return self;
|
||||
}
|
||||
let mut attestations = Vec::new();
|
||||
for attestation in &self.attestations {
|
||||
for attestation in &self.single_attestations {
|
||||
let mut invalid_attestation = attestation.clone();
|
||||
invalid_attestation.data_mut().slot += 1;
|
||||
invalid_attestation.data.slot += 1;
|
||||
|
||||
// add both to ensure we only fail on invalid attestations
|
||||
attestations.push(attestation.clone());
|
||||
@@ -2233,9 +2264,9 @@ impl ApiTester {
|
||||
pub async fn test_get_config_spec(self) -> Self {
|
||||
let result = self
|
||||
.client
|
||||
.get_config_spec::<ConfigAndPresetElectra>()
|
||||
.get_config_spec::<ConfigAndPresetFulu>()
|
||||
.await
|
||||
.map(|res| ConfigAndPreset::Electra(res.data))
|
||||
.map(|res| ConfigAndPreset::Fulu(res.data))
|
||||
.unwrap();
|
||||
let expected = ConfigAndPreset::from_chain_spec::<E>(&self.chain.spec, None);
|
||||
|
||||
@@ -6018,6 +6049,48 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_get_events_electra(self) -> Self {
|
||||
let topics = vec![EventTopic::SingleAttestation];
|
||||
let mut events_future = self
|
||||
.client
|
||||
.get_events::<E>(topics.as_slice())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let expected_attestation_len = self.single_attestations.len();
|
||||
|
||||
let fork_name = self
|
||||
.chain
|
||||
.spec
|
||||
.fork_name_at_slot::<E>(self.chain.slot().unwrap());
|
||||
|
||||
self.client
|
||||
.post_beacon_pool_attestations_v2(&self.single_attestations, fork_name)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let attestation_events = poll_events(
|
||||
&mut events_future,
|
||||
expected_attestation_len,
|
||||
Duration::from_millis(10000),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
attestation_events.as_slice(),
|
||||
self.single_attestations
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|single_attestation| EventKind::SingleAttestation(Box::new(
|
||||
single_attestation
|
||||
)))
|
||||
.collect::<Vec<_>>()
|
||||
.as_slice()
|
||||
);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_get_events_altair(self) -> Self {
|
||||
let topics = vec![EventTopic::ContributionAndProof];
|
||||
let mut events_future = self
|
||||
@@ -6165,6 +6238,20 @@ async fn get_events_altair() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn get_events_electra() {
|
||||
let mut config = ApiTesterConfig::default();
|
||||
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));
|
||||
config.spec.electra_fork_epoch = Some(Epoch::new(0));
|
||||
ApiTester::new_from_config(config)
|
||||
.await
|
||||
.test_get_events_electra()
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn get_events_from_genesis() {
|
||||
ApiTester::new_from_genesis()
|
||||
|
||||
Reference in New Issue
Block a user