mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Handle unknown head during attestation publishing (#5010)
* Handle unknown head during attestation publishing * Merge remote-tracking branch 'origin/unstable' into queue-http-attestations * Simplify task spawner * Improve logging * Add a test * Improve error logging * Merge remote-tracking branch 'origin/unstable' into queue-http-attestations * Fix beta compiler warnings
This commit is contained in:
@@ -16,6 +16,7 @@ mod database;
|
||||
mod metrics;
|
||||
mod produce_block;
|
||||
mod proposer_duties;
|
||||
mod publish_attestations;
|
||||
mod publish_blocks;
|
||||
mod standard_block_rewards;
|
||||
mod state_id;
|
||||
@@ -35,7 +36,7 @@ use beacon_chain::{
|
||||
validator_monitor::timestamp_now, AttestationError as AttnError, BeaconChain, BeaconChainError,
|
||||
BeaconChainTypes, WhenSlotSkipped,
|
||||
};
|
||||
use beacon_processor::BeaconProcessorSend;
|
||||
use beacon_processor::{work_reprocessing_queue::ReprocessQueueMessage, BeaconProcessorSend};
|
||||
pub use block_id::BlockId;
|
||||
use builder_states::get_next_withdrawals;
|
||||
use bytes::Bytes;
|
||||
@@ -129,6 +130,7 @@ pub struct Context<T: BeaconChainTypes> {
|
||||
pub network_senders: Option<NetworkSenders<T::EthSpec>>,
|
||||
pub network_globals: Option<Arc<NetworkGlobals<T::EthSpec>>>,
|
||||
pub beacon_processor_send: Option<BeaconProcessorSend<T::EthSpec>>,
|
||||
pub beacon_processor_reprocess_send: Option<Sender<ReprocessQueueMessage>>,
|
||||
pub eth1_service: Option<eth1::Service>,
|
||||
pub sse_logging_components: Option<SSELoggingComponents>,
|
||||
pub log: Logger,
|
||||
@@ -534,6 +536,11 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.filter(|_| config.enable_beacon_processor);
|
||||
let task_spawner_filter =
|
||||
warp::any().map(move || TaskSpawner::new(beacon_processor_send.clone()));
|
||||
let beacon_processor_reprocess_send = ctx
|
||||
.beacon_processor_reprocess_send
|
||||
.clone()
|
||||
.filter(|_| config.enable_beacon_processor);
|
||||
let reprocess_send_filter = warp::any().map(move || beacon_processor_reprocess_send.clone());
|
||||
|
||||
let duplicate_block_status_code = ctx.config.duplicate_block_status_code;
|
||||
|
||||
@@ -1756,140 +1763,26 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(network_tx_filter.clone())
|
||||
.and(reprocess_send_filter)
|
||||
.and(log_filter.clone())
|
||||
.then(
|
||||
|task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
attestations: Vec<Attestation<T::EthSpec>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
log: Logger| {
|
||||
task_spawner.blocking_json_task(Priority::P0, move || {
|
||||
let seen_timestamp = timestamp_now();
|
||||
let mut failures = Vec::new();
|
||||
let mut num_already_known = 0;
|
||||
|
||||
for (index, attestation) in attestations.as_slice().iter().enumerate() {
|
||||
let attestation = match chain
|
||||
.verify_unaggregated_attestation_for_gossip(attestation, None)
|
||||
{
|
||||
Ok(attestation) => attestation,
|
||||
Err(AttnError::PriorAttestationKnown { .. }) => {
|
||||
num_already_known += 1;
|
||||
|
||||
// Skip to the next attestation since an attestation for this
|
||||
// validator is already known in this epoch.
|
||||
//
|
||||
// There's little value for the network in validating a second
|
||||
// attestation for another validator since it is either:
|
||||
//
|
||||
// 1. A duplicate.
|
||||
// 2. Slashable.
|
||||
// 3. Invalid.
|
||||
//
|
||||
// We are likely to get duplicates in the case where a VC is using
|
||||
// fallback BNs. If the first BN actually publishes some/all of a
|
||||
// batch of attestations but fails to respond in a timely fashion,
|
||||
// the VC is likely to try publishing the attestations on another
|
||||
// BN. That second BN may have already seen the attestations from
|
||||
// the first BN and therefore indicate that the attestations are
|
||||
// "already seen". An attestation that has already been seen has
|
||||
// been published on the network so there's no actual error from
|
||||
// the perspective of the user.
|
||||
//
|
||||
// It's better to prevent slashable attestations from ever
|
||||
// appearing on the network than trying to slash validators,
|
||||
// especially those validators connected to the local API.
|
||||
//
|
||||
// There might be *some* value in determining that this attestation
|
||||
// is invalid, but since a valid attestation already it exists it
|
||||
// appears that this validator is capable of producing valid
|
||||
// attestations and there's no immediate cause for concern.
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
error!(log,
|
||||
"Failure verifying attestation for gossip";
|
||||
"error" => ?e,
|
||||
"request_index" => index,
|
||||
"committee_index" => attestation.data.index,
|
||||
"attestation_slot" => attestation.data.slot,
|
||||
);
|
||||
failures.push(api_types::Failure::new(
|
||||
index,
|
||||
format!("Verification: {:?}", e),
|
||||
));
|
||||
// skip to the next attestation so we do not publish this one to gossip
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
// Notify the validator monitor.
|
||||
chain
|
||||
.validator_monitor
|
||||
.read()
|
||||
.register_api_unaggregated_attestation(
|
||||
seen_timestamp,
|
||||
attestation.indexed_attestation(),
|
||||
&chain.slot_clock,
|
||||
);
|
||||
|
||||
publish_pubsub_message(
|
||||
&network_tx,
|
||||
PubsubMessage::Attestation(Box::new((
|
||||
attestation.subnet_id(),
|
||||
attestation.attestation().clone(),
|
||||
))),
|
||||
)?;
|
||||
|
||||
let committee_index = attestation.attestation().data.index;
|
||||
let slot = attestation.attestation().data.slot;
|
||||
|
||||
if let Err(e) = chain.apply_attestation_to_fork_choice(&attestation) {
|
||||
error!(log,
|
||||
"Failure applying verified attestation to fork choice";
|
||||
"error" => ?e,
|
||||
"request_index" => index,
|
||||
"committee_index" => committee_index,
|
||||
"slot" => slot,
|
||||
);
|
||||
failures.push(api_types::Failure::new(
|
||||
index,
|
||||
format!("Fork choice: {:?}", e),
|
||||
));
|
||||
};
|
||||
|
||||
if let Err(e) = chain.add_to_naive_aggregation_pool(&attestation) {
|
||||
error!(log,
|
||||
"Failure adding verified attestation to the naive aggregation pool";
|
||||
"error" => ?e,
|
||||
"request_index" => index,
|
||||
"committee_index" => committee_index,
|
||||
"slot" => slot,
|
||||
);
|
||||
failures.push(api_types::Failure::new(
|
||||
index,
|
||||
format!("Naive aggregation pool: {:?}", e),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if num_already_known > 0 {
|
||||
debug!(
|
||||
log,
|
||||
"Some unagg attestations already known";
|
||||
"count" => num_already_known
|
||||
);
|
||||
}
|
||||
|
||||
if failures.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(warp_utils::reject::indexed_bad_request(
|
||||
"error processing attestations".to_string(),
|
||||
failures,
|
||||
))
|
||||
}
|
||||
})
|
||||
reprocess_tx: Option<Sender<ReprocessQueueMessage>>,
|
||||
log: Logger| async move {
|
||||
let result = crate::publish_attestations::publish_attestations(
|
||||
task_spawner,
|
||||
chain,
|
||||
attestations,
|
||||
network_tx,
|
||||
reprocess_tx,
|
||||
log,
|
||||
)
|
||||
.await
|
||||
.map(|()| warp::reply::json(&()));
|
||||
task_spawner::convert_rejection(result).await
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user