mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
dcb56fd4cbinterfaces: add interruptWait method (ismaelsadeeq) Pull request description: This is an attempt to fix #33575 see the issue for background and the usefulness of this feature. This PR uses one of the suggested approaches: adding a new `interruptWaitNext()` method to the mining interface. It introduces a new boolean variable, `m_interrupt_wait`, which is set to `false` when the thread starts waiting. The `interruptWaitNext()` method wakes the thread and sets `m_interrupt_wait` to `true`. Whenever the thread wakes up, it checks whether the wait was aborted; if so, it simply set ` m_interrupt_wait ` to false and return`nullptr`. This PR also adds a functional test for the new method. The test uses `asyncio` to spawn two tasks and attempts to ensure that the wait is executed before the interrupt by using an event monitor. It adds a 0.1-second buffer to ensure the wait has started executing. If that buffer elapses without `waitNext` executing, the test will fail because a transaction is created after the buffer. ACKs for top commit: furszy: Code ACKdcb56fd4cbryanofsky: Code review ACKdcb56fd4cb, just tweaking semantics slightly since last review so if an `interruptWait` call is made shortly after a `waitNext` call it will reliably cause the `waitNext` call to return right away without blocking, even if the `waitNext` call had not begun to execute or wait yet. Sjors: tACKdcb56fd4cbTheCharlatan: ACKdcb56fd4cbTree-SHA512: a03f049e1f303b174a9e5d125733b6583dfd8effa12e7b6c37bd9b2cff9541100f5f4514e80f89005c44a57d7e47804afe87aa5fdb6831f3b0cd9b01d83e42be