From d076076f0d6323cc9c70749563b202397548c661 Mon Sep 17 00:00:00 2001 From: Andrei Smirnov Date: Tue, 19 Mar 2024 12:52:54 +0300 Subject: [PATCH] app: logging lock hash and enr (#2972) Added logging of full lock_hash and node's enr when charon starts. category: refactor ticket: #2778 --- app/app.go | 10 +++++++++- cmd/cmd.go | 7 +++++++ cmd/dkg.go | 1 + cmd/relay.go | 1 + cmd/run.go | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index ca31f3349..c23bd37ac 100644 --- a/app/app.go +++ b/app/app.go @@ -58,6 +58,7 @@ import ( "github.com/obolnetwork/charon/core/tracker" "github.com/obolnetwork/charon/core/validatorapi" "github.com/obolnetwork/charon/eth2util" + "github.com/obolnetwork/charon/eth2util/enr" "github.com/obolnetwork/charon/p2p" "github.com/obolnetwork/charon/tbls" "github.com/obolnetwork/charon/tbls/tblsconv" @@ -194,11 +195,18 @@ func Run(ctx context.Context, conf Config) (err error) { return errors.Wrap(err, "private key not matching cluster manifest file") } + enrRec, err := enr.New(p2pKey) + if err != nil { + return errors.Wrap(err, "creating enr record from privkey") + } + log.Info(ctx, "Lock file loaded", z.Str("peer_name", p2p.PeerName(tcpNode.ID())), z.Int("peer_index", nodeIdx.PeerIdx), - z.Str("cluster_hash", lockHashHex), z.Str("cluster_name", cluster.Name), + z.Str("cluster_hash", lockHashHex), + z.Str("cluster_hash_full", hex.EncodeToString(cluster.GetInitialMutationHash())), + z.Str("enr", enrRec.String()), z.Int("peers", len(cluster.Operators))) // Metric and logging labels. diff --git a/cmd/cmd.go b/cmd/cmd.go index be35f60e3..ab6616c80 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -162,6 +162,13 @@ func printFlags(ctx context.Context, flags *pflag.FlagSet) { log.Info(ctx, "Parsed config", flagsToLogFields(flags)...) } +// printLicense INFO logs the license notice. +func printLicense(ctx context.Context) { + log.Info(ctx, "This software is licensed under the Maria DB Business Source License 1.1; "+ + "you may not use this software except in compliance with this license. "+ + "You may obtain a copy of this license at https://github.com/ObolNetwork/charon/blob/main/LICENSE") +} + // flagsToLogFields converts the given flags to log fields. func flagsToLogFields(flags *pflag.FlagSet) []z.Field { var fields []z.Field diff --git a/cmd/dkg.go b/cmd/dkg.go index 554960f11..f42604a33 100644 --- a/cmd/dkg.go +++ b/cmd/dkg.go @@ -30,6 +30,7 @@ this command at the same time.`, } libp2plog.SetPrimaryCore(log.LoggerCore()) // Set libp2p logger to use charon logger + printLicense(cmd.Context()) printFlags(cmd.Context(), cmd.Flags()) return runFunc(cmd.Context(), config) diff --git a/cmd/relay.go b/cmd/relay.go index 311c09031..2c4377775 100644 --- a/cmd/relay.go +++ b/cmd/relay.go @@ -26,6 +26,7 @@ func newRelayCmd(runFunc func(context.Context, relay.Config) error) *cobra.Comma } libp2plog.SetPrimaryCore(log.LoggerCore()) // Set libp2p logger to use charon logger + printLicense(cmd.Context()) printFlags(cmd.Context(), cmd.Flags()) return runFunc(cmd.Context(), config) diff --git a/cmd/run.go b/cmd/run.go index 990b32175..98265e992 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -32,6 +32,7 @@ func newRunCmd(runFunc func(context.Context, app.Config) error, unsafe bool) *co } libp2plog.SetPrimaryCore(log.LoggerCore()) // Set libp2p logger to use charon logger + printLicense(cmd.Context()) printFlags(cmd.Context(), cmd.Flags()) return runFunc(cmd.Context(), conf)