-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: remove circular dependencies through net_processing (1/N) #5782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: remove circular dependencies through net_processing (1/N) #5782
Conversation
92c7b34
to
90aa991
Compare
src/net_types.h
Outdated
int score; | ||
std::string message; | ||
|
||
MisbehavingError(int score, std::string message = "") : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would propose dropping the = ""
and requiring all invocations provide a message; maybe a future refac however
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of places doesn't have a text message.
Also for case of text message it's little too verbose: need to write tl::expected(MisbehavingError>{...})
For other usages (not net_processing) I'd agree if error usually provides text description
src/net_types.h
Outdated
MisbehavingError(int score, std::string message = "") : | ||
score{score}, | ||
message{std::move(message)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we made this a std::string&& to ensure that this is (probably) a compile time constant? Thoughts? Would also need to make std::move into std::forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, please check
Otherwise LGTM |
This pull request has conflicts, please rebase. |
1 similar comment
This pull request has conflicts, please rebase. |
90aa991
to
78e3eb4
Compare
78e3eb4
to
e10199d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
This pull request has conflicts, please rebase. |
e10199d
to
7673bc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-utACK; please state preference for merge commit vs squash
either way works, commits are each atomic and complete. One things that may worth an own commit: |
src/util/expected.h
Outdated
expected_storage_base() : m_has_val(true) {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request has conflicts, please rebase. |
7673bc6
to
bbb342e
Compare
resolved conflicts and added expections for linter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK for merging via merge commit
Source: https://github.com/TartanLlama/expected Also it adds util/expected.h to exclude list of our linters
That's a prior work for removing circular dependencies over net_processing
These functions: - EraseObjectRequest - RequestObject - GetRequestedObjectCount
It is partial de-circularisation of dependencies between that includes net_processing Classes that still depends on net_processing but should not: - llmq/dkgsessionmgr - llmq/signing - llmq/instantsend They have asynchronous processing and with current impl that's impossible to do
bbb342e
to
a9401cc
Compare
…5792) ## Issue being fixed or feature implemented The architecture of bitcoin assumes that there's no any external class that processes network messages and knows anything about PeerManager from net_processing; no any external call for PeerManager::Misbehaving in bitcoin. All logic related to processing messages are located in net_processing. Dash has many many extra types of network messages and many of them processed by external components such as llmq/signing or coinjoin/client. Current architecture creates multiple circular dependency. ## What was done? That's part II of refactorings. This PR removes PeerManager from several constructor and let LLMQContext to forget about PeerManager. Prior work in this PR: #5782 ## What else to do? Some network messages are processed asynchronously in external components such as llmq/signing, llmq/instantsend, llmq/dkgsessionhandler. It doesn't let to refactor them easily, because they can't just simple return status of processing; status of processing would be available sometime later and there's need callback or other way to pass result code without spreading PeerManager over codebase. ## How Has This Been Tested? - Run unit/functional tests - run a linter test/lint/lint-circular-dependencies.sh ## 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
…ction c7c7ee9 test: Check max transaction weight in CoinSelection (Aurèle Oulès) 6b563ca wallet: Check max tx weight in coin selector (Aurèle Oulès) Pull request description: This PR is an attempt to fix dashpay#5782. I have added 4 test scenarios, 3 of them provided here bitcoin#5782 (comment) (slightly modified to use a segwit wallet). Here are my benchmarks : ## PR | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 1,466,341.00 | 681.97 | 0.6% | 11,176,762.00 | 3,358,752.00 | 3.328 | 1,897,839.00 | 0.3% | 0.02 | `CoinSelection` ## Master | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 1,526,029.00 | 655.30 | 0.5% | 11,142,188.00 | 3,499,200.00 | 3.184 | 1,994,156.00 | 0.2% | 0.02 | `CoinSelection` ACKs for top commit: achow101: reACK c7c7ee9 w0xlt: ACK bitcoin@c7c7ee9 furszy: diff ACK c7c7ee9 Tree-SHA512: ef0b28576ff845174651ba494aa9adee234c96e6f886d0e032eceb7050296e45b099dda0039d1dfb9944469f067627b2101f3ff855c70353cf39d1fc7ee81828
…geProcessingResult`, drop `PeerMsgRet` 491ae50 revert: new util class `expected` for return errors by more convenient way (Kittywhiskers Van Gogh) 2020757 trivial: remove `PeerMsgRet` handling logic (Kittywhiskers Van Gogh) 5d1222e chore: drop govobj/govobjvote counts, use `ret.m_inventory.size()` (UdjinM6) 4822b93 refactor: allow submitting multiple `CInv`s to `MessageProcessingResult` (Kittywhiskers Van Gogh) 0517aff refactor: mark `RelayInv{,Filtered}`'s `CInv` argument as const (Kittywhiskers Van Gogh) 9084530 refactor: migrate `CGovernanceManager::ProcessMessage()` and friends (Kittywhiskers Van Gogh) 8b9bf7c refactor: migrate `CCoinJoinServer::ProcessMessage()` (Kittywhiskers Van Gogh) 1d50a1a refactor: migrate `CCoinJoinClientQueueManager::ProcessMessage()` (Kittywhiskers Van Gogh) 6352baf refactor: migrate `CMNAuth::ProcessMessage()` (Kittywhiskers Van Gogh) 9f85bd0 refactor: migrate `CInstantSendManager::ProcessMessage()` (Kittywhiskers Van Gogh) ef4a0bb refactor: migrate `CDKGSessionManager::ProcessMessage()` and friends (Kittywhiskers Van Gogh) 93d68b8 refactor: migrate `CQuorumManager::ProcessMessage()` (Kittywhiskers Van Gogh) 1bbcb95 refactor: migrate `CSporkManager::ProcessMessage()` and friends (Kittywhiskers Van Gogh) e7b23a2 refactor: migrate `CSigningManager::ProcessMessage()` (Kittywhiskers Van Gogh) f3b98ce chore: add redefinition of `NodeId` to avoid repetitive redefinition (Kittywhiskers Van Gogh) f341ef5 chore: add `nodiscard` attrib to `MessageProcessingResult` ret functions (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Dependency for #6821 * To avoid having to redeclare `NodeId` repeatedly to avoid circular dependencies from including `net.h` ([source](https://github.com/dashpay/dash/blob/fb87a5a937dd232d4f2ae60b5b8c5c29d49cb92f/src/net.h#L121)), a redeclaration is made in the relatively lightweight `net_types.h` that as of `develop` (fb87a5a), doesn't have includes outside the standard library ([source](https://github.com/dashpay/dash/blob/fb87a5a937dd232d4f2ae60b5b8c5c29d49cb92f/src/net_types.h#L8-L10)). Redeclarations were flagged during review (see [comment](#6820 (comment)), [comment](#6820 (comment))). * As `tl::expected` was introduced alongside `PeerMsgRet` in [dash#5782](#5782) and has not been used elsewhere, we can safely remove it as we've finished migrating all usage to `MessageProcessingResult`. ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: knst: utACK 491ae50 UdjinM6: utACK 491ae50 Tree-SHA512: c37fe6370555f1c33877fa5a335356e2febf25c2d0d954fa44623f49994647ea2a10aec5ceb9e788bb6fa9315dc00b3e54ca8e0da96c7899fb31c30b888eb732
Issue being fixed or feature implemented
The architecture of bitcoin assumes that there's no any external class that processes network messages and knows anything about PeerManager from net_processing; no any external call for
PeerManager::Misbehaving
in bitcoin. All logic related to processing messages are located in net_processing.Dash has many many extra types of network messages and many of them processed by external components such as llmq/signing or coinjoin/client. Current architecture creates multiple circular dependency.
What was done?
This PR introduces several key changes:
tl::expected
that can be widely used in dash code and it has very similar implementation withstd::expected
and can be replaced tostd::expected
since C++23 is used by default. Please notice that this PR will superseed refactor: convert maybe_error into genericResult
template class #5109PeerMsgRet
that is defined astl::expected<void, MisbehavingError>
inside net_types. That lets external modules that process network messages to don't depend directly on net_processing.PeerMsgRet
type:coinjoin/client
,coinjoin/server
,evo/mnauth
,governance/governance
,llmq/blockprocessor
,llmq/chainlocks
,llmq/quorums
,spork
What else to do?
Some network messages are processed asynchronously in external components such as llmq/signing, llmq/instantsend, llmq/dkgsessionhandler. It doesn't let to refactor them easily, because they can't just simple return status of processing; status of processing would be available sometime later and there's need callback or other way to pass result code without spreading PeerManager over codebase.
How Has This Been Tested?
test/lint/lint-circular-dependencies.sh
Breaking Changes
N/A
Checklist: