Page MenuHomePhabricator

wallet: Ignore chainStateFlushed notifications while attaching chain
Changes PlannedPublic

Authored by PiRK on Sun, Feb 23, 09:12.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

When a rescan is performed during CWallet::AttachChain() (e.g. when loading an old wallet) but this is interrupted by a shutdown signal, the wallet will currently stop the rescan, receive a chainStateFlushed signal, set the saved best block to the tip and shut down. At next startup, the rescan is not continued or repeated because of this. But some blocks have never been scanned by the wallet, which could lead to an incorrect balance.

Fix this by ignoring chainStateFlushed notifications until the chain is attached. Since CWallet::chainStateFlushed is being manually called by AttachChain() anyway after finishing with the rescan, it is not a problem if intermediate notifications are ignored.

Manual rescans started / aborted by the rescanblockchain / abortrescan RPCs are not affected by this (which makes this behavior hard to test).

This is a backport of core#24984 and core#25088

Test Plan

Check for no regressions on existing tested behavior:

ninja all check-all

Event Timeline

PiRK requested review of this revision.Sun, Feb 23, 09:12

Failed tests logs:

====== Bitcoin ABC functional tests: feature_assumevalid.py ======

------- Stdout: -------
2025-02-23T09:16:56.467000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_🏃_20250223_091508/feature_assumevalid_38
2025-02-23T09:18:03.203000Z TestFramework.utils (ERROR): wait_until() failed. Predicate: ''''
        self.wait_until(lambda: self.nodes[0].getblockcount() >= COINBASE_MATURITY + 1)
'''
2025-02-23T09:18:03.203000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 149, in main
    self._run_test_internal()
  File "/work/test/functional/test_framework/test_framework.py", line 139, in _run_test_internal
    self.run_test()
  File "/work/test/functional/feature_assumevalid.py", line 158, in run_test
    self.wait_until(lambda: self.nodes[0].getblockcount() >= COINBASE_MATURITY + 1)
  File "/work/test/functional/test_framework/test_framework.py", line 874, in wait_until
    return wait_until_helper(
           ^^^^^^^^^^^^^^^^^^
  File "/work/test/functional/test_framework/util.py", line 296, in wait_until_helper
    raise AssertionError(
AssertionError: Predicate ''''
        self.wait_until(lambda: self.nodes[0].getblockcount() >= COINBASE_MATURITY + 1)
''' not true after 60.0 seconds
2025-02-23T09:18:03.205000Z TestFramework (INFO): Stopping nodes
2025-02-23T09:18:03.509000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_🏃_20250223_091508/feature_assumevalid_38
2025-02-23T09:18:03.509000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_🏃_20250223_091508/feature_assumevalid_38/test_framework.log
2025-02-23T09:18:03.510000Z TestFramework (ERROR): 
2025-02-23T09:18:03.510000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_🏃_20250223_091508/feature_assumevalid_38' to consolidate all logs
2025-02-23T09:18:03.510000Z TestFramework (ERROR): 
2025-02-23T09:18:03.510000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2025-02-23T09:18:03.510000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2025-02-23T09:18:03.510000Z TestFramework (ERROR):

Each failure log is accessible here:
Bitcoin ABC functional tests: feature_assumevalid.py

PiRK planned changes to this revision.Sun, Feb 23, 09:25

CI failure most likely unrelated, but will have to investigate anyway (tomorrow)