From f9cf8bd0ab77cdf125d78384197a5c466577fd8f Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Wed, 19 Feb 2025 15:54:35 +0100 Subject: [PATCH] Handle negative timeout for waitTipChanged() --- src/interfaces/mining.h | 3 ++- src/node/interfaces.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/interfaces/mining.h b/src/interfaces/mining.h index 435151c5dda..249b9cefd4a 100644 --- a/src/interfaces/mining.h +++ b/src/interfaces/mining.h @@ -93,7 +93,8 @@ public: * * @param[in] current_tip block hash of the current chain tip. Function waits * for the chain tip to differ from this. - * @param[in] timeout how long to wait for a new tip + * @param[in] timeout how long to wait for a new tip (default is forever) + * * @returns Hash and height of the current chain tip after this call. */ virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 50207c658d8..59639414212 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -1072,6 +1072,8 @@ public: BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout) override { + Assume(timeout >= 0ms); // No internal callers should use a negative timeout + if (timeout < 0ms) timeout = 0ms; if (timeout > std::chrono::years{100}) timeout = std::chrono::years{100}; // Upper bound to avoid UB in std::chrono { WAIT_LOCK(notifications().m_tip_block_mutex, lock);