Skip to content

Commit

Permalink
app: logging lock hash and enr (#2972)
Browse files Browse the repository at this point in the history
Added logging of full lock_hash and node's enr when charon starts.

category: refactor
ticket: #2778
  • Loading branch information
pinebit authored Mar 19, 2024
1 parent aaed89d commit d076076
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d076076

Please sign in to comment.