mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 13:17:09 +00:00
Spec v1.7.0-alpha.6 and Gloas genesis (#9190)
Co-Authored-By: Josh King <josh@sigmaprime.io> Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com> Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
@@ -64,6 +64,7 @@ impl GossipVerifiedProposerPreferences {
|
||||
ctx: &GossipVerificationContext<'_, T>,
|
||||
) -> Result<Self, ProposerPreferencesError> {
|
||||
let proposal_slot = signed_preferences.message.proposal_slot;
|
||||
let checkpoint_root = signed_preferences.message.checkpoint_root;
|
||||
let validator_index = signed_preferences.message.validator_index;
|
||||
let cached_head = ctx.canonical_head.cached_head();
|
||||
let current_slot = ctx
|
||||
@@ -74,7 +75,7 @@ impl GossipVerifiedProposerPreferences {
|
||||
|
||||
if ctx
|
||||
.gossip_verified_proposer_preferences_cache
|
||||
.get_seen_validator(&proposal_slot, validator_index)
|
||||
.get_seen_validator(&proposal_slot, checkpoint_root, validator_index)
|
||||
{
|
||||
return Err(ProposerPreferencesError::AlreadySeen {
|
||||
validator_index,
|
||||
@@ -162,6 +163,7 @@ mod tests {
|
||||
|
||||
fn make_preferences(proposal_slot: Slot, validator_index: u64) -> ProposerPreferences {
|
||||
ProposerPreferences {
|
||||
checkpoint_root: types::Hash256::ZERO,
|
||||
proposal_slot,
|
||||
validator_index,
|
||||
fee_recipient: Address::ZERO,
|
||||
|
||||
@@ -5,11 +5,11 @@ use std::{
|
||||
|
||||
use crate::proposer_preferences_verification::gossip_verified_proposer_preferences::GossipVerifiedProposerPreferences;
|
||||
use parking_lot::RwLock;
|
||||
use types::{SignedProposerPreferences, Slot};
|
||||
use types::{Hash256, SignedProposerPreferences, Slot};
|
||||
|
||||
pub struct GossipVerifiedProposerPreferenceCache {
|
||||
preferences: RwLock<BTreeMap<Slot, GossipVerifiedProposerPreferences>>,
|
||||
seen: RwLock<BTreeMap<Slot, HashSet<u64>>>,
|
||||
seen: RwLock<BTreeMap<Slot, HashSet<(Hash256, u64)>>>,
|
||||
}
|
||||
|
||||
impl Default for GossipVerifiedProposerPreferenceCache {
|
||||
@@ -34,21 +34,27 @@ impl GossipVerifiedProposerPreferenceCache {
|
||||
self.preferences.write().insert(slot, preferences);
|
||||
}
|
||||
|
||||
pub fn get_seen_validator(&self, slot: &Slot, validator_index: u64) -> bool {
|
||||
pub fn get_seen_validator(
|
||||
&self,
|
||||
slot: &Slot,
|
||||
checkpoint_root: Hash256,
|
||||
validator_index: u64,
|
||||
) -> bool {
|
||||
self.seen
|
||||
.read()
|
||||
.get(slot)
|
||||
.is_some_and(|seen| seen.contains(&validator_index))
|
||||
.is_some_and(|seen| seen.contains(&(checkpoint_root, validator_index)))
|
||||
}
|
||||
|
||||
pub fn insert_seen_validator(&self, preferences: &GossipVerifiedProposerPreferences) {
|
||||
let slot = preferences.signed_preferences.message.proposal_slot;
|
||||
let checkpoint_root = preferences.signed_preferences.message.checkpoint_root;
|
||||
let validator_index = preferences.signed_preferences.message.validator_index;
|
||||
self.seen
|
||||
.write()
|
||||
.entry(slot)
|
||||
.or_default()
|
||||
.insert(validator_index);
|
||||
.insert((checkpoint_root, validator_index));
|
||||
}
|
||||
|
||||
pub fn prune(&self, current_slot: Slot) {
|
||||
@@ -77,6 +83,7 @@ mod tests {
|
||||
validator_index,
|
||||
fee_recipient: Address::ZERO,
|
||||
gas_limit: 30_000_000,
|
||||
..ProposerPreferences::default()
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
}),
|
||||
@@ -97,11 +104,11 @@ mod tests {
|
||||
|
||||
for slot in [1, 2, 3, 7] {
|
||||
assert!(cache.get_preferences(&Slot::new(slot)).is_none());
|
||||
assert!(!cache.get_seen_validator(&Slot::new(slot), slot));
|
||||
assert!(!cache.get_seen_validator(&Slot::new(slot), types::Hash256::ZERO, slot));
|
||||
}
|
||||
for slot in [8, 9, 10] {
|
||||
assert!(cache.get_preferences(&Slot::new(slot)).is_some());
|
||||
assert!(cache.get_seen_validator(&Slot::new(slot), slot));
|
||||
assert!(cache.get_seen_validator(&Slot::new(slot), types::Hash256::ZERO, slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ fn make_signed_preferences(
|
||||
validator_index,
|
||||
fee_recipient: Address::ZERO,
|
||||
gas_limit: 30_000_000,
|
||||
..ProposerPreferences::default()
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
})
|
||||
@@ -230,10 +231,11 @@ fn correct_proposer_bad_signature() {
|
||||
result,
|
||||
Err(ProposerPreferencesError::BadSignature)
|
||||
));
|
||||
assert!(
|
||||
!ctx.preferences_cache
|
||||
.get_seen_validator(&slot, actual_proposer)
|
||||
);
|
||||
assert!(!ctx.preferences_cache.get_seen_validator(
|
||||
&slot,
|
||||
types::Hash256::ZERO,
|
||||
actual_proposer
|
||||
));
|
||||
assert!(ctx.preferences_cache.get_preferences(&slot).is_none());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user