Skip to content

Commit

Permalink
add v3 logic into vc
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Oct 7, 2023
1 parent d2c7dba commit 33f3411
Showing 1 changed file with 101 additions and 60 deletions.
161 changes: 101 additions & 60 deletions validator_client/src/block_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,30 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
)
}

for validator_pubkey in proposers {
let builder_proposals = self
.validator_store
.get_builder_proposals(&validator_pubkey);
let service = self.clone();
let log = log.clone();
self.inner.context.executor.spawn(
async move {
if builder_proposals {
let deneb_fork_activated = self
.context
.eth2_config
.spec
.altair_fork_epoch
.and_then(|fork_epoch| {
let current_epoch = self.slot_clock.now()?.epoch(E::slots_per_epoch());
Some(current_epoch >= fork_epoch)
})
.unwrap_or(false);

if deneb_fork_activated {
for validator_pubkey in proposers {
let service = self.clone();
let log = log.clone();
self.inner.context.executor.spawn(
async move {
let result = service
.clone()
.publish_block::<BlindedPayload<E>>(slot, validator_pubkey)
.publish_block_v3(slot, validator_pubkey)
.await;

match result {
Ok(_) => {}
Err(BlockError::Recoverable(e)) => {
error!(
log,
Expand All @@ -356,52 +366,92 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
"block_slot" => ?slot,
"info" => "blinded proposal failed, attempting full block"
);
if let Err(e) = service
.publish_block::<FullPayload<E>>(slot, validator_pubkey)
.await
{
// Log a `crit` since a full block
// (non-builder) proposal failed.
crit!(
}
Err(BlockError::Irrecoverable(e)) => {
error!(
log,
"Error whilst producing block";
"error" => ?e,
"block_slot" => ?slot,
"info" => "this error may or may not result in a missed block",
);
}
}
},
"block service",
)
}
} else {
for validator_pubkey in proposers {
let builder_proposals = self
.validator_store
.get_builder_proposals(&validator_pubkey);
let service = self.clone();
let log = log.clone();
self.inner.context.executor.spawn(
async move {
if builder_proposals {
let result = service
.clone()
.publish_block::<BlindedPayload<E>>(slot, validator_pubkey)
.await;

match result {
Err(BlockError::Recoverable(e)) => {
error!(
log,
"Error whilst producing block";
"error" => ?e,
"block_slot" => ?slot,
"info" => "full block attempted after a blinded failure",
"info" => "blinded proposal failed, attempting full block"
);
if let Err(e) = service
.publish_block::<FullPayload<E>>(slot, validator_pubkey)
.await
{
// Log a `crit` since a full block
// (non-builder) proposal failed.
crit!(
log,
"Error whilst producing block";
"error" => ?e,
"block_slot" => ?slot,
"info" => "full block attempted after a blinded failure",
);
}
}
}
Err(BlockError::Irrecoverable(e)) => {
// Only log an `error` since it's common for
// builders to timeout on their response, only
// to publish the block successfully themselves.
error!(
Err(BlockError::Irrecoverable(e)) => {
// Only log an `error` since it's common for
// builders to timeout on their response, only
// to publish the block successfully themselves.
error!(
log,
"Error whilst producing block";
"error" => ?e,
"block_slot" => ?slot,
"info" => "this error may or may not result in a missed block",
)
}
Ok(_) => {}
};
} else if let Err(e) = service
.publish_block::<FullPayload<E>>(slot, validator_pubkey)
.await
{
// Log a `crit` since a full block (non-builder)
// proposal failed.
crit!(
log,
"Error whilst producing block";
"error" => ?e,
"message" => ?e,
"block_slot" => ?slot,
"info" => "this error may or may not result in a missed block",
)
"info" => "proposal did not use a builder",
);
}
Ok(_) => {}
};
} else if let Err(e) = service
.publish_block::<FullPayload<E>>(slot, validator_pubkey)
.await
{
// Log a `crit` since a full block (non-builder)
// proposal failed.
crit!(
log,
"Error whilst producing block";
"message" => ?e,
"block_slot" => ?slot,
"info" => "proposal did not use a builder",
);
}
},
"block service",
);
},
"block service",
)
}
}

Ok(())
Expand Down Expand Up @@ -575,17 +625,6 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
"slot" => slot.as_u64(),
);

let deneb_fork_activated = self
.context
.eth2_config
.spec
.altair_fork_epoch
.and_then(|fork_epoch| {
let current_epoch = self.slot_clock.now()?.epoch(E::slots_per_epoch());
Some(current_epoch >= fork_epoch)
})
.unwrap_or(false);

// Request block from first responsive beacon node.
//
// Try the proposer nodes last, since it's likely that they don't have a
Expand All @@ -599,18 +638,20 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
&metrics::BLOCK_SERVICE_TIMES,
&[metrics::BEACON_BLOCK_HTTP_GET],
);
beacon_node
let block_response = beacon_node
.get_validator_blocks_v3::<E>(slot, randao_reveal_ref, graffiti.as_ref())
.await
.map_err(|e| {
BlockError::Recoverable(format!(
"Error from beacon node when producing block: {:?}",
e
))
})
});

Ok::<_, BlockError>(block_response)
},
)
.await?;
.await??;

match block_response {
eth2::types::ForkVersionedBeaconBlockType::Full(block_response) => {
Expand Down

0 comments on commit 33f3411

Please sign in to comment.