Skip to content

chore(node,wire): lower WARN/ERROR logs that aren't problems - #21

Open
lorenzolfm wants to merge 7 commits into
masterfrom
chore/lower-warn-error
Open

lorenzolfm wants to merge 7 commits into
masterfrom
chore/lower-warn-error

Conversation

@lorenzolfm

Copy link
Copy Markdown
Owner

Description and Notes

Part of getfloresta/floresta#167 ("[tracking-issue] Audit logging and identify improvements").

From the issue:

  • csgui: "identifying which logs could be upgraded or downgraded in terms of their level"
  • Davidson-Souza: "messages can be improved to be more clear"

On a fresh signet start, a restart, and a mainnet start, every WARN/ERROR line florestad printed came from one of the cases below, and none of them was a problem. This PR lowers those lines, and where a real problem is still possible it keeps the WARN and makes the message say what failed. One commit per case, so any of them can be dropped.

before after
WARN Could not read config file, ignoring it ×3 on every start (no config file at the default path) DEBUG No config file at <path>, using defaults, once. A missing explicit --config-file stays WARN and names the path
WARN Could not parse config file, ignoring it ×3, with the parse error only at DEBUG one WARN with the path and the TOML error (also covers "Config errors are effectively silent" from the audit)
WARN Failed to init Utreexo peers: anchors.json does not exist yet, or is invalid on every fresh start missing file → DEBUG; unreadable/invalid file → WARN with the error
ERROR DNS lookup failed: <err> + WARN No peer addresses read from DNS host: <host> for one dead seed WARN DNS lookup failed for host <host>: <err>. An empty answer still logs the existing WARN
WARN unexpected message: Unknown { command: CommandString("sendtemplate"), payload: [] } from peer N DEBUG unexpected message: sendtemplate from peer N (the peer is still disconnected, as before)
ERROR 90: crates/floresta-wire/src/p2p_wire/node/sync_ctx.rs - NoPeersAvailable (and 255:) right after the assume-utreexo jump DEBUG for NoPeersAvailable at these two sites; other errors there stay ERROR
ERROR 484: crates/floresta-wire/src/p2p_wire/node/mod.rs - ChannelSend(SendError { .. }) and WARN No connected Utreexo peers to save to disk on every Ctrl-C both DEBUG

Commit 2 is a small refactor: get_config_file() was called three times during wallet setup (once each for descriptors, xpubs and addresses), so each config message was printed three times. Now it is read once and passed in.

Not in this PR (possible follow-ups):

  • try_and_log! prints {line}: {file} - {err:?}, which doesn't tell an operator what failed. Giving it a context string touches its ~46 call sites.
  • A peer that sends sendtemplate between version and verack is disconnected with UnexpectedMessage. That's behaviour, not logging, so it isn't changed here.

How to verify the changes you have done?

florestad --log-to-file at the default level, same machine, fresh data dirs:

run WARN/ERROR lines, master WARN/ERROR lines, this PR
signet, fresh (master 20 min, PR 5 min) 16 1 (DNS lookup failed for host x1000.signet.seed.utreexo.net: …)
signet, restart (master 3 min, PR 2 min) 8 1 (same dead seed)
mainnet, fresh, past the assume-utreexo jump (master 25 min, PR 15 min) 23 4 (one per unresolvable seed, each naming the host)

All master lines were from the cases above. With RUST_LOG=info,floresta_wire=debug,floresta_node=debug, each lowered message still shows up once at DEBUG: No config file at …, No anchors.json yet…, unexpected message: sendtemplate from peer N, Could not send shutdown to peer N: ChannelSend(..), No connected Utreexo peers to save to disk.

NoPeersAvailable didn't come up in either mainnet run with this PR (15 and 20 min, both past the assume-utreexo jump), so its new DEBUG line wasn't observed at runtime. On master it showed up 9× in the 20 s after the jump. It depends on peer timing, and the change is a match on WireError::NoPeersAvailable that falls through to try_and_log! for any other error.

Config cases (signet, 30 s each):

  • malformed <datadir>/signet/config.toml → one WARN Could not parse config file <path>, ignoring it: TOML parse error at line 1, column 8 … (with toml's caret snippet)
  • --config-file /nonexistent/floresta.toml → one WARN Could not read config file /nonexistent/floresta.toml, ignoring it: No such file or directory (os error 2)

cargo +nightly fmt --check, cargo hack clippy --feature-powerset --all-targets -- -D warnings on floresta-wire and floresta-node, and cargo test -p floresta-wire -p floresta-node pass.

…default at debug

With no config file at the default `{datadir}/config.toml`, every start
printed `WARN Could not read config file, ignoring it`. That's the normal
case, so log it at debug. A missing explicit `--config-file`, or a file
that can't be parsed, stays a warning, now with the path and the error
(the TOML error used to be at debug only).
`get_config_file()` was called once each for descriptors, xpubs and
addresses, so every config warning was printed three times. Read it once
in `setup_wallet` and pass it to the three getters.
anchors.json only exists after a utreexo peer was saved, so a fresh start
always printed `Failed to init Utreexo peers: anchors.json does not exist
yet, or is invalid`. Log a missing file at debug, and keep the warning for
a file that can't be read or parsed, now with the error.
A dead seed printed `ERROR DNS lookup failed: <err>`, without the host,
then `WARN No peer addresses read from DNS host: <host>`. One dead seed
out of several isn't an error: log a single warning with the host and the
error. A lookup that succeeds with no addresses still logs the existing
warning.
This is a remote peer's behaviour (e.g. `sendtemplate` before `verack`),
and the warning Debug-printed the whole message. Log the command name at
debug instead. The peer is still disconnected as before.
Right after the assume-utreexo jump, the sync node logged
`ERROR 90: crates/floresta-wire/src/p2p_wire/node/sync_ctx.rs - NoPeersAvailable`
several times while it had no peer to ask for blocks yet. That's a
transient state, so log it at debug. Other errors at these two sites still
go through `try_and_log!`.
Every Ctrl-C printed `ERROR 484: .../node/mod.rs - ChannelSend(SendError { .. })`
for peers that were already gone, and `WARN No connected Utreexo peers to
save to disk` when no utreexo peer was connected. Neither is a problem
during shutdown, so log both at debug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant