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(MessageValidation): first slot proposals [stage] #1886

Open
wants to merge 5 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
14 changes: 12 additions & 2 deletions message/validation/common_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,20 @@ func (mv *messageValidator) validateBeaconDuty(
role spectypes.RunnerRole,
slot phase0.Slot,
indices []phase0.ValidatorIndex,
partialMessageType *spectypes.PartialSigMsgType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this could be just replaced with a boolean? and do the check outside. since you only use it to see if its a randao message. this could just be randao bool

) error {
epoch := mv.netCfg.Beacon.EstimatedEpochAtSlot(slot)

// Rule: For a proposal duty message, we check if the validator is assigned to it
if role == spectypes.RoleProposer {
epoch := mv.netCfg.Beacon.EstimatedEpochAtSlot(slot)
if partialMessageType != nil && *partialMessageType == spectypes.RandaoPartialSig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following other comments

Suggested change
if partialMessageType != nil && *partialMessageType == spectypes.RandaoPartialSig {
if rando && !mv.dutyStore.Proposer.IsEpochSet(epoch) {

if mv.netCfg.Beacon.IsFirstSlotOfEpoch(slot) {
if !mv.dutyStore.Proposer.IsEpochSet(epoch) {
return nil // Accept message even if duties are not set
}
}
}

// Non-committee roles always have one validator index.
validatorIndex := indices[0]
if mv.dutyStore.Proposer.ValidatorDuty(epoch, slot, validatorIndex) == nil {
Expand All @@ -130,7 +140,7 @@ func (mv *messageValidator) validateBeaconDuty(

// Rule: For a sync committee aggregation duty message, we check if the validator is assigned to it
if role == spectypes.RoleSyncCommitteeContribution {
period := mv.netCfg.Beacon.EstimatedSyncCommitteePeriodAtEpoch(mv.netCfg.Beacon.EstimatedEpochAtSlot(slot))
period := mv.netCfg.Beacon.EstimatedSyncCommitteePeriodAtEpoch(epoch)
// Non-committee roles always have one validator index.
validatorIndex := indices[0]
if mv.dutyStore.SyncCommittee.Duty(period, validatorIndex) == nil {
Expand Down
2 changes: 1 addition & 1 deletion message/validation/consensus_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (mv *messageValidator) validateQBFTMessageByDutyLogic(
}

msgSlot := phase0.Slot(consensusMessage.Height)
if err := mv.validateBeaconDuty(role, msgSlot, validatorIndices); err != nil {
if err := mv.validateBeaconDuty(role, msgSlot, validatorIndices, nil); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions message/validation/partial_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (mv *messageValidator) validatePartialSigMessagesByDutyLogic(
signerStateBySlot := state.GetOrCreate(signer)

// Rule: Height must not be "old". I.e., signer must not have already advanced to a later slot.
if signedSSVMessage.SSVMessage.MsgID.GetRoleType() != types.RoleCommittee { // Rule only for validator runners
if role != types.RoleCommittee { // Rule only for validator runners
maxSlot := signerStateBySlot.MaxSlot()
if maxSlot != 0 && maxSlot > partialSignatureMessages.Slot {
e := ErrSlotAlreadyAdvanced
Expand All @@ -155,7 +155,7 @@ func (mv *messageValidator) validatePartialSigMessagesByDutyLogic(
}
}

if err := mv.validateBeaconDuty(signedSSVMessage.SSVMessage.GetID().GetRoleType(), messageSlot, committeeInfo.indices); err != nil {
if err := mv.validateBeaconDuty(role, messageSlot, committeeInfo.indices, &partialSignatureMessages.Type); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the above comment

Suggested change
if err := mv.validateBeaconDuty(role, messageSlot, committeeInfo.indices, &partialSignatureMessages.Type); err != nil {
if err := mv.validateBeaconDuty(role, messageSlot, committeeInfo.indices, &partialSignatureMessages.Type == spectypes.RandaoPartialSig); err != nil {

return err
}

Expand Down
8 changes: 8 additions & 0 deletions operator/duties/dutystore/duties.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ func (d *Duties[D]) ResetEpoch(epoch phase0.Epoch) {

delete(d.m, epoch)
}

func (d *Duties[D]) IsEpochSet(epoch phase0.Epoch) bool {
d.mu.RLock()
defer d.mu.RUnlock()

_, exists := d.m[epoch]
return exists
}
Loading