Commit 0b53690
committed
feat(rpc): add ?topics= filtering to the events stream
Third PR of the chain-events series: server-side topic filtering for
GET /lean/v0/events, split out so the previous PR's transport stayed a
review of pure axum plumbing.
The filter lives in the bus (EventBus::subscribe(TopicSet) returning an
EventSubscription with a receive-side skip loop) rather than in the SSE
handler, so future non-SSE consumers get filtering for free and the
handler stays transport-only. TopicSet is a Copy bitmask: no allocation
and one AND per event; lag is surfaced to the caller rather than
swallowed by the skip loop. The signature also survives a later
per-topic-channel split behind the facade, since callers only ever see
subscribe(TopicSet).
The handler parses ?topics=head,block via Topic::from_str (the exact
inverse of as_str, so names cannot drift) and returns 400 naming the
offending value on an unknown topic. A missing or empty parameter
defaults to all topics: the Beacon API makes topics required, lean is
friendlier here (documented as a divergence in docs/rpc.md).
BroadcastStream no longer fits (it wraps a raw receiver, not the
filtered subscription), so the bridge is futures-util's stream::unfold
around EventSubscription::recv, preserving the Lagged skip + debug-log
behavior; tokio-stream and futures-core are dropped for futures-util,
already present in the dependency tree.
EventSubscription also gains a non-blocking try_recv (same skip loop as
recv, over the receiver's try_recv), so the previous PR's lib.rs unit
tests (which assert on already-buffered events without spinning up a
runtime) can move onto the filtered type after subscribe()'s signature
changed here.1 parent 8bc49c0 commit 0b53690
6 files changed
Lines changed: 313 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
40 | 94 | | |
41 | 95 | | |
42 | 96 | | |
| |||
111 | 165 | | |
112 | 166 | | |
113 | 167 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
117 | 214 | | |
118 | 215 | | |
119 | 216 | | |
| |||
129 | 226 | | |
130 | 227 | | |
131 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
132 | 236 | | |
133 | 237 | | |
134 | 238 | | |
135 | | - | |
| 239 | + | |
136 | 240 | | |
137 | 241 | | |
138 | 242 | | |
139 | | - | |
| 243 | + | |
140 | 244 | | |
141 | 245 | | |
142 | 246 | | |
143 | 247 | | |
144 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
145 | 294 | | |
146 | 295 | | |
147 | 296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
1514 | 1516 | | |
1515 | 1517 | | |
1516 | 1518 | | |
1517 | | - | |
| 1519 | + | |
1518 | 1520 | | |
1519 | 1521 | | |
1520 | 1522 | | |
| |||
1529 | 1531 | | |
1530 | 1532 | | |
1531 | 1533 | | |
1532 | | - | |
| 1534 | + | |
1533 | 1535 | | |
1534 | 1536 | | |
1535 | 1537 | | |
| |||
1580 | 1582 | | |
1581 | 1583 | | |
1582 | 1584 | | |
1583 | | - | |
| 1585 | + | |
1584 | 1586 | | |
1585 | 1587 | | |
1586 | 1588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
| 29 | + | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
0 commit comments