scripted-diff: Remove trailing newlines from one-line log messages

bitcoin/bitcoin: PR #36904

3 suggestions

Optional improvements

Link

[suggestion] · Single-line CTransaction::ToString() also flattens the Qt debug view

When log categories are enabled, the Qt transaction-details debug section loses its explicit header, input, witness, and output line breaks because it shares the formatter now flattened for logging.

Location: src/primitives/transaction.cpp:118 (head).

Details and suggested fix

TransactionDesc::toHTML() passes this string through GUIUtil::HtmlEscape(..., true), which converts each newline into <br>. Previously, the header and each input, witness, and output occupied separate lines. The new formatter instead produces one paragraph subject to automatic wrapping, and HTML collapses the four-space separators. The separate Inputs list does not restore this layout or display the witnesses. Preserve the multiline shared representation and flatten it locally at the CommitTransaction log call instead. The logger already escapes embedded newlines, so retaining the GUI layout does not require a logging-safety exception.


Link

[suggestion] · fa885f4 leaves additional transaction-format changes unexplained

The newline-removal commit also renames and reorders fields, expands the txid, and pairs inputs with witnesses; documenting these choices would distinguish presentation changes from newline normalization.

Location: src/primitives/transaction.cpp:118 at fa885f4e0b4a (commit) (commit).

Details and suggested fix

Commit fa885f4e0b4a58bb5b390baf5c80189bf35ec252 renames hash, ver, vin.size, vout.size, and nLockTime; moves locktime ahead of the counts; replaces the ten-character hash prefix with the full txid; and pairs each input with its witness instead of printing all witnesses afterward. Expand its message to describe these choices and acknowledge that the debug-enabled Qt consumer converts newlines into <br>, not \x0a.

The preceding scripted commit, fafab6ed42658b9cbfdc1f0c02d94e689aa6c7bb, can retain its mechanical scope. Alternatively, split the manual commit into newline normalization followed by the field, hash, and witness-layout changes. Keep any required util/string.h include and the CommitTransaction adjustment with the normalization step. This would let reviewers validate newline removal separately from the additional presentation choices.


Link

[suggestion] · Removing the format-string newline can hide an argument's trailing newline

Converted calls ending in %s now lose one argument-supplied trailing newline instead of logging \x0a; no current caller producing such an argument was identified, so production impact is unconfirmed.

Location: src/noui.cpp:29 (head).

Details and suggested fix

For a non-secure error message whose message.original is "x\n", the old LogError("%s\n", message.original) produced "x\n\n". Logger::Format() removed one newline and escaped the other, leaving x\x0a in the record. The new LogError("%s", message.original) produces "x\n", so the unchanged RemoveSuffixView() removes the argument's newline before escaping. This loses the diagnostic marker that LogEscapeMessage() deliberately preserves for troubleshooting; it does not enable forged log lines. Document this conditional behavior change in the scripted-diff commit message rather than describing every removal as output-neutral.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Escaping embedded newlines was introduced to prevent untrusted input from forging apparently genuine node log records, not merely to standardize presentation.

Historical PR #35833 identifies restricted RPC method names and wallet names as injection paths. This explains the single-line logging constraint affecting transaction dumps. The security objective concerns what the logging framework emits; it does not itself specify the representation returned by CTransaction::ToString() to non-log consumers.

Source 1

The logging change explicitly traded some multiline readability for safety: an attempted SplitLines accommodation was dropped after it allowed attacker-controlled text to appear as separately prefixed log lines.

The historical discussion explains why preserving readable multiline log output was not accepted as a general exception. It supports treating embedded transaction newlines as escaped data when logged, but contains no inspected decision requiring changes to transaction field labels, hash abbreviation, or the shared formatter's GUI presentation.

Source 1 · Source 2

Transaction-family ToString methods have an explicitly stated debugging purpose, and their content and ordering have previously been discussed as debugging presentation choices.

Historical PR #33711 proposed including witnesses in CTxIn::ToString() to help debugging. Its discussion recognized that CTransaction::ToString() already printed inputs and then witnesses, and considered removing duplication or changing their order. This supports a human-debugging role, but does not establish a promise to preserve the exact multiline or abbreviated-hash format.

Source 1 · Source 2 · Source 3