Skip to content

Commit a1eef44

Browse files
rkapkanalepae
andauthored
Update slasher service to Electra (#14812)
* Update slasher service to Electra * Update beacon-chain/slasher/chunks.go Co-authored-by: Manu NALEPA <[email protected]> * Update beacon-chain/slasher/chunks_test.go Co-authored-by: Manu NALEPA <[email protected]> * Manu's review * Manu's review again --------- Co-authored-by: Manu NALEPA <[email protected]>
1 parent 2845ab9 commit a1eef44

File tree

14 files changed

+1274
-802
lines changed

14 files changed

+1274
-802
lines changed

beacon-chain/slasher/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ go_library(
4141
"//encoding/bytesutil:go_default_library",
4242
"//monitoring/tracing/trace:go_default_library",
4343
"//proto/prysm/v1alpha1:go_default_library",
44+
"//runtime/version:go_default_library",
4445
"//time/slots:go_default_library",
4546
"@com_github_pkg_errors//:go_default_library",
4647
"@com_github_prometheus_client_golang//prometheus:go_default_library",
@@ -83,6 +84,7 @@ go_test(
8384
"//crypto/bls/common:go_default_library",
8485
"//encoding/bytesutil:go_default_library",
8586
"//proto/prysm/v1alpha1:go_default_library",
87+
"//runtime/version:go_default_library",
8688
"//testing/assert:go_default_library",
8789
"//testing/require:go_default_library",
8890
"//testing/util:go_default_library",

beacon-chain/slasher/chunks.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
slashertypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/slasher/types"
1212
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
1313
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
14+
"github.com/prysmaticlabs/prysm/v5/runtime/version"
1415
"github.com/sirupsen/logrus"
1516
)
1617

@@ -232,6 +233,43 @@ func (m *MinSpanChunksSlice) CheckSlashable(
232233

233234
surroundingVotesTotal.Inc()
234235

236+
// Both attestations should have the same type. If not, we convert both to Electra attestations.
237+
unifyAttWrapperVersion(existingAttWrapper, incomingAttWrapper)
238+
239+
postElectra := existingAttWrapper.IndexedAttestation.Version() >= version.Electra
240+
if postElectra {
241+
existing, ok := existingAttWrapper.IndexedAttestation.(*ethpb.IndexedAttestationElectra)
242+
if !ok {
243+
return nil, fmt.Errorf(
244+
"existing attestation has wrong type (expected %T, got %T)",
245+
&ethpb.IndexedAttestationElectra{},
246+
existingAttWrapper.IndexedAttestation,
247+
)
248+
}
249+
incoming, ok := incomingAttWrapper.IndexedAttestation.(*ethpb.IndexedAttestationElectra)
250+
if !ok {
251+
return nil, fmt.Errorf(
252+
"incoming attestation has wrong type (expected %T, got %T)",
253+
&ethpb.IndexedAttestationElectra{},
254+
incomingAttWrapper.IndexedAttestation,
255+
)
256+
}
257+
slashing := &ethpb.AttesterSlashingElectra{
258+
Attestation_1: existing,
259+
Attestation_2: incoming,
260+
}
261+
262+
// Ensure the attestation with the lower data root is the first attestation.
263+
if bytes.Compare(existingAttWrapper.DataRoot[:], incomingAttWrapper.DataRoot[:]) > 0 {
264+
slashing = &ethpb.AttesterSlashingElectra{
265+
Attestation_1: incoming,
266+
Attestation_2: existing,
267+
}
268+
}
269+
270+
return slashing, nil
271+
}
272+
235273
existing, ok := existingAttWrapper.IndexedAttestation.(*ethpb.IndexedAttestation)
236274
if !ok {
237275
return nil, fmt.Errorf(
@@ -328,6 +366,43 @@ func (m *MaxSpanChunksSlice) CheckSlashable(
328366

329367
surroundedVotesTotal.Inc()
330368

369+
// Both attestations should have the same type. If not, we convert the non-Electra attestation into an Electra attestation.
370+
unifyAttWrapperVersion(existingAttWrapper, incomingAttWrapper)
371+
372+
postElectra := existingAttWrapper.IndexedAttestation.Version() >= version.Electra
373+
if postElectra {
374+
existing, ok := existingAttWrapper.IndexedAttestation.(*ethpb.IndexedAttestationElectra)
375+
if !ok {
376+
return nil, fmt.Errorf(
377+
"existing attestation has wrong type (expected %T, got %T)",
378+
&ethpb.IndexedAttestationElectra{},
379+
existingAttWrapper.IndexedAttestation,
380+
)
381+
}
382+
incoming, ok := incomingAttWrapper.IndexedAttestation.(*ethpb.IndexedAttestationElectra)
383+
if !ok {
384+
return nil, fmt.Errorf(
385+
"incoming attestation has wrong type (expected %T, got %T)",
386+
&ethpb.IndexedAttestationElectra{},
387+
incomingAttWrapper.IndexedAttestation,
388+
)
389+
}
390+
slashing := &ethpb.AttesterSlashingElectra{
391+
Attestation_1: existing,
392+
Attestation_2: incoming,
393+
}
394+
395+
// Ensure the attestation with the lower data root is the first attestation.
396+
if bytes.Compare(existingAttWrapper.DataRoot[:], incomingAttWrapper.DataRoot[:]) > 0 {
397+
slashing = &ethpb.AttesterSlashingElectra{
398+
Attestation_1: incoming,
399+
Attestation_2: existing,
400+
}
401+
}
402+
403+
return slashing, nil
404+
}
405+
331406
existing, ok := existingAttWrapper.IndexedAttestation.(*ethpb.IndexedAttestation)
332407
if !ok {
333408
return nil, fmt.Errorf(

0 commit comments

Comments
 (0)