Skip to content

Commit

Permalink
chore(hlao/app): improve logging (#1858)
Browse files Browse the repository at this point in the history
Improve halo logs

issue: none
  • Loading branch information
corverroos authored Sep 12, 2024
1 parent eaf9639 commit e270f4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions halo/app/lazyvoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion halo/app/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
20 changes: 19 additions & 1 deletion halo/app/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"context"
"encoding/hex"
"os"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}

0 comments on commit e270f4e

Please sign in to comment.