Repository navigation
fix: assertion in CMNHFManager due to missing data in evoDB - #5736
Merged
Merged
Conversation
2 of 5 tasks
knst
force-pushed
the
fix-mnehf-reindex
branch
from
November 30, 2023 07:00
4b0eee0 to
1bd1dab
Compare
knst
marked this pull request as ready for review
November 30, 2023 07:10
UdjinM6
requested changes
Nov 30, 2023
knst
force-pushed
the
fix-mnehf-reindex
branch
from
November 30, 2023 08:59
1bd1dab to
131bc3d
Compare
|
This pull request has conflicts, please rebase. |
…voDB Assertion failure: assertion: ok file: evo/mnhftx.cpp, line: 287 function: AbstractEHFManager::Signals CMNHFManager::GetFromCache(const CBlockIndex*) No debug information available for stacktrace. You should add debug information and then run: dash-qt -printcrashinfo=bvcgc43iinzgc43ijfxgm3ybaadwiyltnawxc5e3ifzxgzlsoruw63ramzqws3dvojstucraebqxg43foj2gs33ohiqg62ykeaqgm2lmmu5cazlwn4xw23timz2hqltdobycyidmnfxgkoragi4docraebthk3tdoruw63r2ebawe43uojqwg5cfjbde2ylomftwk4r2hjjwsz3omfwhgicdjvheqrsnmfxgcz3foi5dur3fordhe33ninqwg2dffbrw63ttoqqegqtmn5rwwslomrsxqkrjbyrelhyaaaaaaaedgkiaaaaaaaadsm4qaaaaaaaa7gpyqaaaaaaaa2njraaaaaaaadkl3caaaaaaaabhxznqaaaaaaadqa2eaaaaaaaax33twaaaaaaabwaihqaaaaaaac7yooqbaaaaaahba45qcaaaaaacwkz2aeaaaaaaeitgeaiaaaaaaaa= dash-qt: evo/mnhftx.cpp:287: AbstractEHFManager::Signals CMNHFManager::GetFromCache(const CBlockIndex*): Assertion `ok' failed. This can happen in case if Dash Core has been update from v19 (or earlier v20.alphaX) to v20.0.0 after v20 activation without re-indexing
knst
force-pushed
the
fix-mnehf-reindex
branch
from
December 1, 2023 15:14
131bc3d to
9fc5e64
Compare
PastaPastaPasta
approved these changes
Dec 1, 2023
PastaPastaPasta
left a comment
Member
There was a problem hiding this comment.
utACK for squash merge
2 of 5 tasks
3 of 5 tasks
UdjinM6
added a commit
that referenced
this pull request
Dec 4, 2023
…#5747) ## Issue being fixed or feature implemented Fixes a bug we missed in #5736 ## What was done? Use all collected indexes, not just the last one ## How Has This Been Tested? ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
UdjinM6
added a commit
that referenced
this pull request
Dec 4, 2023
## Issue being fixed or feature implemented Missing changes in #5736 The prior backport of bitcoin#19438 has been needed to this particular changes: drop the mutex `cs_llmq_vbc`. This mutex can potentially cause deadlock such as: ``` 'cs_dip3list' in qt/masternodelist.cpp:135 (TRY) (in thread 'main') (2) 'cs_llmq_vbc' in llmq/utils.cpp:704 (in thread 'main') 'm_mutex' in versionbits.cpp:253 (in thread 'main') (1) 'cs_main' in node/blockstorage.cpp:77 (in thread 'main') Current lock order is: 'cs_Shutdown' in init.cpp:220 (TRY) (in thread 'shutoff') (1) 'cs_main' in init.cpp:328 (in thread 'shutoff') (2) 'llmq::cs_llmq_vbc' in llmq/context.cpp:64 (in thread 'shutoff') Assertion failed: detected inconsistent lock order for 'llmq::cs_llmq_vbc' in llmq/context.cpp:64 (in thread 'shutoff'), details in debug log. ``` ## What was done? Drop `cs_llmq_vbc` mutex from llmq/utils ## How Has This Been Tested? Re-started app several times -> no other deadlock happens. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone --------- Co-authored-by: UdjinM6 <[email protected]>
ab4cus
pushed a commit
to ab4cus/e4Coin-core
that referenced
this pull request
Jul 8, 2026
## Issue being fixed or feature implemented Missing changes in dashpay/dash#5736 The prior backport of bitcoin/bitcoin#19438 has been needed to this particular changes: drop the mutex `cs_llmq_vbc`. This mutex can potentially cause deadlock such as: ``` 'cs_dip3list' in qt/masternodelist.cpp:135 (TRY) (in thread 'main') (2) 'cs_llmq_vbc' in llmq/utils.cpp:704 (in thread 'main') 'm_mutex' in versionbits.cpp:253 (in thread 'main') (1) 'cs_main' in node/blockstorage.cpp:77 (in thread 'main') Current lock order is: 'cs_Shutdown' in init.cpp:220 (TRY) (in thread 'shutoff') (1) 'cs_main' in init.cpp:328 (in thread 'shutoff') (2) 'llmq::cs_llmq_vbc' in llmq/context.cpp:64 (in thread 'shutoff') Assertion failed: detected inconsistent lock order for 'llmq::cs_llmq_vbc' in llmq/context.cpp:64 (in thread 'shutoff'), details in debug log. ``` ## What was done? Drop `cs_llmq_vbc` mutex from llmq/utils ## How Has This Been Tested? Re-started app several times -> no other deadlock happens. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone --------- Co-authored-by: UdjinM6 <[email protected]>
ab4cus
pushed a commit
to ab4cus/e4Coin-core
that referenced
this pull request
Jul 8, 2026
## Issue being fixed or feature implemented Missing changes in dashpay/dash#5736 The prior backport of bitcoin/bitcoin#19438 has been needed to this particular changes: drop the mutex `cs_llmq_vbc`. This mutex can potentially cause deadlock such as: ``` 'cs_dip3list' in qt/masternodelist.cpp:135 (TRY) (in thread 'main') (2) 'cs_llmq_vbc' in llmq/utils.cpp:704 (in thread 'main') 'm_mutex' in versionbits.cpp:253 (in thread 'main') (1) 'cs_main' in node/blockstorage.cpp:77 (in thread 'main') Current lock order is: 'cs_Shutdown' in init.cpp:220 (TRY) (in thread 'shutoff') (1) 'cs_main' in init.cpp:328 (in thread 'shutoff') (2) 'llmq::cs_llmq_vbc' in llmq/context.cpp:64 (in thread 'shutoff') Assertion failed: detected inconsistent lock order for 'llmq::cs_llmq_vbc' in llmq/context.cpp:64 (in thread 'shutoff'), details in debug log. ``` ## What was done? Drop `cs_llmq_vbc` mutex from llmq/utils ## How Has This Been Tested? Re-started app several times -> no other deadlock happens. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone --------- Co-authored-by: UdjinM6 <[email protected]>
3 tasks done
knst
added a commit
that referenced
this pull request
Nov 20, 2026
…blocks d682da6 fix: stop rebuilding MNHF signal state from unvalidated blocks (pasta) Pull request description: ## Issue being fixed or feature implemented `getdeploymentinfo <blockhash>` and `GET /rest/deploymentinfo/<blockhash>` accept any stored block, including blocks that were never connected (a stale sibling of the tip, or a block that was rejected). For such blocks `CMNHFManager::GetForBlock` rebuilds the MNHF signal state from block data that was never validated: - It persists the result through `AddToCache` → `CEvoDB::WriteDerived` outside any EvoDB transaction. The next full flush (or a clean `stop`) then aborts on `assert(cur_transaction.IsClean())` after the coins DB was already written, and the node needs `-reindex` to start again. Querying an ordinary stale block is enough. - A stored block whose MNHF transaction carries a version bit of 29 or above reaches `assert(nBit < VERSIONBITS_NUM_BITS)` in `CChainParams::IsValidMNActivation` and aborts the node. ## What was done? Signal state now only comes from connecting a block, so no caller can make `CMNHFManager` trust unvalidated block data, whatever block it passes. - `GetForBlock` / `GetSignalsStage` only read the in-memory cache and EvoDB. When nothing is stored they throw `EvoDbMissingStateError`, a new subclass of `EvoDbInconsistencyError`. The existing typed catches therefore treat a miss as a local error and never mark the block invalid. It does not abort the node, because an RPC can legitimately ask about a block that has no stored state. - The walk back and rebuild from block data moved to `RebuildSignals`. It requires `cs_main` (`EXCLUSIVE_LOCKS_REQUIRED` plus `AssertLockHeld`), throws for any block that never reached script validity, and only runs at startup. A block that was connected and later marked invalid still counts, so an `invalidateblock` interrupted by a crash does not block the replay. That is its original purpose: migrating datadirs that predate the stored state (#5736). `ForceSignalDBUpdate` runs it for the tip. `ReplayBlocks` also runs it for the last flushed tip, inside its EvoDB transaction: replaying an interrupted coins flush reads that block's signal state, and it runs before `ForceSignalDBUpdate`. Without this, a datadir last run on v21.x or older (v22.0.0 was the first release to store the current `mnhf_s2` state) that also had an interrupted flush would fail to start. - The lookup treats the genesis block as having no signals, whatever the V20 height. It is never connected, so nothing is stored for it. - The manager never takes `cs_main` itself. `GetSignalsStage` is reached from `VersionBitsCache::State()` while the cache's mutex is held, and taking `cs_main` there would invert the lock order (#5736 hit exactly this deadlock report). - `getdeploymentinfo`, and the REST endpoint that wraps it, reject invalid and unvalidated blocks up front, under the `cs_main` the RPC already holds. The genesis block is exempt: `ConnectBlock` skips it, so it never reaches `BLOCK_VALID_SCRIPTS`, and it has no signal state to get wrong. The guard is still needed with the read-only manager, because a block whose connection failed part-way can leave an entry in the in-memory cache. - `AddToCache` checks `Assume(HasActiveTransaction())` before the EvoDB write. Every remaining caller connects a block inside a transaction. - `IsValidMNActivation` returns false for out-of-range bits instead of asserting. With the changes above nothing reaches it with such a bit any more (`CheckMNHFTx` rejects it first), so this is defense in depth: the function takes block-derived data and should not assert on it. Block processing is unchanged. `ConnectBlock` only asks about the parent, whose state was stored when the parent was connected. Stored state is never erased, so blocks that were connected and later reorged out stay queryable. ### Edge case that now returns an error instead of rebuilding After `-reindex-chainstate`, `getdeploymentinfo` on a stale side-chain block that was never reconnected returns an error. ## How Has This Been Tested? - `evo_mnhf_tests`: - `IsValidMNActivation` rejects -1, 29 and 255 (29 and 255 abort on `develop`; -1 is a boundary check). - A new case stores a sibling block that was never connected. `GetSignalsStage` on it throws `EvoDbMissingStateError`, and succeeds once a reorg connects it. With the on-demand rebuild put back, the case fails. - With V20 active from height 0, `GetSignalsStage` on the genesis block returns no signals. Without the genesis case it throws. - `interface_rest.py`: `/rest/deploymentinfo` on a header-only block returns the new error, and `getdeploymentinfo` on the genesis block works. - Never-connected and rejected stored blocks have no functional test; `evo_mnhf_tests` covers the cause. They were checked end to end at 59db81c, with a scenario that was removed from `interface_rest.py` in review: RPC and REST `deploymentinfo` on a stale stored block, and on a block rejected for MNHF bit 200, returned an error, and a flush and a clean restart followed. Against `develop`'s `dashd` the stale-block query succeeds and the node then aborts on `IsClean()` at shutdown, and the query on the block rejected for bit 200 aborts the node on the `IsValidMNActivation` assert. - At 59db81c, rebased onto `develop`: `evo_mnhf_tests`, `versionbits_tests`, `validation_chainstate_tests` and `rpc_tests` pass, as do `interface_rest.py`, `feature_mnehf.py`, `rpc_blockchain.py`, `feature_dbcrash.py` and `rpc_help.py`. The current head differs from it only in `interface_rest.py`, which passes. On an earlier head, removing the RPC's genesis exemption made `interface_rest.py` fail on the genesis query. - Accepting a block that was connected and later marked invalid in `RebuildSignals` has no automated test, for the same reason as the replay migration below. - The replay migration has no automated test, because it needs a datadir without `mnhf_s2` state. Checked by hand on regtest: a throwaway build that never writes `mnhf_s2` mined 1100 blocks, flushed, then crashed mid-flush (`-dbcrashratio=1 -dbbatchsize=1`) two blocks later. Without the `ReplayBlocks` call, startup on that datadir fails while rolling forward the first block (`MNHF signals unavailable for block ...`). With it, startup rebuilds the state, replays both blocks, and `getdeploymentinfo`, mining and a clean restart work. `feature_asset_locks.py` covers the replay on a current datadir, where the call finds the state already stored. ## Breaking Changes `getdeploymentinfo` / `/rest/deploymentinfo` now return an error, instead of a result computed from unvalidated data, for a block that is not fully validated: a header-only block, a stored block that was never connected, a rejected block, and a block marked invalid with `invalidateblock`, together with each descendant that is marked failed with it (until `reconsiderblock`). ## Checklist: - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(if you have permission to set one)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) ACKs for top commit: knst: utACK d682da6 Tree-SHA512: 849dbf30ff9845046a9df7e8929e6d67fe1a3fb95185509211c4c03f2c12416dc42a4442b1922bff16b10b6e8da0fba00a5894fa8815cf9a932922374590e3f5
PastaPastaPasta
pushed a commit
to PastaPastaPasta/dash
that referenced
this pull request
Nov 20, 2026
…idated blocks d682da6 fix: stop rebuilding MNHF signal state from unvalidated blocks (pasta) Pull request description: ## Issue being fixed or feature implemented `getdeploymentinfo <blockhash>` and `GET /rest/deploymentinfo/<blockhash>` accept any stored block, including blocks that were never connected (a stale sibling of the tip, or a block that was rejected). For such blocks `CMNHFManager::GetForBlock` rebuilds the MNHF signal state from block data that was never validated: - It persists the result through `AddToCache` → `CEvoDB::WriteDerived` outside any EvoDB transaction. The next full flush (or a clean `stop`) then aborts on `assert(cur_transaction.IsClean())` after the coins DB was already written, and the node needs `-reindex` to start again. Querying an ordinary stale block is enough. - A stored block whose MNHF transaction carries a version bit of 29 or above reaches `assert(nBit < VERSIONBITS_NUM_BITS)` in `CChainParams::IsValidMNActivation` and aborts the node. ## What was done? Signal state now only comes from connecting a block, so no caller can make `CMNHFManager` trust unvalidated block data, whatever block it passes. - `GetForBlock` / `GetSignalsStage` only read the in-memory cache and EvoDB. When nothing is stored they throw `EvoDbMissingStateError`, a new subclass of `EvoDbInconsistencyError`. The existing typed catches therefore treat a miss as a local error and never mark the block invalid. It does not abort the node, because an RPC can legitimately ask about a block that has no stored state. - The walk back and rebuild from block data moved to `RebuildSignals`. It requires `cs_main` (`EXCLUSIVE_LOCKS_REQUIRED` plus `AssertLockHeld`), throws for any block that never reached script validity, and only runs at startup. A block that was connected and later marked invalid still counts, so an `invalidateblock` interrupted by a crash does not block the replay. That is its original purpose: migrating datadirs that predate the stored state (dashpay#5736). `ForceSignalDBUpdate` runs it for the tip. `ReplayBlocks` also runs it for the last flushed tip, inside its EvoDB transaction: replaying an interrupted coins flush reads that block's signal state, and it runs before `ForceSignalDBUpdate`. Without this, a datadir last run on v21.x or older (v22.0.0 was the first release to store the current `mnhf_s2` state) that also had an interrupted flush would fail to start. - The lookup treats the genesis block as having no signals, whatever the V20 height. It is never connected, so nothing is stored for it. - The manager never takes `cs_main` itself. `GetSignalsStage` is reached from `VersionBitsCache::State()` while the cache's mutex is held, and taking `cs_main` there would invert the lock order (dashpay#5736 hit exactly this deadlock report). - `getdeploymentinfo`, and the REST endpoint that wraps it, reject invalid and unvalidated blocks up front, under the `cs_main` the RPC already holds. The genesis block is exempt: `ConnectBlock` skips it, so it never reaches `BLOCK_VALID_SCRIPTS`, and it has no signal state to get wrong. The guard is still needed with the read-only manager, because a block whose connection failed part-way can leave an entry in the in-memory cache. - `AddToCache` checks `Assume(HasActiveTransaction())` before the EvoDB write. Every remaining caller connects a block inside a transaction. - `IsValidMNActivation` returns false for out-of-range bits instead of asserting. With the changes above nothing reaches it with such a bit any more (`CheckMNHFTx` rejects it first), so this is defense in depth: the function takes block-derived data and should not assert on it. Block processing is unchanged. `ConnectBlock` only asks about the parent, whose state was stored when the parent was connected. Stored state is never erased, so blocks that were connected and later reorged out stay queryable. ### Edge case that now returns an error instead of rebuilding After `-reindex-chainstate`, `getdeploymentinfo` on a stale side-chain block that was never reconnected returns an error. ## How Has This Been Tested? - `evo_mnhf_tests`: - `IsValidMNActivation` rejects -1, 29 and 255 (29 and 255 abort on `develop`; -1 is a boundary check). - A new case stores a sibling block that was never connected. `GetSignalsStage` on it throws `EvoDbMissingStateError`, and succeeds once a reorg connects it. With the on-demand rebuild put back, the case fails. - With V20 active from height 0, `GetSignalsStage` on the genesis block returns no signals. Without the genesis case it throws. - `interface_rest.py`: `/rest/deploymentinfo` on a header-only block returns the new error, and `getdeploymentinfo` on the genesis block works. - Never-connected and rejected stored blocks have no functional test; `evo_mnhf_tests` covers the cause. They were checked end to end at 59db81c, with a scenario that was removed from `interface_rest.py` in review: RPC and REST `deploymentinfo` on a stale stored block, and on a block rejected for MNHF bit 200, returned an error, and a flush and a clean restart followed. Against `develop`'s `dashd` the stale-block query succeeds and the node then aborts on `IsClean()` at shutdown, and the query on the block rejected for bit 200 aborts the node on the `IsValidMNActivation` assert. - At 59db81c, rebased onto `develop`: `evo_mnhf_tests`, `versionbits_tests`, `validation_chainstate_tests` and `rpc_tests` pass, as do `interface_rest.py`, `feature_mnehf.py`, `rpc_blockchain.py`, `feature_dbcrash.py` and `rpc_help.py`. The current head differs from it only in `interface_rest.py`, which passes. On an earlier head, removing the RPC's genesis exemption made `interface_rest.py` fail on the genesis query. - Accepting a block that was connected and later marked invalid in `RebuildSignals` has no automated test, for the same reason as the replay migration below. - The replay migration has no automated test, because it needs a datadir without `mnhf_s2` state. Checked by hand on regtest: a throwaway build that never writes `mnhf_s2` mined 1100 blocks, flushed, then crashed mid-flush (`-dbcrashratio=1 -dbbatchsize=1`) two blocks later. Without the `ReplayBlocks` call, startup on that datadir fails while rolling forward the first block (`MNHF signals unavailable for block ...`). With it, startup rebuilds the state, replays both blocks, and `getdeploymentinfo`, mining and a clean restart work. `feature_asset_locks.py` covers the replay on a current datadir, where the call finds the state already stored. ## Breaking Changes `getdeploymentinfo` / `/rest/deploymentinfo` now return an error, instead of a result computed from unvalidated data, for a block that is not fully validated: a header-only block, a stored block that was never connected, a rejected block, and a block marked invalid with `invalidateblock`, together with each descendant that is marked failed with it (until `reconsiderblock`). ## Checklist: - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(if you have permission to set one)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) ACKs for top commit: knst: utACK d682da6 Tree-SHA512: 849dbf30ff9845046a9df7e8929e6d67fe1a3fb95185509211c4c03f2c12416dc42a4442b1922bff16b10b6e8da0fba00a5894fa8815cf9a932922374590e3f5 (cherry picked from commit a374e91) Backport adaptation: v24.0.x has neither the BLS scheme refactor nor CSpecialTxProcessor's ownership of the MNHF manager. - src/evo/mnhftx.cpp: ForceSignalDBUpdate() keeps v24.0.x's switch to the basic BLS scheme around the walk and calls RebuildSignals() in place of GetSignalsStage(). It includes <util/check.h> for the new Assume(), which develop gets through other headers. - src/evo/specialtxman.{h,cpp}: the RebuildMNHFSignals() passthrough calls m_mnhfman.RebuildSignals(); v24.0.x's CSpecialTxProcessor holds the manager by reference. Only the comment changes apply to the rest of these files; the develop-only code around them is left out. - src/validation.cpp: ReplayBlocks() reaches the passthrough through m_chain_helper->special_tx. The walk verifies no BLS signature, so it needs no BLS scheme switch. - The IsValidMNActivation() change goes to src/chainparams.cpp (src/kernel/chainparams.cpp on develop). - src/test/evo_mnhf_tests.cpp: the new tests reach the manager through m_node.chain_helper->ehf_manager and include <evo/chainhelper.h>. The other changes, including test/functional/interface_rest.py, are identical to the develop pick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior required changes: bitcoin#19438 from #5740
Issue being fixed or feature implemented
Assertion failure:
This can happen in case if Dash Core has been update from v19 (or earlier v20.alphaX) to v20.0.0 after v20 activation without re-indexing
What was done?
CMNHFManageris visiting missing blocks recursively until reach first v20 block or first block actually saved in evoDb.Without changes from bitcoin#19438 there's an other issue:
How Has This Been Tested?
Run unit/functional test; run dash-qt on my local backup of problematic storage (succeed without error); reindex testnet.
Breaking Changes
N/A
Checklist: