Commit 9607277
committed
Merge bitcoin#30111: locks: introduce mutex for tx download, flush rejection filters once per tip change
c85acce [refactor] delete EraseTxNoLock, just use EraseTx (glozow)
6ff8406 remove obsoleted TxOrphanage::m_mutex (glozow)
61745c7 lock m_recent_confirmed_transactions using m_tx_download_mutex (glozow)
723ea0f remove obsoleted hashRecentRejectsChainTip (glozow)
18a4355 update recent_rejects filters on ActiveTipChange (glozow)
36f170d add ValidationInterface::ActiveTipChange (glozow)
3eb1307 guard TxRequest and rejection caches with new mutex (glozow)
Pull request description:
See bitcoin#27463 for full project tracking.
This contains the first few commits of bitcoin#30110, which require some thinking about thread safety in review.
- Introduce a new `m_tx_download_mutex` which guards the transaction download data structures including `m_txrequest`, the rolling bloom filters, and `m_orphanage`. Later this should become the mutex guarding `TxDownloadManager`.
- `m_txrequest` doesn't need to be guarded using `cs_main` anymore
- `m_recent_confirmed_transactions` doesn't need its own lock anymore
- `m_orphanage` doesn't need its own lock anymore
- Adds a new `ValidationInterface` event, `ActiveTipChanged`, which is a synchronous callback whenever the tip of the active chainstate changes.
- Flush `m_recent_rejects` and `m_recent_rejects_reconsiderable` on `ActiveTipChanged` just once instead of checking the tip every time `AlreadyHaveTx` is called. This should speed up calls to that function (no longer comparing a block hash each time) and removes the need to lock `cs_main` every time it is called.
Motivation:
- These data structures need synchronization. While we are holding `m_tx_download_mutex`, these should hold:
- a tx hash in `m_txrequest` is not also in `m_orphanage`
- a tx hash in `m_txrequest` is not also in `m_recent_rejects` or `m_recent_confirmed_transactions`
- In the future, orphan resolution tracking should also be synchronized. If a tx has an entry in the orphan resolution tracker, it is also in `m_orphanage`, and not in `m_txrequest`, etc.
- Currently, `cs_main` is used to e.g. sync accesses to `m_txrequest`. We should not broaden the scope of things it locks.
- Currently, we need to know the current chainstate every time we call `AlreadyHaveTx` so we can decide whether we should update it. Every call compares the current tip hash with `hashRecentRejectsChainTip`. It is more efficient to have a validation interface callback that updates the rejection filters whenever the chain tip changes.
ACKs for top commit:
instagibbs:
reACK c85acce
dergoegge:
Code review ACK c85acce
theStack:
Light code-review ACK c85acce
hebasto:
ACK c85acce, I have reviewed the code and it looks OK.
Tree-SHA512: c3bd524b5de1cafc9a10770dadb484cc479d6d4c687d80dd0f176d339fd95f73b85cb44cb3b6b464d38a52e20feda00aa2a1da5a73339e31831687e4bd0aa0c5File tree
7 files changed
+128
-124
lines changed- src
- test
7 files changed
+128
-124
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
| 29 | + | |
31 | 30 | | |
32 | | - | |
33 | 31 | | |
34 | 32 | | |
35 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
55 | 53 | | |
56 | 54 | | |
57 | 55 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 56 | | |
66 | 57 | | |
67 | 58 | | |
| |||
97 | 88 | | |
98 | 89 | | |
99 | 90 | | |
100 | | - | |
101 | | - | |
102 | 91 | | |
103 | 92 | | |
104 | 93 | | |
| |||
108 | 97 | | |
109 | 98 | | |
110 | 99 | | |
111 | | - | |
| 100 | + | |
112 | 101 | | |
113 | 102 | | |
114 | 103 | | |
115 | 104 | | |
116 | 105 | | |
117 | 106 | | |
118 | 107 | | |
119 | | - | |
120 | | - | |
121 | 108 | | |
122 | 109 | | |
123 | 110 | | |
| |||
129 | 116 | | |
130 | 117 | | |
131 | 118 | | |
132 | | - | |
| 119 | + | |
133 | 120 | | |
134 | 121 | | |
135 | 122 | | |
| |||
142 | 129 | | |
143 | 130 | | |
144 | 131 | | |
145 | | - | |
| 132 | + | |
146 | 133 | | |
147 | 134 | | |
148 | 135 | | |
149 | 136 | | |
150 | 137 | | |
151 | 138 | | |
152 | 139 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | 140 | | |
157 | 141 | | |
158 | 142 | | |
| |||
171 | 155 | | |
172 | 156 | | |
173 | 157 | | |
174 | | - | |
175 | 158 | | |
176 | 159 | | |
177 | 160 | | |
178 | 161 | | |
179 | 162 | | |
180 | | - | |
181 | | - | |
182 | 163 | | |
183 | 164 | | |
184 | 165 | | |
| |||
197 | 178 | | |
198 | 179 | | |
199 | 180 | | |
200 | | - | |
201 | | - | |
202 | 181 | | |
203 | 182 | | |
204 | 183 | | |
| |||
209 | 188 | | |
210 | 189 | | |
211 | 190 | | |
212 | | - | |
213 | | - | |
214 | 191 | | |
215 | 192 | | |
216 | 193 | | |
| |||
231 | 208 | | |
232 | 209 | | |
233 | 210 | | |
234 | | - | |
| 211 | + | |
235 | 212 | | |
236 | 213 | | |
237 | 214 | | |
238 | 215 | | |
239 | 216 | | |
240 | 217 | | |
241 | 218 | | |
242 | | - | |
243 | | - | |
244 | 219 | | |
245 | 220 | | |
246 | 221 | | |
| |||
281 | 256 | | |
282 | 257 | | |
283 | 258 | | |
284 | | - | |
285 | | - | |
286 | 259 | | |
287 | 260 | | |
288 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | | - | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 70 | | |
75 | 71 | | |
76 | 72 | | |
| |||
80 | 76 | | |
81 | 77 | | |
82 | 78 | | |
83 | | - | |
| 79 | + | |
84 | 80 | | |
85 | 81 | | |
86 | | - | |
| 82 | + | |
87 | 83 | | |
88 | 84 | | |
89 | 85 | | |
| |||
98 | 94 | | |
99 | 95 | | |
100 | 96 | | |
101 | | - | |
| 97 | + | |
102 | 98 | | |
103 | 99 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 100 | + | |
108 | 101 | | |
109 | 102 | | |
110 | | - | |
| 103 | + | |
111 | 104 | | |
112 | 105 | | |
113 | 106 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3473 | 3473 | | |
3474 | 3474 | | |
3475 | 3475 | | |
| 3476 | + | |
3476 | 3477 | | |
3477 | 3478 | | |
3478 | 3479 | | |
| |||
3549 | 3550 | | |
3550 | 3551 | | |
3551 | 3552 | | |
3552 | | - | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
3553 | 3559 | | |
3554 | 3560 | | |
3555 | 3561 | | |
| |||
3768 | 3774 | | |
3769 | 3775 | | |
3770 | 3776 | | |
| 3777 | + | |
| 3778 | + | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
3771 | 3783 | | |
3772 | 3784 | | |
3773 | 3785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
186 | 192 | | |
187 | 193 | | |
188 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| |||
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
| 221 | + | |
217 | 222 | | |
218 | 223 | | |
219 | 224 | | |
| |||
0 commit comments