mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-03 17:54:28 +00:00
Batch API for address changes (#3798)
This commit is contained in:
parent
75dd8780e0
commit
63d3dd27fc
@ -1673,36 +1673,62 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.and(warp::path::end())
|
.and(warp::path::end())
|
||||||
.and(warp::body::json())
|
.and(warp::body::json())
|
||||||
.and(network_tx_filter.clone())
|
.and(network_tx_filter.clone())
|
||||||
|
.and(log_filter.clone())
|
||||||
.and_then(
|
.and_then(
|
||||||
|chain: Arc<BeaconChain<T>>,
|
|chain: Arc<BeaconChain<T>>,
|
||||||
address_change: SignedBlsToExecutionChange,
|
address_changes: Vec<SignedBlsToExecutionChange>,
|
||||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>| {
|
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||||
|
log: Logger| {
|
||||||
blocking_json_task(move || {
|
blocking_json_task(move || {
|
||||||
let outcome = chain
|
let mut failures = vec![];
|
||||||
.verify_bls_to_execution_change_for_gossip(address_change)
|
|
||||||
.map_err(|e| {
|
|
||||||
warp_utils::reject::object_invalid(format!(
|
|
||||||
"gossip verification failed: {:?}",
|
|
||||||
e
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if let ObservationOutcome::New(address_change) = outcome {
|
for (index, address_change) in address_changes.into_iter().enumerate() {
|
||||||
#[cfg(feature = "withdrawals-processing")]
|
let validator_index = address_change.message.validator_index;
|
||||||
{
|
|
||||||
publish_pubsub_message(
|
match chain.verify_bls_to_execution_change_for_gossip(address_change) {
|
||||||
&network_tx,
|
Ok(ObservationOutcome::New(verified_address_change)) => {
|
||||||
PubsubMessage::BlsToExecutionChange(Box::new(
|
#[cfg(feature = "withdrawals-processing")]
|
||||||
address_change.as_inner().clone(),
|
{
|
||||||
)),
|
publish_pubsub_message(
|
||||||
)?;
|
&network_tx,
|
||||||
|
PubsubMessage::BlsToExecutionChange(Box::new(
|
||||||
|
verified_address_change.as_inner().clone(),
|
||||||
|
)),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
chain.import_bls_to_execution_change(verified_address_change);
|
||||||
|
}
|
||||||
|
Ok(ObservationOutcome::AlreadyKnown) => {
|
||||||
|
debug!(
|
||||||
|
log,
|
||||||
|
"BLS to execution change already known";
|
||||||
|
"validator_index" => validator_index,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!(
|
||||||
|
log,
|
||||||
|
"Invalid BLS to execution change";
|
||||||
|
"validator_index" => validator_index,
|
||||||
|
"source" => "HTTP API",
|
||||||
|
);
|
||||||
|
failures.push(api_types::Failure::new(
|
||||||
|
index,
|
||||||
|
format!("invalid: {e:?}"),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
drop(network_tx);
|
|
||||||
|
|
||||||
chain.import_bls_to_execution_change(address_change);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
if failures.is_empty() {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(warp_utils::reject::indexed_bad_request(
|
||||||
|
"some BLS to execution changes failed to verify".into(),
|
||||||
|
failures,
|
||||||
|
))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user