mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
fixing electra committee logs (#14992)
* fixing logs * fixing tests * addressing feedback * fixing tests based on feedback
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 := ðpb.SingleAttestation{
|
||||
sa := ðpb.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 := ðpb.Attestation{
|
||||
a := ðpb.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()
|
||||
|
||||
@@ -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
|
||||
|
||||
84
validator/client/log_test.go
Normal file
84
validator/client/log_test.go
Normal 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(ðpb.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(ðpb.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(ðpb.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(ðpb.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 := ðpb.AggregateAttestationAndProof{}
|
||||
agg.Aggregate = util.HydrateAttestation(ðpb.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 := ðpb.AggregateAttestationAndProofElectra{}
|
||||
agg.Aggregate = util.HydrateAttestationElectra(ðpb.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]\"")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user