mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-25 13:28:35 +01:00
Handle negative timeout for waitTipChanged()
This commit is contained in:
@@ -93,7 +93,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param[in] current_tip block hash of the current chain tip. Function waits
|
* @param[in] current_tip block hash of the current chain tip. Function waits
|
||||||
* for the chain tip to differ from this.
|
* 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.
|
* @returns Hash and height of the current chain tip after this call.
|
||||||
*/
|
*/
|
||||||
virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
|
virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
|
||||||
|
|||||||
@@ -1072,6 +1072,8 @@ public:
|
|||||||
|
|
||||||
BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout) override
|
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
|
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);
|
WAIT_LOCK(notifications().m_tip_block_mutex, lock);
|
||||||
|
|||||||
Reference in New Issue
Block a user