From e270f4e0c5ebeae412a9a3aad741b2185d1ef30f Mon Sep 17 00:00:00 2001 From: corver Date: Thu, 12 Sep 2024 14:58:05 +0200 Subject: [PATCH] chore(hlao/app): improve logging (#1858) Improve halo logs issue: none --- halo/app/lazyvoter.go | 6 ++++++ halo/app/monitor.go | 4 +++- halo/app/start.go | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/halo/app/lazyvoter.go b/halo/app/lazyvoter.go index f5a4a517c..0ba15a068 100644 --- a/halo/app/lazyvoter.go +++ b/halo/app/lazyvoter.go @@ -75,6 +75,10 @@ func (l *voterLoader) LazyLoad( log.Warn(ctx, "Flag --xchain-evm-rpc-endpoints empty. The app will crash if it becomes a validator since it cannot perform xchain voting duties", nil) } + if !l.isValidator() { + log.Info(ctx, "Local halo node is not a validator") + } + // Wait until this node becomes a validator before initializing voter. // This mitigates crashes due to invalid rpc endpoint config in non-validator nodes. backoff := expbackoff.New(ctx, expbackoff.WithPeriodicConfig(time.Second)) @@ -85,6 +89,8 @@ func (l *voterLoader) LazyLoad( } } + log.Info(ctx, "🫡 Local halo node is a validator, starting voter") + if len(endpoints) == 0 { // Note that this negatively affects chain liveness, but xchain liveness already negatively affected so rather // highlight the issue to the operator by crashing. #allornothing diff --git a/halo/app/monitor.go b/halo/app/monitor.go index df2355fd7..ba2b2a227 100644 --- a/halo/app/monitor.go +++ b/halo/app/monitor.go @@ -149,7 +149,9 @@ func monitorEVMOnce(ctx context.Context, ethCl ethclient.Client) error { func dirSize(path string) (int64, error) { var size int64 err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { - if err != nil { + if os.IsNotExist(err) { + return nil // Ignore files deleted during walk + } else if err != nil { return err } diff --git a/halo/app/start.go b/halo/app/start.go index 88a7a5047..c31bdd325 100644 --- a/halo/app/start.go +++ b/halo/app/start.go @@ -2,6 +2,7 @@ package app import ( "context" + "encoding/hex" "os" "time" @@ -21,11 +22,13 @@ import ( "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" + "github.com/cometbft/cometbft/privval" "github.com/cometbft/cometbft/proxy" rpclocal "github.com/cometbft/cometbft/rpc/client/local" cmttypes "github.com/cometbft/cometbft/types" "github.com/ethereum/go-ethereum/common" + ethcrypto "github.com/ethereum/go-ethereum/crypto" "cosmossdk.io/store" pruningtypes "cosmossdk.io/store/pruning/types" @@ -86,7 +89,7 @@ func Run(ctx context.Context, cfg Config) error { // Note that the original context used to start the app must be canceled first // before calling the stop function and a fresh context should be passed into the stop function. func Start(ctx context.Context, cfg Config) (<-chan error, func(context.Context) error, error) { - log.Info(ctx, "Starting halo consensus client") + log.Info(ctx, "Starting halo consensus client", "moniker", cfg.Comet.Moniker) if err := cfg.Verify(); err != nil { return nil, nil, errors.Wrap(err, "verify halo config") @@ -108,6 +111,7 @@ func Start(ctx context.Context, cfg Config) (<-chan error, func(context.Context) if err != nil { return nil, nil, errors.Wrap(err, "load validator key") } + logPrivVal(ctx, privVal) db, err := dbm.NewDB("application", cfg.BackendType(), cfg.DataDir()) if err != nil { @@ -410,3 +414,17 @@ func serverAppOptsFromCfg(cfg Config) serverAppOpts { sdkserver.FlagUnsafeSkipUpgrades: cfg.UnsafeSkipUpgrades, } } + +// logPrivVal logs the private validator key details. +func logPrivVal(ctx context.Context, privVal *privval.FilePV) { + pk := privVal.Key.PubKey + ethPK, err := ethcrypto.DecompressPubkey(pk.Bytes()) + if err != nil { + return + } + + log.Info(ctx, "Loaded consensus private validator key from disk", + "pubkey", hex.EncodeToString(pk.Bytes()), + "comet_addr", pk.Address(), + "eth_addr", ethcrypto.PubkeyToAddress(*ethPK)) +}