Skip to content

refactor: remove g_txindex from TestChainSetup as optional step#7455

Merged
PastaPastaPasta merged 3 commits into
dashpay:developfrom
knst:refactor-regtest-avoid-txindex
Jul 14, 2026
Merged

refactor: remove g_txindex from TestChainSetup as optional step#7455
PastaPastaPasta merged 3 commits into
dashpay:developfrom
knst:refactor-regtest-avoid-txindex

Conversation

@knst

@knst knst commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

g_txindex has own tests and there's no needs in tx-index in the common environment for regression tests

This PR is a blocker for #7462 - particularly bitcoin#25494

What was done?

Removed usages of g_txindex by calling GetTransaction from block_reward_reallocation_tests.cpp, evo_deterministicmns_tests.cpp

Simplified and removed duplicated code from evo_deterministicmns_tests.cpp

How Has This Been Tested?

Run unit & functional tests.

Breaking Changes

n/a

Checklist:

  • 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
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@thepastaclaw

thepastaclaw commented Jul 13, 2026

Copy link
Copy Markdown

⛔ Blockers found — Sonnet deferred (commit 198dc72)
Canonical validated blockers: 1

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Test transaction helpers now store full Coin data, select inputs through ChainstateManager, and sign using returned coin maps instead of mempool or transaction-index lookups. ProTx, collateral, reorg, and signature tests were migrated to the new helpers, including external-collateral construction. Governance setup now owns its manager lifecycle, and test setups no longer manage the global transaction index.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • dashpay/dash#7339: Related masternode reward-era API changes affect the same reward and deterministic masternode test areas.

Suggested reviewers: udjinm6, pastapastapasta

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: removing g_txindex as an optional TestChainSetup step.
Description check ✅ Passed The description matches the changeset and explains the tx-index cleanup and test refactors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/test/evo_deterministicmns_tests.cpp`:
- Around line 139-147: Update GetCollateralOutpoint to assert with BOOST_REQUIRE
when no transaction output matches dmn_types::Regular.collat_amount, instead of
returning a default null COutPoint. Preserve returning the matching COutPoint
for valid transactions and make the missing-collateral invariant fail explicitly
before callers use the result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2eab2b26-efd9-43fd-be07-f1d00baddf54

📥 Commits

Reviewing files that changed from the base of the PR and between 408ae55 and db95db1.

📒 Files selected for processing (3)
  • src/test/block_reward_reallocation_tests.cpp
  • src/test/evo_deterministicmns_tests.cpp
  • src/test/util/setup_common.cpp
💤 Files with no reviewable changes (1)
  • src/test/util/setup_common.cpp

Comment on lines +139 to +147
static COutPoint GetCollateralOutpoint(const CMutableTransaction& tx)
{
for (size_t i = 0; i < tx.vout.size(); ++i) {
if (tx.vout[i].nValue == dmn_types::Regular.collat_amount) {
return COutPoint(tx.GetHash(), i);
}
}
return COutPoint();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

GetCollateralOutpoint silently returns a null outpoint on miss.

If no output matches collat_amount, the function returns a default COutPoint() (n == 0xFFFFFFFF). This is a silent failure: FuncVerifyDB later does tx_collateral.vout[collateralOutpoint.n] (Line 1343), which becomes an out-of-bounds vector::operator[] access, and other callers assign the null outpoint into proTx.collateralOutpoint, producing an opaque validation failure instead of a clear one. A BOOST_REQUIRE makes the invariant explicit for these consensus-path tests.

🛡️ Proposed guard
 static COutPoint GetCollateralOutpoint(const CMutableTransaction& tx)
 {
     for (size_t i = 0; i < tx.vout.size(); ++i) {
         if (tx.vout[i].nValue == dmn_types::Regular.collat_amount) {
             return COutPoint(tx.GetHash(), i);
         }
     }
-    return COutPoint();
+    BOOST_REQUIRE_MESSAGE(false, "no collateral output found");
+    return COutPoint(); // unreachable
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static COutPoint GetCollateralOutpoint(const CMutableTransaction& tx)
{
for (size_t i = 0; i < tx.vout.size(); ++i) {
if (tx.vout[i].nValue == dmn_types::Regular.collat_amount) {
return COutPoint(tx.GetHash(), i);
}
}
return COutPoint();
}
static COutPoint GetCollateralOutpoint(const CMutableTransaction& tx)
{
for (size_t i = 0; i < tx.vout.size(); ++i) {
if (tx.vout[i].nValue == dmn_types::Regular.collat_amount) {
return COutPoint(tx.GetHash(), i);
}
}
BOOST_REQUIRE_MESSAGE(false, "no collateral output found");
return COutPoint(); // unreachable
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/evo_deterministicmns_tests.cpp` around lines 139 - 147, Update
GetCollateralOutpoint to assert with BOOST_REQUIRE when no transaction output
matches dmn_types::Regular.collat_amount, instead of returning a default null
COutPoint. Preserve returning the matching COutPoint for valid transactions and
make the missing-collateral invariant fail explicitly before callers use the
result.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Codex + Sonnet

Independently verified at exact head db95db1. The three-commit stack removes g_txindex/GetTransaction dependencies from TestChainSetup and its two consumer test files, replacing lookups with a Coin-based SimpleUTXOMap threaded through FundTransaction/SignTransaction into script/sign.cpp's SignTransaction(). Verified: no other file under src/test references g_txindex/GetTransaction after this change; the remaining g_txindex use in setup_common.cpp's mineBlocks() is null-guarded and unaffected; UTXO snapshots are captured before consumption in both refactored test files. No correctness, consensus-safety, or build-breaking issues found. Commit-message quality is the only actionable item: two preparatory subjects are 95/104 characters, and the final commit uses a misleading feat: prefix and vague wording for a change that only removes unused test-fixture initialization (sibling commits correctly use refactor:). Note for the record: linux64_tsan-test failed at this exact head on p2p_node_network_limited.py --v2transport, unrelated to any file this PR touches (setup_common.cpp, evo_deterministicmns_tests.cpp, block_reward_reallocation_tests.cpp) — the Codex general agent's claim that CI passed is not fully accurate, though this does not indicate a defect introduced by this PR.

Review provenance

  • Codex reviewers: gpt-5.6-sol — general (failed), gpt-5.6-sol — dash-core-commit-history (failed), gpt-5.6-sol — general (completed), gpt-5.6-sol — dash-core-commit-history (completed)
  • Verifier: claude-sonnet-5 — final-verifier
  • Sonnet reviewers: claude-sonnet-5 — general (failed), claude-sonnet-5 — dash-core-commit-history (failed), claude-sonnet-5 — dash-core-commit-history (failed), claude-sonnet-5 — general (completed), claude-sonnet-5 — dash-core-commit-history (completed)

💬 1 nitpick(s)

1 additional finding(s) omitted (not in diff).

@knst
knst requested review from PastaPastaPasta and UdjinM6 July 14, 2026 06:45
knst added 3 commits July 14, 2026 21:50
g_txindex has own tests and no need in general environment for regression tests
@knst

knst commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

rebased due to changes in #7451

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/test/util/setup_common.cpp (2)

337-339: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Capture __func__ to avoid printing operator() in logs.

Using __func__ directly inside a lambda evaluates to operator(), which makes log messages less descriptive. Consider capturing the outer function's name to preserve context.

♻️ Proposed refactor
-    options.notify_bls_state = [](bool bls_state) {
-        LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls_state);
+    const char* func = __func__;
+    options.notify_bls_state = [func](bool bls_state) {
+        LogPrintf("%s: bls_legacy_scheme=%d\n", func, bls_state);
     };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/util/setup_common.cpp` around lines 337 - 339, Update the lambda
assigned to options.notify_bls_state so it captures the enclosing function’s
name before the lambda is created, then use that captured name in LogPrintf
instead of referencing __func__ inside the lambda. Preserve the existing
bls_state value and log format.

627-633: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update stale comment referencing tx index.

Since g_txindex lifecycle management has been removed from this fixture, specifically citing it as the reason for syncing is slightly misleading. Consider generalizing the comment to refer to background validation tasks.

♻️ Proposed refactor
 TestChainSetup::~TestChainSetup()
 {
-    // Allow tx index to catch up with the block index cause otherwise
-    // we might be destroying it while scheduler still has some work for it
-    // e.g. via BlockConnected signal
+    // Allow background tasks to catch up with the block index cause otherwise
+    // we might be destroying resources while the scheduler still has some work for them
+    // e.g. via BlockConnected signal
     SyncWithValidationInterfaceQueue();
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/util/setup_common.cpp` around lines 627 - 633, Update the comment
above TestChainSetup::~TestChainSetup and SyncWithValidationInterfaceQueue to
remove the stale tx index reference, generalizing the explanation to background
validation or scheduler tasks that must finish before fixture destruction. Leave
the synchronization behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/test/util/setup_common.cpp`:
- Around line 337-339: Update the lambda assigned to options.notify_bls_state so
it captures the enclosing function’s name before the lambda is created, then use
that captured name in LogPrintf instead of referencing __func__ inside the
lambda. Preserve the existing bls_state value and log format.
- Around line 627-633: Update the comment above TestChainSetup::~TestChainSetup
and SyncWithValidationInterfaceQueue to remove the stale tx index reference,
generalizing the explanation to background validation or scheduler tasks that
must finish before fixture destruction. Leave the synchronization behavior
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3f604969-001c-4c6f-8ffc-88b99830654f

📥 Commits

Reviewing files that changed from the base of the PR and between db95db1 and 198dc72.

📒 Files selected for processing (5)
  • src/test/block_reward_reallocation_tests.cpp
  • src/test/evo_deterministicmns_tests.cpp
  • src/test/governance_inv_tests.cpp
  • src/test/util/setup_common.cpp
  • src/test/validation_chainstatemanager_tests.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/test/block_reward_reallocation_tests.cpp
  • src/test/evo_deterministicmns_tests.cpp

@PastaPastaPasta
PastaPastaPasta merged commit f2b15fb into dashpay:develop Jul 14, 2026
43 of 44 checks passed
@knst
knst deleted the refactor-regtest-avoid-txindex branch July 14, 2026 16:21

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary review — Codex only

New latest-delta finding: exact head 198dc72 introduces a confirmed use-after-free during partial GovernanceInvSetup construction, so changes are required. Carried-forward prior finding bd3618963324 remains valid because all three commit subjects are unchanged in the relevant respects; the remaining txindex and Coin-backed signing refactors appear correct.

Validated blockers were found in the Codex precheck. Sonnet is deferred until a fresh Codex revalidation clears the blocker gate.

Review provenance

  • Codex reviewers: gpt-5.6-sol — general (completed), gpt-5.6-sol — dash-core-commit-history (completed)
  • Verifier: gpt-5.6-sol — verifier
  • Sonnet: not run (deferred by blocker gate)

🔴 1 blocking | 💬 1 nitpick(s)

1 additional finding(s) omitted (not in diff).

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/test/governance_inv_tests.cpp`:
- [BLOCKING] src/test/governance_inv_tests.cpp:79-83: Preserve governance cleanup when fixture construction fails
  After `m_node.govman` is assigned at line 52, any subsequent `BOOST_REQUIRE` failure throws `boost::execution_aborted`. Because `GovernanceInvSetup` has not finished construction, this destructor is skipped and only the completed base subobjects are destroyed. `TestingSetup::~TestingSetup()` then calls `DashChainstateSetupClose()`, which resets `chain_helper`; later, destruction of the still-live governance manager calls `m_superblocks.Clear()` through its dangling `SuperblockManager` reference. Restore `m_node.govman.reset()` in `TestingSetup::~TestingSetup()` before `DashChainstateSetupClose()` so both normal and partial-construction teardown preserve the required lifetime ordering.

Comment on lines +79 to +83
~GovernanceInvSetup() {
// govman holds a reference to chain_helper->superblocks, so it must be reset before chain_helper (matches PrepareShutdown
// ordering in init.cpp).
m_node.peerman->RemoveHandlers();
m_node.govman.reset();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Blocking: Preserve governance cleanup when fixture construction fails

After m_node.govman is assigned at line 52, any subsequent BOOST_REQUIRE failure throws boost::execution_aborted. Because GovernanceInvSetup has not finished construction, this destructor is skipped and only the completed base subobjects are destroyed. TestingSetup::~TestingSetup() then calls DashChainstateSetupClose(), which resets chain_helper; later, destruction of the still-live governance manager calls m_superblocks.Clear() through its dangling SuperblockManager reference. Restore m_node.govman.reset() in TestingSetup::~TestingSetup() before DashChainstateSetupClose() so both normal and partial-construction teardown preserve the required lifetime ordering.

source: ['codex']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants