Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(zetaclient): improve logging by adding and moving data to attributes #2875

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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")

Check warning on line 243 in zetaclient/chains/bitcoin/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/observer.go#L243

Added line #L243 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit tests for WatchRPCStatus.

The static analysis hints indicate that the added lines in the WatchRPCStatus function are not covered by tests. To ensure the correctness of the RPC status checks and error handling, consider adding unit tests for this function.

Some test cases to consider:

  1. Test successful RPC status check with valid block and TSS address details.
  2. Test error handling for each failed RPC call (GetBlockCount, GetBlockHash, GetBlockHeader, ListUnspentMinMaxAddresses).
  3. Test error handling for old blocks and missing TSS address UTXOs.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Also applies to: 249-251, 257-260, 265-271, 292-297

Tools
GitHub Check: codecov/patch

[warning] 243-243: zetaclient/chains/bitcoin/observer/observer.go#L243
Added line #L243 was not covered by tests

gartnera marked this conversation as resolved.
Show resolved Hide resolved
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")

Check warning on line 251 in zetaclient/chains/bitcoin/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/observer.go#L249-L251

Added lines #L249 - L251 were not covered by tests
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")

Check warning on line 260 in zetaclient/chains/bitcoin/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/observer.go#L257-L260

Added lines #L257 - L260 were not covered by tests
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("block_age_seconds", blockAgeSeconds).
Msg("RPC status check failed: block is old")

Check warning on line 271 in zetaclient/chains/bitcoin/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/observer.go#L265-L271

Added lines #L265 - L271 were not covered by tests
continue
}

Expand All @@ -280,7 +289,12 @@
}

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")

Check warning on line 297 in zetaclient/chains/bitcoin/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/observer.go#L292-L297

Added lines #L292 - L297 were not covered by tests

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 @@
}
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")

Check warning on line 220 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L220

Added line #L220 was not covered by tests
gartnera marked this conversation as resolved.
Show resolved Hide resolved
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")

Check warning on line 227 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L225-L227

Added lines #L225 - L227 were not covered by tests
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")

Check warning on line 234 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L232-L234

Added lines #L232 - L234 were not covered by tests
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 {

Check warning on line 240 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L239-L240

Added lines #L239 - L240 were not covered by tests
gartnera marked this conversation as resolved.
Show resolved Hide resolved
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)

Check warning on line 242 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L242

Added line #L242 was not covered by tests
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")

Check warning on line 250 in zetaclient/chains/evm/observer/observer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/evm/observer/observer.go#L246-L250

Added lines #L246 - L250 were not covered by tests
case <-ob.StopChannel():
return nil
}
Expand Down
Loading