Skip to content

Commit

Permalink
Ignore Late Message Logs (#12525)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas authored Jun 14, 2023
1 parent 1862422 commit a75e78d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 11 additions & 1 deletion beacon-chain/core/altair/sync_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package altair

import (
"context"
goErrors "errors"
"fmt"
"time"

Expand All @@ -22,6 +23,10 @@ import (

const maxRandomByte = uint64(1<<8 - 1)

var (
ErrTooLate = errors.New("sync message is too late")
)

// ValidateNilSyncContribution validates the following fields are not nil:
// -the contribution and proof itself
// -the message within contribution and proof
Expand Down Expand Up @@ -217,7 +222,7 @@ func ValidateSyncMessageTime(slot primitives.Slot, genesisTime time.Time, clockD
upperBound := time.Now().Add(clockDisparity)
// Verify sync message slot is within the time range.
if messageTime.Before(lowerBound) || messageTime.After(upperBound) {
return fmt.Errorf(
syncErr := fmt.Errorf(
"sync message time %v (slot %d) not within allowable range of %v (slot %d) to %v (slot %d)",
messageTime,
slot,
Expand All @@ -226,6 +231,11 @@ func ValidateSyncMessageTime(slot primitives.Slot, genesisTime time.Time, clockD
upperBound,
uint64(upperBound.Unix()-genesisTime.Unix())/params.BeaconConfig().SecondsPerSlot,
)
// Wrap error message if sync message is too late.
if messageTime.Before(lowerBound) {
syncErr = goErrors.Join(ErrTooLate, syncErr)
}
return syncErr
}
return nil
}
6 changes: 5 additions & 1 deletion beacon-chain/core/helpers/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/prysmaticlabs/prysm/v4/time/slots"
)

var (
ErrTooLate = errors.New("attestation is too late")
)

// ValidateNilAttestation checks if any composite field of input attestation is nil.
// Access to these nil fields will result in run time panic,
// it is recommended to run these checks as first line of defense.
Expand Down Expand Up @@ -164,7 +168,7 @@ func ValidateAttestationTime(attSlot primitives.Slot, genesisTime time.Time, clo
)
if attTime.Before(lowerBounds) {
attReceivedTooLateCount.Inc()
return attError
return errors.Join(ErrTooLate, attError)
}
if attTime.After(upperBounds) {
attReceivedTooEarlyCount.Inc()
Expand Down
15 changes: 14 additions & 1 deletion beacon-chain/sync/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sync

import (
"context"
"errors"
"fmt"
"reflect"
"runtime/debug"
Expand All @@ -13,6 +14,8 @@ import (
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/p2p/peers"
"github.com/prysmaticlabs/prysm/v4/cmd/beacon-chain/flags"
Expand Down Expand Up @@ -283,7 +286,7 @@ func (s *Service) wrapAndReportValidation(topic string, v wrappedVal) (string, p
messageFailedValidationCounter.WithLabelValues(topic).Inc()
}
if b == pubsub.ValidationIgnore {
if err != nil {
if err != nil && !errorIsIgnored(err) {
log.WithError(err).WithFields(logrus.Fields{
"topic": topic,
"multiaddress": multiAddr(pid, s.cfg.p2p.Peers()),
Expand Down Expand Up @@ -781,3 +784,13 @@ func multiAddr(pid peer.ID, stat *peers.Status) string {
}
return addrs.String()
}

func errorIsIgnored(err error) bool {
if errors.Is(err, helpers.ErrTooLate) {
return true
}
if errors.Is(err, altair.ErrTooLate) {
return true
}
return false
}

0 comments on commit a75e78d

Please sign in to comment.