mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 19:04:27 +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:
@@ -22,11 +22,12 @@ use types::{
|
||||
AbstractExecPayload, Address, AggregateAndProof, Attestation, BeaconBlock, BlindedPayload,
|
||||
ChainSpec, ContributionAndProof, Domain, Epoch, EthSpec, ExecutionPayloadEnvelope, Fork,
|
||||
FullPayload, Graffiti, Hash256, PayloadAttestationData, PayloadAttestationMessage,
|
||||
SelectionProof, SignedAggregateAndProof, SignedBeaconBlock, SignedContributionAndProof,
|
||||
SignedExecutionPayloadEnvelope, SignedRoot, SignedValidatorRegistrationData,
|
||||
SignedVoluntaryExit, Slot, SyncAggregatorSelectionData, SyncCommitteeContribution,
|
||||
SyncCommitteeMessage, SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData,
|
||||
VoluntaryExit, graffiti::GraffitiString,
|
||||
ProposerPreferences, SelectionProof, SignedAggregateAndProof, SignedBeaconBlock,
|
||||
SignedContributionAndProof, SignedExecutionPayloadEnvelope, SignedProposerPreferences,
|
||||
SignedRoot, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot,
|
||||
SyncAggregatorSelectionData, SyncCommitteeContribution, SyncCommitteeMessage,
|
||||
SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData, VoluntaryExit,
|
||||
graffiti::GraffitiString,
|
||||
};
|
||||
use validator_store::{
|
||||
AggregateToSign, AttestationToSign, ContributionToSign, DoppelgangerStatus,
|
||||
@@ -1485,4 +1486,32 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore for LighthouseValidatorS
|
||||
signature,
|
||||
})
|
||||
}
|
||||
|
||||
async fn sign_proposer_preferences(
|
||||
&self,
|
||||
validator_pubkey: PublicKeyBytes,
|
||||
preferences: ProposerPreferences,
|
||||
) -> Result<SignedProposerPreferences, Error> {
|
||||
let signing_context = self.signing_context(
|
||||
Domain::ProposerPreferences,
|
||||
preferences.proposal_slot.epoch(E::slots_per_epoch()),
|
||||
);
|
||||
|
||||
let signing_method = self.doppelganger_bypassed_signing_method(validator_pubkey)?;
|
||||
|
||||
let signature = signing_method
|
||||
.get_signature::<E, FullPayload<E>>(
|
||||
SignableMessage::ProposerPreferences(&preferences),
|
||||
signing_context,
|
||||
&self.spec,
|
||||
&self.task_executor,
|
||||
)
|
||||
.await
|
||||
.map_err(Error::SpecificError)?;
|
||||
|
||||
Ok(SignedProposerPreferences {
|
||||
message: preferences,
|
||||
signature,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ pub enum SignableMessage<'a, E: EthSpec, Payload: AbstractExecPayload<E> = FullP
|
||||
VoluntaryExit(&'a VoluntaryExit),
|
||||
ExecutionPayloadEnvelope(&'a ExecutionPayloadEnvelope<E>),
|
||||
PayloadAttestationData(&'a PayloadAttestationData),
|
||||
ProposerPreferences(&'a ProposerPreferences),
|
||||
}
|
||||
|
||||
impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignableMessage<'_, E, Payload> {
|
||||
@@ -74,6 +75,7 @@ impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignableMessage<'_, E, Payload
|
||||
SignableMessage::VoluntaryExit(exit) => exit.signing_root(domain),
|
||||
SignableMessage::ExecutionPayloadEnvelope(e) => e.signing_root(domain),
|
||||
SignableMessage::PayloadAttestationData(d) => d.signing_root(domain),
|
||||
SignableMessage::ProposerPreferences(p) => p.signing_root(domain),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,6 +245,9 @@ impl SigningMethod {
|
||||
SignableMessage::PayloadAttestationData(d) => {
|
||||
Web3SignerObject::PayloadAttestationData(d)
|
||||
}
|
||||
SignableMessage::ProposerPreferences(p) => {
|
||||
Web3SignerObject::ProposerPreferences(p)
|
||||
}
|
||||
};
|
||||
|
||||
// Determine the Web3Signer message type.
|
||||
|
||||
@@ -22,6 +22,7 @@ pub enum MessageType {
|
||||
// TODO(gloas) verify w/ web3signer specs
|
||||
ExecutionPayloadEnvelope,
|
||||
PayloadAttestation,
|
||||
ProposerPreferences,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Serialize)]
|
||||
@@ -80,6 +81,7 @@ pub enum Web3SignerObject<'a, E: EthSpec, Payload: AbstractExecPayload<E>> {
|
||||
ValidatorRegistration(&'a ValidatorRegistrationData),
|
||||
ExecutionPayloadEnvelope(&'a ExecutionPayloadEnvelope<E>),
|
||||
PayloadAttestationData(&'a PayloadAttestationData),
|
||||
ProposerPreferences(&'a ProposerPreferences),
|
||||
}
|
||||
|
||||
impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> Web3SignerObject<'a, E, Payload> {
|
||||
@@ -147,6 +149,7 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> Web3SignerObject<'a, E, Pa
|
||||
Web3SignerObject::ValidatorRegistration(_) => MessageType::ValidatorRegistration,
|
||||
Web3SignerObject::ExecutionPayloadEnvelope(_) => MessageType::ExecutionPayloadEnvelope,
|
||||
Web3SignerObject::PayloadAttestationData(_) => MessageType::PayloadAttestation,
|
||||
Web3SignerObject::ProposerPreferences(_) => MessageType::ProposerPreferences,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ use validator_services::{
|
||||
latency_service,
|
||||
payload_attestation_service::PayloadAttestationService,
|
||||
preparation_service::{PreparationService, PreparationServiceBuilder},
|
||||
proposer_preferences_service::ProposerPreferencesService,
|
||||
sync_committee_service::SyncCommitteeService,
|
||||
};
|
||||
use validator_store::ValidatorStore as ValidatorStoreTrait;
|
||||
@@ -85,6 +86,8 @@ pub struct ProductionValidatorClient<E: EthSpec> {
|
||||
attestation_service: AttestationService<ValidatorStore<E>, SystemTimeSlotClock>,
|
||||
sync_committee_service: SyncCommitteeService<ValidatorStore<E>, SystemTimeSlotClock>,
|
||||
payload_attestation_service: PayloadAttestationService<ValidatorStore<E>, SystemTimeSlotClock>,
|
||||
proposer_preferences_service:
|
||||
ProposerPreferencesService<ValidatorStore<E>, SystemTimeSlotClock>,
|
||||
doppelganger_service: Option<Arc<DoppelgangerService>>,
|
||||
preparation_service: PreparationService<ValidatorStore<E>, SystemTimeSlotClock>,
|
||||
validator_store: Arc<ValidatorStore<E>>,
|
||||
@@ -563,6 +566,15 @@ impl<E: EthSpec> ProductionValidatorClient<E> {
|
||||
context.eth2_config.spec.clone(),
|
||||
);
|
||||
|
||||
let proposer_preferences_service = ProposerPreferencesService::new(
|
||||
duties_service.clone(),
|
||||
validator_store.clone(),
|
||||
slot_clock.clone(),
|
||||
beacon_nodes.clone(),
|
||||
context.executor.clone(),
|
||||
context.eth2_config.spec.clone(),
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
context,
|
||||
duties_service,
|
||||
@@ -570,6 +582,7 @@ impl<E: EthSpec> ProductionValidatorClient<E> {
|
||||
attestation_service,
|
||||
sync_committee_service,
|
||||
payload_attestation_service,
|
||||
proposer_preferences_service,
|
||||
doppelganger_service,
|
||||
preparation_service,
|
||||
validator_store,
|
||||
@@ -646,6 +659,11 @@ impl<E: EthSpec> ProductionValidatorClient<E> {
|
||||
.clone()
|
||||
.start_update_service()
|
||||
.map_err(|e| format!("Unable to start payload attestation service: {}", e))?;
|
||||
|
||||
self.proposer_preferences_service
|
||||
.clone()
|
||||
.start_update_service()
|
||||
.map_err(|e| format!("Unable to start proposer preferences service: {}", e))?;
|
||||
}
|
||||
|
||||
self.preparation_service
|
||||
|
||||
@@ -5,5 +5,6 @@ pub mod latency_service;
|
||||
pub mod notifier_service;
|
||||
pub mod payload_attestation_service;
|
||||
pub mod preparation_service;
|
||||
pub mod proposer_preferences_service;
|
||||
pub mod sync;
|
||||
pub mod sync_committee_service;
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
use crate::duties_service::DutiesService;
|
||||
use beacon_node_fallback::BeaconNodeFallback;
|
||||
use slot_clock::SlotClock;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use task_executor::TaskExecutor;
|
||||
use tokio::time::sleep;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use types::{ChainSpec, Epoch, EthSpec, ForkName, ProposerPreferences};
|
||||
use validator_store::ValidatorStore;
|
||||
|
||||
pub struct Inner<S, T> {
|
||||
duties_service: Arc<DutiesService<S, T>>,
|
||||
validator_store: Arc<S>,
|
||||
slot_clock: T,
|
||||
beacon_nodes: Arc<BeaconNodeFallback<T>>,
|
||||
executor: TaskExecutor,
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
}
|
||||
|
||||
pub struct ProposerPreferencesService<S, T> {
|
||||
inner: Arc<Inner<S, T>>,
|
||||
}
|
||||
|
||||
impl<S, T> Clone for ProposerPreferencesService<S, T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> Deref for ProposerPreferencesService<S, T> {
|
||||
type Target = Inner<S, T>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.inner.deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: ValidatorStore + 'static, T: SlotClock + 'static> ProposerPreferencesService<S, T> {
|
||||
pub fn new(
|
||||
duties_service: Arc<DutiesService<S, T>>,
|
||||
validator_store: Arc<S>,
|
||||
slot_clock: T,
|
||||
beacon_nodes: Arc<BeaconNodeFallback<T>>,
|
||||
executor: TaskExecutor,
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
) -> Self {
|
||||
Self {
|
||||
inner: Arc::new(Inner {
|
||||
duties_service,
|
||||
validator_store,
|
||||
slot_clock,
|
||||
beacon_nodes,
|
||||
executor,
|
||||
chain_spec,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_update_service(self) -> Result<(), String> {
|
||||
let slot_duration = self.chain_spec.get_slot_duration();
|
||||
info!("Proposer preferences service started");
|
||||
|
||||
let executor = self.executor.clone();
|
||||
|
||||
let interval_fut = async move {
|
||||
loop {
|
||||
let Some(current_slot) = self.slot_clock.now() else {
|
||||
error!("Failed to read slot clock");
|
||||
sleep(slot_duration).await;
|
||||
continue;
|
||||
};
|
||||
|
||||
if !self
|
||||
.chain_spec
|
||||
.fork_name_at_slot::<S::E>(current_slot)
|
||||
.gloas_enabled()
|
||||
{
|
||||
let duration_to_next_epoch = self
|
||||
.slot_clock
|
||||
.duration_to_next_epoch(S::E::slots_per_epoch())
|
||||
.unwrap_or_else(|| slot_duration * S::E::slots_per_epoch() as u32);
|
||||
sleep(duration_to_next_epoch).await;
|
||||
continue;
|
||||
}
|
||||
|
||||
let current_epoch = current_slot.epoch(S::E::slots_per_epoch());
|
||||
let fork_name = self.chain_spec.fork_name_at_slot::<S::E>(current_slot);
|
||||
self.publish_proposer_preferences(current_epoch, fork_name)
|
||||
.await;
|
||||
|
||||
let duration_to_next_epoch = self
|
||||
.slot_clock
|
||||
.duration_to_next_epoch(S::E::slots_per_epoch())
|
||||
.unwrap_or_else(|| slot_duration * S::E::slots_per_epoch() as u32);
|
||||
sleep(duration_to_next_epoch).await;
|
||||
}
|
||||
};
|
||||
|
||||
executor.spawn(interval_fut, "proposer_preferences_service");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn publish_proposer_preferences(&self, current_epoch: Epoch, fork_name: ForkName) {
|
||||
let (dependent_root, duties) = {
|
||||
let proposers = self.duties_service.proposers.read();
|
||||
match proposers.get(¤t_epoch) {
|
||||
Some((root, duties)) => (*root, duties.clone()),
|
||||
None => return,
|
||||
}
|
||||
};
|
||||
|
||||
let preferences_to_sign: Vec<_> = {
|
||||
let mut result = vec![];
|
||||
for duty in &duties {
|
||||
let Some(proposal_data) = self.validator_store.proposal_data(&duty.pubkey) else {
|
||||
warn!(
|
||||
validator = ?duty.pubkey,
|
||||
"Missing proposal data for proposer preferences"
|
||||
);
|
||||
continue;
|
||||
};
|
||||
let Some(fee_recipient) = proposal_data.fee_recipient else {
|
||||
warn!(
|
||||
validator = ?duty.pubkey,
|
||||
"Missing fee recipient for proposer preferences"
|
||||
);
|
||||
continue;
|
||||
};
|
||||
result.push((
|
||||
duty.pubkey,
|
||||
ProposerPreferences {
|
||||
dependent_root,
|
||||
proposal_slot: duty.slot,
|
||||
validator_index: duty.validator_index,
|
||||
fee_recipient,
|
||||
gas_limit: proposal_data.gas_limit,
|
||||
},
|
||||
));
|
||||
}
|
||||
result
|
||||
};
|
||||
|
||||
if preferences_to_sign.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
debug!(
|
||||
%current_epoch,
|
||||
count = preferences_to_sign.len(),
|
||||
"Signing proposer preferences"
|
||||
);
|
||||
|
||||
let mut signed = Vec::with_capacity(preferences_to_sign.len());
|
||||
for (pubkey, preferences) in preferences_to_sign {
|
||||
match self
|
||||
.validator_store
|
||||
.sign_proposer_preferences(pubkey, preferences)
|
||||
.await
|
||||
{
|
||||
Ok(signed_prefs) => signed.push(signed_prefs),
|
||||
Err(e) => {
|
||||
error!(
|
||||
error = ?e,
|
||||
validator = ?pubkey,
|
||||
"Failed to sign proposer preferences"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if signed.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let count = signed.len();
|
||||
let signed = Arc::new(signed);
|
||||
let result = self
|
||||
.beacon_nodes
|
||||
.first_success(|beacon_node| {
|
||||
let signed = signed.clone();
|
||||
async move {
|
||||
match beacon_node
|
||||
.post_validator_proposer_preferences_ssz(&signed, fork_name)
|
||||
.await
|
||||
{
|
||||
Ok(()) => Ok(()),
|
||||
Err(ssz_err) => {
|
||||
debug!(error = ?ssz_err, "SSZ publish failed, falling back to JSON");
|
||||
beacon_node
|
||||
.post_validator_proposer_preferences(&signed, fork_name)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
format!("Failed to publish proposer preferences: {e:?}")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
info!(
|
||||
%current_epoch,
|
||||
%count,
|
||||
"Successfully published proposer preferences"
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
error!(
|
||||
error = %e,
|
||||
%current_epoch,
|
||||
"Failed to publish proposer preferences"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ use std::sync::Arc;
|
||||
use types::{
|
||||
Address, Attestation, AttestationError, BlindedBeaconBlock, Epoch, EthSpec,
|
||||
ExecutionPayloadEnvelope, Graffiti, Hash256, PayloadAttestationData, PayloadAttestationMessage,
|
||||
SelectionProof, SignedAggregateAndProof, SignedBlindedBeaconBlock, SignedContributionAndProof,
|
||||
SignedExecutionPayloadEnvelope, SignedValidatorRegistrationData, Slot,
|
||||
SyncCommitteeContribution, SyncCommitteeMessage, SyncSelectionProof, SyncSubnetId,
|
||||
ValidatorRegistrationData,
|
||||
ProposerPreferences, SelectionProof, SignedAggregateAndProof, SignedBlindedBeaconBlock,
|
||||
SignedContributionAndProof, SignedExecutionPayloadEnvelope, SignedProposerPreferences,
|
||||
SignedValidatorRegistrationData, Slot, SyncCommitteeContribution, SyncCommitteeMessage,
|
||||
SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
@@ -213,6 +213,13 @@ pub trait ValidatorStore: Send + Sync {
|
||||
data: PayloadAttestationData,
|
||||
) -> impl Future<Output = Result<PayloadAttestationMessage, Error<Self::Error>>> + Send;
|
||||
|
||||
/// Sign a `ProposerPreferences` message.
|
||||
fn sign_proposer_preferences(
|
||||
&self,
|
||||
validator_pubkey: PublicKeyBytes,
|
||||
preferences: ProposerPreferences,
|
||||
) -> impl Future<Output = Result<SignedProposerPreferences, Error<Self::Error>>> + Send;
|
||||
|
||||
/// Returns `ProposalData` for the provided `pubkey` if it exists in `InitializedValidators`.
|
||||
/// `ProposalData` fields include defaulting logic described in `get_fee_recipient_defaulting`,
|
||||
/// `get_gas_limit_defaulting`, and `get_builder_proposals_defaulting`.
|
||||
|
||||
Reference in New Issue
Block a user