Skip to content

Commit

Permalink
chore(zetaclient): improve logging by adding and moving data to attri…
Browse files Browse the repository at this point in the history
…butes
  • Loading branch information
gartnera committed Sep 13, 2024
1 parent 19c929c commit cc78c1e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
28 changes: 21 additions & 7 deletions zetaclient/chains/bitcoin/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,35 @@ func (ob *Observer) WatchRPCStatus(_ context.Context) error {

bn, err := ob.btcClient.GetBlockCount()
if err != nil {
ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ")
ob.logger.Chain.Error().Err(err).Msg("RPC status check failed: GetBlockCount")
continue
}

hash, err := ob.btcClient.GetBlockHash(bn)
if err != nil {
ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ")
ob.logger.Chain.Error().Err(err).
Int64("block_number", bn).
Msg("RPC status check failed: GetBlockHash")
continue
}

header, err := ob.btcClient.GetBlockHeader(hash)
if err != nil {
ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ")
ob.logger.Chain.Error().
Err(err).
Int64("block_number", bn).
Msg("RPC status check failed: GetBlockHeader")
continue
}

blockTime := header.Timestamp
elapsedSeconds := time.Since(blockTime).Seconds()
if elapsedSeconds > 1200 {
ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ")
blockAgeSeconds := time.Since(blockTime).Seconds()
if blockAgeSeconds > 1200 {
ob.logger.Chain.Error().
Err(err).
Int64("block_number", bn).
Float64("age", blockAgeSeconds).
Msg("RPC status check failed: block is old")
continue
}

Expand All @@ -280,7 +289,12 @@ func (ob *Observer) WatchRPCStatus(_ context.Context) error {
}

ob.logger.Chain.Info().
Msgf("[OK] RPC status check: latest block number %d, timestamp %s (%.fs ago), tss addr %s, #utxos: %d", bn, blockTime, elapsedSeconds, tssAddr, len(res))
Int64("block_number", bn).
Time("block_timestamp", blockTime).
Float64("block_age_seconds", blockAgeSeconds).
Str("tss_address", tssAddr.EncodeAddress()).
Int("utxo_count", len(res)).
Msg("RPC status OK")

case <-ob.StopChannel():
return nil
Expand Down
22 changes: 15 additions & 7 deletions zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,29 +217,37 @@ func (ob *Observer) WatchRPCStatus(ctx context.Context) error {
}
bn, err := ob.evmClient.BlockNumber(ctx)
if err != nil {
ob.Logger().Chain.Error().Err(err).Msg("RPC Status Check error: RPC down?")
ob.Logger().Chain.Error().Err(err).Msg("RPC status check failed: BlockNumber")
continue
}
gasPrice, err := ob.evmClient.SuggestGasPrice(ctx)
if err != nil {
ob.Logger().Chain.Error().Err(err).Msg("RPC Status Check error: RPC down?")
ob.Logger().Chain.Error().
Uint64("block_number", bn).
Err(err).Msg("RPC status check failed: SuggestGasPrice")
continue
}
header, err := ob.evmClient.HeaderByNumber(ctx, new(big.Int).SetUint64(bn))
if err != nil {
ob.Logger().Chain.Error().Err(err).Msg("RPC Status Check error: RPC down?")
ob.Logger().Chain.Error().
Uint64("block_number", bn).
Err(err).Msg("RPC status check failed: HeaderByNumber")
continue
}
// #nosec G115 always in range
blockTime := time.Unix(int64(header.Time), 0).UTC()
elapsedSeconds := time.Since(blockTime).Seconds()
if elapsedSeconds > 100 {
blockAgeSeconds := time.Since(blockTime).Seconds()
if blockAgeSeconds > 100 {
ob.Logger().Chain.Warn().
Msgf("RPC Status Check warning: RPC stale or chain stuck (check explorer)? Latest block %d timestamp is %.0fs ago", bn, elapsedSeconds)
Msgf("RPC status check warning: RPC stale or chain stuck (check explorer)? Latest block %d timestamp is %.0fs ago", bn, blockAgeSeconds)
continue
}
ob.Logger().Chain.Info().
Msgf("[OK] RPC status: latest block num %d, timestamp %s ( %.0fs ago), suggested gas price %d", header.Number, blockTime.String(), elapsedSeconds, gasPrice.Uint64())
Uint64("block_number", header.Number.Uint64()).
Time("block_timestamp", blockTime).
Float64("block_age_seconds", blockAgeSeconds).
Uint64("suggested_gas_price", gasPrice.Uint64()).
Msg("RPC status OK")
case <-ob.StopChannel():
return nil
}
Expand Down

0 comments on commit cc78c1e

Please sign in to comment.