mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Send success code for duplicate blocks on HTTP (#4655)
## Issue Addressed Closes #4473 (take 3) ## Proposed Changes - Send a 202 status code by default for duplicate blocks, instead of 400. This conveys to the caller that the block was published, but makes no guarantees about its validity. Block relays can count this as a success or a failure as they wish. - For users wanting finer-grained control over which status is returned for duplicates, a flag `--http-duplicate-block-status` can be used to adjust the behaviour. A 400 status can be supplied to restore the old (spec-compliant) behaviour, or a 200 status can be used to silence VCs that warn loudly for non-200 codes (e.g. Lighthouse prior to v4.4.0). - Update the Lighthouse VC to gracefully handle success codes other than 200. The info message isn't the nicest thing to read, but it covers all bases and isn't a nasty `ERRO`/`CRIT` that will wake anyone up. ## Additional Info I'm planning to raise a PR to `beacon-APIs` to specify that clients may return 202 for duplicate blocks. Really it would be nice to use some 2xx code that _isn't_ the same as the code for "published but invalid". I think unfortunately there aren't any suitable codes, and maybe the best fit is `409 CONFLICT`. Given that we need to fix this promptly for our release, I think using the 202 code temporarily with configuration strikes a nice compromise.
This commit is contained in:
@@ -10,7 +10,8 @@ use crate::{
|
||||
validator_store::{Error as ValidatorStoreError, ValidatorStore},
|
||||
};
|
||||
use environment::RuntimeContext;
|
||||
use eth2::BeaconNodeHttpClient;
|
||||
use eth2::{BeaconNodeHttpClient, StatusCode};
|
||||
use slog::Logger;
|
||||
use slog::{crit, debug, error, info, trace, warn};
|
||||
use slot_clock::SlotClock;
|
||||
use std::fmt::Debug;
|
||||
@@ -593,12 +594,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
|
||||
beacon_node
|
||||
.post_beacon_blocks(&signed_block)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
BlockError::Irrecoverable(format!(
|
||||
"Error from beacon node when publishing block: {:?}",
|
||||
e
|
||||
))
|
||||
})?
|
||||
.or_else(|e| handle_block_post_error(e, slot, log))?
|
||||
}
|
||||
BlockType::Blinded => {
|
||||
let _post_timer = metrics::start_timer_vec(
|
||||
@@ -608,12 +604,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
|
||||
beacon_node
|
||||
.post_beacon_blinded_blocks(&signed_block)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
BlockError::Irrecoverable(format!(
|
||||
"Error from beacon node when publishing block: {:?}",
|
||||
e
|
||||
))
|
||||
})?
|
||||
.or_else(|e| handle_block_post_error(e, slot, log))?
|
||||
}
|
||||
}
|
||||
Ok::<_, BlockError>(())
|
||||
@@ -634,3 +625,29 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_block_post_error(err: eth2::Error, slot: Slot, log: &Logger) -> Result<(), BlockError> {
|
||||
// Handle non-200 success codes.
|
||||
if let Some(status) = err.status() {
|
||||
if status == StatusCode::ACCEPTED {
|
||||
info!(
|
||||
log,
|
||||
"Block is already known to BN or might be invalid";
|
||||
"slot" => slot,
|
||||
"status_code" => status.as_u16(),
|
||||
);
|
||||
return Ok(());
|
||||
} else if status.is_success() {
|
||||
debug!(
|
||||
log,
|
||||
"Block published with non-standard success code";
|
||||
"slot" => slot,
|
||||
"status_code" => status.as_u16(),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(BlockError::Irrecoverable(format!(
|
||||
"Error from beacon node when publishing block: {err:?}",
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user