diff --git a/.github/workflows/check-logs.yml b/.github/workflows/check-logs.yml new file mode 100644 index 000000000000..adb1c999771e --- /dev/null +++ b/.github/workflows/check-logs.yml @@ -0,0 +1,23 @@ +name: Check log.go files +on: [ pull_request ] + +jobs: + check-logs: + runs-on: ubuntu-4 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go 1.25.1 + uses: actions/setup-go@v5 + with: + go-version: '1.25.1' + + - name: Install ripgrep + run: sudo apt-get install -y ripgrep + + - name: Check log.go files + run: ./hack/check-logs.sh diff --git a/api/apiutil/BUILD.bazel b/api/apiutil/BUILD.bazel index 8cb1cb1fcb70..520fa32db6f6 100644 --- a/api/apiutil/BUILD.bazel +++ b/api/apiutil/BUILD.bazel @@ -5,6 +5,7 @@ go_library( srcs = [ "common.go", "header.go", + "log.go", ], importpath = "github.com/OffchainLabs/prysm/v7/api/apiutil", visibility = ["//visibility:public"], diff --git a/api/apiutil/header.go b/api/apiutil/header.go index 37fdf988e09b..54f820435440 100644 --- a/api/apiutil/header.go +++ b/api/apiutil/header.go @@ -5,8 +5,6 @@ import ( "sort" "strconv" "strings" - - log "github.com/sirupsen/logrus" ) type mediaRange struct { diff --git a/api/apiutil/log.go b/api/apiutil/log.go new file mode 100644 index 000000000000..39ad8aec5d09 --- /dev/null +++ b/api/apiutil/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package apiutil + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/apiutil") diff --git a/api/client/beacon/log.go b/api/client/beacon/log.go index b566d20bb59c..66cf5aa2b85d 100644 --- a/api/client/beacon/log.go +++ b/api/client/beacon/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package beacon import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "beacon") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/client/beacon") diff --git a/api/client/builder/BUILD.bazel b/api/client/builder/BUILD.bazel index ef6d736a37c5..3bdfa953e417 100644 --- a/api/client/builder/BUILD.bazel +++ b/api/client/builder/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "bid.go", "client.go", "errors.go", + "log.go", "types.go", ], importpath = "github.com/OffchainLabs/prysm/v7/api/client/builder", @@ -63,6 +64,5 @@ go_test( "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", ], ) diff --git a/api/client/builder/client.go b/api/client/builder/client.go index 6139a95629f7..78e2807a9eba 100644 --- a/api/client/builder/client.go +++ b/api/client/builder/client.go @@ -25,7 +25,7 @@ import ( ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" "github.com/OffchainLabs/prysm/v7/runtime/version" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" ) @@ -70,7 +70,7 @@ type requestLogger struct{} func (*requestLogger) observe(r *http.Request) (e error) { b := bytes.NewBuffer(nil) if r.Body == nil { - log.WithFields(log.Fields{ + log.WithFields(logrus.Fields{ "bodyBase64": "(nil value)", "url": r.URL.String(), }).Info("Builder http request") @@ -87,7 +87,7 @@ func (*requestLogger) observe(r *http.Request) (e error) { return err } r.Body = io.NopCloser(b) - log.WithFields(log.Fields{ + log.WithFields(logrus.Fields{ "bodyBase64": string(body), "url": r.URL.String(), }).Info("Builder http request") diff --git a/api/client/builder/client_test.go b/api/client/builder/client_test.go index 6ca43f7e66d5..263c0159ca37 100644 --- a/api/client/builder/client_test.go +++ b/api/client/builder/client_test.go @@ -23,7 +23,6 @@ import ( "github.com/OffchainLabs/prysm/v7/testing/assert" "github.com/OffchainLabs/prysm/v7/testing/require" "github.com/OffchainLabs/prysm/v7/testing/util" - log "github.com/sirupsen/logrus" ) type roundtrip func(*http.Request) (*http.Response, error) diff --git a/api/client/builder/log.go b/api/client/builder/log.go new file mode 100644 index 000000000000..e8dbb135c3bf --- /dev/null +++ b/api/client/builder/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package builder + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/client/builder") diff --git a/api/client/event/BUILD.bazel b/api/client/event/BUILD.bazel index 31f7ebbf3870..d68ab6e2b42b 100644 --- a/api/client/event/BUILD.bazel +++ b/api/client/event/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "event_stream.go", + "log.go", "utils.go", ], importpath = "github.com/OffchainLabs/prysm/v7/api/client/event", @@ -23,8 +24,5 @@ go_test( "utils_test.go", ], embed = [":go_default_library"], - deps = [ - "//testing/require:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", - ], + deps = ["//testing/require:go_default_library"], ) diff --git a/api/client/event/event_stream.go b/api/client/event/event_stream.go index 3244225883ee..3d8992e4b046 100644 --- a/api/client/event/event_stream.go +++ b/api/client/event/event_stream.go @@ -10,7 +10,6 @@ import ( "github.com/OffchainLabs/prysm/v7/api" "github.com/OffchainLabs/prysm/v7/api/client" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) const ( diff --git a/api/client/event/event_stream_test.go b/api/client/event/event_stream_test.go index b366ad3671f7..76e2b94a3b83 100644 --- a/api/client/event/event_stream_test.go +++ b/api/client/event/event_stream_test.go @@ -8,7 +8,6 @@ import ( "time" "github.com/OffchainLabs/prysm/v7/testing/require" - log "github.com/sirupsen/logrus" ) func TestNewEventStream(t *testing.T) { diff --git a/api/client/event/log.go b/api/client/event/log.go new file mode 100644 index 000000000000..39c40d0ac812 --- /dev/null +++ b/api/client/event/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package event + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/client/event") diff --git a/api/grpc/BUILD.bazel b/api/grpc/BUILD.bazel index bf45352f9066..16b0e63a6f50 100644 --- a/api/grpc/BUILD.bazel +++ b/api/grpc/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "grpcutils.go", + "log.go", "parameters.go", ], importpath = "github.com/OffchainLabs/prysm/v7/api/grpc", diff --git a/api/grpc/grpcutils.go b/api/grpc/grpcutils.go index 54ac97958c03..2f710a2ac096 100644 --- a/api/grpc/grpcutils.go +++ b/api/grpc/grpcutils.go @@ -32,7 +32,7 @@ func LogRequests( ) start := time.Now() err := invoker(ctx, method, req, reply, cc, opts...) - logrus.WithField("backend", header["x-backend"]). + log.WithField("backend", header["x-backend"]). WithField("method", method).WithField("duration", time.Since(start)). Debug("gRPC request finished.") return err @@ -58,7 +58,7 @@ func LogStream( grpc.Header(&header), ) strm, err := streamer(ctx, sd, conn, method, opts...) - logrus.WithField("backend", header["x-backend"]). + log.WithField("backend", header["x-backend"]). WithField("method", method). Debug("gRPC stream started.") return strm, err @@ -71,7 +71,7 @@ func AppendHeaders(parent context.Context, headers []string) context.Context { if h != "" { keyValue := strings.Split(h, "=") if len(keyValue) < 2 { - logrus.Warnf("Incorrect gRPC header flag format. Skipping %v", keyValue[0]) + log.Warnf("Incorrect gRPC header flag format. Skipping %v", keyValue[0]) continue } parent = metadata.AppendToOutgoingContext(parent, keyValue[0], strings.Join(keyValue[1:], "=")) // nolint:fatcontext diff --git a/api/grpc/log.go b/api/grpc/log.go new file mode 100644 index 000000000000..3957b1de2ff7 --- /dev/null +++ b/api/grpc/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package grpc + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/grpc") diff --git a/api/server/httprest/log.go b/api/server/httprest/log.go index 6208a403ea4d..3a12e72bc012 100644 --- a/api/server/httprest/log.go +++ b/api/server/httprest/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package httprest import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "httprest") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/server/httprest") diff --git a/api/server/middleware/BUILD.bazel b/api/server/middleware/BUILD.bazel index d234346feade..d39a4b7859f4 100644 --- a/api/server/middleware/BUILD.bazel +++ b/api/server/middleware/BUILD.bazel @@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = [ + "log.go", "middleware.go", "util.go", ], @@ -27,6 +28,5 @@ go_test( "//api:go_default_library", "//testing/assert:go_default_library", "//testing/require:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", ], ) diff --git a/api/server/middleware/log.go b/api/server/middleware/log.go new file mode 100644 index 000000000000..a397be65d104 --- /dev/null +++ b/api/server/middleware/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package middleware + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "api/server/middleware") diff --git a/api/server/middleware/middleware.go b/api/server/middleware/middleware.go index 412db4469726..33c38448b35b 100644 --- a/api/server/middleware/middleware.go +++ b/api/server/middleware/middleware.go @@ -9,7 +9,6 @@ import ( "github.com/OffchainLabs/prysm/v7/api" "github.com/OffchainLabs/prysm/v7/api/apiutil" "github.com/rs/cors" - log "github.com/sirupsen/logrus" ) type Middleware func(http.Handler) http.Handler diff --git a/api/server/middleware/middleware_test.go b/api/server/middleware/middleware_test.go index c5bacce68636..67dcef283bf5 100644 --- a/api/server/middleware/middleware_test.go +++ b/api/server/middleware/middleware_test.go @@ -10,7 +10,6 @@ import ( "github.com/OffchainLabs/prysm/v7/api" "github.com/OffchainLabs/prysm/v7/testing/require" - log "github.com/sirupsen/logrus" ) // frozenHeaderRecorder allows asserting that response headers were not modified diff --git a/async/BUILD.bazel b/async/BUILD.bazel index e1ff1fb81186..230763251a95 100644 --- a/async/BUILD.bazel +++ b/async/BUILD.bazel @@ -5,6 +5,7 @@ go_library( srcs = [ "debounce.go", "every.go", + "log.go", "multilock.go", "scatter.go", ], diff --git a/async/every.go b/async/every.go index 4173235b8c70..3d56e483b0fa 100644 --- a/async/every.go +++ b/async/every.go @@ -6,8 +6,6 @@ import ( "reflect" "runtime" "time" - - log "github.com/sirupsen/logrus" ) // RunEvery runs the provided command periodically. diff --git a/async/log.go b/async/log.go new file mode 100644 index 000000000000..333182ca3043 --- /dev/null +++ b/async/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package async + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "async") diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 7f89e64c277f..1eb74a893498 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -14,6 +14,7 @@ go_library( "head_sync_committee_info.go", "init_sync_process_block.go", "log.go", + "log_helpers.go", "merge_ascii_art.go", "metrics.go", "options.go", diff --git a/beacon-chain/blockchain/log.go b/beacon-chain/blockchain/log.go index 8e768a5f2549..ebd57f783e9f 100644 --- a/beacon-chain/blockchain/log.go +++ b/beacon-chain/blockchain/log.go @@ -1,164 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package blockchain -import ( - "encoding/hex" - "fmt" - "time" +import "github.com/sirupsen/logrus" - "github.com/OffchainLabs/prysm/v7/beacon-chain/core/blocks" - "github.com/OffchainLabs/prysm/v7/config/params" - consensus_types "github.com/OffchainLabs/prysm/v7/consensus-types" - "github.com/OffchainLabs/prysm/v7/consensus-types/interfaces" - "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" - ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" - "github.com/OffchainLabs/prysm/v7/runtime/version" - prysmTime "github.com/OffchainLabs/prysm/v7/time" - "github.com/OffchainLabs/prysm/v7/time/slots" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -var log = logrus.WithField("prefix", "blockchain") - -// logs state transition related data every slot. -func logStateTransitionData(b interfaces.ReadOnlyBeaconBlock) error { - log := log.WithField("slot", b.Slot()) - if len(b.Body().Attestations()) > 0 { - log = log.WithField("attestations", len(b.Body().Attestations())) - } - if len(b.Body().AttesterSlashings()) > 0 { - log = log.WithField("attesterSlashings", len(b.Body().AttesterSlashings())) - } - if len(b.Body().ProposerSlashings()) > 0 { - log = log.WithField("proposerSlashings", len(b.Body().ProposerSlashings())) - } - if len(b.Body().VoluntaryExits()) > 0 { - log = log.WithField("voluntaryExits", len(b.Body().VoluntaryExits())) - } - if b.Version() >= version.Altair { - agg, err := b.Body().SyncAggregate() - if err != nil { - return err - } - log = log.WithField("syncBitsCount", agg.SyncCommitteeBits.Count()) - } - if b.Version() >= version.Bellatrix { - p, err := b.Body().Execution() - if err != nil { - return err - } - log = log.WithField("payloadHash", fmt.Sprintf("%#x", bytesutil.Trunc(p.BlockHash()))) - txs, err := p.Transactions() - switch { - case errors.Is(err, consensus_types.ErrUnsupportedField): - case err != nil: - return err - default: - log = log.WithField("txCount", len(txs)) - txsPerSlotCount.Set(float64(len(txs))) - } - } - if b.Version() >= version.Deneb { - kzgs, err := b.Body().BlobKzgCommitments() - if err != nil { - log.WithError(err).Error("Failed to get blob KZG commitments") - } else if len(kzgs) > 0 { - log = log.WithField("kzgCommitmentCount", len(kzgs)) - } - } - if b.Version() >= version.Electra { - eReqs, err := b.Body().ExecutionRequests() - if err != nil { - log.WithError(err).Error("Failed to get execution requests") - } else { - if len(eReqs.Deposits) > 0 { - log = log.WithField("depositRequestCount", len(eReqs.Deposits)) - } - if len(eReqs.Consolidations) > 0 { - log = log.WithField("consolidationRequestCount", len(eReqs.Consolidations)) - } - if len(eReqs.Withdrawals) > 0 { - log = log.WithField("withdrawalRequestCount", len(eReqs.Withdrawals)) - } - } - } - log.Info("Finished applying state transition") - return nil -} - -func logBlockSyncStatus(block interfaces.ReadOnlyBeaconBlock, blockRoot [32]byte, justified, finalized *ethpb.Checkpoint, receivedTime time.Time, genesis time.Time, daWaitedTime time.Duration) error { - startTime, err := slots.StartTime(genesis, block.Slot()) - if err != nil { - return err - } - level := log.Logger.GetLevel() - if level >= logrus.DebugLevel { - parentRoot := block.ParentRoot() - lf := logrus.Fields{ - "slot": block.Slot(), - "slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch, - "block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]), - "epoch": slots.ToEpoch(block.Slot()), - "justifiedEpoch": justified.Epoch, - "justifiedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(justified.Root)[:8]), - "finalizedEpoch": finalized.Epoch, - "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), - "parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(parentRoot[:])[:8]), - "version": version.String(block.Version()), - "sinceSlotStartTime": prysmTime.Now().Sub(startTime), - "chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime) - daWaitedTime, - "dataAvailabilityWaitedTime": daWaitedTime, - } - log.WithFields(lf).Debug("Synced new block") - } else { - log.WithFields(logrus.Fields{ - "slot": block.Slot(), - "block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]), - "finalizedEpoch": finalized.Epoch, - "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), - "epoch": slots.ToEpoch(block.Slot()), - }).Info("Synced new block") - } - return nil -} - -// logs payload related data every slot. -func logPayload(block interfaces.ReadOnlyBeaconBlock) error { - isExecutionBlk, err := blocks.IsExecutionBlock(block.Body()) - if err != nil { - return errors.Wrap(err, "could not determine if block is execution block") - } - if !isExecutionBlk { - return nil - } - payload, err := block.Body().Execution() - if err != nil { - return err - } - if payload.GasLimit() == 0 { - return errors.New("gas limit should not be 0") - } - gasUtilized := float64(payload.GasUsed()) / float64(payload.GasLimit()) - fields := logrus.Fields{ - "blockHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.BlockHash())), - "parentHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.ParentHash())), - "blockNumber": payload.BlockNumber(), - "gasUtilized": fmt.Sprintf("%.2f", gasUtilized), - } - if block.Version() >= version.Capella { - withdrawals, err := payload.Withdrawals() - if err != nil { - return errors.Wrap(err, "could not get withdrawals") - } - fields["withdrawals"] = len(withdrawals) - changes, err := block.Body().BLSToExecutionChanges() - if err != nil { - return errors.Wrap(err, "could not get BLSToExecutionChanges") - } - if len(changes) > 0 { - fields["blsToExecutionChanges"] = len(changes) - } - } - log.WithFields(fields).Debug("Synced new payload") - return nil -} +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/blockchain") diff --git a/beacon-chain/blockchain/log_helpers.go b/beacon-chain/blockchain/log_helpers.go new file mode 100644 index 000000000000..83d5238a5020 --- /dev/null +++ b/beacon-chain/blockchain/log_helpers.go @@ -0,0 +1,162 @@ +package blockchain + +import ( + "encoding/hex" + "fmt" + "time" + + "github.com/OffchainLabs/prysm/v7/beacon-chain/core/blocks" + "github.com/OffchainLabs/prysm/v7/config/params" + consensus_types "github.com/OffchainLabs/prysm/v7/consensus-types" + "github.com/OffchainLabs/prysm/v7/consensus-types/interfaces" + "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" + ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" + "github.com/OffchainLabs/prysm/v7/runtime/version" + prysmTime "github.com/OffchainLabs/prysm/v7/time" + "github.com/OffchainLabs/prysm/v7/time/slots" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" +) + +// logs state transition related data every slot. +func logStateTransitionData(b interfaces.ReadOnlyBeaconBlock) error { + log := log.WithField("slot", b.Slot()) + if len(b.Body().Attestations()) > 0 { + log = log.WithField("attestations", len(b.Body().Attestations())) + } + if len(b.Body().AttesterSlashings()) > 0 { + log = log.WithField("attesterSlashings", len(b.Body().AttesterSlashings())) + } + if len(b.Body().ProposerSlashings()) > 0 { + log = log.WithField("proposerSlashings", len(b.Body().ProposerSlashings())) + } + if len(b.Body().VoluntaryExits()) > 0 { + log = log.WithField("voluntaryExits", len(b.Body().VoluntaryExits())) + } + if b.Version() >= version.Altair { + agg, err := b.Body().SyncAggregate() + if err != nil { + return err + } + log = log.WithField("syncBitsCount", agg.SyncCommitteeBits.Count()) + } + if b.Version() >= version.Bellatrix { + p, err := b.Body().Execution() + if err != nil { + return err + } + log = log.WithField("payloadHash", fmt.Sprintf("%#x", bytesutil.Trunc(p.BlockHash()))) + txs, err := p.Transactions() + switch { + case errors.Is(err, consensus_types.ErrUnsupportedField): + case err != nil: + return err + default: + log = log.WithField("txCount", len(txs)) + txsPerSlotCount.Set(float64(len(txs))) + } + } + if b.Version() >= version.Deneb { + kzgs, err := b.Body().BlobKzgCommitments() + if err != nil { + log.WithError(err).Error("Failed to get blob KZG commitments") + } else if len(kzgs) > 0 { + log = log.WithField("kzgCommitmentCount", len(kzgs)) + } + } + if b.Version() >= version.Electra { + eReqs, err := b.Body().ExecutionRequests() + if err != nil { + log.WithError(err).Error("Failed to get execution requests") + } else { + if len(eReqs.Deposits) > 0 { + log = log.WithField("depositRequestCount", len(eReqs.Deposits)) + } + if len(eReqs.Consolidations) > 0 { + log = log.WithField("consolidationRequestCount", len(eReqs.Consolidations)) + } + if len(eReqs.Withdrawals) > 0 { + log = log.WithField("withdrawalRequestCount", len(eReqs.Withdrawals)) + } + } + } + log.Info("Finished applying state transition") + return nil +} + +func logBlockSyncStatus(block interfaces.ReadOnlyBeaconBlock, blockRoot [32]byte, justified, finalized *ethpb.Checkpoint, receivedTime time.Time, genesis time.Time, daWaitedTime time.Duration) error { + startTime, err := slots.StartTime(genesis, block.Slot()) + if err != nil { + return err + } + level := log.Logger.GetLevel() + if level >= logrus.DebugLevel { + parentRoot := block.ParentRoot() + lf := logrus.Fields{ + "slot": block.Slot(), + "slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch, + "block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]), + "epoch": slots.ToEpoch(block.Slot()), + "justifiedEpoch": justified.Epoch, + "justifiedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(justified.Root)[:8]), + "finalizedEpoch": finalized.Epoch, + "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), + "parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(parentRoot[:])[:8]), + "version": version.String(block.Version()), + "sinceSlotStartTime": prysmTime.Now().Sub(startTime), + "chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime) - daWaitedTime, + "dataAvailabilityWaitedTime": daWaitedTime, + } + log.WithFields(lf).Debug("Synced new block") + } else { + log.WithFields(logrus.Fields{ + "slot": block.Slot(), + "block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]), + "finalizedEpoch": finalized.Epoch, + "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), + "epoch": slots.ToEpoch(block.Slot()), + }).Info("Synced new block") + } + return nil +} + +// logs payload related data every slot. +func logPayload(block interfaces.ReadOnlyBeaconBlock) error { + isExecutionBlk, err := blocks.IsExecutionBlock(block.Body()) + if err != nil { + return errors.Wrap(err, "could not determine if block is execution block") + } + if !isExecutionBlk { + return nil + } + payload, err := block.Body().Execution() + if err != nil { + return err + } + if payload.GasLimit() == 0 { + return errors.New("gas limit should not be 0") + } + gasUtilized := float64(payload.GasUsed()) / float64(payload.GasLimit()) + fields := logrus.Fields{ + "blockHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.BlockHash())), + "parentHash": fmt.Sprintf("%#x", bytesutil.Trunc(payload.ParentHash())), + "blockNumber": payload.BlockNumber(), + "gasUtilized": fmt.Sprintf("%.2f", gasUtilized), + } + if block.Version() >= version.Capella { + withdrawals, err := payload.Withdrawals() + if err != nil { + return errors.Wrap(err, "could not get withdrawals") + } + fields["withdrawals"] = len(withdrawals) + changes, err := block.Body().BLSToExecutionChanges() + if err != nil { + return errors.Wrap(err, "could not get BLSToExecutionChanges") + } + if len(changes) > 0 { + fields["blsToExecutionChanges"] = len(changes) + } + } + log.WithFields(fields).Debug("Synced new payload") + return nil +} diff --git a/beacon-chain/blockchain/log_test.go b/beacon-chain/blockchain/log_test.go index 5f64aaa78aa5..03917944f76a 100644 --- a/beacon-chain/blockchain/log_test.go +++ b/beacon-chain/blockchain/log_test.go @@ -34,7 +34,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" prefix=blockchain slot=0", + want: "\"Finished applying state transition\" package=beacon-chain/blockchain slot=0", }, {name: "has attestation", b: func() interfaces.ReadOnlyBeaconBlock { @@ -42,7 +42,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" attestations=1 prefix=blockchain slot=0", + want: "\"Finished applying state transition\" attestations=1 package=beacon-chain/blockchain slot=0", }, {name: "has deposit", b: func() interfaces.ReadOnlyBeaconBlock { @@ -53,7 +53,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" attestations=1 prefix=blockchain slot=0", + want: "\"Finished applying state transition\" attestations=1 package=beacon-chain/blockchain slot=0", }, {name: "has attester slashing", b: func() interfaces.ReadOnlyBeaconBlock { @@ -62,7 +62,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" attesterSlashings=1 prefix=blockchain slot=0", + want: "\"Finished applying state transition\" attesterSlashings=1 package=beacon-chain/blockchain slot=0", }, {name: "has proposer slashing", b: func() interfaces.ReadOnlyBeaconBlock { @@ -71,7 +71,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" prefix=blockchain proposerSlashings=1 slot=0", + want: "\"Finished applying state transition\" package=beacon-chain/blockchain proposerSlashings=1 slot=0", }, {name: "has exit", b: func() interfaces.ReadOnlyBeaconBlock { @@ -80,7 +80,7 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" prefix=blockchain slot=0 voluntaryExits=1", + want: "\"Finished applying state transition\" package=beacon-chain/blockchain slot=0 voluntaryExits=1", }, {name: "has everything", b: func() interfaces.ReadOnlyBeaconBlock { @@ -93,11 +93,11 @@ func Test_logStateTransitionData(t *testing.T) { require.NoError(t, err) return wb }, - want: "\"Finished applying state transition\" attestations=1 attesterSlashings=1 prefix=blockchain proposerSlashings=1 slot=0 voluntaryExits=1", + want: "\"Finished applying state transition\" attestations=1 attesterSlashings=1 package=beacon-chain/blockchain proposerSlashings=1 slot=0 voluntaryExits=1", }, {name: "has payload", b: func() interfaces.ReadOnlyBeaconBlock { return wrappedPayloadBlk }, - want: "\"Finished applying state transition\" payloadHash=0x010203 prefix=blockchain slot=0 syncBitsCount=0 txCount=2", + want: "\"Finished applying state transition\" package=beacon-chain/blockchain payloadHash=0x010203 slot=0 syncBitsCount=0 txCount=2", }, } for _, tt := range tests { diff --git a/beacon-chain/blockchain/testing/BUILD.bazel b/beacon-chain/blockchain/testing/BUILD.bazel index e47969f03f06..c40bd118b6c0 100644 --- a/beacon-chain/blockchain/testing/BUILD.bazel +++ b/beacon-chain/blockchain/testing/BUILD.bazel @@ -3,7 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", testonly = True, - srcs = ["mock.go"], + srcs = [ + "log.go", + "mock.go", + ], importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/blockchain/testing", visibility = [ "//beacon-chain:__subpackages__", diff --git a/beacon-chain/blockchain/testing/log.go b/beacon-chain/blockchain/testing/log.go new file mode 100644 index 000000000000..aed45a8dec86 --- /dev/null +++ b/beacon-chain/blockchain/testing/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package testing + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/blockchain/testing") diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index f9a406bb1dd2..0fdedcc0b897 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -30,7 +30,6 @@ import ( enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1" ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) var ErrNilState = errors.New("nil state") @@ -267,7 +266,7 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interf if err := s.DB.SaveBlock(ctx, block); err != nil { return err } - logrus.Infof("Saved block with root: %#x at slot %d", signingRoot, block.Block().Slot()) + log.Infof("Saved block with root: %#x at slot %d", signingRoot, block.Block().Slot()) } s.Root = signingRoot[:] s.Block = block @@ -296,7 +295,7 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []blocks.ROBl if err := s.DB.SaveBlock(ctx, b); err != nil { return err } - logrus.Infof("Saved block with root: %#x at slot %d", signingRoot, b.Block().Slot()) + log.Infof("Saved block with root: %#x at slot %d", signingRoot, b.Block().Slot()) } s.Root = signingRoot[:] s.Block = b @@ -328,7 +327,7 @@ func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.ReadOn if err := s.DB.SaveBlock(ctx, block); err != nil { return err } - logrus.Infof("Saved block with root: %#x at slot %d", signingRoot, block.Block().Slot()) + log.Infof("Saved block with root: %#x at slot %d", signingRoot, block.Block().Slot()) } s.Root = signingRoot[:] s.Block = block @@ -585,11 +584,11 @@ func (s *ChainService) UpdateHead(ctx context.Context, slot primitives.Slot) { ojc := ðpb.Checkpoint{} st, root, err := prepareForkchoiceState(ctx, slot, bytesutil.ToBytes32(s.Root), [32]byte{}, [32]byte{}, ojc, ojc) if err != nil { - logrus.WithError(err).Error("Could not update head") + log.WithError(err).Error("Could not update head") } err = s.ForkChoiceStore.InsertNode(ctx, st, root) if err != nil { - logrus.WithError(err).Error("Could not insert node to forkchoice") + log.WithError(err).Error("Could not insert node to forkchoice") } } diff --git a/beacon-chain/builder/log.go b/beacon-chain/builder/log.go index 5c4cab050f94..7cf167fd993c 100644 --- a/beacon-chain/builder/log.go +++ b/beacon-chain/builder/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package builder import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "builder") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/builder") diff --git a/beacon-chain/cache/BUILD.bazel b/beacon-chain/cache/BUILD.bazel index a6eb511615e9..05be25d211a8 100644 --- a/beacon-chain/cache/BUILD.bazel +++ b/beacon-chain/cache/BUILD.bazel @@ -16,6 +16,7 @@ go_library( "doc.go", "error.go", "interfaces.go", + "log.go", "payload_id.go", "proposer_indices.go", "proposer_indices_disabled.go", # keep diff --git a/beacon-chain/cache/attestation.go b/beacon-chain/cache/attestation.go index 17f2ef3c61bb..eb19d56d5454 100644 --- a/beacon-chain/cache/attestation.go +++ b/beacon-chain/cache/attestation.go @@ -9,7 +9,6 @@ import ( ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1/attestation" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) type attGroup struct { diff --git a/beacon-chain/cache/committee.go b/beacon-chain/cache/committee.go index 3f0430833c94..396ebb1e61a8 100644 --- a/beacon-chain/cache/committee.go +++ b/beacon-chain/cache/committee.go @@ -17,7 +17,6 @@ import ( lru "github.com/hashicorp/golang-lru" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - log "github.com/sirupsen/logrus" ) const ( diff --git a/beacon-chain/cache/depositsnapshot/BUILD.bazel b/beacon-chain/cache/depositsnapshot/BUILD.bazel index 964a7c5b8268..81b50b4085cb 100644 --- a/beacon-chain/cache/depositsnapshot/BUILD.bazel +++ b/beacon-chain/cache/depositsnapshot/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "deposit_pruner.go", "deposit_tree.go", "deposit_tree_snapshot.go", + "log.go", "merkle_tree.go", ], importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/cache/depositsnapshot", diff --git a/beacon-chain/cache/depositsnapshot/deposit_inserter.go b/beacon-chain/cache/depositsnapshot/deposit_inserter.go index 17703edf568d..7f36e03cf264 100644 --- a/beacon-chain/cache/depositsnapshot/deposit_inserter.go +++ b/beacon-chain/cache/depositsnapshot/deposit_inserter.go @@ -20,7 +20,6 @@ var ( Name: "beacondb_all_deposits_eip4881", Help: "The number of total deposits in memory", }) - log = logrus.WithField("prefix", "cache") ) // InsertDeposit into the database. If deposit or block number are nil diff --git a/beacon-chain/cache/depositsnapshot/log.go b/beacon-chain/cache/depositsnapshot/log.go new file mode 100644 index 000000000000..11d1b8bf8818 --- /dev/null +++ b/beacon-chain/cache/depositsnapshot/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package depositsnapshot + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/cache/depositsnapshot") diff --git a/beacon-chain/cache/log.go b/beacon-chain/cache/log.go new file mode 100644 index 000000000000..c8e6f06ae543 --- /dev/null +++ b/beacon-chain/cache/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package cache + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/cache") diff --git a/beacon-chain/cache/sync_committee.go b/beacon-chain/cache/sync_committee.go index 4ba9f5730ed9..aff9a80f858e 100644 --- a/beacon-chain/cache/sync_committee.go +++ b/beacon-chain/cache/sync_committee.go @@ -11,7 +11,6 @@ import ( "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - log "github.com/sirupsen/logrus" "k8s.io/client-go/tools/cache" ) diff --git a/beacon-chain/cache/tracked_validators.go b/beacon-chain/cache/tracked_validators.go index 06a63a98ec85..33c84a8fa45e 100644 --- a/beacon-chain/cache/tracked_validators.go +++ b/beacon-chain/cache/tracked_validators.go @@ -9,7 +9,6 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/sirupsen/logrus" ) const ( @@ -67,7 +66,7 @@ func (t *TrackedValidatorsCache) Validator(index primitives.ValidatorIndex) (Tra val, ok := item.(TrackedValidator) if !ok { - logrus.Errorf("Failed to cast tracked validator from cache, got unexpected item type %T", item) + log.Errorf("Failed to cast tracked validator from cache, got unexpected item type %T", item) return TrackedValidator{}, false } @@ -113,7 +112,7 @@ func (t *TrackedValidatorsCache) Indices() map[primitives.ValidatorIndex]bool { for cacheKey := range items { index, err := fromCacheKey(cacheKey) if err != nil { - logrus.WithError(err).Error("Failed to get validator index from cache key") + log.WithError(err).Error("Failed to get validator index from cache key") continue } diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 5b87a7efa049..86cfe9f05ff4 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "deposit.go", "epoch_precompute.go", "epoch_spec.go", + "log.go", "reward.go", "sync_committee.go", "transition.go", diff --git a/beacon-chain/core/altair/epoch_spec.go b/beacon-chain/core/altair/epoch_spec.go index 352e36f41f6b..03cd06b43ad9 100644 --- a/beacon-chain/core/altair/epoch_spec.go +++ b/beacon-chain/core/altair/epoch_spec.go @@ -7,7 +7,6 @@ import ( "github.com/OffchainLabs/prysm/v7/beacon-chain/core/time" "github.com/OffchainLabs/prysm/v7/beacon-chain/state" "github.com/OffchainLabs/prysm/v7/config/params" - log "github.com/sirupsen/logrus" ) // ProcessSyncCommitteeUpdates processes sync client committee updates for the beacon state. diff --git a/beacon-chain/core/altair/log.go b/beacon-chain/core/altair/log.go new file mode 100644 index 000000000000..4e1530997751 --- /dev/null +++ b/beacon-chain/core/altair/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package altair + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/core/altair") diff --git a/beacon-chain/core/blocks/log.go b/beacon-chain/core/blocks/log.go index 07260da51ca3..230801f058e7 100644 --- a/beacon-chain/core/blocks/log.go +++ b/beacon-chain/core/blocks/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package blocks import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "blocks") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/core/blocks") diff --git a/beacon-chain/core/electra/BUILD.bazel b/beacon-chain/core/electra/BUILD.bazel index 0086f060eb60..7829e8c68a69 100644 --- a/beacon-chain/core/electra/BUILD.bazel +++ b/beacon-chain/core/electra/BUILD.bazel @@ -9,6 +9,7 @@ go_library( "deposits.go", "effective_balance_updates.go", "error.go", + "log.go", "registry_updates.go", "transition.go", "transition_no_verify_sig.go", diff --git a/beacon-chain/core/electra/consolidations.go b/beacon-chain/core/electra/consolidations.go index 603f271e290f..44fbc54ee61a 100644 --- a/beacon-chain/core/electra/consolidations.go +++ b/beacon-chain/core/electra/consolidations.go @@ -17,7 +17,6 @@ import ( "github.com/OffchainLabs/prysm/v7/time/slots" "github.com/ethereum/go-ethereum/common/math" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) // ProcessPendingConsolidations implements the spec definition below. This method makes mutating diff --git a/beacon-chain/core/electra/deposits.go b/beacon-chain/core/electra/deposits.go index 6eb80555eebc..f311f900212b 100644 --- a/beacon-chain/core/electra/deposits.go +++ b/beacon-chain/core/electra/deposits.go @@ -18,7 +18,6 @@ import ( "github.com/OffchainLabs/prysm/v7/runtime/version" "github.com/OffchainLabs/prysm/v7/time/slots" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) // ProcessDeposits is one of the operations performed on each processed diff --git a/beacon-chain/core/electra/log.go b/beacon-chain/core/electra/log.go new file mode 100644 index 000000000000..e971482bc9d2 --- /dev/null +++ b/beacon-chain/core/electra/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package electra + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/core/electra") diff --git a/beacon-chain/core/electra/withdrawals.go b/beacon-chain/core/electra/withdrawals.go index 89aa4b16ba31..4ceda644f274 100644 --- a/beacon-chain/core/electra/withdrawals.go +++ b/beacon-chain/core/electra/withdrawals.go @@ -17,7 +17,6 @@ import ( "github.com/OffchainLabs/prysm/v7/time/slots" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) // ProcessWithdrawalRequests processes the validator withdrawals from the provided execution payload diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index 86cd9684ac90..bfaeed336ed7 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "block.go", "genesis.go", "legacy.go", + "log.go", "metrics.go", "randao.go", "ranges.go", diff --git a/beacon-chain/core/helpers/log.go b/beacon-chain/core/helpers/log.go new file mode 100644 index 000000000000..874113c3a9ef --- /dev/null +++ b/beacon-chain/core/helpers/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package helpers + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/core/helpers") diff --git a/beacon-chain/core/helpers/sync_committee.go b/beacon-chain/core/helpers/sync_committee.go index 53bca04ac64b..dd1340162c84 100644 --- a/beacon-chain/core/helpers/sync_committee.go +++ b/beacon-chain/core/helpers/sync_committee.go @@ -14,7 +14,6 @@ import ( "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" "github.com/OffchainLabs/prysm/v7/time/slots" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) var ( diff --git a/beacon-chain/core/helpers/validators.go b/beacon-chain/core/helpers/validators.go index 171b484bceb0..dcfca7d3f10a 100644 --- a/beacon-chain/core/helpers/validators.go +++ b/beacon-chain/core/helpers/validators.go @@ -21,7 +21,6 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - log "github.com/sirupsen/logrus" ) var ( diff --git a/beacon-chain/core/transition/interop/log.go b/beacon-chain/core/transition/interop/log.go index 21f8e40cdbda..dc1c2f3c58ae 100644 --- a/beacon-chain/core/transition/interop/log.go +++ b/beacon-chain/core/transition/interop/log.go @@ -1,10 +1,9 @@ -// Package interop contains useful utilities for persisting -// ssz-encoded states and blocks to disk during each state -// transition for development purposes. +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package interop -import ( - "github.com/sirupsen/logrus" -) +import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "interop") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/core/transition/interop") diff --git a/beacon-chain/core/transition/log.go b/beacon-chain/core/transition/log.go index 090b6224a53d..91598fc30f44 100644 --- a/beacon-chain/core/transition/log.go +++ b/beacon-chain/core/transition/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package transition import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "state") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/core/transition") diff --git a/beacon-chain/das/BUILD.bazel b/beacon-chain/das/BUILD.bazel index 9fd326fc149f..b1c8e1121487 100644 --- a/beacon-chain/das/BUILD.bazel +++ b/beacon-chain/das/BUILD.bazel @@ -7,6 +7,7 @@ go_library( "blob_cache.go", "data_column_cache.go", "iface.go", + "log.go", "mock.go", ], importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/das", diff --git a/beacon-chain/das/availability_blobs.go b/beacon-chain/das/availability_blobs.go index 6bb8136d2113..49607e87924b 100644 --- a/beacon-chain/das/availability_blobs.go +++ b/beacon-chain/das/availability_blobs.go @@ -13,7 +13,7 @@ import ( "github.com/OffchainLabs/prysm/v7/runtime/version" "github.com/OffchainLabs/prysm/v7/time/slots" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" ) var ( @@ -112,7 +112,7 @@ func (s *LazilyPersistentStoreBlob) IsDataAvailable(ctx context.Context, current ok := errors.As(err, &me) if ok { fails := me.Failures() - lf := make(log.Fields, len(fails)) + lf := make(logrus.Fields, len(fails)) for i := range fails { lf[fmt.Sprintf("fail_%d", i)] = fails[i].Error() } diff --git a/beacon-chain/das/log.go b/beacon-chain/das/log.go new file mode 100644 index 000000000000..328cab2ae5e4 --- /dev/null +++ b/beacon-chain/das/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package das + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/das") diff --git a/beacon-chain/db/filesystem/log.go b/beacon-chain/db/filesystem/log.go index 8a85d549c67f..9cdeab09ff19 100644 --- a/beacon-chain/db/filesystem/log.go +++ b/beacon-chain/db/filesystem/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package filesystem import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "filesystem") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/db/filesystem") diff --git a/beacon-chain/db/kv/log.go b/beacon-chain/db/kv/log.go index 5c1d80880ce6..086e55288704 100644 --- a/beacon-chain/db/kv/log.go +++ b/beacon-chain/db/kv/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package kv import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "db") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/db/kv") diff --git a/beacon-chain/db/log.go b/beacon-chain/db/log.go index f320f2fe6ab7..2740265fe3d6 100644 --- a/beacon-chain/db/log.go +++ b/beacon-chain/db/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package db import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "db") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/db") diff --git a/beacon-chain/db/pruner/BUILD.bazel b/beacon-chain/db/pruner/BUILD.bazel index 26d5e32cf22e..5474232ed2f0 100644 --- a/beacon-chain/db/pruner/BUILD.bazel +++ b/beacon-chain/db/pruner/BUILD.bazel @@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["pruner.go"], + srcs = [ + "log.go", + "pruner.go", + ], importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/db/pruner", visibility = [ "//beacon-chain:__subpackages__", diff --git a/beacon-chain/db/pruner/log.go b/beacon-chain/db/pruner/log.go new file mode 100644 index 000000000000..b24b5c1b20de --- /dev/null +++ b/beacon-chain/db/pruner/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package pruner + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/db/pruner") diff --git a/beacon-chain/db/pruner/pruner.go b/beacon-chain/db/pruner/pruner.go index a078b1aab1be..118aa3aff157 100644 --- a/beacon-chain/db/pruner/pruner.go +++ b/beacon-chain/db/pruner/pruner.go @@ -13,8 +13,6 @@ import ( "github.com/sirupsen/logrus" ) -var log = logrus.WithField("prefix", "db-pruner") - const ( // defaultPrunableBatchSize is the number of slots that can be pruned at once. defaultPrunableBatchSize = 32 diff --git a/beacon-chain/db/slasherkv/log.go b/beacon-chain/db/slasherkv/log.go index bbd258122005..d2825073f0c8 100644 --- a/beacon-chain/db/slasherkv/log.go +++ b/beacon-chain/db/slasherkv/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package slasherkv import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "slasherdb") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/db/slasherkv") diff --git a/beacon-chain/execution/log.go b/beacon-chain/execution/log.go index 1d1840a9e477..ffef82774f3a 100644 --- a/beacon-chain/execution/log.go +++ b/beacon-chain/execution/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package execution import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "execution") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/execution") diff --git a/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel b/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel index 619c9fc046a9..12e5a293aff9 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel +++ b/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel @@ -7,6 +7,7 @@ go_library( "errors.go", "forkchoice.go", "last_root.go", + "log.go", "metrics.go", "node.go", "on_tick.go", diff --git a/beacon-chain/forkchoice/doubly-linked-tree/log.go b/beacon-chain/forkchoice/doubly-linked-tree/log.go new file mode 100644 index 000000000000..2954898deb25 --- /dev/null +++ b/beacon-chain/forkchoice/doubly-linked-tree/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package doublylinkedtree + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/forkchoice/doubly-linked-tree") diff --git a/beacon-chain/forkchoice/doubly-linked-tree/metrics.go b/beacon-chain/forkchoice/doubly-linked-tree/metrics.go index ed6d4ad1eb81..c6a13ed8969d 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/metrics.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/metrics.go @@ -3,12 +3,9 @@ package doublylinkedtree import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/sirupsen/logrus" ) var ( - log = logrus.WithField("prefix", "forkchoice-doublylinkedtree") - headSlotNumber = promauto.NewGauge( prometheus.GaugeOpts{ Name: "doublylinkedtree_head_slot", diff --git a/beacon-chain/light-client/log.go b/beacon-chain/light-client/log.go index 755e9b685aa7..0655c0b77095 100644 --- a/beacon-chain/light-client/log.go +++ b/beacon-chain/light-client/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package light_client import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "light-client") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/light-client") diff --git a/beacon-chain/monitor/BUILD.bazel b/beacon-chain/monitor/BUILD.bazel index de5b433c3103..8fbd58cca9a9 100644 --- a/beacon-chain/monitor/BUILD.bazel +++ b/beacon-chain/monitor/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "doc.go", + "log.go", "metrics.go", "process_attestation.go", "process_block.go", diff --git a/beacon-chain/monitor/log.go b/beacon-chain/monitor/log.go new file mode 100644 index 000000000000..2333b4db93b4 --- /dev/null +++ b/beacon-chain/monitor/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package monitor + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/monitor") diff --git a/beacon-chain/monitor/metrics.go b/beacon-chain/monitor/metrics.go index a45fb5c98396..a7bc9a9b864b 100644 --- a/beacon-chain/monitor/metrics.go +++ b/beacon-chain/monitor/metrics.go @@ -3,11 +3,9 @@ package monitor import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - "github.com/sirupsen/logrus" ) var ( - log = logrus.WithField("prefix", "monitor") // TODO: The Prometheus gauge vectors and counters in this package deprecate the // corresponding gauge vectors and counters in the validator client. diff --git a/beacon-chain/monitor/process_attestation_test.go b/beacon-chain/monitor/process_attestation_test.go index fcd4665e1c99..88907bdf881d 100644 --- a/beacon-chain/monitor/process_attestation_test.go +++ b/beacon-chain/monitor/process_attestation_test.go @@ -54,8 +54,8 @@ func TestProcessIncludedAttestationTwoTracked(t *testing.T) { AggregationBits: bitfield.Bitlist{0b11, 0b1}, } s.processIncludedAttestation(t.Context(), state, att) - wanted1 := "\"Attestation included\" balanceChange=0 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2" - wanted2 := "\"Attestation included\" balanceChange=100000000 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12" + wanted1 := "\"Attestation included\" balanceChange=0 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2" + wanted2 := "\"Attestation included\" balanceChange=100000000 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12" require.LogsContain(t, hook, wanted1) require.LogsContain(t, hook, wanted2) } @@ -123,8 +123,8 @@ func TestProcessUnaggregatedAttestationStateCached(t *testing.T) { } require.NoError(t, s.config.StateGen.SaveState(ctx, root, state)) s.processUnaggregatedAttestation(t.Context(), att) - wanted1 := "\"Processed unaggregated attestation\" head=0x68656c6c6f2d prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2" - wanted2 := "\"Processed unaggregated attestation\" head=0x68656c6c6f2d prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12" + wanted1 := "\"Processed unaggregated attestation\" head=0x68656c6c6f2d package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2" + wanted2 := "\"Processed unaggregated attestation\" head=0x68656c6c6f2d package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12" require.LogsContain(t, hook, wanted1) require.LogsContain(t, hook, wanted2) } @@ -161,7 +161,7 @@ func TestProcessAggregatedAttestationStateNotCached(t *testing.T) { }, } s.processAggregatedAttestation(ctx, att) - require.LogsContain(t, hook, "\"Processed attestation aggregation\" aggregatorIndex=2 beaconBlockRoot=0x000000000000 prefix=monitor slot=1 sourceRoot=0x68656c6c6f2d targetRoot=0x68656c6c6f2d") + require.LogsContain(t, hook, "\"Processed attestation aggregation\" aggregatorIndex=2 beaconBlockRoot=0x000000000000 package=beacon-chain/monitor slot=1 sourceRoot=0x68656c6c6f2d targetRoot=0x68656c6c6f2d") require.LogsContain(t, hook, "Skipping aggregated attestation due to state not found in cache") logrus.SetLevel(logrus.InfoLevel) } @@ -199,9 +199,9 @@ func TestProcessAggregatedAttestationStateCached(t *testing.T) { require.NoError(t, s.config.StateGen.SaveState(ctx, root, state)) s.processAggregatedAttestation(ctx, att) - require.LogsContain(t, hook, "\"Processed attestation aggregation\" aggregatorIndex=2 beaconBlockRoot=0x68656c6c6f2d prefix=monitor slot=1 sourceRoot=0x68656c6c6f2d targetRoot=0x68656c6c6f2d") - require.LogsContain(t, hook, "\"Processed aggregated attestation\" head=0x68656c6c6f2d prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2") - require.LogsDoNotContain(t, hook, "\"Processed aggregated attestation\" head=0x68656c6c6f2d prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12") + require.LogsContain(t, hook, "\"Processed attestation aggregation\" aggregatorIndex=2 beaconBlockRoot=0x68656c6c6f2d package=beacon-chain/monitor slot=1 sourceRoot=0x68656c6c6f2d targetRoot=0x68656c6c6f2d") + require.LogsContain(t, hook, "\"Processed aggregated attestation\" head=0x68656c6c6f2d package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2") + require.LogsDoNotContain(t, hook, "\"Processed aggregated attestation\" head=0x68656c6c6f2d package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12") } func TestProcessAttestations(t *testing.T) { @@ -239,8 +239,8 @@ func TestProcessAttestations(t *testing.T) { wrappedBlock, err := blocks.NewBeaconBlock(block) require.NoError(t, err) s.processAttestations(ctx, state, wrappedBlock) - wanted1 := "\"Attestation included\" balanceChange=0 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2" - wanted2 := "\"Attestation included\" balanceChange=100000000 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 prefix=monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12" + wanted1 := "\"Attestation included\" balanceChange=0 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=2" + wanted2 := "\"Attestation included\" balanceChange=100000000 correctHead=true correctSource=true correctTarget=true head=0x68656c6c6f2d inclusionSlot=2 newBalance=32000000000 package=beacon-chain/monitor slot=1 source=0x68656c6c6f2d target=0x68656c6c6f2d validatorIndex=12" require.LogsContain(t, hook, wanted1) require.LogsContain(t, hook, wanted2) diff --git a/beacon-chain/monitor/process_block_test.go b/beacon-chain/monitor/process_block_test.go index 7000d5eac27e..5734fc1cca7c 100644 --- a/beacon-chain/monitor/process_block_test.go +++ b/beacon-chain/monitor/process_block_test.go @@ -43,7 +43,7 @@ func TestProcessSlashings(t *testing.T) { }, }, }, - wantedErr: "\"Proposer slashing was included\" bodyRoot1= bodyRoot2= prefix=monitor proposerIndex=2", + wantedErr: "\"Proposer slashing was included\" bodyRoot1= bodyRoot2= package=beacon-chain/monitor proposerIndex=2", }, { name: "Proposer slashing an untracked index", @@ -89,7 +89,7 @@ func TestProcessSlashings(t *testing.T) { }, }, wantedErr: "\"Attester slashing was included\" attestationSlot1=0 attestationSlot2=0 attesterIndex=1 " + - "beaconBlockRoot1=0x000000000000 beaconBlockRoot2=0x000000000000 blockInclusionSlot=0 prefix=monitor sourceEpoch1=1 sourceEpoch2=0 targetEpoch1=0 targetEpoch2=0", + "beaconBlockRoot1=0x000000000000 beaconBlockRoot2=0x000000000000 blockInclusionSlot=0 package=beacon-chain/monitor sourceEpoch1=1 sourceEpoch2=0 targetEpoch1=0 targetEpoch2=0", }, { name: "Attester slashing untracked index", @@ -149,7 +149,7 @@ func TestProcessProposedBlock(t *testing.T) { StateRoot: bytesutil.PadTo([]byte("state-world"), 32), Body: ðpb.BeaconBlockBody{}, }, - wantedErr: "\"Proposed beacon block was included\" balanceChange=100000000 blockRoot=0x68656c6c6f2d newBalance=32000000000 parentRoot=0x68656c6c6f2d prefix=monitor proposerIndex=12 slot=6 version=0", + wantedErr: "\"Proposed beacon block was included\" balanceChange=100000000 blockRoot=0x68656c6c6f2d newBalance=32000000000 package=beacon-chain/monitor parentRoot=0x68656c6c6f2d proposerIndex=12 slot=6 version=0", }, { name: "Block proposed by untracked validator", @@ -224,10 +224,10 @@ func TestProcessBlock_AllEventsTrackedVals(t *testing.T) { root, err := b.GetBlock().HashTreeRoot() require.NoError(t, err) require.NoError(t, s.config.StateGen.SaveState(ctx, root, genesis)) - wanted1 := fmt.Sprintf("\"Proposed beacon block was included\" balanceChange=100000000 blockRoot=%#x newBalance=32000000000 parentRoot=0xf732eaeb7fae prefix=monitor proposerIndex=15 slot=1 version=1", bytesutil.Trunc(root[:])) - wanted2 := fmt.Sprintf("\"Proposer slashing was included\" bodyRoot1=0x000100000000 bodyRoot2=0x000200000000 prefix=monitor proposerIndex=%d slashingSlot=0 slot=1", idx) - wanted3 := "\"Sync committee contribution included\" balanceChange=0 contribCount=3 expectedContribCount=3 newBalance=32000000000 prefix=monitor validatorIndex=1" - wanted4 := "\"Sync committee contribution included\" balanceChange=0 contribCount=1 expectedContribCount=1 newBalance=32000000000 prefix=monitor validatorIndex=2" + wanted1 := fmt.Sprintf("\"Proposed beacon block was included\" balanceChange=100000000 blockRoot=%#x newBalance=32000000000 package=beacon-chain/monitor parentRoot=0xf732eaeb7fae proposerIndex=15 slot=1 version=1", bytesutil.Trunc(root[:])) + wanted2 := fmt.Sprintf("\"Proposer slashing was included\" bodyRoot1=0x000100000000 bodyRoot2=0x000200000000 package=beacon-chain/monitor proposerIndex=%d slashingSlot=0 slot=1", idx) + wanted3 := "\"Sync committee contribution included\" balanceChange=0 contribCount=3 expectedContribCount=3 newBalance=32000000000 package=beacon-chain/monitor validatorIndex=1" + wanted4 := "\"Sync committee contribution included\" balanceChange=0 contribCount=1 expectedContribCount=1 newBalance=32000000000 package=beacon-chain/monitor validatorIndex=2" wrapped, err := blocks.NewSignedBeaconBlock(b) require.NoError(t, err) s.processBlock(ctx, wrapped) @@ -279,7 +279,7 @@ func TestLogAggregatedPerformance(t *testing.T) { s.logAggregatedPerformance() wanted := "\"Aggregated performance since launch\" attestationInclusion=\"80.00%\"" + " averageInclusionDistance=1.2 balanceChangePct=\"0.95%\" correctlyVotedHeadPct=\"66.67%\" " + - "correctlyVotedSourcePct=\"91.67%\" correctlyVotedTargetPct=\"100.00%\" prefix=monitor startBalance=31700000000 " + + "correctlyVotedSourcePct=\"91.67%\" correctlyVotedTargetPct=\"100.00%\" package=beacon-chain/monitor startBalance=31700000000 " + "startEpoch=0 totalAggregations=0 totalProposedBlocks=1 totalRequested=15 totalSyncContributions=0 " + "validatorIndex=1" require.LogsContain(t, hook, wanted) diff --git a/beacon-chain/monitor/process_exit_test.go b/beacon-chain/monitor/process_exit_test.go index 0375463c136b..e1db6c2ad25b 100644 --- a/beacon-chain/monitor/process_exit_test.go +++ b/beacon-chain/monitor/process_exit_test.go @@ -43,7 +43,7 @@ func TestProcessExitsFromBlockTrackedIndices(t *testing.T) { wb, err := blocks.NewBeaconBlock(block) require.NoError(t, err) s.processExitsFromBlock(wb) - require.LogsContain(t, hook, "\"Voluntary exit was included\" prefix=monitor slot=0 validatorIndex=2") + require.LogsContain(t, hook, "\"Voluntary exit was included\" package=beacon-chain/monitor slot=0 validatorIndex=2") } func TestProcessExitsFromBlockUntrackedIndices(t *testing.T) { @@ -99,7 +99,7 @@ func TestProcessExitP2PTrackedIndices(t *testing.T) { Signature: make([]byte, 96), } s.processExit(exit) - require.LogsContain(t, hook, "\"Voluntary exit was processed\" prefix=monitor validatorIndex=1") + require.LogsContain(t, hook, "\"Voluntary exit was processed\" package=beacon-chain/monitor validatorIndex=1") } func TestProcessExitP2PUntrackedIndices(t *testing.T) { diff --git a/beacon-chain/monitor/process_sync_committee_test.go b/beacon-chain/monitor/process_sync_committee_test.go index a1365f9aa56a..a2d6b55168a6 100644 --- a/beacon-chain/monitor/process_sync_committee_test.go +++ b/beacon-chain/monitor/process_sync_committee_test.go @@ -22,7 +22,7 @@ func TestProcessSyncCommitteeContribution(t *testing.T) { } s.processSyncCommitteeContribution(contrib) - require.LogsContain(t, hook, "\"Sync committee aggregation processed\" prefix=monitor validatorIndex=1") + require.LogsContain(t, hook, "\"Sync committee aggregation processed\" package=beacon-chain/monitor validatorIndex=1") require.LogsDoNotContain(t, hook, "validatorIndex=2") } @@ -53,7 +53,7 @@ func TestProcessSyncAggregate(t *testing.T) { require.NoError(t, err) s.processSyncAggregate(beaconState, wrappedBlock) - require.LogsContain(t, hook, "\"Sync committee contribution included\" balanceChange=0 contribCount=1 expectedContribCount=4 newBalance=32000000000 prefix=monitor validatorIndex=1") - require.LogsContain(t, hook, "\"Sync committee contribution included\" balanceChange=100000000 contribCount=2 expectedContribCount=2 newBalance=32000000000 prefix=monitor validatorIndex=12") + require.LogsContain(t, hook, "\"Sync committee contribution included\" balanceChange=0 contribCount=1 expectedContribCount=4 newBalance=32000000000 package=beacon-chain/monitor validatorIndex=1") + require.LogsContain(t, hook, "\"Sync committee contribution included\" balanceChange=100000000 contribCount=2 expectedContribCount=2 newBalance=32000000000 package=beacon-chain/monitor validatorIndex=12") require.LogsDoNotContain(t, hook, "validatorIndex=2") } diff --git a/beacon-chain/monitor/service_test.go b/beacon-chain/monitor/service_test.go index 0e83bd46c281..e6004ee8e0b9 100644 --- a/beacon-chain/monitor/service_test.go +++ b/beacon-chain/monitor/service_test.go @@ -148,7 +148,7 @@ func TestStart(t *testing.T) { // wait for Logrus time.Sleep(1000 * time.Millisecond) require.LogsContain(t, hook, "Synced to head epoch, starting reporting performance") - require.LogsContain(t, hook, "\"Starting service\" prefix=monitor validatorIndices=\"[1 2 12 15]\"") + require.LogsContain(t, hook, "\"Starting service\" package=beacon-chain/monitor validatorIndices=\"[1 2 12 15]\"") s.Lock() require.Equal(t, s.isLogging, true, "monitor is not running") s.Unlock() @@ -235,7 +235,7 @@ func TestMonitorRoutine(t *testing.T) { // Wait for Logrus time.Sleep(1000 * time.Millisecond) - wanted1 := fmt.Sprintf("\"Proposed beacon block was included\" balanceChange=100000000 blockRoot=%#x newBalance=32000000000 parentRoot=0xf732eaeb7fae prefix=monitor proposerIndex=15 slot=1 version=1", bytesutil.Trunc(root[:])) + wanted1 := fmt.Sprintf("\"Proposed beacon block was included\" balanceChange=100000000 blockRoot=%#x newBalance=32000000000 package=beacon-chain/monitor parentRoot=0xf732eaeb7fae proposerIndex=15 slot=1 version=1", bytesutil.Trunc(root[:])) require.LogsContain(t, hook, wanted1) } diff --git a/beacon-chain/node/log.go b/beacon-chain/node/log.go index 2c3b06e82296..8e5e0ee0321e 100644 --- a/beacon-chain/node/log.go +++ b/beacon-chain/node/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package node import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "node") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/node") diff --git a/beacon-chain/node/registration/log.go b/beacon-chain/node/registration/log.go index 0e3ed0b8e3cc..cbf6740f5706 100644 --- a/beacon-chain/node/registration/log.go +++ b/beacon-chain/node/registration/log.go @@ -1 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package registration + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/node/registration") diff --git a/beacon-chain/node/registration/p2p.go b/beacon-chain/node/registration/p2p.go index 3fdabfc7a589..a864f8e355a2 100644 --- a/beacon-chain/node/registration/p2p.go +++ b/beacon-chain/node/registration/p2p.go @@ -7,7 +7,6 @@ import ( "github.com/OffchainLabs/prysm/v7/cmd" "github.com/OffchainLabs/prysm/v7/config/params" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "gopkg.in/yaml.v2" ) diff --git a/beacon-chain/operations/attestations/kv/BUILD.bazel b/beacon-chain/operations/attestations/kv/BUILD.bazel index f2251084da7b..1cfdac868e26 100644 --- a/beacon-chain/operations/attestations/kv/BUILD.bazel +++ b/beacon-chain/operations/attestations/kv/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "aggregated.go", "block.go", "kv.go", + "log.go", "seen_bits.go", "unaggregated.go", ], diff --git a/beacon-chain/operations/attestations/kv/aggregated.go b/beacon-chain/operations/attestations/kv/aggregated.go index 3339f36d89ae..8a5b021af3e6 100644 --- a/beacon-chain/operations/attestations/kv/aggregated.go +++ b/beacon-chain/operations/attestations/kv/aggregated.go @@ -13,7 +13,6 @@ import ( attaggregation "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1/attestation/aggregation/attestations" "github.com/OffchainLabs/prysm/v7/runtime/version" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) // AggregateUnaggregatedAttestations aggregates the unaggregated attestations and saves the diff --git a/beacon-chain/operations/attestations/kv/log.go b/beacon-chain/operations/attestations/kv/log.go new file mode 100644 index 000000000000..2d407204b6a5 --- /dev/null +++ b/beacon-chain/operations/attestations/kv/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package kv + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/operations/attestations/kv") diff --git a/beacon-chain/operations/attestations/kv/unaggregated.go b/beacon-chain/operations/attestations/kv/unaggregated.go index dc258b84b77e..bb4190712eaa 100644 --- a/beacon-chain/operations/attestations/kv/unaggregated.go +++ b/beacon-chain/operations/attestations/kv/unaggregated.go @@ -9,7 +9,6 @@ import ( "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1/attestation" "github.com/OffchainLabs/prysm/v7/runtime/version" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" ) // SaveUnaggregatedAttestation saves an unaggregated attestation in cache. diff --git a/beacon-chain/operations/attestations/log.go b/beacon-chain/operations/attestations/log.go index 9a30bf344e06..95b310dfdc65 100644 --- a/beacon-chain/operations/attestations/log.go +++ b/beacon-chain/operations/attestations/log.go @@ -1,7 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package attestations -import ( - "github.com/sirupsen/logrus" -) +import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "pool/attestations") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/operations/attestations") diff --git a/beacon-chain/operations/blstoexec/BUILD.bazel b/beacon-chain/operations/blstoexec/BUILD.bazel index 4fcc38d76054..3a74fce40895 100644 --- a/beacon-chain/operations/blstoexec/BUILD.bazel +++ b/beacon-chain/operations/blstoexec/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "doc.go", + "log.go", "pool.go", ], importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/operations/blstoexec", diff --git a/beacon-chain/operations/blstoexec/log.go b/beacon-chain/operations/blstoexec/log.go new file mode 100644 index 000000000000..cbcded494116 --- /dev/null +++ b/beacon-chain/operations/blstoexec/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package blstoexec + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/operations/blstoexec") diff --git a/beacon-chain/operations/slashings/log.go b/beacon-chain/operations/slashings/log.go index 7c2a498e5db8..17419dc1c42c 100644 --- a/beacon-chain/operations/slashings/log.go +++ b/beacon-chain/operations/slashings/log.go @@ -1,7 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package slashings -import ( - "github.com/sirupsen/logrus" -) +import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "pool/slashings") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/operations/slashings") diff --git a/beacon-chain/operations/voluntaryexits/BUILD.bazel b/beacon-chain/operations/voluntaryexits/BUILD.bazel index 5a76900e8ede..7968a45205c4 100644 --- a/beacon-chain/operations/voluntaryexits/BUILD.bazel +++ b/beacon-chain/operations/voluntaryexits/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "doc.go", + "log.go", "pool.go", ], importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/operations/voluntaryexits", diff --git a/beacon-chain/operations/voluntaryexits/log.go b/beacon-chain/operations/voluntaryexits/log.go new file mode 100644 index 000000000000..db584d7f0c1a --- /dev/null +++ b/beacon-chain/operations/voluntaryexits/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package voluntaryexits + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/operations/voluntaryexits") diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 5f7866fad472..06b5a2f42136 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -19,6 +19,7 @@ go_library( "info.go", "interfaces.go", "log.go", + "log_helpers.go", "message_id.go", "monitoring.go", "options.go", diff --git a/beacon-chain/p2p/log.go b/beacon-chain/p2p/log.go index bc848a1dbbd4..6f4aa218117b 100644 --- a/beacon-chain/p2p/log.go +++ b/beacon-chain/p2p/log.go @@ -1,54 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package p2p -import ( - "net" - "strconv" - "strings" +import "github.com/sirupsen/logrus" - "github.com/libp2p/go-libp2p/core/peer" - ma "github.com/multiformats/go-multiaddr" - "github.com/sirupsen/logrus" -) - -var log = logrus.WithField("prefix", "p2p") - -func logIPAddr(id peer.ID, addrs ...ma.Multiaddr) { - for _, addr := range addrs { - if !(strings.Contains(addr.String(), "/ip4/") || strings.Contains(addr.String(), "/ip6/")) { - continue - } - - log.WithField( - "multiAddr", - addr.String()+"/p2p/"+id.String(), - ).Info("Node started p2p server") - } -} - -func logExternalIPAddr(id peer.ID, addr string, tcpPort, quicPort uint) { - if addr != "" { - multiAddrs, err := MultiAddressBuilder(net.ParseIP(addr), tcpPort, quicPort) - if err != nil { - log.WithError(err).Error("Could not create multiaddress") - return - } - - for _, multiAddr := range multiAddrs { - log.WithField( - "multiAddr", - multiAddr.String()+"/p2p/"+id.String(), - ).Info("Node started external p2p server") - } - } -} - -func logExternalDNSAddr(id peer.ID, addr string, port uint) { - if addr != "" { - p := strconv.FormatUint(uint64(port), 10) - - log.WithField( - "multiAddr", - "/dns4/"+addr+"/tcp/"+p+"/p2p/"+id.String(), - ).Info("Node started external p2p server") - } -} +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/p2p") diff --git a/beacon-chain/p2p/log_helpers.go b/beacon-chain/p2p/log_helpers.go new file mode 100644 index 000000000000..d402b0fbb5d8 --- /dev/null +++ b/beacon-chain/p2p/log_helpers.go @@ -0,0 +1,51 @@ +package p2p + +import ( + "net" + "strconv" + "strings" + + "github.com/libp2p/go-libp2p/core/peer" + ma "github.com/multiformats/go-multiaddr" +) + +func logIPAddr(id peer.ID, addrs ...ma.Multiaddr) { + for _, addr := range addrs { + if !(strings.Contains(addr.String(), "/ip4/") || strings.Contains(addr.String(), "/ip6/")) { + continue + } + + log.WithField( + "multiAddr", + addr.String()+"/p2p/"+id.String(), + ).Info("Node started p2p server") + } +} + +func logExternalIPAddr(id peer.ID, addr string, tcpPort, quicPort uint) { + if addr != "" { + multiAddrs, err := MultiAddressBuilder(net.ParseIP(addr), tcpPort, quicPort) + if err != nil { + log.WithError(err).Error("Could not create multiaddress") + return + } + + for _, multiAddr := range multiAddrs { + log.WithField( + "multiAddr", + multiAddr.String()+"/p2p/"+id.String(), + ).Info("Node started external p2p server") + } + } +} + +func logExternalDNSAddr(id peer.ID, addr string, port uint) { + if addr != "" { + p := strconv.FormatUint(uint64(port), 10) + + log.WithField( + "multiAddr", + "/dns4/"+addr+"/tcp/"+p+"/p2p/"+id.String(), + ).Info("Node started external p2p server") + } +} diff --git a/beacon-chain/p2p/peers/log.go b/beacon-chain/p2p/peers/log.go index eca49d07c11f..27941f4c5620 100644 --- a/beacon-chain/p2p/peers/log.go +++ b/beacon-chain/p2p/peers/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package peers import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "peers") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/p2p/peers") diff --git a/beacon-chain/rpc/core/log.go b/beacon-chain/rpc/core/log.go index 6fa185587184..4d73afc2aea0 100644 --- a/beacon-chain/rpc/core/log.go +++ b/beacon-chain/rpc/core/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package core import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "rpc/core") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc/core") diff --git a/beacon-chain/rpc/eth/beacon/log.go b/beacon-chain/rpc/eth/beacon/log.go index b13781302afd..d062044b0a2e 100644 --- a/beacon-chain/rpc/eth/beacon/log.go +++ b/beacon-chain/rpc/eth/beacon/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package beacon import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "rpc/beaconv1") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc/eth/beacon") diff --git a/beacon-chain/rpc/eth/events/events_test.go b/beacon-chain/rpc/eth/events/events_test.go index f34181f00365..284c33190540 100644 --- a/beacon-chain/rpc/eth/events/events_test.go +++ b/beacon-chain/rpc/eth/events/events_test.go @@ -36,6 +36,7 @@ import ( ) var testEventWriteTimeout = 100 * time.Millisecond +var logger = logrus.StandardLogger() func requireAllEventsReceived(t *testing.T, stn, opn *mockChain.EventFeedWrapper, events []*feed.Event, req *topicRequest, s *Server, w *StreamingResponseWriterRecorder, logs chan *logrus.Entry) { // maxBufferSize param copied from sse lib client code diff --git a/beacon-chain/rpc/eth/events/log.go b/beacon-chain/rpc/eth/events/log.go index 6d218a4f034a..543facfbc66a 100644 --- a/beacon-chain/rpc/eth/events/log.go +++ b/beacon-chain/rpc/eth/events/log.go @@ -1,6 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package events import "github.com/sirupsen/logrus" -var logger = logrus.StandardLogger() -var log = logger.WithField("prefix", "events") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc/eth/events") diff --git a/beacon-chain/rpc/eth/validator/log.go b/beacon-chain/rpc/eth/validator/log.go index de331ebcf670..8bfd2739d87e 100644 --- a/beacon-chain/rpc/eth/validator/log.go +++ b/beacon-chain/rpc/eth/validator/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package validator import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "beacon-api") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc/eth/validator") diff --git a/beacon-chain/rpc/log.go b/beacon-chain/rpc/log.go index 5c2ea5ccf32e..4f697a1b74e0 100644 --- a/beacon-chain/rpc/log.go +++ b/beacon-chain/rpc/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package rpc import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "rpc") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc") diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/log.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/log.go index 99ec18c4db23..6d241c27565b 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/log.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package beacon import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "rpc") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc/prysm/v1alpha1/beacon") diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/log.go b/beacon-chain/rpc/prysm/v1alpha1/validator/log.go index 43f3b2870b80..2be7cdffc03c 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/log.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package validator import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "rpc/validator") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/rpc/prysm/v1alpha1/validator") diff --git a/beacon-chain/slasher/log.go b/beacon-chain/slasher/log.go index d45613e76e50..d9c69638974d 100644 --- a/beacon-chain/slasher/log.go +++ b/beacon-chain/slasher/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package slasher import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "slasher") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/slasher") diff --git a/beacon-chain/state/stategen/log.go b/beacon-chain/state/stategen/log.go index b3414dc6cf66..0225f47e2d9d 100644 --- a/beacon-chain/state/stategen/log.go +++ b/beacon-chain/state/stategen/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package stategen import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "state-gen") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/state/stategen") diff --git a/beacon-chain/state/stateutil/BUILD.bazel b/beacon-chain/state/stateutil/BUILD.bazel index 7d711446b2b2..ebb36a0d5cac 100644 --- a/beacon-chain/state/stateutil/BUILD.bazel +++ b/beacon-chain/state/stateutil/BUILD.bazel @@ -13,6 +13,7 @@ go_library( "field_root_validator.go", "field_root_vector.go", "historical_summaries_root.go", + "log.go", "participation_bit_root.go", "pending_attestation_root.go", "pending_consolidations_root.go", diff --git a/beacon-chain/state/stateutil/log.go b/beacon-chain/state/stateutil/log.go new file mode 100644 index 000000000000..4464e2aafc37 --- /dev/null +++ b/beacon-chain/state/stateutil/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package stateutil + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/state/stateutil") diff --git a/beacon-chain/sync/backfill/log.go b/beacon-chain/sync/backfill/log.go index 9d88c5f24804..b3298c9f93ce 100644 --- a/beacon-chain/sync/backfill/log.go +++ b/beacon-chain/sync/backfill/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package backfill import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "backfill") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/sync/backfill") diff --git a/beacon-chain/sync/checkpoint/log.go b/beacon-chain/sync/checkpoint/log.go index 3cf5fad74cb2..3d16723484b2 100644 --- a/beacon-chain/sync/checkpoint/log.go +++ b/beacon-chain/sync/checkpoint/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package checkpoint import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "checkpoint-sync") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/sync/checkpoint") diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go index e7fef8674c20..1dffd6bb0d8a 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go @@ -601,7 +601,7 @@ func TestBlocksFetcher_RequestBlocksRateLimitingLocks(t *testing.T) { // p3 responded w/o waiting for rate limiter's lock (on which p2 spins). } // Make sure that p2 has been rate limited. - require.LogsContain(t, hook, fmt.Sprintf("msg=\"Slowing down for rate limit\" peer=%s", p2.PeerID())) + require.LogsContain(t, hook, fmt.Sprintf("msg=\"Slowing down for rate limit\" package=beacon-chain/sync/initial-sync peer=%s", p2.PeerID())) } func TestBlocksFetcher_WaitForBandwidth(t *testing.T) { diff --git a/beacon-chain/sync/initial-sync/log.go b/beacon-chain/sync/initial-sync/log.go index 1f79b69d6e65..12bdc2390b67 100644 --- a/beacon-chain/sync/initial-sync/log.go +++ b/beacon-chain/sync/initial-sync/log.go @@ -1,7 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package initialsync -import ( - "github.com/sirupsen/logrus" -) +import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "initial-sync") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/sync/initial-sync") diff --git a/beacon-chain/sync/log.go b/beacon-chain/sync/log.go index 5ad819f5c443..166efd4e8158 100644 --- a/beacon-chain/sync/log.go +++ b/beacon-chain/sync/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package sync import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "sync") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/sync") diff --git a/beacon-chain/verification/log.go b/beacon-chain/verification/log.go index d49834803f7c..d9d7ae032748 100644 --- a/beacon-chain/verification/log.go +++ b/beacon-chain/verification/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package verification import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "verification") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "beacon-chain/verification") diff --git a/changelog/bastin_logrus-hooks-add.md b/changelog/bastin_logrus-hooks-add.md new file mode 100644 index 000000000000..4bc52321af8c --- /dev/null +++ b/changelog/bastin_logrus-hooks-add.md @@ -0,0 +1,4 @@ +### Added + +- Added separate logrus hooks for handling the formatting and output of terminal logs vs log-file logs, instead of the + default logrus output. \ No newline at end of file diff --git a/changelog/bastin_switch-logging-to-packaga-path.md b/changelog/bastin_switch-logging-to-packaga-path.md new file mode 100644 index 000000000000..c148c4b2b618 --- /dev/null +++ b/changelog/bastin_switch-logging-to-packaga-path.md @@ -0,0 +1,6 @@ +### Changed + +- Added a log.go file for every important package with a logger variable containing a `package` field set to the package + path. +- Added a CI check to ensure every important package has a log.go file with the correct `package` field. +- Changed the log formatter to use this `package` field instead of the previous `prefix` field. \ No newline at end of file diff --git a/cmd/beacon-chain/main.go b/cmd/beacon-chain/main.go index 21c43f01b83f..e5a46fb60d4e 100644 --- a/cmd/beacon-chain/main.go +++ b/cmd/beacon-chain/main.go @@ -4,6 +4,7 @@ package main import ( "context" "fmt" + "io" "os" "path/filepath" runtimeDebug "runtime/debug" @@ -170,14 +171,20 @@ func before(ctx *cli.Context) error { switch format { case "text": + // disabling logrus default output so we can control it via different hooks + logrus.SetOutput(io.Discard) + + // create a custom formatter and hook for terminal output formatter := new(prefixed.TextFormatter) formatter.TimestampFormat = "2006-01-02 15:04:05.00" formatter.FullTimestamp = true + formatter.ForceFormatting = true + formatter.ForceColors = true - // If persistent log files are written - we disable the log messages coloring because - // the colors are ANSI codes and seen as gibberish in the log files. - formatter.DisableColors = ctx.String(cmd.LogFileName.Name) != "" - logrus.SetFormatter(formatter) + logrus.AddHook(&logs.WriterHook{ + Formatter: formatter, + Writer: os.Stderr, + }) case "fluentd": f := joonix.NewFormatter() diff --git a/cmd/validator/main.go b/cmd/validator/main.go index 284df48efd4d..18406a6f7265 100644 --- a/cmd/validator/main.go +++ b/cmd/validator/main.go @@ -5,6 +5,7 @@ package main import ( "fmt" + "io" "os" "path/filepath" runtimeDebug "runtime/debug" @@ -151,13 +152,20 @@ func main() { format := ctx.String(cmd.LogFormat.Name) switch format { case "text": + // disabling logrus default output so we can control it via different hooks + logrus.SetOutput(io.Discard) + + // create a custom formatter and hook for terminal output formatter := new(prefixed.TextFormatter) formatter.TimestampFormat = "2006-01-02 15:04:05.00" formatter.FullTimestamp = true - // If persistent log files are written - we disable the log messages coloring because - // the colors are ANSI codes and seen as gibberish in the log files. - formatter.DisableColors = logFileName != "" - logrus.SetFormatter(formatter) + formatter.ForceFormatting = true + formatter.ForceColors = true + + logrus.AddHook(&logs.WriterHook{ + Formatter: formatter, + Writer: os.Stderr, + }) case "fluentd": f := joonix.NewFormatter() if err := joonix.DisableTimestampFormat(f); err != nil { diff --git a/config/BUILD.bazel b/config/BUILD.bazel index e2baca572fc5..c8bfdb7e2c84 100644 --- a/config/BUILD.bazel +++ b/config/BUILD.bazel @@ -16,7 +16,10 @@ config_setting( go_library( name = "go_default_library", - srcs = ["util.go"], + srcs = [ + "log.go", + "util.go", + ], importpath = "github.com/OffchainLabs/prysm/v7/config", visibility = ["//visibility:public"], deps = [ diff --git a/config/features/BUILD.bazel b/config/features/BUILD.bazel index 93a4d9dbc7f3..4fe901ebfcb5 100644 --- a/config/features/BUILD.bazel +++ b/config/features/BUILD.bazel @@ -7,6 +7,7 @@ go_library( "deprecated_flags.go", "filter_flags.go", "flags.go", + "log.go", ], importpath = "github.com/OffchainLabs/prysm/v7/config/features", visibility = ["//visibility:public"], diff --git a/config/features/config.go b/config/features/config.go index c641cdda6be8..bf00b1ca9904 100644 --- a/config/features/config.go +++ b/config/features/config.go @@ -28,12 +28,9 @@ import ( "github.com/OffchainLabs/prysm/v7/cmd" "github.com/OffchainLabs/prysm/v7/config/params" "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) -var log = logrus.WithField("prefix", "flags") - const enabledFeatureFlag = "Enabled feature flag" const disabledFeatureFlag = "Disabled feature flag" diff --git a/config/features/log.go b/config/features/log.go new file mode 100644 index 000000000000..a5f25ffa8a26 --- /dev/null +++ b/config/features/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package features + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "config/features") diff --git a/config/log.go b/config/log.go new file mode 100644 index 000000000000..7c615b880074 --- /dev/null +++ b/config/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package config + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "config") diff --git a/config/params/log.go b/config/params/log.go index 355f415c38b5..56323bd19cbc 100644 --- a/config/params/log.go +++ b/config/params/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package params import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "params") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "config/params") diff --git a/config/proposer/loader/BUILD.bazel b/config/proposer/loader/BUILD.bazel index ef18044bbac0..d69415563762 100644 --- a/config/proposer/loader/BUILD.bazel +++ b/config/proposer/loader/BUILD.bazel @@ -26,7 +26,10 @@ go_test( go_library( name = "go_default_library", - srcs = ["loader.go"], + srcs = [ + "loader.go", + "log.go", + ], importpath = "github.com/OffchainLabs/prysm/v7/config/proposer/loader", visibility = ["//visibility:public"], deps = [ diff --git a/config/proposer/loader/loader.go b/config/proposer/loader/loader.go index bb5d015fb4ce..96c94d08d99b 100644 --- a/config/proposer/loader/loader.go +++ b/config/proposer/loader/loader.go @@ -14,7 +14,6 @@ import ( "github.com/OffchainLabs/prysm/v7/validator/db/iface" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) diff --git a/config/proposer/loader/log.go b/config/proposer/loader/log.go new file mode 100644 index 000000000000..52be1f26fbe4 --- /dev/null +++ b/config/proposer/loader/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package loader + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "config/proposer/loader") diff --git a/config/util.go b/config/util.go index 54eb90d16a40..3781f2623517 100644 --- a/config/util.go +++ b/config/util.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/util/yaml" ) diff --git a/consensus-types/hdiff/BUILD.bazel b/consensus-types/hdiff/BUILD.bazel index da7b3201ebe4..cb5babad0dea 100644 --- a/consensus-types/hdiff/BUILD.bazel +++ b/consensus-types/hdiff/BUILD.bazel @@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["state_diff.go"], + srcs = [ + "log.go", + "state_diff.go", + ], importpath = "github.com/OffchainLabs/prysm/v7/consensus-types/hdiff", visibility = ["//visibility:public"], deps = [ diff --git a/consensus-types/hdiff/log.go b/consensus-types/hdiff/log.go new file mode 100644 index 000000000000..de91eb3c1530 --- /dev/null +++ b/consensus-types/hdiff/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package hdiff + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "consensus-types/hdiff") diff --git a/crypto/keystore/BUILD.bazel b/crypto/keystore/BUILD.bazel index 53ebdeb785e5..007e737d874a 100644 --- a/crypto/keystore/BUILD.bazel +++ b/crypto/keystore/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "keccak256.go", "key.go", "keystore.go", + "log.go", "utils.go", ], importpath = "github.com/OffchainLabs/prysm/v7/crypto/keystore", diff --git a/crypto/keystore/keystore.go b/crypto/keystore/keystore.go index 9fb01d9efbbe..de273b17b72a 100644 --- a/crypto/keystore/keystore.go +++ b/crypto/keystore/keystore.go @@ -35,7 +35,6 @@ import ( "github.com/OffchainLabs/prysm/v7/crypto/bls" "github.com/minio/sha256-simd" "github.com/pborman/uuid" - log "github.com/sirupsen/logrus" "golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/scrypt" ) diff --git a/crypto/keystore/log.go b/crypto/keystore/log.go new file mode 100644 index 000000000000..4a204eb64f32 --- /dev/null +++ b/crypto/keystore/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package keystore + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "crypto/keystore") diff --git a/crypto/random/BUILD.bazel b/crypto/random/BUILD.bazel index cd4a615a246d..95822eb2c42f 100644 --- a/crypto/random/BUILD.bazel +++ b/crypto/random/BUILD.bazel @@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["random.go"], + srcs = [ + "log.go", + "random.go", + ], importpath = "github.com/OffchainLabs/prysm/v7/crypto/random", visibility = ["//visibility:public"], deps = [ diff --git a/crypto/random/log.go b/crypto/random/log.go new file mode 100644 index 000000000000..e45ca9d85014 --- /dev/null +++ b/crypto/random/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package random + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "crypto/random") diff --git a/genesis/log.go b/genesis/log.go index 5240aa2b10b8..05f12c8176b2 100644 --- a/genesis/log.go +++ b/genesis/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package genesis import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "genesis") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "genesis") diff --git a/hack/check-logs.sh b/hack/check-logs.sh new file mode 100755 index 000000000000..2fb69bb1d088 --- /dev/null +++ b/hack/check-logs.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" +cd "$ROOT_DIR" + +# Regenerate all log.go files +./hack/gen-logs.sh + +# Fail if that changed anything +if ! git diff --quiet -- ./; then + echo "ERROR: log.go files are out of date. Please run:" + echo " ./hack/gen-logs.sh" + echo "and commit the changes." + echo + git diff --stat -- ./ || true + exit 1 +fi + +echo "log.go files are up to date." diff --git a/hack/gen-logs.sh b/hack/gen-logs.sh new file mode 100755 index 000000000000..4b88dd1ddc2d --- /dev/null +++ b/hack/gen-logs.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ---------- config ---------- +# Paths (relative to repo root) to exclude. +# Each entry excludes that directory AND all its subdirectories. +EXCLUDED_PATH_PREFIXES=( + "testing" + "validator/client/testutil" + "beacon-chain/p2p/testing" + "beacon-chain/rpc/eth/config" + "beacon-chain/rpc/prysm/v1alpha1/debug" + "tools" + "runtime" + "monitoring" + "io" + "cmd" + ".well-known" + "changelog" + "hack" + "specrefs" + "third_party" + "bazel-out" + "bazel-bin" + "bazel-prysm" + "bazel-testlogs" + "build" + ".git" + ".github" + ".jj" + ".idea" + ".vscode" +) + +# The logrus import path +LOGRUS_IMPORT="github.com/sirupsen/logrus" +# ---------------------------- + +# Require ripgrep +if ! command -v rg >/dev/null 2>&1; then + echo "Error: ripgrep (rg) is required but not installed." >&2 + exit 1 +fi + +# Find project root (git repo root if available, else current dir) +ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" +cd "$ROOT_DIR" + +# Helper: return 0 if path starts with any excluded prefix +is_excluded() { + local rel="$1" + rel="${rel#./}" # strip leading "./" if present + + for ex in "${EXCLUDED_PATH_PREFIXES[@]}"; do + if [[ "$rel" == "$ex" || "$rel" == "$ex"/* ]]; then + return 0 + fi + done + return 1 +} + +# Build rg command: +# - respects .gitignore automatically +# - searches only *.go, excluding *_test.go +# - excludes EXCLUDED_PATH_PREFIXES via negative globs so rg doesn't even enter them +rg_args=( + rg -F "$LOGRUS_IMPORT" + --glob '*.go' + --glob '!*_test.go' + -l # list matching files + -0 # NUL-delimited output +) + +for ex in "${EXCLUDED_PATH_PREFIXES[@]}"; do + rg_args+=( --glob "!$ex/**" ) +done + +# 1) Use ripgrep to find all non-test .go files that import logrus. +mapfile -d '' -t FILES < <( + "${rg_args[@]}" . || true +) + +# 2) Collect unique directories containing such files (is_excluded is now redundant but harmless) +declare -A DIRS=() +for f in "${FILES[@]}"; do + dir="$(dirname "$f")" + if is_excluded "$dir"; then + continue + fi + DIRS["$dir"]=1 +done + +# 3) For each directory, (re)generate log.go +for dir in "${!DIRS[@]}"; do + # Collect Go files in this directory + shopt -s nullglob + gofiles=( "$dir"/*.go ) + shopt -u nullglob + if [[ ${#gofiles[@]} -eq 0 ]]; then + continue + fi + + # Prefer non-log.go, non-test files to determine package name + src_files=() + for gf in "${gofiles[@]}"; do + base="$(basename "$gf")" + if [[ "$base" == "log.go" ]]; then + continue + fi + if [[ "$base" == *_test.go ]]; then + continue + fi + src_files+=( "$gf" ) + done + + # Fallback: if there are no such files, use whatever .go files exist (e.g. only log.go) + if [[ ${#src_files[@]} -eq 0 ]]; then + src_files=( "${gofiles[@]}" ) + fi + + pkg_name="$( + grep -h '^package ' "${src_files[@]}" \ + | head -n 1 \ + | awk '{print $2}' + )" + + if [[ -z "$pkg_name" ]]; then + echo "Could not determine package name for $dir, skipping" + continue + fi + + # Path relative to project root (no project name) + rel_path="${dir#./}" + + cat > "$dir/log.go" < 0 { - prefix = colorScheme.PrefixColor(" " + prefixValue + ":") - message = trimmedMsg - } + prefix := "" + prefixValue, message := getPrefixAndMessage(entry) + if len(prefixValue) > 0 { + prefix = colorScheme.PrefixColor(" " + prefixValue + ":") } messageFormat := "%s" @@ -293,7 +289,7 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys _, err = fmt.Fprintf(b, "%s %s%s "+messageFormat, colorScheme.TimestampColor(timestamp), level, prefix, message) } for _, k := range keys { - if k != "prefix" { + if k != "package" { v := entry.Data[k] format := "%+v" @@ -333,9 +329,39 @@ func (f *TextFormatter) needsQuoting(text string) bool { return false } +// getPrefixAndMessage extracts the prefix and the message from the entry by the following order: +// 1. If the "prefix" field is set in entry.Data, use that as prefix. +// 2. If the "package" field is set in entry.Data, use that to determine the prefix. +// If a replacement is found in prefixReplacements, use that. Otherwise, use the package name. +// 3. Try to extract the prefix from the message itself by looking for a pattern like "[prefix] message". +// 4. If none of the above methods yield a prefix, return an empty prefix and the original message. +func getPrefixAndMessage(entry *logrus.Entry) (string, string) { + prefix := "" + msg := entry.Message + + if prefixOldMethod, ok := entry.Data["prefix"]; ok { + return prefixOldMethod.(string), msg + } + + if packagePath, ok := entry.Data["package"]; ok { + if prefixReplacement, ok := prefixReplacements[packagePath.(string)]; ok { + return prefixReplacement, msg + } + pathSplit := strings.Split(packagePath.(string), "/") + prefix = pathSplit[len(pathSplit)-1] + return prefix, msg + } + + if prefixExtracted, trimmedMsg := extractPrefix(msg); len(prefixExtracted) > 0 { + return prefixExtracted, trimmedMsg + } + + return "", msg +} + func extractPrefix(msg string) (string, string) { prefix := "" - regex := regexp.MustCompile(`^\\[(.*?)\\]`) + if regex.MatchString(msg) { match := regex.FindString(msg) prefix, msg = match[1:len(match)-1], strings.TrimSpace(msg[len(match):]) diff --git a/runtime/logging/logrus-prefixed-formatter/prefix-replacements.go b/runtime/logging/logrus-prefixed-formatter/prefix-replacements.go new file mode 100644 index 000000000000..c2a315193a85 --- /dev/null +++ b/runtime/logging/logrus-prefixed-formatter/prefix-replacements.go @@ -0,0 +1,24 @@ +package prefixed + +var prefixReplacements = map[string]string{ + "beacon-chain/cache/depositsnapshot": "cache", + "beacon-chain/core/transition": "state", + "beacon-chain/db/kv": "db", + "beacon-chain/db/slasherkv": "slasherdb", + "beacon-chain/db/pruner": "db-pruner", + "beacon-chain/rpc/core": "rpc/core", + "beacon-chain/rpc/eth/beacon": "rpc/beacon", + "beacon-chain/rpc/eth/validator": "beacon-api", + "beacon-chain/rpc/prysm/v1alpha1/beacon": "rpc", + "beacon-chain/rpc/prysm/v1alpha1/validator": "rpc/validator", + "beacon-chain/sync/checkpoint": "checkpoint-sync", + "config/features": "flags", + "proto/prysm/v1alpha1": "protobuf", + "validator/db/kv": "db", + "validator/db/filesystem": "db", + "validator/keymanager/derived": "derived-keymanager", + "validator/keymanager/local": "local-keymanager", + "validator/keymanager/remote-web3signer": "remote-keymanager", + "validator/keymanager/remote-web3signer/internal": "remote-keymanager-internal", + "beacon-chain/forkchoice/doubly-linked-tree": "forkchoice-doublylinkedtree", +} diff --git a/time/slots/BUILD.bazel b/time/slots/BUILD.bazel index 45289a08dba5..7688bd070981 100644 --- a/time/slots/BUILD.bazel +++ b/time/slots/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", srcs = [ "countdown.go", + "log.go", "slotticker.go", "slottime.go", ], diff --git a/time/slots/countdown.go b/time/slots/countdown.go index 46a5c2a787f4..1df8eb84cf65 100644 --- a/time/slots/countdown.go +++ b/time/slots/countdown.go @@ -10,8 +10,6 @@ import ( "github.com/sirupsen/logrus" ) -var log = logrus.WithField("prefix", "slotutil") - // CountdownToGenesis starts a ticker at the specified duration // logging the remaining minutes until the genesis chainstart event // along with important genesis state metadata such as number diff --git a/time/slots/log.go b/time/slots/log.go new file mode 100644 index 000000000000..3655984991e9 --- /dev/null +++ b/time/slots/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package slots + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "time/slots") diff --git a/validator/accounts/log.go b/validator/accounts/log.go index 21a541d77dee..139e230d7f0a 100644 --- a/validator/accounts/log.go +++ b/validator/accounts/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package accounts import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "accounts") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/accounts") diff --git a/validator/accounts/userprompt/log.go b/validator/accounts/userprompt/log.go index 044a03d8fb3c..1f683f4476e1 100644 --- a/validator/accounts/userprompt/log.go +++ b/validator/accounts/userprompt/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package userprompt import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "userprompt") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/accounts/userprompt") diff --git a/validator/accounts/wallet/log.go b/validator/accounts/wallet/log.go index ff6bb92eabac..bc5f41500f80 100644 --- a/validator/accounts/wallet/log.go +++ b/validator/accounts/wallet/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package wallet import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "wallet") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/accounts/wallet") diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index 3a26a17e2bea..9e74d9cb18f7 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "health_monitor.go", "key_reload.go", "log.go", + "log_helpers.go", "metrics.go", "multiple_endpoints_grpc_resolver.go", "propose.go", diff --git a/validator/client/beacon-api/log.go b/validator/client/beacon-api/log.go index b087cf219468..aadedf1d2ef0 100644 --- a/validator/client/beacon-api/log.go +++ b/validator/client/beacon-api/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package beacon_api import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "beacon-api") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/client/beacon-api") diff --git a/validator/client/grpc-api/BUILD.bazel b/validator/client/grpc-api/BUILD.bazel index d116021ec939..adc82fdc8c75 100644 --- a/validator/client/grpc-api/BUILD.bazel +++ b/validator/client/grpc-api/BUILD.bazel @@ -7,6 +7,7 @@ go_library( "grpc_node_client.go", "grpc_prysm_beacon_chain_client.go", "grpc_validator_client.go", + "log.go", ], importpath = "github.com/OffchainLabs/prysm/v7/validator/client/grpc-api", visibility = ["//validator:__subpackages__"], diff --git a/validator/client/grpc-api/grpc_node_client.go b/validator/client/grpc-api/grpc_node_client.go index 983fd4f55c1c..ff472a8fde22 100644 --- a/validator/client/grpc-api/grpc_node_client.go +++ b/validator/client/grpc-api/grpc_node_client.go @@ -6,7 +6,6 @@ import ( ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" "github.com/OffchainLabs/prysm/v7/validator/client/iface" "github.com/golang/protobuf/ptypes/empty" - log "github.com/sirupsen/logrus" "google.golang.org/grpc" ) diff --git a/validator/client/grpc-api/grpc_validator_client.go b/validator/client/grpc-api/grpc_validator_client.go index 85663483b33e..490c43ff2b93 100644 --- a/validator/client/grpc-api/grpc_validator_client.go +++ b/validator/client/grpc-api/grpc_validator_client.go @@ -17,7 +17,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" - log "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/validator/client/grpc-api/log.go b/validator/client/grpc-api/log.go new file mode 100644 index 000000000000..4b0608b815e6 --- /dev/null +++ b/validator/client/grpc-api/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package grpc_api + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/client/grpc-api") diff --git a/validator/client/log.go b/validator/client/log.go index 952831aed1f5..fe41f5f654fc 100644 --- a/validator/client/log.go +++ b/validator/client/log.go @@ -1,147 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package client -import ( - "fmt" - "strconv" +import "github.com/sirupsen/logrus" - "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" - "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" - ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -var log = logrus.WithField("prefix", "client") - -type submittedAttData struct { - beaconBlockRoot []byte - source *ethpb.Checkpoint - target *ethpb.Checkpoint -} - -type submittedAtt struct { - data submittedAttData - pubkeys [][]byte - committees []primitives.CommitteeIndex -} - -// submittedAttKey is defined as a concatenation of: -// - AttestationData.BeaconBlockRoot -// - AttestationData.Source.HashTreeRoot() -// - AttestationData.Target.HashTreeRoot() -type submittedAttKey [96]byte - -func (k submittedAttKey) FromAttData(data *ethpb.AttestationData) error { - sourceRoot, err := data.Source.HashTreeRoot() - if err != nil { - return err - } - targetRoot, err := data.Target.HashTreeRoot() - if err != nil { - return err - } - copy(k[0:], data.BeaconBlockRoot) - copy(k[32:], sourceRoot[:]) - copy(k[64:], targetRoot[:]) - return nil -} - -// 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(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") - } - d := submittedAttData{ - beaconBlockRoot: data.BeaconBlockRoot, - source: data.Source, - target: data.Target, - } - - var submittedAtts map[submittedAttKey]*submittedAtt - if isAggregate { - submittedAtts = v.submittedAggregates - } else { - submittedAtts = v.submittedAtts - } - - if submittedAtts[key] == nil { - submittedAtts[key] = &submittedAtt{ - d, - [][]byte{}, - []primitives.CommitteeIndex{}, - } - } - submittedAtts[key] = &submittedAtt{ - d, - append(submittedAtts[key].pubkeys, pubkey), - append(submittedAtts[key].committees, att.GetCommitteeIndex()), - } - - return nil -} - -// LogSubmittedAtts logs info about submitted attestations. -func (v *validator) LogSubmittedAtts(slot primitives.Slot) { - v.attLogsLock.Lock() - defer v.attLogsLock.Unlock() - - for _, attLog := range v.submittedAtts { - pubkeys := make([]string, len(attLog.pubkeys)) - for i, p := range attLog.pubkeys { - pubkeys[i] = fmt.Sprintf("%#x", bytesutil.Trunc(p)) - } - committees := make([]string, len(attLog.committees)) - for i, c := range attLog.committees { - committees[i] = strconv.FormatUint(uint64(c), 10) - } - log.WithFields(logrus.Fields{ - "slot": slot, - "committeeIndices": committees, - "pubkeys": pubkeys, - "blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.beaconBlockRoot)), - "sourceEpoch": attLog.data.source.Epoch, - "sourceRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.source.Root)), - "targetEpoch": attLog.data.target.Epoch, - "targetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.target.Root)), - }).Info("Submitted new attestations") - } - for _, attLog := range v.submittedAggregates { - pubkeys := make([]string, len(attLog.pubkeys)) - for i, p := range attLog.pubkeys { - pubkeys[i] = fmt.Sprintf("%#x", bytesutil.Trunc(p)) - } - committees := make([]string, len(attLog.committees)) - for i, c := range attLog.committees { - committees[i] = strconv.FormatUint(uint64(c), 10) - } - log.WithFields(logrus.Fields{ - "slot": slot, - "committeeIndices": committees, - "pubkeys": pubkeys, - "blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.beaconBlockRoot)), - "sourceEpoch": attLog.data.source.Epoch, - "sourceRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.source.Root)), - "targetEpoch": attLog.data.target.Epoch, - "targetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.target.Root)), - }).Info("Submitted new aggregate attestations") - } - - v.submittedAtts = make(map[submittedAttKey]*submittedAtt) - v.submittedAggregates = make(map[submittedAttKey]*submittedAtt) -} - -// LogSubmittedSyncCommitteeMessages logs info about submitted sync committee messages. -func (v *validator) LogSubmittedSyncCommitteeMessages() { - if count := v.syncCommitteeStats.totalMessagesSubmitted.Load(); count > 0 { - log.WithField("messages", count). - Debug("Submitted sync committee messages successfully to beacon node") - - // Reset the amount. - v.syncCommitteeStats.totalMessagesSubmitted.Store(0) - } -} +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/client") diff --git a/validator/client/log_helpers.go b/validator/client/log_helpers.go new file mode 100644 index 000000000000..dcb4a2f6f4a6 --- /dev/null +++ b/validator/client/log_helpers.go @@ -0,0 +1,145 @@ +package client + +import ( + "fmt" + "strconv" + + "github.com/OffchainLabs/prysm/v7/consensus-types/primitives" + "github.com/OffchainLabs/prysm/v7/encoding/bytesutil" + ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" +) + +type submittedAttData struct { + beaconBlockRoot []byte + source *ethpb.Checkpoint + target *ethpb.Checkpoint +} + +type submittedAtt struct { + data submittedAttData + pubkeys [][]byte + committees []primitives.CommitteeIndex +} + +// submittedAttKey is defined as a concatenation of: +// - AttestationData.BeaconBlockRoot +// - AttestationData.Source.HashTreeRoot() +// - AttestationData.Target.HashTreeRoot() +type submittedAttKey [96]byte + +func (k submittedAttKey) FromAttData(data *ethpb.AttestationData) error { + sourceRoot, err := data.Source.HashTreeRoot() + if err != nil { + return err + } + targetRoot, err := data.Target.HashTreeRoot() + if err != nil { + return err + } + copy(k[0:], data.BeaconBlockRoot) + copy(k[32:], sourceRoot[:]) + copy(k[64:], targetRoot[:]) + return nil +} + +// 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(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") + } + d := submittedAttData{ + beaconBlockRoot: data.BeaconBlockRoot, + source: data.Source, + target: data.Target, + } + + var submittedAtts map[submittedAttKey]*submittedAtt + if isAggregate { + submittedAtts = v.submittedAggregates + } else { + submittedAtts = v.submittedAtts + } + + if submittedAtts[key] == nil { + submittedAtts[key] = &submittedAtt{ + d, + [][]byte{}, + []primitives.CommitteeIndex{}, + } + } + submittedAtts[key] = &submittedAtt{ + d, + append(submittedAtts[key].pubkeys, pubkey), + append(submittedAtts[key].committees, att.GetCommitteeIndex()), + } + + return nil +} + +// LogSubmittedAtts logs info about submitted attestations. +func (v *validator) LogSubmittedAtts(slot primitives.Slot) { + v.attLogsLock.Lock() + defer v.attLogsLock.Unlock() + + for _, attLog := range v.submittedAtts { + pubkeys := make([]string, len(attLog.pubkeys)) + for i, p := range attLog.pubkeys { + pubkeys[i] = fmt.Sprintf("%#x", bytesutil.Trunc(p)) + } + committees := make([]string, len(attLog.committees)) + for i, c := range attLog.committees { + committees[i] = strconv.FormatUint(uint64(c), 10) + } + log.WithFields(logrus.Fields{ + "slot": slot, + "committeeIndices": committees, + "pubkeys": pubkeys, + "blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.beaconBlockRoot)), + "sourceEpoch": attLog.data.source.Epoch, + "sourceRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.source.Root)), + "targetEpoch": attLog.data.target.Epoch, + "targetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.target.Root)), + }).Info("Submitted new attestations") + } + for _, attLog := range v.submittedAggregates { + pubkeys := make([]string, len(attLog.pubkeys)) + for i, p := range attLog.pubkeys { + pubkeys[i] = fmt.Sprintf("%#x", bytesutil.Trunc(p)) + } + committees := make([]string, len(attLog.committees)) + for i, c := range attLog.committees { + committees[i] = strconv.FormatUint(uint64(c), 10) + } + log.WithFields(logrus.Fields{ + "slot": slot, + "committeeIndices": committees, + "pubkeys": pubkeys, + "blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.beaconBlockRoot)), + "sourceEpoch": attLog.data.source.Epoch, + "sourceRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.source.Root)), + "targetEpoch": attLog.data.target.Epoch, + "targetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(attLog.data.target.Root)), + }).Info("Submitted new aggregate attestations") + } + + v.submittedAtts = make(map[submittedAttKey]*submittedAtt) + v.submittedAggregates = make(map[submittedAttKey]*submittedAtt) +} + +// LogSubmittedSyncCommitteeMessages logs info about submitted sync committee messages. +func (v *validator) LogSubmittedSyncCommitteeMessages() { + if count := v.syncCommitteeStats.totalMessagesSubmitted.Load(); count > 0 { + log.WithField("messages", count). + Debug("Submitted sync committee messages successfully to beacon node") + + // Reset the amount. + v.syncCommitteeStats.totalMessagesSubmitted.Store(0) + } +} diff --git a/validator/client/metrics_test.go b/validator/client/metrics_test.go index 7f1bc252e048..51409b6fa313 100644 --- a/validator/client/metrics_test.go +++ b/validator/client/metrics_test.go @@ -83,7 +83,7 @@ func TestUpdateLogAggregateStats(t *testing.T) { "correctlyVotedHeadPct=\"100%\" correctlyVotedSourcePct=\"100%\" correctlyVotedTargetPct=\"50%\" epoch=2") require.LogsContain(t, hook, "msg=\"Vote summary since launch\" attestationsInclusionPct=\"78%\" "+ "averageInclusionDistance=\"0.00 slots\" correctlyVotedHeadPct=\"86%\" correctlyVotedSourcePct=\"100%\" "+ - "correctlyVotedTargetPct=\"86%\" numberOfEpochs=3 pctChangeCombinedBalance=\"0.20555%\"") + "correctlyVotedTargetPct=\"86%\" numberOfEpochs=3 package=validator/client pctChangeCombinedBalance=\"0.20555%\"") } @@ -161,5 +161,5 @@ func TestUpdateLogAltairAggregateStats(t *testing.T) { "averageInactivityScore=0 correctlyVotedHeadPct=\"100%\" correctlyVotedSourcePct=\"100%\" correctlyVotedTargetPct=\"50%\" epoch=74242") require.LogsContain(t, hook, "msg=\"Vote summary since launch\" attestationsInclusionPct=\"78%\" "+ "correctlyVotedHeadPct=\"86%\" correctlyVotedSourcePct=\"100%\" "+ - "correctlyVotedTargetPct=\"71%\" numberOfEpochs=3 pctChangeCombinedBalance=\"0.20555%\"") + "correctlyVotedTargetPct=\"71%\" numberOfEpochs=3 package=validator/client pctChangeCombinedBalance=\"0.20555%\"") } diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index 92e214ce7c7e..605dbf4b04b7 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -775,7 +775,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) { PositionInActivationQueue: 30, }, }, - log: "Validator deposited, entering activation queue after finalization\" prefix=client pubkey=0x000000000000 status=DEPOSITED validatorIndex=30", + log: "Validator deposited, entering activation queue after finalization\" package=validator/client pubkey=0x000000000000 status=DEPOSITED validatorIndex=30", active: false, }, { @@ -789,7 +789,7 @@ func TestCheckAndLogValidatorStatus_OK(t *testing.T) { PositionInActivationQueue: 6, }, }, - log: "Waiting for activation... Check validator queue status in a block explorer\" prefix=client pubkey=0x000000000000 status=PENDING validatorIndex=50", + log: "Waiting for activation... Check validator queue status in a block explorer\" package=validator/client pubkey=0x000000000000 status=PENDING validatorIndex=50", active: false, }, { diff --git a/validator/db/filesystem/BUILD.bazel b/validator/db/filesystem/BUILD.bazel index 7d5f1e81b30e..e09134c5dca6 100644 --- a/validator/db/filesystem/BUILD.bazel +++ b/validator/db/filesystem/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "genesis.go", "graffiti.go", "import.go", + "log.go", "migration.go", "proposer_protection.go", "proposer_settings.go", diff --git a/validator/db/filesystem/db.go b/validator/db/filesystem/db.go index 1b39352842f6..1ec43f30a282 100644 --- a/validator/db/filesystem/db.go +++ b/validator/db/filesystem/db.go @@ -73,9 +73,6 @@ type ( // Ensure the filesystem store implements the interface. var _ = iface.ValidatorDB(&Store{}) -// Logging. -var log = logrus.WithField("prefix", "db") - // NewStore creates a new filesystem store. func NewStore(databaseParentPath string, config *Config) (*Store, error) { s := &Store{ diff --git a/validator/db/filesystem/log.go b/validator/db/filesystem/log.go new file mode 100644 index 000000000000..aa7eac814c84 --- /dev/null +++ b/validator/db/filesystem/log.go @@ -0,0 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. +package filesystem + +import "github.com/sirupsen/logrus" + +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/db/filesystem") diff --git a/validator/db/kv/log.go b/validator/db/kv/log.go index 5c1d80880ce6..cdba98d278ab 100644 --- a/validator/db/kv/log.go +++ b/validator/db/kv/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package kv import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "db") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/db/kv") diff --git a/validator/db/log.go b/validator/db/log.go index f320f2fe6ab7..d71321985d5a 100644 --- a/validator/db/log.go +++ b/validator/db/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package db import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "db") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/db") diff --git a/validator/graffiti/log.go b/validator/graffiti/log.go index b689212ba49a..5d032e92ea7d 100644 --- a/validator/graffiti/log.go +++ b/validator/graffiti/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package graffiti import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "graffiti") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/graffiti") diff --git a/validator/keymanager/derived/log.go b/validator/keymanager/derived/log.go index a4b39d299a0c..d41f15a71b2c 100644 --- a/validator/keymanager/derived/log.go +++ b/validator/keymanager/derived/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package derived import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "derived-keymanager") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/keymanager/derived") diff --git a/validator/keymanager/local/log.go b/validator/keymanager/local/log.go index 2a39bc2bf57a..9c7f4199fdc8 100644 --- a/validator/keymanager/local/log.go +++ b/validator/keymanager/local/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package local import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "local-keymanager") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/keymanager/local") diff --git a/validator/keymanager/remote-web3signer/internal/log.go b/validator/keymanager/remote-web3signer/internal/log.go index b96e4ca4f650..614f02203b66 100644 --- a/validator/keymanager/remote-web3signer/internal/log.go +++ b/validator/keymanager/remote-web3signer/internal/log.go @@ -1,7 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package internal -import ( - "github.com/sirupsen/logrus" -) +import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "remote-web3signer-internal") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/keymanager/remote-web3signer/internal") diff --git a/validator/keymanager/remote-web3signer/log.go b/validator/keymanager/remote-web3signer/log.go index f579bdb7ae3a..1859e37e28a3 100644 --- a/validator/keymanager/remote-web3signer/log.go +++ b/validator/keymanager/remote-web3signer/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package remote_web3signer import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "remote-keymanager") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/keymanager/remote-web3signer") diff --git a/validator/node/log.go b/validator/node/log.go index 2c3b06e82296..f493c0c527f7 100644 --- a/validator/node/log.go +++ b/validator/node/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package node import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "node") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/node") diff --git a/validator/rpc/log.go b/validator/rpc/log.go index 5c2ea5ccf32e..d48eeb26e079 100644 --- a/validator/rpc/log.go +++ b/validator/rpc/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package rpc import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "rpc") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/rpc") diff --git a/validator/web/log.go b/validator/web/log.go index cea59bae0aa6..6a9403a3ca67 100644 --- a/validator/web/log.go +++ b/validator/web/log.go @@ -1,5 +1,9 @@ +// Code generated by hack/gen-logs.sh; DO NOT EDIT. +// This file is created and regenerated automatically. Anything added here might get removed. package web import "github.com/sirupsen/logrus" -var log = logrus.WithField("prefix", "web") +// The prefix for logs from this package will be the text after the last slash in the package path. +// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file. +var log = logrus.WithField("package", "validator/web")