mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
@@ -28,8 +28,8 @@ pub struct ValidatorDuty {
|
||||
pub attestation_committee_index: Option<CommitteeIndex>,
|
||||
/// The position of the validator in the committee.
|
||||
pub attestation_committee_position: Option<usize>,
|
||||
/// The slot in which a validator must propose a block, or `null` if block production is not required.
|
||||
pub block_proposal_slot: Option<Slot>,
|
||||
/// The slots in which a validator must propose a block (can be empty).
|
||||
pub block_proposal_slots: Vec<Slot>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone, Encode, Decode)]
|
||||
@@ -161,17 +161,18 @@ fn return_validator_duties<T: BeaconChainTypes>(
|
||||
))
|
||||
})?;
|
||||
|
||||
let block_proposal_slot = validator_proposers
|
||||
let block_proposal_slots = validator_proposers
|
||||
.iter()
|
||||
.find(|(i, _slot)| validator_index == *i)
|
||||
.map(|(_i, slot)| *slot);
|
||||
.filter(|(i, _slot)| validator_index == *i)
|
||||
.map(|(_i, slot)| *slot)
|
||||
.collect();
|
||||
|
||||
Ok(ValidatorDuty {
|
||||
validator_pubkey,
|
||||
attestation_slot: duties.map(|d| d.slot),
|
||||
attestation_committee_index: duties.map(|d| d.index),
|
||||
attestation_committee_position: duties.map(|d| d.committee_position),
|
||||
block_proposal_slot,
|
||||
block_proposal_slots,
|
||||
})
|
||||
} else {
|
||||
Ok(ValidatorDuty {
|
||||
@@ -179,7 +180,7 @@ fn return_validator_duties<T: BeaconChainTypes>(
|
||||
attestation_slot: None,
|
||||
attestation_committee_index: None,
|
||||
attestation_committee_position: None,
|
||||
block_proposal_slot: None,
|
||||
block_proposal_slots: vec![],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -294,14 +294,16 @@ fn check_duties<T: BeaconChainTypes>(
|
||||
"attestation index should match"
|
||||
);
|
||||
|
||||
if let Some(slot) = duty.block_proposal_slot {
|
||||
let expected_proposer = state
|
||||
.get_beacon_proposer_index(slot, spec)
|
||||
.expect("should know proposer");
|
||||
assert_eq!(
|
||||
expected_proposer, validator_index,
|
||||
"should get correct proposal slot"
|
||||
);
|
||||
if !duty.block_proposal_slots.is_empty() {
|
||||
for slot in &duty.block_proposal_slots {
|
||||
let expected_proposer = state
|
||||
.get_beacon_proposer_index(*slot, spec)
|
||||
.expect("should know proposer");
|
||||
assert_eq!(
|
||||
expected_proposer, validator_index,
|
||||
"should get correct proposal slot"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
epoch.slot_iter(E::slots_per_epoch()).for_each(|slot| {
|
||||
let slot_proposer = state
|
||||
@@ -314,6 +316,16 @@ fn check_duties<T: BeaconChainTypes>(
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
// Validator duties should include a proposer for every slot of the epoch.
|
||||
let mut all_proposer_slots: Vec<Slot> = duties
|
||||
.iter()
|
||||
.flat_map(|duty| duty.block_proposal_slots.clone())
|
||||
.collect();
|
||||
all_proposer_slots.sort();
|
||||
|
||||
let all_slots: Vec<Slot> = epoch.slot_iter(E::slots_per_epoch()).collect();
|
||||
assert_eq!(all_proposer_slots, all_slots);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user