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

Add flag to enable logging on rejected gossip message #11524

Merged
merged 10 commits into from
Oct 5, 2022
1 change: 1 addition & 0 deletions beacon-chain/sync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ go_library(
"//runtime/version:go_default_library",
"//time:go_default_library",
"//time/slots:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_hashicorp_golang_lru//:go_default_library",
"@com_github_kevinms_leakybucket_go//:go_default_library",
"@com_github_libp2p_go_libp2p_core//:go_default_library",
Expand Down
10 changes: 8 additions & 2 deletions beacon-chain/sync/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"strings"
"time"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/peers"
"github.com/prysmaticlabs/prysm/v3/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/v3/config/features"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/container/slice"
Expand Down Expand Up @@ -257,13 +259,17 @@ func (s *Service) wrapAndReportValidation(topic string, v wrappedVal) (string, p
}
b, err := v(ctx, pid, msg)
if b == pubsub.ValidationReject {
log.WithError(err).WithFields(logrus.Fields{
fields := logrus.Fields{
"topic": topic,
"multiaddress": multiAddr(pid, s.cfg.p2p.Peers()),
"peer id": pid.String(),
"agent": agentString(pid, s.cfg.p2p.Host()),
"gossip score": s.cfg.p2p.Peers().Scorers().GossipScorer().Score(pid),
}).Debugf("Gossip message was rejected")
}
if features.Get().EnableFullSSZDataLogging {
fields["message"] = hexutil.Encode(msg.Data)
}
log.WithError(err).WithFields(fields).Debugf("Gossip message was rejected")
messageFailedValidationCounter.WithLabelValues(topic).Inc()
}
if b == pubsub.ValidationIgnore {
Expand Down
5 changes: 5 additions & 0 deletions config/features/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Flags struct {
EnableHistoricalSpaceRepresentation bool // EnableHistoricalSpaceRepresentation enables the saving of registry validators in separate buckets to save space
// Logging related toggles.
DisableGRPCConnectionLogs bool // Disables logging when a new grpc client has connected.
EnableFullSSZDataLogging bool // Enables logging for full ssz data on rejected gossip messages

// Slasher toggles.
DisableBroadcastSlashings bool // DisableBroadcastSlashings disables p2p broadcasting of proposer and attester slashings.
Expand Down Expand Up @@ -251,6 +252,10 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
logEnabled(enableStartupOptimistic)
cfg.EnableStartOptimistic = true
}
if ctx.IsSet(enableFullSSZDataLogging.Name) {
logEnabled(enableFullSSZDataLogging)
cfg.EnableFullSSZDataLogging = true
}
Init(cfg)
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions config/features/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ var (
Value: false,
Hidden: true,
}
enableFullSSZDataLogging = &cli.BoolFlag{
Name: "enable-full-ssz-data-logging",
Usage: "Enables displaying logs for full ssz data on rejected gossip messages",
}
)

// devModeFlags holds list of flags that are set when development mode is on.
Expand Down Expand Up @@ -168,6 +172,7 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c
EnableOnlyBlindedBeaconBlocks,
enableStartupOptimistic,
disableDefensivePull,
enableFullSSZDataLogging,
}...)...)

// E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E.
Expand Down