mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-03 04:44:28 +00:00
convert op pool messages to electra in electra
This commit is contained in:
@@ -1834,18 +1834,35 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
.filter(|&att| query_filter(att.data()))
|
.filter(|&att| query_filter(att.data()))
|
||||||
.cloned(),
|
.cloned(),
|
||||||
);
|
);
|
||||||
let slot = query
|
// Use the current slot to find the fork version, and convert all messages to the
|
||||||
.slot
|
// current fork's format. This is to ensure consistent message types matching
|
||||||
.or_else(|| {
|
// `Eth-Consensus-Version`.
|
||||||
attestations
|
let current_slot =
|
||||||
.first()
|
chain
|
||||||
.map(|att| att.data().slot)
|
.slot_clock
|
||||||
.or_else(|| chain.slot_clock.now())
|
.now()
|
||||||
})
|
.ok_or(warp_utils::reject::custom_server_error(
|
||||||
.ok_or(warp_utils::reject::custom_server_error(
|
"unable to read slot clock".to_string(),
|
||||||
"unable to read slot clock".to_string(),
|
))?;
|
||||||
))?;
|
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(current_slot);
|
||||||
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
|
|
||||||
|
let attestations = if fork_name.electra_enabled() {
|
||||||
|
attestations
|
||||||
|
.into_iter()
|
||||||
|
.map(|att| match att {
|
||||||
|
Attestation::Base(a) => Ok(Attestation::Electra(a.try_into()?)),
|
||||||
|
Attestation::Electra(a) => Ok(Attestation::Electra(a)),
|
||||||
|
})
|
||||||
|
.collect::<Result<Vec<_>, types::attestation::Error>>()
|
||||||
|
.map_err(|e| {
|
||||||
|
warp_utils::reject::custom_server_error(format!(
|
||||||
|
"could not convert base attestations to electra {e:?}"
|
||||||
|
))
|
||||||
|
})?
|
||||||
|
} else {
|
||||||
|
attestations
|
||||||
|
};
|
||||||
|
|
||||||
let res = fork_versioned_response(endpoint_version, fork_name, &attestations)?;
|
let res = fork_versioned_response(endpoint_version, fork_name, &attestations)?;
|
||||||
Ok(add_consensus_version_header(
|
Ok(add_consensus_version_header(
|
||||||
warp::reply::json(&res).into_response(),
|
warp::reply::json(&res).into_response(),
|
||||||
@@ -1914,14 +1931,30 @@ pub fn serve<T: BeaconChainTypes>(
|
|||||||
chain: Arc<BeaconChain<T>>| {
|
chain: Arc<BeaconChain<T>>| {
|
||||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||||
let slashings = chain.op_pool.get_all_attester_slashings();
|
let slashings = chain.op_pool.get_all_attester_slashings();
|
||||||
let slot = slashings
|
|
||||||
.first()
|
// Use the current slot to find the fork version, and convert all messages to the
|
||||||
.map(|slashing| slashing.attestation_1().data().slot)
|
// current fork's format. This is to ensure consistent message types matching
|
||||||
.or_else(|| chain.slot_clock.now())
|
// `Eth-Consensus-Version`.
|
||||||
.ok_or(warp_utils::reject::custom_server_error(
|
let current_slot =
|
||||||
"unable to read slot clock".to_string(),
|
chain
|
||||||
))?;
|
.slot_clock
|
||||||
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
|
.now()
|
||||||
|
.ok_or(warp_utils::reject::custom_server_error(
|
||||||
|
"unable to read slot clock".to_string(),
|
||||||
|
))?;
|
||||||
|
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(current_slot);
|
||||||
|
|
||||||
|
let slashings = if fork_name.electra_enabled() {
|
||||||
|
slashings
|
||||||
|
.into_iter()
|
||||||
|
.map(|att| match att {
|
||||||
|
AttesterSlashing::Base(a) => AttesterSlashing::Electra(a.into()),
|
||||||
|
AttesterSlashing::Electra(a) => AttesterSlashing::Electra(a),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
} else {
|
||||||
|
slashings
|
||||||
|
};
|
||||||
let res = fork_versioned_response(endpoint_version, fork_name, &slashings)?;
|
let res = fork_versioned_response(endpoint_version, fork_name, &slashings)?;
|
||||||
Ok(add_consensus_version_header(
|
Ok(add_consensus_version_header(
|
||||||
warp::reply::json(&res).into_response(),
|
warp::reply::json(&res).into_response(),
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ pub enum Error {
|
|||||||
InvalidCommitteeIndex,
|
InvalidCommitteeIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ssz_types::Error> for Error {
|
||||||
|
fn from(e: ssz_types::Error) -> Self {
|
||||||
|
Error::SszTypesError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[superstruct(
|
#[superstruct(
|
||||||
variants(Base, Electra),
|
variants(Base, Electra),
|
||||||
variant_attributes(
|
variant_attributes(
|
||||||
@@ -416,6 +422,35 @@ impl<E: EthSpec> AttestationBase<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: EthSpec> TryFrom<AttestationBase<E>> for AttestationElectra<E> {
|
||||||
|
type Error = Error;
|
||||||
|
fn try_from(att: AttestationBase<E>) -> Result<Self, Self::Error> {
|
||||||
|
// Extend the aggregation bits list.
|
||||||
|
let aggregation_bits = att.extend_aggregation_bits()?;
|
||||||
|
let AttestationBase {
|
||||||
|
aggregation_bits: _,
|
||||||
|
mut data,
|
||||||
|
signature,
|
||||||
|
} = att;
|
||||||
|
|
||||||
|
// Set the committee index based on the index field.
|
||||||
|
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
|
||||||
|
committee_bits
|
||||||
|
.set(data.index as usize, true)
|
||||||
|
.map_err(|_| Error::InvalidCommitteeIndex)?;
|
||||||
|
|
||||||
|
// Set the attestation data's index to zero.
|
||||||
|
data.index = 0;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
aggregation_bits,
|
||||||
|
data,
|
||||||
|
committee_bits,
|
||||||
|
signature,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> SlotData for Attestation<E> {
|
impl<E: EthSpec> SlotData for Attestation<E> {
|
||||||
fn get_slot(&self) -> Slot {
|
fn get_slot(&self) -> Slot {
|
||||||
self.data().slot
|
self.data().slot
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::indexed_attestation::{
|
use crate::indexed_attestation::{
|
||||||
IndexedAttestationBase, IndexedAttestationElectra, IndexedAttestationRef,
|
IndexedAttestation, IndexedAttestationBase, IndexedAttestationElectra, IndexedAttestationRef,
|
||||||
};
|
};
|
||||||
use crate::{test_utils::TestRandom, EthSpec};
|
use crate::{test_utils::TestRandom, EthSpec};
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
@@ -161,6 +161,19 @@ impl<E: EthSpec> AttesterSlashing<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: EthSpec> From<AttesterSlashingBase<E>> for AttesterSlashingElectra<E> {
|
||||||
|
fn from(attester_slashing: AttesterSlashingBase<E>) -> Self {
|
||||||
|
let AttesterSlashingBase {
|
||||||
|
attestation_1,
|
||||||
|
attestation_2,
|
||||||
|
} = attester_slashing;
|
||||||
|
AttesterSlashingElectra {
|
||||||
|
attestation_1: IndexedAttestation::Base(attestation_1).to_electra(),
|
||||||
|
attestation_2: IndexedAttestation::Base(attestation_2).to_electra(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E: EthSpec> TestRandom for AttesterSlashing<E> {
|
impl<E: EthSpec> TestRandom for AttesterSlashing<E> {
|
||||||
fn random_for_test(rng: &mut impl RngCore) -> Self {
|
fn random_for_test(rng: &mut impl RngCore) -> Self {
|
||||||
if rng.gen_bool(0.5) {
|
if rng.gen_bool(0.5) {
|
||||||
|
|||||||
Reference in New Issue
Block a user