mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 04:37:13 +00:00
Implement gloas proposer preference vc duty (#9208)
Allow for the vc to submit its proposer preferences to the network Co-Authored-By: Eitan Seri-Levi <eserilev@ucsc.edu> Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
@@ -252,11 +252,11 @@ fn make_signed_preferences(
|
||||
) -> Arc<SignedProposerPreferences> {
|
||||
Arc::new(SignedProposerPreferences {
|
||||
message: ProposerPreferences {
|
||||
dependent_root: Hash256::ZERO,
|
||||
proposal_slot,
|
||||
validator_index,
|
||||
fee_recipient,
|
||||
gas_limit,
|
||||
..ProposerPreferences::default()
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
})
|
||||
|
||||
@@ -154,7 +154,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use types::{Address, BeaconState, EthSpec, MinimalEthSpec, ProposerPreferences, Slot};
|
||||
use types::{
|
||||
Address, BeaconState, EthSpec, Hash256, MinimalEthSpec, ProposerPreferences, Slot,
|
||||
};
|
||||
|
||||
use super::verify_preferences_consistency;
|
||||
use crate::proposer_preferences_verification::ProposerPreferencesError;
|
||||
@@ -163,7 +165,7 @@ mod tests {
|
||||
|
||||
fn make_preferences(proposal_slot: Slot, validator_index: u64) -> ProposerPreferences {
|
||||
ProposerPreferences {
|
||||
dependent_root: types::Hash256::ZERO,
|
||||
dependent_root: Hash256::ZERO,
|
||||
proposal_slot,
|
||||
validator_index,
|
||||
fee_recipient: Address::ZERO,
|
||||
|
||||
@@ -70,20 +70,24 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
|
||||
use bls::Signature;
|
||||
use types::{Address, ProposerPreferences, SignedProposerPreferences, Slot};
|
||||
use types::{Address, Hash256, ProposerPreferences, SignedProposerPreferences, Slot};
|
||||
|
||||
use super::GossipVerifiedProposerPreferenceCache;
|
||||
use crate::proposer_preferences_verification::gossip_verified_proposer_preferences::GossipVerifiedProposerPreferences;
|
||||
|
||||
fn make_gossip_verified(slot: Slot, validator_index: u64) -> GossipVerifiedProposerPreferences {
|
||||
fn make_gossip_verified(
|
||||
slot: Slot,
|
||||
validator_index: u64,
|
||||
dependent_root: Hash256,
|
||||
) -> GossipVerifiedProposerPreferences {
|
||||
GossipVerifiedProposerPreferences {
|
||||
signed_preferences: Arc::new(SignedProposerPreferences {
|
||||
message: ProposerPreferences {
|
||||
dependent_root,
|
||||
proposal_slot: slot,
|
||||
validator_index,
|
||||
fee_recipient: Address::ZERO,
|
||||
gas_limit: 30_000_000,
|
||||
..ProposerPreferences::default()
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
}),
|
||||
@@ -93,9 +97,10 @@ mod tests {
|
||||
#[test]
|
||||
fn prune_removes_old_retains_current() {
|
||||
let cache = GossipVerifiedProposerPreferenceCache::default();
|
||||
let root = Hash256::ZERO;
|
||||
|
||||
for slot in [1, 2, 3, 7, 8, 9, 10] {
|
||||
let verified = make_gossip_verified(Slot::new(slot), slot);
|
||||
let verified = make_gossip_verified(Slot::new(slot), slot, root);
|
||||
cache.insert_seen_validator(&verified);
|
||||
cache.insert_preferences(verified);
|
||||
}
|
||||
@@ -104,11 +109,26 @@ 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), types::Hash256::ZERO, slot));
|
||||
assert!(!cache.get_seen_validator(&Slot::new(slot), root, slot));
|
||||
}
|
||||
for slot in [8, 9, 10] {
|
||||
assert!(cache.get_preferences(&Slot::new(slot)).is_some());
|
||||
assert!(cache.get_seen_validator(&Slot::new(slot), types::Hash256::ZERO, slot));
|
||||
assert!(cache.get_seen_validator(&Slot::new(slot), root, slot));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_dependent_roots_not_deduped() {
|
||||
let cache = GossipVerifiedProposerPreferenceCache::default();
|
||||
let slot = Slot::new(5);
|
||||
let root_a = Hash256::repeat_byte(0xaa);
|
||||
let root_b = Hash256::repeat_byte(0xbb);
|
||||
let validator_index = 42;
|
||||
|
||||
let verified_a = make_gossip_verified(slot, validator_index, root_a);
|
||||
cache.insert_seen_validator(&verified_a);
|
||||
|
||||
assert!(cache.get_seen_validator(&slot, root_a, validator_index));
|
||||
assert!(!cache.get_seen_validator(&slot, root_b, validator_index));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,11 +127,11 @@ fn make_signed_preferences(
|
||||
) -> Arc<SignedProposerPreferences> {
|
||||
Arc::new(SignedProposerPreferences {
|
||||
message: ProposerPreferences {
|
||||
dependent_root: Hash256::ZERO,
|
||||
proposal_slot,
|
||||
validator_index,
|
||||
fee_recipient: Address::ZERO,
|
||||
gas_limit: 30_000_000,
|
||||
..ProposerPreferences::default()
|
||||
},
|
||||
signature: Signature::empty(),
|
||||
})
|
||||
@@ -231,11 +231,10 @@ fn correct_proposer_bad_signature() {
|
||||
result,
|
||||
Err(ProposerPreferencesError::BadSignature)
|
||||
));
|
||||
assert!(!ctx.preferences_cache.get_seen_validator(
|
||||
&slot,
|
||||
types::Hash256::ZERO,
|
||||
actual_proposer
|
||||
));
|
||||
assert!(
|
||||
!ctx.preferences_cache
|
||||
.get_seen_validator(&slot, Hash256::ZERO, actual_proposer)
|
||||
);
|
||||
assert!(ctx.preferences_cache.get_preferences(&slot).is_none());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user