Skip to content

Conversation

@knst
Copy link
Collaborator

@knst knst commented Jun 20, 2025

Issue being fixed or feature implemented

Addressed some exception from test/lint/lint-circular-dependencies.py

What was done?

See commits descriptions.

How Has This Been Tested?

Updated these exception in linter:

-    "dsnotificationinterface -> llmq/chainlocks -> node/blockstorage -> dsnotificationinterface",
-    "evo/chainhelper -> evo/specialtxman -> evo/deterministicmns -> evo/chainhelper",
-    "evo/chainhelper -> llmq/chainlocks -> evo/chainhelper",
-    "evo/chainhelper -> llmq/instantsend -> evo/chainhelper",
-    "evo/chainhelper -> masternode/payments -> governance/classes -> governance/object -> evo/chainhelper",
-    "evo/chainhelper -> node/transaction -> node/context -> evo/chainhelper",
-    "evo/deterministicmns -> llmq/commitment -> validation -> evo/deterministicmns",
-    "evo/deterministicmns -> llmq/commitment -> validation -> txmempool -> evo/deterministicmns",
-    "evo/mnhftx -> validation -> evo/mnhftx",
+    "evo/deterministicmns -> index/txindex -> validation -> evo/deterministicmns",
+    "evo/deterministicmns -> index/txindex -> validation -> txmempool -> evo/deterministicmns",

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

@knst knst added this to the 23 milestone Jun 20, 2025
@knst knst requested review from PastaPastaPasta, UdjinM6 and kwvg June 20, 2025 09:20
@coderabbitai
Copy link

coderabbitai bot commented Jun 20, 2025

Walkthrough

This set of changes removes the GetTransactionBlock function and its associated type alias and header dependencies from the codebase. Code previously using GetTransactionBlock is modified to directly query the global transaction index (g_txindex) or to call the GetTransaction function with explicit parameters. The ThreadImport function signature in block storage is simplified by removing masternode-related parameters and logic. Correspondingly, masternode collateral UTXO coin cache prefetching and active masternode manager initialization are moved out of ThreadImport and handled separately after block import. The circular dependency linting script is updated to reflect these structural changes. No other logic or control flow modifications are introduced.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 045cf03 and 1f4a5a6.

📒 Files selected for processing (12)
  • src/dsnotificationinterface.h (1 hunks)
  • src/evo/chainhelper.cpp (0 hunks)
  • src/evo/chainhelper.h (0 hunks)
  • src/evo/deterministicmns.cpp (2 hunks)
  • src/governance/object.cpp (2 hunks)
  • src/init.cpp (1 hunks)
  • src/llmq/chainlocks.cpp (2 hunks)
  • src/llmq/instantsend.cpp (4 hunks)
  • src/node/blockstorage.cpp (1 hunks)
  • src/node/blockstorage.h (1 hunks)
  • src/validation.cpp (2 hunks)
  • test/lint/lint-circular-dependencies.py (1 hunks)
💤 Files with no reviewable changes (2)
  • src/evo/chainhelper.cpp
  • src/evo/chainhelper.h
✅ Files skipped from review due to trivial changes (2)
  • src/dsnotificationinterface.h
  • test/lint/lint-circular-dependencies.py
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/governance/object.cpp
  • src/llmq/chainlocks.cpp
  • src/node/blockstorage.h
  • src/node/blockstorage.cpp
  • src/llmq/instantsend.cpp
  • src/evo/deterministicmns.cpp
  • src/init.cpp
  • src/validation.cpp
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/llmq/instantsend.cpp (1)

30-32: Update the comment to accurately reflect the dependency being broken.

The comment states "Forward declaration to break dependency over node/transaction.h" but according to the AI summary, the GetTransactionBlock function was moved TO node/transaction.h. The comment should clarify that this avoids including node/transaction.h directly to prevent potential circular dependencies.

-// Forward declaration to break dependency over node/transaction.h
+// Forward declaration to avoid including node/transaction.h and prevent circular dependencies
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba93745 and f3a9cb6.

📒 Files selected for processing (10)
  • src/evo/chainhelper.cpp (0 hunks)
  • src/evo/chainhelper.h (0 hunks)
  • src/evo/deterministicmns.cpp (2 hunks)
  • src/governance/object.cpp (2 hunks)
  • src/llmq/chainlocks.cpp (1 hunks)
  • src/llmq/instantsend.cpp (1 hunks)
  • src/node/transaction.cpp (1 hunks)
  • src/node/transaction.h (1 hunks)
  • src/validation.cpp (1 hunks)
  • test/lint/lint-circular-dependencies.py (0 hunks)
💤 Files with no reviewable changes (3)
  • test/lint/lint-circular-dependencies.py
  • src/evo/chainhelper.h
  • src/evo/chainhelper.cpp
🧰 Additional context used
🪛 GitHub Actions: Clang Diff Format Check
src/governance/object.cpp

[error] 10-21: Clang format differences found. The file does not adhere to the expected code style. Please run clang-format to fix formatting issues.

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
🔇 Additional comments (10)
src/llmq/chainlocks.cpp (1)

26-27: LGTM! Clean forward declaration approach.

The forward declaration correctly breaks the circular dependency on node/transaction.h while maintaining the required functionality. The explanatory comment is helpful and the function signature matches the usage pattern.

src/node/transaction.h (1)

60-66: LGTM! Well-documented function declaration.

The new GetTransactionBlock function declaration is properly documented and serves its purpose as a wrapper to break circular dependencies. The function signature is consistent with its usage in the calling code.

src/validation.cpp (1)

120-121: Appropriately forward declare GetTransactionBlock to break dependency
The signature matches the implementation in node/transaction.cpp/node/transaction.h. All referenced types (CTransactionRef, CTxMemPool, uint256) are already available via existing includes. This cleanly removes the need to include evo/chainhelper.h here and breaks the circular dependency.

src/governance/object.cpp (2)

18-18: LGTM: Appropriate header inclusion for direct txindex access.

The inclusion of <index/txindex.h> is necessary for the direct usage of g_txindex in the refactored code.


456-463: LGTM: Direct txindex usage with proper error handling.

The refactored code correctly handles the case where g_txindex is not available by returning an error. This approach is equivalent to the previous GetTransactionBlock function but eliminates the dependency on evo/chainhelper.h.

However, there's a formatting issue reported by the pipeline that needs to be addressed.

The pipeline reports formatting issues in this file. Please run clang-format to fix the code style:

#!/bin/bash
# Check formatting issues in the file
clang-format --dry-run src/governance/object.cpp
src/evo/deterministicmns.cpp (2)

29-31: LGTM: Proper forward declarations to break header dependencies.

The forward declarations for CTxMemPool and GetTransactionBlock effectively break the dependency on node/transaction.h while maintaining functionality.


56-56: LGTM: Function call updated to match new signature.

The updated call to GetTransactionBlock correctly passes nullptr for the mempool parameter, which is appropriate since this code doesn't have access to a mempool instance.

src/node/transaction.cpp (1)

152-157: LGTM: Well-implemented wrapper function with proper fast-fail logic.

The new GetTransactionBlock function effectively wraps the existing GetTransaction function and provides appropriate fast-fail behavior when neither g_txindex nor mempool are available. The implementation maintains the same behavior as the original function while centralizing transaction retrieval logic in the node layer.

src/llmq/instantsend.cpp (2)

580-580: The function usage is consistent with the forward declaration.

All three usage sites correctly use structured binding and match the expected signature of the forward-declared function. The refactoring successfully maintains the existing functionality while breaking the circular dependency.

Also applies to: 637-637, 1016-1016


30-31: ```shell
#!/bin/bash

Correctly search for all declarations/definitions of GetTransactionBlock across the repo

echo "=== Matches in headers and sources for GetTransactionBlock (escaped parentheses) ==="
rg -n "GetTransactionBlock\(" -H .

echo -e "\n=== Specific search in src/node/transaction.* ==="
rg -n "GetTransactionBlock" -H src/node/transaction.*


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@PastaPastaPasta
Copy link
Member

Not sure I like this; feels more like "suppressing" a circular dependency rather than breaking it, as we still have a logical circular dependency, but just we've hacked around it so the linter is happy. Might make re-compiles a bit better, but feels there should be a more correct way to properly resolve this circular dependency.

@knst
Copy link
Collaborator Author

knst commented Jun 21, 2025

is this PR a dependency for another PR where these circular dependencies must be broken?

no, this PR on its own; I just noticed while doing unrelated changes.

any updates to the function name and arguments will require four additional updates on top of the header change

yes, but compilation will cause linkage error and it's easy to fix all of them at once.

feels more like "suppressing" a circular dependency rather than breaking it, as we still have a logical circular dependency, but just we've hacked around it so the linter is happy. Might make re-compiles a bit better, but feels there should be a more correct way to properly resolve this circular dependency

yes, that's true; real dependency over the function GetTransaction is still here, but I'd say firstly that helper GetTransactionBlock is already kind of workaround to hide dependency of llmq/chainlocks, evo/deterministic, llmq/instantsend and some other modules on GetTransaction which create multiple dependencies and keeping helper GetTransactionBlock inside evo/chainhelper is already kind of hacky. And indeed it makes re-compiles a bit better (not significant).

But I'd still created this PR, because having these exceptions inside lint-circular-dependencies.py is a positive reinforcement to make even more circular dependencies over evo/chainhelper without knowing it due to exceptions. so, I'd prefer to have several forward declarations rather that new circular dependencies over evo/chainhelper to appear without knowing it.

And thirdly, please notice that it's now so much hacky, because this approach is already used in Bitcoin Core, for example:

  • extern RecursiveMutex cs_main; in 15 files, such as txmempool.h, chain.h, etc
  • multiple forward declaration in RPC code such as:
RPCHelpMan importmulti();
RPCHelpMan dumpwallet();
RPCHelpMan importwallet();
extern RPCHelpMan getnewaddress();
extern RPCHelpMan getrawchangeaddress();
extern RPCHelpMan getaddressinfo();
extern RPCHelpMan addmultisigaddress();
  • More in RPC: extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const CChainState& active_chainstate, const llmq::CChainLocksHandler& clhandler, const llmq::CInstantSendManager& isman, UniValue& entry);
  • looking exactly same definition in unit test to avoid dependency on validation.h:
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);

(that's just few examples that I found right away in seconds)

@knst knst force-pushed the fix-circular-chainhelper branch from f3a9cb6 to f6895c1 Compare June 21, 2025 06:06
@knst knst changed the title refactor: break circular dependencies over evo/mnhftx.h and evo/chainhelper.h refactor: removed exception for circular dependencies over evo/mnhftx.h and evo/chainhelper.h Jun 21, 2025
@knst knst changed the title refactor: removed exception for circular dependencies over evo/mnhftx.h and evo/chainhelper.h refactor: removed some exceptions for circular dependencies over evo/mnhftx.h and evo/chainhelper.h Jun 21, 2025
@UdjinM6
Copy link

UdjinM6 commented Jun 24, 2025

pls consider 5e4685a

@knst
Copy link
Collaborator Author

knst commented Jun 24, 2025

pls consider 5e4685a

Added + couple extra changes to follow them.

@knst knst force-pushed the fix-circular-chainhelper branch from 2140ec0 to 454681a Compare June 25, 2025 20:30
@knst knst changed the title refactor: removed some exceptions for circular dependencies over evo/mnhftx.h and evo/chainhelper.h refactor: removed some exceptions for circular dependencies over evo/mnhftx and evo/chainhelper Jun 27, 2025
@knst knst changed the title refactor: removed some exceptions for circular dependencies over evo/mnhftx and evo/chainhelper refactor: removed some exceptions for circular dependencies over evo/mnhftx, evo/chainhelper and dsnotificationinterface Jun 27, 2025
@knst knst requested a review from kwvg June 27, 2025 15:16
kwvg
kwvg previously approved these changes Jun 28, 2025
Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

utACK 045cf03

@github-actions
Copy link

This pull request has conflicts, please rebase.

@knst knst force-pushed the fix-circular-chainhelper branch from 045cf03 to 1f4a5a6 Compare July 1, 2025 15:00
@knst knst requested a review from kwvg July 1, 2025 15:03
Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

utACK 1f4a5a6

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK 1f4a5a6

@PastaPastaPasta PastaPastaPasta merged commit d84483f into dashpay:develop Jul 4, 2025
29 of 34 checks passed
@knst knst deleted the fix-circular-chainhelper branch July 16, 2025 08:16
PastaPastaPasta added a commit that referenced this pull request Jul 23, 2025
9aa039c refactor: removed multiple unused includes; added some must-have headers (Konstantin Akimov)
b389d0b refactor: drop several circular dependencies by removing unused headers (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  Some includes are leftover after code movements, refactors or feature edits.
  Some includes meant to be, but included indirectly.

  ## What was done?
  I run iwyu [include what you use] analyzer and got 15k lines diff which touches 800 files. It's a bit too big diff and not quite useful! See full set of changes here:  https://github.com/knst/dash/tree/refactor-iwyu-all

  Though, it helped to remove 11 exception for circular dependencies linter, so, this PR has a small sub-set of original changes that are split to 2 commits:
   - breakage of circular dependencies (some includes are removed)
   - compilation time improvements by removing obviously unused includes from Dash specific code

  ## How Has This Been Tested?
  Here're steps to run iwyu analyser:

      make clean
      bear -- make -j14
      iwyu_tool -p compile_commands.json -j14 > out.txt
      fix_include

  See test/lint/lint-circular-dependencies.py, it removed 10 exception for circular dependencies.
  Originally has been 11 of them, but one has been found before manually, and merged as #6728, so, 10 only left for this PR.

  Compilation time is reduced insignificantly, only 1 minute out of 98 minutes (assuming single core compilation).

  ## 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
  - [x] 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

ACKs for top commit:
  UdjinM6:
    utACK 9aa039c
  kwvg:
    utACK 9aa039c

Tree-SHA512: 63b131b993d09b1911bdca73337b6ad40717229db4beca4a55171434bac861a12dc94d698a800b62914baab4e9ad3515eaa01dc79cf3fc3f2c48ca6b76e7cf68
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.

4 participants