Skip to content

Commit f9cf8bd

Browse files
committed
Handle negative timeout for waitTipChanged()
1 parent c20a5ce commit f9cf8bd

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/interfaces/mining.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class Mining
9393
*
9494
* @param[in] current_tip block hash of the current chain tip. Function waits
9595
* for the chain tip to differ from this.
96-
* @param[in] timeout how long to wait for a new tip
96+
* @param[in] timeout how long to wait for a new tip (default is forever)
97+
*
9798
* @returns Hash and height of the current chain tip after this call.
9899
*/
99100
virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;

src/node/interfaces.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,8 @@ class MinerImpl : public Mining
10721072

10731073
BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout) override
10741074
{
1075+
Assume(timeout >= 0ms); // No internal callers should use a negative timeout
1076+
if (timeout < 0ms) timeout = 0ms;
10751077
if (timeout > std::chrono::years{100}) timeout = std::chrono::years{100}; // Upper bound to avoid UB in std::chrono
10761078
{
10771079
WAIT_LOCK(notifications().m_tip_block_mutex, lock);

0 commit comments

Comments
 (0)