mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 14:28:37 +00:00
Fix slasher tests (#5906)
* Fix electra tests * Add electra attestations to double vote tests
This commit is contained in:
@@ -60,49 +60,46 @@ impl<E: EthSpec> AttesterSlashingStatus<E> {
|
||||
Ok(match self {
|
||||
NotSlashable => None,
|
||||
AlreadyDoubleVoted => None,
|
||||
DoubleVote(existing) | SurroundedByExisting(existing) => match *existing {
|
||||
IndexedAttestation::Base(existing_att) => {
|
||||
Some(AttesterSlashing::Base(AttesterSlashingBase {
|
||||
attestation_1: existing_att,
|
||||
attestation_2: new_attestation
|
||||
.as_base()
|
||||
.map_err(|e| format!("{e:?}"))?
|
||||
.clone(),
|
||||
}))
|
||||
}
|
||||
IndexedAttestation::Electra(existing_att) => {
|
||||
Some(AttesterSlashing::Electra(AttesterSlashingElectra {
|
||||
attestation_1: existing_att,
|
||||
// A double vote should never convert, a surround vote where the surrounding
|
||||
// vote is electra may convert.
|
||||
DoubleVote(existing) | SurroundedByExisting(existing) => {
|
||||
match (&*existing, new_attestation) {
|
||||
(IndexedAttestation::Base(existing_att), IndexedAttestation::Base(new)) => {
|
||||
Some(AttesterSlashing::Base(AttesterSlashingBase {
|
||||
attestation_1: existing_att.clone(),
|
||||
attestation_2: new.clone(),
|
||||
}))
|
||||
}
|
||||
// A slashing involving an electra attestation type must return an `AttesterSlashingElectra` type
|
||||
(_, _) => Some(AttesterSlashing::Electra(AttesterSlashingElectra {
|
||||
attestation_1: existing
|
||||
.clone()
|
||||
.to_electra()
|
||||
.map_err(|e| format!("{e:?}"))?,
|
||||
attestation_2: new_attestation
|
||||
.clone()
|
||||
.to_electra()
|
||||
.map_err(|e| format!("{e:?}"))?,
|
||||
}))
|
||||
}
|
||||
},
|
||||
SurroundsExisting(existing) => {
|
||||
match new_attestation {
|
||||
IndexedAttestation::Base(new_attestation) => {
|
||||
Some(AttesterSlashing::Base(AttesterSlashingBase {
|
||||
attestation_1: existing
|
||||
.as_base()
|
||||
.map_err(|e| format!("{e:?}"))?
|
||||
.clone(),
|
||||
attestation_2: new_attestation.clone(),
|
||||
}))
|
||||
}
|
||||
IndexedAttestation::Electra(new_attestation) => {
|
||||
Some(AttesterSlashing::Electra(AttesterSlashingElectra {
|
||||
attestation_1: existing.to_electra().map_err(|e| format!("{e:?}"))?,
|
||||
// A double vote should never convert, a surround vote where the surrounding
|
||||
// vote is electra may convert.
|
||||
attestation_2: new_attestation.clone(),
|
||||
}))
|
||||
}
|
||||
})),
|
||||
}
|
||||
}
|
||||
SurroundsExisting(existing) => match (&*existing, new_attestation) {
|
||||
(IndexedAttestation::Base(existing_att), IndexedAttestation::Base(new)) => {
|
||||
Some(AttesterSlashing::Base(AttesterSlashingBase {
|
||||
attestation_1: new.clone(),
|
||||
attestation_2: existing_att.clone(),
|
||||
}))
|
||||
}
|
||||
// A slashing involving an electra attestation type must return an `AttesterSlashingElectra` type
|
||||
(_, _) => Some(AttesterSlashing::Electra(AttesterSlashingElectra {
|
||||
attestation_1: new_attestation
|
||||
.clone()
|
||||
.to_electra()
|
||||
.map_err(|e| format!("{e:?}"))?,
|
||||
attestation_2: existing
|
||||
.clone()
|
||||
.to_electra()
|
||||
.map_err(|e| format!("{e:?}"))?,
|
||||
})),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ pub fn att_slashing(
|
||||
attestation_1: &IndexedAttestation<E>,
|
||||
attestation_2: &IndexedAttestation<E>,
|
||||
) -> AttesterSlashing<E> {
|
||||
// TODO(electra): fix this one we superstruct IndexedAttestation (return the correct type)
|
||||
match (attestation_1, attestation_2) {
|
||||
(IndexedAttestation::Base(att1), IndexedAttestation::Base(att2)) => {
|
||||
AttesterSlashing::Base(AttesterSlashingBase {
|
||||
@@ -71,13 +70,11 @@ pub fn att_slashing(
|
||||
attestation_2: att2.clone(),
|
||||
})
|
||||
}
|
||||
(IndexedAttestation::Electra(att1), IndexedAttestation::Electra(att2)) => {
|
||||
AttesterSlashing::Electra(AttesterSlashingElectra {
|
||||
attestation_1: att1.clone(),
|
||||
attestation_2: att2.clone(),
|
||||
})
|
||||
}
|
||||
_ => panic!("attestations must be of the same type"),
|
||||
// A slashing involving an electra attestation type must return an electra AttesterSlashing type
|
||||
(_, _) => AttesterSlashing::Electra(AttesterSlashingElectra {
|
||||
attestation_1: attestation_1.clone().to_electra().unwrap(),
|
||||
attestation_2: attestation_2.clone().to_electra().unwrap(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user