diff --git a/api/client/beacon/BUILD.bazel b/api/client/beacon/BUILD.bazel index afa1af766..60691a029 100644 --- a/api/client/beacon/BUILD.bazel +++ b/api/client/beacon/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "checkpoint.go", "client.go", "doc.go", + "log.go", ], importpath = "github.com/prysmaticlabs/prysm/v5/api/client/beacon", visibility = ["//visibility:public"], diff --git a/api/client/beacon/checkpoint.go b/api/client/beacon/checkpoint.go index 1f35655ea..bfe3f503e 100644 --- a/api/client/beacon/checkpoint.go +++ b/api/client/beacon/checkpoint.go @@ -17,7 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/v5/io/file" "github.com/prysmaticlabs/prysm/v5/runtime/version" "github.com/prysmaticlabs/prysm/v5/time/slots" - log "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" "golang.org/x/mod/semver" ) @@ -74,7 +74,12 @@ func DownloadFinalizedData(ctx context.Context, client *Client) (*OriginData, er if err != nil { return nil, errors.Wrap(err, "error detecting chain config for finalized state") } - log.Printf("detected supported config in remote finalized state, name=%s, fork=%s", vu.Config.ConfigName, version.String(vu.Fork)) + + log.WithFields(logrus.Fields{ + "name": vu.Config.ConfigName, + "fork": version.String(vu.Fork), + }).Info("Detected supported config in remote finalized state") + s, err := vu.UnmarshalBeaconState(sb) if err != nil { return nil, errors.Wrap(err, "error unmarshaling finalized state to correct version") diff --git a/api/client/beacon/client.go b/api/client/beacon/client.go index 028e04200..04cdd46fa 100644 --- a/api/client/beacon/client.go +++ b/api/client/beacon/client.go @@ -22,7 +22,7 @@ import ( "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" "github.com/prysmaticlabs/prysm/v5/network/forks" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" - log "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" ) const ( @@ -309,7 +309,7 @@ func (c *Client) SubmitChangeBLStoExecution(ctx context.Context, request []*stru } for _, failure := range errorJson.Failures { w := request[failure.Index].Message - log.WithFields(log.Fields{ + log.WithFields(logrus.Fields{ "validatorIndex": w.ValidatorIndex, "withdrawalAddress": w.ToExecutionAddress, }).Error(failure.Message) @@ -341,9 +341,9 @@ type forkScheduleResponse struct { func (fsr *forkScheduleResponse) OrderedForkSchedule() (forks.OrderedSchedule, error) { ofs := make(forks.OrderedSchedule, 0) for _, d := range fsr.Data { - epoch, err := strconv.Atoi(d.Epoch) + epoch, err := strconv.ParseUint(d.Epoch, 10, 64) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "error parsing epoch %s", d.Epoch) } vSlice, err := hexutil.Decode(d.CurrentVersion) if err != nil { @@ -355,7 +355,7 @@ func (fsr *forkScheduleResponse) OrderedForkSchedule() (forks.OrderedSchedule, e version := bytesutil.ToBytes4(vSlice) ofs = append(ofs, forks.ForkScheduleEntry{ Version: version, - Epoch: primitives.Epoch(uint64(epoch)), + Epoch: primitives.Epoch(epoch), }) } sort.Sort(ofs) diff --git a/api/client/beacon/log.go b/api/client/beacon/log.go new file mode 100644 index 000000000..b566d20bb --- /dev/null +++ b/api/client/beacon/log.go @@ -0,0 +1,5 @@ +package beacon + +import "github.com/sirupsen/logrus" + +var log = logrus.WithField("prefix", "beacon") diff --git a/beacon-chain/db/kv/kv.go b/beacon-chain/db/kv/kv.go index 2da41fe98..90f01a63d 100644 --- a/beacon-chain/db/kv/kv.go +++ b/beacon-chain/db/kv/kv.go @@ -137,7 +137,7 @@ func NewKVStore(ctx context.Context, dirPath string, opts ...KVStoreOption) (*St } } datafile := StoreDatafilePath(dirPath) - log.Infof("Opening Bolt DB at %s", datafile) + log.WithField("path", datafile).Info("Opening Bolt DB") boltDB, err := bolt.Open( datafile, params.BeaconIoConfig().ReadWritePermissions, diff --git a/beacon-chain/db/kv/wss.go b/beacon-chain/db/kv/wss.go index 0cdd645c1..4412b61c5 100644 --- a/beacon-chain/db/kv/wss.go +++ b/beacon-chain/db/kv/wss.go @@ -11,6 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/v5/proto/dbval" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/runtime/version" + "github.com/sirupsen/logrus" ) // SaveOrigin loads an ssz serialized Block & BeaconState from an io.Reader @@ -27,7 +28,11 @@ func (s *Store) SaveOrigin(ctx context.Context, serState, serBlock []byte) error return fmt.Errorf("config mismatch, beacon node configured to connect to %s, detected state is for %s", params.BeaconConfig().ConfigName, cf.Config.ConfigName) } - log.Infof("detected supported config for state & block version, config name=%s, fork name=%s", cf.Config.ConfigName, version.String(cf.Fork)) + log.WithFields(logrus.Fields{ + "configName": cf.Config.ConfigName, + "forkName": version.String(cf.Fork), + }).Info("Detected supported config for state & block version") + state, err := cf.UnmarshalBeaconState(serState) if err != nil { return errors.Wrap(err, "failed to initialize origin state w/ bytes + config+fork") @@ -57,13 +62,13 @@ func (s *Store) SaveOrigin(ctx context.Context, serState, serBlock []byte) error return errors.Wrap(err, "unable to save backfill status data to db for checkpoint sync") } - log.Infof("saving checkpoint block to db, w/ root=%#x", blockRoot) + log.WithField("root", fmt.Sprintf("%#x", blockRoot)).Info("Saving checkpoint block to db") if err := s.SaveBlock(ctx, wblk); err != nil { return errors.Wrap(err, "could not save checkpoint block") } // save state - log.Infof("calling SaveState w/ blockRoot=%x", blockRoot) + log.WithField("blockRoot", fmt.Sprintf("%#x", blockRoot)).Info("Calling SaveState") if err = s.SaveState(ctx, state, blockRoot); err != nil { return errors.Wrap(err, "could not save state") } diff --git a/beacon-chain/execution/rpc_connection.go b/beacon-chain/execution/rpc_connection.go index b287d0261..04e63ab2a 100644 --- a/beacon-chain/execution/rpc_connection.go +++ b/beacon-chain/execution/rpc_connection.go @@ -77,7 +77,7 @@ func (s *Service) pollConnectionStatus(ctx context.Context) { if currClient != nil { currClient.Close() } - log.Infof("Connected to new endpoint: %s", logs.MaskCredentialsLogging(s.cfg.currHttpEndpoint.Url)) + log.WithField("endpoint", logs.MaskCredentialsLogging(s.cfg.currHttpEndpoint.Url)).Info("Connected to new endpoint") return case <-s.ctx.Done(): log.Debug("Received cancelled context,closing existing powchain service") diff --git a/beacon-chain/sync/initial-sync/round_robin.go b/beacon-chain/sync/initial-sync/round_robin.go index b22b6b7e8..b9c105e5e 100644 --- a/beacon-chain/sync/initial-sync/round_robin.go +++ b/beacon-chain/sync/initial-sync/round_robin.go @@ -243,13 +243,13 @@ func (s *Service) logBatchSyncStatus(genesis time.Time, firstBlk blocks.ROBlock, firstRoot := firstBlk.Root() timeRemaining := time.Duration(float64(slots.Since(genesis)-firstBlk.Block().Slot())/rate) * time.Second log.WithFields(logrus.Fields{ - "peers": len(s.cfg.P2P.Peers().Connected()), - "blocksPerSecond": fmt.Sprintf("%.1f", rate), - }).Infof( - "Processing block batch of size %d starting from %s %d/%d - estimated time remaining %s", - nBlocks, fmt.Sprintf("0x%s...", hex.EncodeToString(firstRoot[:])[:8]), - firstBlk.Block().Slot(), slots.Since(genesis), timeRemaining, - ) + "peers": len(s.cfg.P2P.Peers().Connected()), + "blocksPerSecond": fmt.Sprintf("%.1f", rate), + "batchSize": nBlocks, + "startingFrom": fmt.Sprintf("0x%s...", hex.EncodeToString(firstRoot[:])[:8]), + "latestProcessedSlot/currentSlot": fmt.Sprintf("%d/%d", firstBlk.Block().Slot(), slots.Since(genesis)), + "estimatedTimeRemaining": timeRemaining, + }).Info("Processing blocks") } // processBlock performs basic checks on incoming block, and triggers receiver function. diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index 876d9dc80..3593aae24 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -194,7 +194,7 @@ func (s *Service) Start() { } panic(err) } - log.Infof("Synced up to slot %d", s.cfg.Chain.HeadSlot()) + log.WithField("slot", s.cfg.Chain.HeadSlot()).Info("Synced up to") s.markSynced() } diff --git a/beacon-chain/sync/subscriber.go b/beacon-chain/sync/subscriber.go index 8c6438b90..05195316e 100644 --- a/beacon-chain/sync/subscriber.go +++ b/beacon-chain/sync/subscriber.go @@ -248,7 +248,7 @@ func (s *Service) subscribeWithBase(topic string, validator wrappedVal, handle s } go messageLoop() - log.WithField("topic", topic).Info("Subscribed to topic") + log.WithField("topic", topic).Info("Subscribed to") return sub } @@ -687,7 +687,7 @@ func (s *Service) retrievePersistentSubs(currSlot primitives.Slot) []uint64 { return slice.SetUint64(append(persistentSubs, wantedSubs...)) } -func (_ *Service) retrieveActiveSyncSubnets(currEpoch primitives.Epoch) []uint64 { +func (*Service) retrieveActiveSyncSubnets(currEpoch primitives.Epoch) []uint64 { subs := cache.SyncSubnetIDs.GetAllSubnets(currEpoch) return slice.SetUint64(subs) } @@ -742,17 +742,17 @@ func (s *Service) filterNeededPeers(pids []peer.ID) []peer.ID { } // Add fork digest to topic. -func (_ *Service) addDigestToTopic(topic string, digest [4]byte) string { +func (*Service) addDigestToTopic(topic string, digest [4]byte) string { if !strings.Contains(topic, "%x") { - log.Fatal("Topic does not have appropriate formatter for digest") + log.Error("Topic does not have appropriate formatter for digest") } return fmt.Sprintf(topic, digest) } // Add the digest and index to subnet topic. -func (_ *Service) addDigestAndIndexToTopic(topic string, digest [4]byte, idx uint64) string { +func (*Service) addDigestAndIndexToTopic(topic string, digest [4]byte, idx uint64) string { if !strings.Contains(topic, "%x") { - log.Fatal("Topic does not have appropriate formatter for digest") + log.Error("Topic does not have appropriate formatter for digest") } return fmt.Sprintf(topic, digest, idx) } diff --git a/cmd/beacon-chain/execution/BUILD.bazel b/cmd/beacon-chain/execution/BUILD.bazel index 0546d0c64..e19ccdbd0 100644 --- a/cmd/beacon-chain/execution/BUILD.bazel +++ b/cmd/beacon-chain/execution/BUILD.bazel @@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["options.go"], + srcs = [ + "log.go", + "options.go", + ], importpath = "github.com/prysmaticlabs/prysm/v5/cmd/beacon-chain/execution", visibility = [ "//beacon-chain:__subpackages__", diff --git a/cmd/beacon-chain/execution/log.go b/cmd/beacon-chain/execution/log.go new file mode 100644 index 000000000..1d1840a9e --- /dev/null +++ b/cmd/beacon-chain/execution/log.go @@ -0,0 +1,5 @@ +package execution + +import "github.com/sirupsen/logrus" + +var log = logrus.WithField("prefix", "execution") diff --git a/cmd/beacon-chain/execution/options.go b/cmd/beacon-chain/execution/options.go index 5ffc83bd4..27cea090a 100644 --- a/cmd/beacon-chain/execution/options.go +++ b/cmd/beacon-chain/execution/options.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v5/beacon-chain/execution" "github.com/prysmaticlabs/prysm/v5/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/v5/io/file" - log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -53,7 +52,7 @@ func parseJWTSecretFromFile(c *cli.Context) ([]byte, error) { return nil, err } strData := strings.TrimSpace(string(enc)) - if len(strData) == 0 { + if strData == "" { return nil, fmt.Errorf("provided JWT secret in file %s cannot be empty", jwtSecretFile) } secret, err := hex.DecodeString(strings.TrimPrefix(strData, "0x"))