Commit c965990
committed
Merge #7113: refactor: new chainlock::Chainlocks interface
0f1f8f1 fix: reset chainlock; make objects `chainlocks` and `clhandler` consistent (Konstantin Akimov)
a418c9f fmt: clang-format for all changes in this PR (Konstantin Akimov)
5deb316 refactor: rename llmq::CChainLocksHandler to chainlock::ChainlockHandler (Konstantin Akimov)
b57b68c fix: misusing chainlocks to determine expiring of cj's tx (Konstantin Akimov)
a894ff7 refactor: drop clhandler and chainloks from dsnotificationinterface completely (Konstantin Akimov)
040a458 refactor: don't call m_chainlocks directly in dsnotificationinterface (Konstantin Akimov)
ac22100 fix: drop dependency of CChainLocksHandler on qman; so CChainLocksHandler could be initialized before llmq_ctx (Konstantin Akimov)
a0b6483 refactor: move out VerifyChainlock from CChainLocksHandler as a function (Konstantin Akimov)
5d97d57 refactor: move clhandler from llmq_ctx to NodeContext (Konstantin Akimov)
fdfc092 fix: it should be used ChainManager inside chainlock's handler, not chainstate (Konstantin Akimov)
0d90bc1 refactor: break dependency of clhandler on chainlock/signing completely (Konstantin Akimov)
b79e2a8 refactor: chainlocks's signer to have own scheduler for cleanup and signing (Konstantin Akimov)
cf2e9b5 refactor: drop unused validation.h from spork (Konstantin Akimov)
34c05d3 refactor: move all spork usages for chainlock inside single module chainlock/chainlock (Konstantin Akimov)
3bb3433 refactor: split out lightweight chainlock::Chainlocks and widely used it interface (Konstantin Akimov)
57f661c refactor: code-move only CChainLockHandler from chainlock.h to handler.h (Konstantin Akimov)
Pull request description:
## Issue being fixed or feature implemented
Currently, there are several blockers that prevent pulling consensus code out from various handlers, schedulers, mempool, etc. One of them is `CChainLocksHandler` which does too many things.
- `CChainLocksHandler` depends on the mempool and — because it is part of `LLMQContext` — it makes `LLMQContext` depend on the mempool (which is an unexpected dependency)
- Chainlocks depends on Instant Send, and Instant Send depends on Chainlocks (this is logically expected), but it creates a circular dependency between `CChainLocksHandler` and the initialization of these objects. See:
`CChainLocksHandler::Start(const llmq::CInstantSendManager& isman)`
and
`CInstantSendManager::CInstantSendManager(CChainLocksHandler& _clhandler, ...)`
- `CChainLocksHandler` depends on masternode-only code (`chainlock::ChainLockSigner`). It is hidden behind the interface `chainlock::ChainLockSignerParent`, but this increases implementation complexity
- `CChainLocksHandler` is used for blocks validation (`clhandler.HasConflictingChainLock`), but at the same time `CChainLocksHandler` can switch the chain tip itself via its background worker (see calls to `EnforceBestChainLock`). This creates another dependency loop that prevents independent initialization of `CChainLocksHandler` and the Chain State.
## What was done?
This PR introduces a new lightweight interface `chainlock::Chainlocks`
- `chainlock::Chainlocks` knows about the chain state and the best known chainlock, but it does not enforce chainlocks, has no dependency on mempool or transactions, and keeps no permanent on-disk state (no dependency on evodb).
It does depend on `SporkManager` (to know whether chainlocks are enabled/disabled) and provides a clean interface over it.
- `llmq::CChainLocksHandler` (`chainlock::ChainlocksHandler` in future commits) is the component that actually changes Chain State by enforcing the best tip, tracks transaction's times and runs a background thread.
It is responsible for processing newly signed chainlocks and related network messages.
However, it no longer handles any masternode-related logic or signing — that code was fully moved to `llmq::ChainLockSigner`.
Other less important but noticeable changes:
- `clhandler` now uses its own subscriptions to validation notifications (no longer goes through `dsnotificationinterface`)
- `llmq::CChainLocksHandler` was renamed and moved to a different namespace (`chainlock::ChainlocksHandler`) since it no longer belongs to `llmq::`
- `clhandler` was removed from `llmq-ctx` and its initialization can now be skipped completely [as required for kernel project]; only `ChainLockSigner` and `PeerManager` still strongly depend on it
- `clhandler` no longer depends on `CQuorumManager`
Noticeable, some circular dependencies over codebase has been untangled by this PR:
- chainlock/chainlock <-> instantsend/instantsend
- chainlock/chainlock <-> validation
See linter's exception list for details.
After this PR the next step to apply similar refactoring to `CInstantSendManager` which does too many things the similar to CChainLocksHandler: keeps track of instant-send locked transactions [as expected], but also knows about masternode's code [see `instantsend::InstantSendSigner`], removes conflicting transactions from mempool, invalidates blocks in Chain State (see `CInstantSendManager::ResolveBlockConflicts`). CInstantSendManager creates logical dependencies over masternode's signer; over chainstate; over mempool and finally there are the same issues with initialization of `isman` as `clhandler` had.
## How Has This Been Tested?
Run unit & functional tests
## 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
- [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 0f1f8f1
kwvg:
utACK 0f1f8f1
Tree-SHA512: bee59b0e0e0d3530e562a8381303cf4bca721550c412ddc34edc77faee17ec02469e44f5d37fb3801fb789924b257e4dc12ac39d5ceb32087eb242c57a9bc1f3File tree
47 files changed
+985
-833
lines changed- src
- active
- bench
- chainlock
- coinjoin
- evo
- instantsend
- llmq
- node
- rpc
- test
- util
- test/lint
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
47 files changed
+985
-833
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| |||
499 | 500 | | |
500 | 501 | | |
501 | 502 | | |
| 503 | + | |
502 | 504 | | |
503 | 505 | | |
504 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
47 | | - | |
48 | | - | |
49 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | | - | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
| |||
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | | - | |
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
| |||
77 | 74 | | |
78 | 75 | | |
79 | 76 | | |
| 77 | + | |
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
| 81 | + | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
0 commit comments