From 640b9c91f94396226af6cd72d079fa21934f9787 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Sat, 26 Jul 2025 11:52:19 +0700 Subject: [PATCH] refactor(logging): use JLOG directly in Manifest.cpp for correct line numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace logMftAct template functions with macros to preserve call site line numbers - Use do-while(0) pattern to avoid dangling else warnings - Add #undef at end of file to prevent namespace pollution - Maintains exact same log format while fixing line number attribution 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/ripple/app/misc/impl/Manifest.cpp | 57 ++++++++++++--------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/ripple/app/misc/impl/Manifest.cpp b/src/ripple/app/misc/impl/Manifest.cpp index 60b521330..44e19244a 100644 --- a/src/ripple/app/misc/impl/Manifest.cpp +++ b/src/ripple/app/misc/impl/Manifest.cpp @@ -156,34 +156,22 @@ deserializeManifest(Slice s, beast::Journal journal) } } -template -Stream& -logMftAct( - Stream& s, - std::string const& action, - PublicKey const& pk, - std::uint32_t seq) -{ - s << "Manifest: " << action - << ";Pk: " << toBase58(TokenType::NodePublic, pk) << ";Seq: " << seq - << ";"; - return s; -} +// Helper macros to format manifest log messages while preserving line numbers +#define LOG_MANIFEST_ACTION(stream, action, pk, seq) \ + do \ + { \ + JLOG(stream) << "Manifest: " << action \ + << ";Pk: " << toBase58(TokenType::NodePublic, pk) \ + << ";Seq: " << seq << ";"; \ + } while (0) -template -Stream& -logMftAct( - Stream& s, - std::string const& action, - PublicKey const& pk, - std::uint32_t seq, - std::uint32_t oldSeq) -{ - s << "Manifest: " << action - << ";Pk: " << toBase58(TokenType::NodePublic, pk) << ";Seq: " << seq - << ";OldSeq: " << oldSeq << ";"; - return s; -} +#define LOG_MANIFEST_ACTION_WITH_OLD(stream, action, pk, seq, oldSeq) \ + do \ + { \ + JLOG(stream) << "Manifest: " << action \ + << ";Pk: " << toBase58(TokenType::NodePublic, pk) \ + << ";Seq: " << seq << ";OldSeq: " << oldSeq << ";"; \ + } while (0) bool Manifest::verify() const @@ -381,7 +369,7 @@ ManifestCache::applyManifest(Manifest m) // several cases including when we receive manifests from a peer who // doesn't have the latest data. if (auto stream = j_.debug()) - logMftAct( + LOG_MANIFEST_ACTION_WITH_OLD( stream, "Stale", m.masterKey, @@ -393,7 +381,7 @@ ManifestCache::applyManifest(Manifest m) if (checkSignature && !m.verify()) { if (auto stream = j_.warn()) - logMftAct(stream, "Invalid", m.masterKey, m.sequence); + LOG_MANIFEST_ACTION(stream, "Invalid", m.masterKey, m.sequence); return ManifestDisposition::invalid; } @@ -407,7 +395,7 @@ ManifestCache::applyManifest(Manifest m) bool const revoked = m.revoked(); if (auto stream = j_.warn(); stream && revoked) - logMftAct(stream, "Revoked", m.masterKey, m.sequence); + LOG_MANIFEST_ACTION(stream, "Revoked", m.masterKey, m.sequence); // Sanity check: the master key of this manifest should not be used as // the ephemeral key of another manifest: @@ -476,7 +464,7 @@ ManifestCache::applyManifest(Manifest m) if (iter == map_.end()) { if (auto stream = j_.info()) - logMftAct(stream, "AcceptedNew", m.masterKey, m.sequence); + LOG_MANIFEST_ACTION(stream, "AcceptedNew", m.masterKey, m.sequence); if (!revoked) signingToMasterKeys_[m.signingKey] = m.masterKey; @@ -489,7 +477,7 @@ ManifestCache::applyManifest(Manifest m) // An ephemeral key was revoked and superseded by a new key. This is // expected, but should happen infrequently. if (auto stream = j_.info()) - logMftAct( + LOG_MANIFEST_ACTION_WITH_OLD( stream, "AcceptedUpdate", m.masterKey, @@ -584,4 +572,9 @@ ManifestCache::save( saveManifests(*db, dbTable, isTrusted, map_, j_); } + +// Clean up macros to avoid namespace pollution +#undef LOG_MANIFEST_ACTION +#undef LOG_MANIFEST_ACTION_WITH_OLD + } // namespace ripple