Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slasher tests #5906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions slasher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (&*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:?}"))?,
})),
},
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(),
}))
}
}
}
})
}
}
13 changes: 5 additions & 8 deletions slasher/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,18 @@ 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 {
attestation_1: att1.clone(),
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(),
}),
}
}

Expand Down
Loading
Loading