-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Improve vc logs #13573
Merged
Merged
Improve vc logs #13573
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b78dd8
duties
rkapka 407bb2f
atts
rkapka aede437
revert some changes
rkapka 3b5256d
revert timeTillDuty
rkapka 6806ca9
Manu's review
rkapka af89707
Revert "Auxiliary commit to revert individual files from 6806ca9fbe18…
rkapka df8da78
remove trash
rkapka f9f30eb
more reivew
rkapka 2b66988
making Manu happy
rkapka e538cc0
test fixes
rkapka b198f1e
Merge branch 'develop' into improve-vc-logs
rkapka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ import ( | |
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams" | ||
"github.com/prysmaticlabs/prysm/v4/config/params" | ||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v4/crypto/hash" | ||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" | ||
"github.com/prysmaticlabs/prysm/v4/monitoring/tracing" | ||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" | ||
|
@@ -144,6 +143,11 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot primitives.Slot, | |
tracing.AnnotateError(span, err) | ||
return | ||
} | ||
r, err := data.HashTreeRoot() | ||
if err != nil { | ||
return | ||
} | ||
logrus.Infof("Submitting attestation %#x", r) | ||
attResp, err := v.validatorClient.ProposeAttestation(ctx, attestation) | ||
if err != nil { | ||
log.WithError(err).Error("Could not submit attestation to beacon node") | ||
|
@@ -154,7 +158,7 @@ func (v *validator) SubmitAttestation(ctx context.Context, slot primitives.Slot, | |
return | ||
} | ||
|
||
if err := v.saveAttesterIndexToData(data, duty.ValidatorIndex); err != nil { | ||
if err := v.saveSubmittedAtt(data, duty.PublicKey); err != nil { | ||
log.WithError(err).Error("Could not save validator index for logging") | ||
if v.emitAccountMetrics { | ||
ValidatorAttestFailVec.WithLabelValues(fmtKey).Inc() | ||
|
@@ -228,21 +232,21 @@ func (v *validator) getDomainAndSigningRoot(ctx context.Context, data *ethpb.Att | |
return domain, root, nil | ||
} | ||
|
||
// For logging, this saves the last submitted attester index to its attestation data. The purpose of this | ||
// is to enhance attesting logs to be readable when multiple validator keys ran in a single client. | ||
func (v *validator) saveAttesterIndexToData(data *ethpb.AttestationData, index primitives.ValidatorIndex) 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) error { | ||
v.attLogsLock.Lock() | ||
defer v.attLogsLock.Unlock() | ||
|
||
h, err := hash.Proto(data) | ||
r, err := data.HashTreeRoot() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have we benchmarked against the two? |
||
if err != nil { | ||
return err | ||
} | ||
|
||
if v.attLogs[h] == nil { | ||
v.attLogs[h] = &attSubmitted{data, []primitives.ValidatorIndex{}, []primitives.ValidatorIndex{}} | ||
if v.submittedAtts[r] == nil { | ||
v.submittedAtts[r] = &submittedAtt{data, [][]byte{}, [][]byte{}} | ||
} | ||
v.attLogs[h] = &attSubmitted{data, append(v.attLogs[h].attesterIndices, index), []primitives.ValidatorIndex{}} | ||
v.submittedAtts[r] = &submittedAtt{data, append(v.submittedAtts[r].attesterPubkeys, pubkey), [][]byte{}} | ||
|
||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ type validator struct { | |
slashableKeysLock sync.RWMutex | ||
eipImportBlacklistedPublicKeys map[[fieldparams.BLSPubkeyLength]byte]bool | ||
walletInitializedFeed *event.Feed | ||
attLogs map[[32]byte]*attSubmitted | ||
submittedAtts map[[32]byte]*submittedAtt | ||
startBalances map[[fieldparams.BLSPubkeyLength]byte]uint64 | ||
dutiesLock sync.RWMutex | ||
duties *ethpb.DutiesResponse | ||
|
@@ -540,7 +540,7 @@ func retrieveLatestRecord(recs []*kv.AttestationRecord) *kv.AttestationRecord { | |
// list of upcoming assignments needs to be updated. For example, at the | ||
// beginning of a new epoch. | ||
func (v *validator) UpdateDuties(ctx context.Context, slot primitives.Slot) error { | ||
if slot%params.BeaconConfig().SlotsPerEpoch != 0 && v.duties != nil { | ||
if !slots.IsEpochStart(slot) && v.duties != nil { | ||
// Do nothing if not epoch start AND assignments already exist. | ||
return nil | ||
} | ||
|
@@ -889,12 +889,16 @@ func (v *validator) logDuties(slot primitives.Slot, currentEpochDuties []*ethpb. | |
attesterKeys[i] = make([]string, 0) | ||
} | ||
proposerKeys := make([]string, params.BeaconConfig().SlotsPerEpoch) | ||
slotOffset := slot - (slot % params.BeaconConfig().SlotsPerEpoch) | ||
var totalAttestingKeys uint64 | ||
epochStartSlot, err := slots.EpochStart(slots.ToEpoch(slot)) | ||
if err != nil { | ||
log.WithError(err).Error("Could not calculate epoch start. Ignoring logging duties.") | ||
return | ||
} | ||
var totalProposingKeys, totalAttestingKeys uint64 | ||
for _, duty := range currentEpochDuties { | ||
validatorNotTruncatedKey := fmt.Sprintf("%#x", duty.PublicKey) | ||
pubkey := fmt.Sprintf("%#x", duty.PublicKey) | ||
if v.emitAccountMetrics { | ||
ValidatorStatusesGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(duty.Status)) | ||
ValidatorStatusesGaugeVec.WithLabelValues(pubkey).Set(float64(duty.Status)) | ||
} | ||
|
||
// Only interested in validators who are attesting/proposing. | ||
|
@@ -903,39 +907,40 @@ func (v *validator) logDuties(slot primitives.Slot, currentEpochDuties []*ethpb. | |
continue | ||
} | ||
|
||
validatorKey := fmt.Sprintf("%#x", bytesutil.Trunc(duty.PublicKey)) | ||
attesterIndex := duty.AttesterSlot - slotOffset | ||
if attesterIndex >= params.BeaconConfig().SlotsPerEpoch { | ||
truncatedPubkey := fmt.Sprintf("%#x", bytesutil.Trunc(duty.PublicKey)) | ||
attesterSlotInEpoch := duty.AttesterSlot - epochStartSlot | ||
if attesterSlotInEpoch >= params.BeaconConfig().SlotsPerEpoch { | ||
log.WithField("duty", duty).Warn("Invalid attester slot") | ||
} else { | ||
attesterKeys[duty.AttesterSlot-slotOffset] = append(attesterKeys[duty.AttesterSlot-slotOffset], validatorKey) | ||
attesterKeys[attesterSlotInEpoch] = append(attesterKeys[attesterSlotInEpoch], truncatedPubkey) | ||
totalAttestingKeys++ | ||
if v.emitAccountMetrics { | ||
ValidatorNextAttestationSlotGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(duty.AttesterSlot)) | ||
ValidatorNextAttestationSlotGaugeVec.WithLabelValues(pubkey).Set(float64(duty.AttesterSlot)) | ||
} | ||
} | ||
if v.emitAccountMetrics && duty.IsSyncCommittee { | ||
ValidatorInSyncCommitteeGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(1)) | ||
ValidatorInSyncCommitteeGaugeVec.WithLabelValues(pubkey).Set(float64(1)) | ||
} else if v.emitAccountMetrics && !duty.IsSyncCommittee { | ||
// clear the metric out if the validator is not in the current sync committee anymore otherwise it will be left at 1 | ||
ValidatorInSyncCommitteeGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(0)) | ||
ValidatorInSyncCommitteeGaugeVec.WithLabelValues(pubkey).Set(float64(0)) | ||
} | ||
|
||
for _, proposerSlot := range duty.ProposerSlots { | ||
proposerIndex := proposerSlot - slotOffset | ||
if proposerIndex >= params.BeaconConfig().SlotsPerEpoch { | ||
proposerSlotInEpoch := proposerSlot - epochStartSlot | ||
if proposerSlotInEpoch >= params.BeaconConfig().SlotsPerEpoch { | ||
log.WithField("duty", duty).Warn("Invalid proposer slot") | ||
} else { | ||
proposerKeys[proposerIndex] = validatorKey | ||
proposerKeys[proposerSlotInEpoch] = truncatedPubkey | ||
totalProposingKeys++ | ||
} | ||
if v.emitAccountMetrics { | ||
ValidatorNextProposalSlotGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(proposerSlot)) | ||
ValidatorNextProposalSlotGaugeVec.WithLabelValues(pubkey).Set(float64(proposerSlot)) | ||
} | ||
} | ||
} | ||
for _, duty := range nextEpochDuties { | ||
// for the next epoch, currently we are only interested in whether the validator is in the next sync committee or not | ||
validatorNotTruncatedKey := fmt.Sprintf("%#x", duty.PublicKey) | ||
pubkey := fmt.Sprintf("%#x", duty.PublicKey) | ||
|
||
// Only interested in validators who are attesting/proposing. | ||
// Note that slashed validators will have duties but their results are ignored by the network so we don't bother with them. | ||
|
@@ -944,36 +949,37 @@ func (v *validator) logDuties(slot primitives.Slot, currentEpochDuties []*ethpb. | |
} | ||
|
||
if v.emitAccountMetrics && duty.IsSyncCommittee { | ||
ValidatorInNextSyncCommitteeGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(1)) | ||
ValidatorInNextSyncCommitteeGaugeVec.WithLabelValues(pubkey).Set(float64(1)) | ||
} else if v.emitAccountMetrics && !duty.IsSyncCommittee { | ||
// clear the metric out if the validator is now not in the next sync committee otherwise it will be left at 1 | ||
ValidatorInNextSyncCommitteeGaugeVec.WithLabelValues(validatorNotTruncatedKey).Set(float64(0)) | ||
ValidatorInNextSyncCommitteeGaugeVec.WithLabelValues(pubkey).Set(float64(0)) | ||
} | ||
} | ||
|
||
log.WithFields(logrus.Fields{ | ||
"proposerCount": totalProposingKeys, | ||
"attesterCount": totalAttestingKeys, | ||
}).Infof("Schedule for epoch %d", slots.ToEpoch(slot)) | ||
for i := primitives.Slot(0); i < params.BeaconConfig().SlotsPerEpoch; i++ { | ||
startTime := slots.StartTime(v.genesisTime, slotOffset+i) | ||
startTime := slots.StartTime(v.genesisTime, epochStartSlot+i) | ||
durationTillDuty := (time.Until(startTime) + time.Second).Truncate(time.Second) // Round up to next second. | ||
|
||
slotLog := log.WithFields(logrus.Fields{}) | ||
if proposerKeys[i] != "" { | ||
slotLog = slotLog.WithField("proposerPubkey", proposerKeys[i]) | ||
} | ||
if len(attesterKeys[i]) > 0 { | ||
attestationLog := log.WithFields(logrus.Fields{ | ||
"slot": slotOffset + i, | ||
"slotInEpoch": (slotOffset + i) % params.BeaconConfig().SlotsPerEpoch, | ||
"attesterDutiesAtSlot": len(attesterKeys[i]), | ||
"totalAttestersInEpoch": totalAttestingKeys, | ||
"pubKeys": attesterKeys[i], | ||
slotLog = slotLog.WithFields(logrus.Fields{ | ||
"slot": epochStartSlot + i, | ||
"slotInEpoch": (epochStartSlot + i) % params.BeaconConfig().SlotsPerEpoch, | ||
"attesterCount": len(attesterKeys[i]), | ||
"attesterPubkeys": attesterKeys[i], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a |
||
}) | ||
if durationTillDuty > 0 { | ||
attestationLog = attestationLog.WithField("timeTillDuty", durationTillDuty) | ||
} | ||
attestationLog.Info("Attestation schedule") | ||
} | ||
if proposerKeys[i] != "" { | ||
proposerLog := log.WithField("slot", slotOffset+i).WithField("pubKey", proposerKeys[i]) | ||
if durationTillDuty > 0 { | ||
proposerLog = proposerLog.WithField("timeTillDuty", durationTillDuty) | ||
} | ||
proposerLog.Info("Proposal schedule") | ||
if durationTillDuty > 0 { | ||
slotLog = slotLog.WithField("timeTillDuty", durationTillDuty) | ||
} | ||
slotLog.Infof("Duties schedule") | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using
l
as a variable name?(the letter
l
is not insubmittedAtts
).Why not using something like
att
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is outdated