|
34 | 34 | #include <node/interface_ui.h>
|
35 | 35 | #include <node/mini_miner.h>
|
36 | 36 | #include <node/miner.h>
|
| 37 | +#include <node/kernel_notifications.h> |
37 | 38 | #include <node/transaction.h>
|
38 | 39 | #include <node/types.h>
|
39 | 40 | #include <node/warnings.h>
|
@@ -935,6 +936,27 @@ class MinerImpl : public Mining
|
935 | 936 | return BlockRef{tip->GetBlockHash(), tip->nHeight};
|
936 | 937 | }
|
937 | 938 |
|
| 939 | + BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout) override |
| 940 | + { |
| 941 | + // Interrupt check interval |
| 942 | + const MillisecondsDouble tick{1000}; |
| 943 | + auto now{std::chrono::steady_clock::now()}; |
| 944 | + auto deadline = now + timeout; |
| 945 | + // std::chrono does not check against overflow |
| 946 | + if (deadline < now) deadline = std::chrono::steady_clock::time_point::max(); |
| 947 | + { |
| 948 | + WAIT_LOCK(notifications().m_tip_block_mutex, lock); |
| 949 | + while ((notifications().m_tip_block == uint256() || notifications().m_tip_block == current_tip) && !chainman().m_interrupt) { |
| 950 | + now = std::chrono::steady_clock::now(); |
| 951 | + if (now >= deadline) break; |
| 952 | + notifications().m_tip_block_cv.wait_until(lock, std::min(deadline, now + tick)); |
| 953 | + } |
| 954 | + } |
| 955 | + // Must release m_tip_block_mutex before locking cs_main, to avoid deadlocks. |
| 956 | + LOCK(::cs_main); |
| 957 | + return BlockRef{chainman().ActiveChain().Tip()->GetBlockHash(), chainman().ActiveChain().Tip()->nHeight}; |
| 958 | + } |
| 959 | + |
938 | 960 | bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) override
|
939 | 961 | {
|
940 | 962 | return chainman().ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/new_block);
|
@@ -967,6 +989,7 @@ class MinerImpl : public Mining
|
967 | 989 |
|
968 | 990 | NodeContext* context() override { return &m_node; }
|
969 | 991 | ChainstateManager& chainman() { return *Assert(m_node.chainman); }
|
| 992 | + KernelNotifications& notifications() { return *Assert(m_node.notifications); } |
970 | 993 | NodeContext& m_node;
|
971 | 994 | };
|
972 | 995 | } // namespace
|
|
0 commit comments