fixing electra committee logs (#14992)

* fixing logs

* fixing tests

* addressing feedback

* fixing tests based on feedback
This commit is contained in:
james-prysm
2025-03-03 09:35:45 -06:00
committed by GitHub
parent 2131254722
commit c6344e7c3e
6 changed files with 100 additions and 10 deletions

View File

@@ -105,6 +105,7 @@ go_test(
"aggregate_test.go",
"attest_test.go",
"key_reload_test.go",
"log_test.go",
"metrics_test.go",
"propose_test.go",
"registration_test.go",

View File

@@ -158,7 +158,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot primitives
}
}
if err := v.saveSubmittedAtt(agg.AggregateVal().GetData(), pubKey[:], true); err != nil {
if err := v.saveSubmittedAtt(agg.AggregateVal(), pubKey[:], true); err != nil {
log.WithError(err).Error("Could not add aggregator indices to logs")
if v.emitAccountMetrics {
ValidatorAggFailVec.WithLabelValues(fmtKey).Inc()

View File

@@ -133,16 +133,17 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot primitives.Slot,
}
var aggregationBitfield bitfield.Bitlist
var attestation ethpb.Att
var attResp *ethpb.AttestResponse
if postElectra {
attestation := &ethpb.SingleAttestation{
sa := &ethpb.SingleAttestation{
Data: data,
AttesterIndex: duty.ValidatorIndex,
CommitteeId: duty.CommitteeIndex,
Signature: sig,
}
attResp, err = v.validatorClient.ProposeAttestationElectra(ctx, attestation)
attestation = sa
attResp, err = v.validatorClient.ProposeAttestationElectra(ctx, sa)
} else {
var indexInCommittee uint64
var found bool
@@ -162,12 +163,13 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot primitives.Slot,
}
aggregationBitfield = bitfield.NewBitlist(uint64(len(duty.Committee)))
aggregationBitfield.SetBitAt(indexInCommittee, true)
attestation := &ethpb.Attestation{
a := &ethpb.Attestation{
Data: data,
AggregationBits: aggregationBitfield,
Signature: sig,
}
attResp, err = v.validatorClient.ProposeAttestation(ctx, attestation)
attestation = a
attResp, err = v.validatorClient.ProposeAttestation(ctx, a)
}
if err != nil {
log.WithError(err).Error("Could not submit attestation to beacon node")
@@ -178,7 +180,7 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot primitives.Slot,
return
}
if err := v.saveSubmittedAtt(data, pubKey[:], false); err != nil {
if err := v.saveSubmittedAtt(attestation, pubKey[:], false); err != nil {
log.WithError(err).Error("Could not save validator index for logging")
if v.emitAccountMetrics {
ValidatorAttestFailVec.WithLabelValues(fmtKey).Inc()

View File

@@ -49,10 +49,10 @@ func (k submittedAttKey) FromAttData(data *ethpb.AttestationData) error {
// saveSubmittedAtt saves the submitted attestation data along with the attester's pubkey.
// The purpose of this is to display combined attesting logs for all keys managed by the validator client.
func (v *validator) saveSubmittedAtt(data *ethpb.AttestationData, pubkey []byte, isAggregate bool) error {
func (v *validator) saveSubmittedAtt(att ethpb.Att, pubkey []byte, isAggregate bool) error {
v.attLogsLock.Lock()
defer v.attLogsLock.Unlock()
data := att.GetData()
key := submittedAttKey{}
if err := key.FromAttData(data); err != nil {
return errors.Wrapf(err, "could not create submitted attestation key")
@@ -80,7 +80,7 @@ func (v *validator) saveSubmittedAtt(data *ethpb.AttestationData, pubkey []byte,
submittedAtts[key] = &submittedAtt{
d,
append(submittedAtts[key].pubkeys, pubkey),
append(submittedAtts[key].committees, data.CommitteeIndex),
append(submittedAtts[key].committees, att.GetCommitteeIndex()),
}
return nil

View File

@@ -0,0 +1,84 @@
package client
import (
"testing"
field_params "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
"github.com/prysmaticlabs/prysm/v5/testing/util"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestLogSubmittedAtts(t *testing.T) {
t.Run("phase0 attestations", func(t *testing.T) {
logHook := logTest.NewGlobal()
v := validator{
submittedAtts: make(map[submittedAttKey]*submittedAtt),
}
att := util.HydrateAttestation(&ethpb.Attestation{})
att.Data.CommitteeIndex = 12
require.NoError(t, v.saveSubmittedAtt(att, make([]byte, field_params.BLSPubkeyLength), false))
v.LogSubmittedAtts(0)
assert.LogsContain(t, logHook, "committeeIndices=\"[12]\"")
})
t.Run("electra attestations", func(t *testing.T) {
logHook := logTest.NewGlobal()
v := validator{
submittedAtts: make(map[submittedAttKey]*submittedAtt),
}
att := util.HydrateAttestationElectra(&ethpb.AttestationElectra{})
att.Data.CommitteeIndex = 0
att.CommitteeBits = primitives.NewAttestationCommitteeBits()
att.CommitteeBits.SetBitAt(44, true)
require.NoError(t, v.saveSubmittedAtt(att, make([]byte, field_params.BLSPubkeyLength), false))
v.LogSubmittedAtts(0)
assert.LogsContain(t, logHook, "committeeIndices=\"[44]\"")
})
t.Run("electra attestations multiple saved", func(t *testing.T) {
logHook := logTest.NewGlobal()
v := validator{
submittedAtts: make(map[submittedAttKey]*submittedAtt),
}
att := util.HydrateAttestationElectra(&ethpb.AttestationElectra{})
att.Data.CommitteeIndex = 0
att.CommitteeBits = primitives.NewAttestationCommitteeBits()
att.CommitteeBits.SetBitAt(23, true)
require.NoError(t, v.saveSubmittedAtt(att, make([]byte, field_params.BLSPubkeyLength), false))
att2 := util.HydrateAttestationElectra(&ethpb.AttestationElectra{})
att2.Data.CommitteeIndex = 0
att2.CommitteeBits = primitives.NewAttestationCommitteeBits()
att2.CommitteeBits.SetBitAt(2, true)
require.NoError(t, v.saveSubmittedAtt(att2, make([]byte, field_params.BLSPubkeyLength), false))
v.LogSubmittedAtts(0)
assert.LogsContain(t, logHook, "committeeIndices=\"[23 2]\"")
})
t.Run("phase0 aggregates", func(t *testing.T) {
logHook := logTest.NewGlobal()
v := validator{
submittedAggregates: make(map[submittedAttKey]*submittedAtt),
}
agg := &ethpb.AggregateAttestationAndProof{}
agg.Aggregate = util.HydrateAttestation(&ethpb.Attestation{})
agg.Aggregate.Data.CommitteeIndex = 12
require.NoError(t, v.saveSubmittedAtt(agg.AggregateVal(), make([]byte, field_params.BLSPubkeyLength), true))
v.LogSubmittedAtts(0)
assert.LogsContain(t, logHook, "committeeIndices=\"[12]\"")
})
t.Run("electra aggregates", func(t *testing.T) {
logHook := logTest.NewGlobal()
v := validator{
submittedAggregates: make(map[submittedAttKey]*submittedAtt),
}
agg := &ethpb.AggregateAttestationAndProofElectra{}
agg.Aggregate = util.HydrateAttestationElectra(&ethpb.AttestationElectra{})
agg.Aggregate.Data.CommitteeIndex = 0
agg.Aggregate.CommitteeBits = primitives.NewAttestationCommitteeBits()
agg.Aggregate.CommitteeBits.SetBitAt(63, true)
require.NoError(t, v.saveSubmittedAtt(agg.AggregateVal(), make([]byte, field_params.BLSPubkeyLength), true))
v.LogSubmittedAtts(0)
assert.LogsContain(t, logHook, "committeeIndices=\"[63]\"")
})
}