Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/net/rpc/src/beacon/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ async fn post_committee_subscriptions(

/// Each validator's execution-layer fee recipient, as its validator client
/// last named it. Read by block production, which puts the proposer's into
/// the payload attributes. In memory only: a validator client repeats the call
/// every epoch, so a restarted node relearns the map within one.
/// the payload attributes. In memory only: a validator client repeats the
/// call (ethlambda's and Lighthouse's every slot), so a restarted node
/// relearns the map from its next one.
pub(crate) type FeeRecipients = Arc<std::sync::Mutex<HashMap<ValidatorIndex, ExecutionAddress>>>;

/// One entry of `prepare_beacon_proposer`.
Expand Down
49 changes: 49 additions & 0 deletions crates/validator/src/beacon_node/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,22 @@ impl<B: BeaconNodeApi> BeaconNodeApi for FallbackBeaconNode<B> {
.await
}

/// Every node too, quietly: the duty loop sends this again each slot and
/// logs its own failure, so a node that is down costs a `debug!` line a
/// slot rather than two warnings, one of them claiming a missed duty.
async fn prepare_beacon_proposer_quietly(
&self,
preparations: &[ProposerPreparationDto],
) -> Result<()> {
self.try_all_quiet(
"prepare_beacon_proposer",
"it keeps the fee recipients it was last given",
|node| node.prepare_beacon_proposer(preparations),
)
.await
.map(|_| ())
}

/// Every node, for the same reason, and with more at stake. A subscription
/// is what puts a node on the attestation subnets and what makes it collect
/// the votes an aggregate is folded from, so a node that never received one
Expand Down Expand Up @@ -1108,6 +1124,39 @@ mod tests {
assert_eq!(fallback.nodes[1].preparations().len(), 1);
}

/// The per-slot send goes to every node like the epoch's, and fails only
/// when none accepted. What it changes is the logging, which this does
/// not see.
#[tokio::test]
async fn the_quiet_fee_recipient_send_reaches_every_node_too() {
let preparations = [ProposerPreparationDto {
validator_index: 1,
fee_recipient: "0xab".to_string(),
}];
let fallback = FallbackBeaconNode::new(vec![
MockBeaconNode::failing("down"),
MockBeaconNode::new(),
MockBeaconNode::new(),
]);
fallback
.prepare_beacon_proposer_quietly(&preparations)
.await
.expect("two nodes accepted");
assert!(fallback.nodes[0].preparations().is_empty());
assert_eq!(fallback.nodes[1].preparations().len(), 1);
assert_eq!(fallback.nodes[2].preparations().len(), 1);

let down = FallbackBeaconNode::new(vec![
MockBeaconNode::failing("down"),
MockBeaconNode::failing("down"),
]);
let err = down
.prepare_beacon_proposer_quietly(&preparations)
.await
.expect_err("no node accepted");
assert!(matches!(err, Error::AllBeaconNodesFailed(_)), "got {err:?}");
}

/// One unreachable node must not stop the reachable ones being told.
#[tokio::test]
async fn one_failing_node_does_not_stop_the_others_being_subscribed() {
Expand Down
23 changes: 23 additions & 0 deletions crates/validator/src/beacon_node/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ pub struct MockBeaconNode {
/// records its batch, so a test releases calls one at a time instead of
/// guessing how long a delay must be.
pub registration_gate: Option<Arc<Semaphore>>,
/// When set, each `prepare_beacon_proposer` call takes a permit before it
/// records its preparations and answers, as a slow node does, for as long
/// as the test holds it back.
pub preparation_gate: Option<Arc<Semaphore>>,
/// Notified when `prepare_beacon_proposer` is called, before the gate.
/// Every call stores a permit (`notify_one`), so a test that awaits it
/// must not make an earlier call it does not mean to wait for: that call's
/// permit would answer the wait.
pub preparation_entered: Arc<Notify>,
/// Every blinded block published, as (fork, body).
pub published_blinded: Mutex<Vec<(ForkName, Vec<u8>)>>,
/// What `publish_blinded_block` reports. `None` is `Ok(HandedToBuilder)`;
Expand Down Expand Up @@ -426,6 +435,13 @@ impl MockBeaconNode {
self
}

/// Make each `prepare_beacon_proposer` call wait for a permit from `gate`
/// before it records its preparations.
pub fn with_preparation_gate(mut self, gate: Arc<Semaphore>) -> Self {
self.preparation_gate = Some(gate);
self
}

/// Make `produce_block` wait for a permit from `gate` before it answers.
pub fn with_produce_gate(mut self, gate: Arc<Semaphore>) -> Self {
self.produce_gate = Some(gate);
Expand Down Expand Up @@ -1215,6 +1231,13 @@ impl BeaconNodeApi for MockBeaconNode {

async fn prepare_beacon_proposer(&self, preparations: &[ProposerPreparationDto]) -> Result<()> {
self.guard("prepare_beacon_proposer")?;
self.preparation_entered.notify_one();
if let Some(gate) = &self.preparation_gate {
gate.acquire()
.await
.expect("the gate is never closed")
.forget();
}
self.preparations
.lock()
.expect("lock")
Expand Down
17 changes: 17 additions & 0 deletions crates/validator/src/beacon_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,23 @@ pub trait BeaconNodeApi: Send + Sync {
/// before it is signed rather than assumed.
async fn prepare_beacon_proposer(&self, preparations: &[ProposerPreparationDto]) -> Result<()>;

/// [`Self::prepare_beacon_proposer`] for a caller that sends it again
/// every slot and reports a failure itself. The same request; what
/// differs is the logging around it. The fallback logs a refusing node at
/// `debug!` and says nothing when none accepts, where the plain call warns
/// for each refusal and then that the duty was likely missed: once a slot,
/// for as long as a node is down, and on slots with no duty.
///
/// The default is the plain call because the logging is the fallback's
/// alone: one node (`HttpBeaconNode`) logs nothing about its answer either
/// way, so it has nothing to quieten.
async fn prepare_beacon_proposer_quietly(
&self,
preparations: &[ProposerPreparationDto],
) -> Result<()> {
self.prepare_beacon_proposer(preparations).await
}

/// Tells the node which committees this client's validators care about
/// this epoch, so it can manage subnet subscriptions on their behalf.
async fn subscribe_committees(&self, subscriptions: &[CommitteeSubscriptionDto]) -> Result<()>;
Expand Down
3 changes: 2 additions & 1 deletion crates/validator/src/http_api/proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ pub async fn set_fee_recipient(
info!(
pubkey = %encode_hex(&pubkey.0),
fee_recipient = %encode_hex(&address.0),
"Fee recipient set; registered with the beacon node at the next epoch"
"Fee recipient set; sent to the beacon node with the next proposer preparation that \
includes this validator"
);
Ok(StatusCode::ACCEPTED)
}
Expand Down
Loading
Loading