Commit 2d10f57
Eric Price
fix(channels_sv2): widen hash_rate_from_target multiply to U512
The *100 -> *100_000 scaling fix in hash_rate_from_target lowered the
safe target ceiling from ~2^246.4 to ~2^236.4, because the intermediate
product `(t+1) * shares_occurrency_frequence` is computed in U256.
Routine vardiff-driven targets at low realized share rates push above
the new boundary, and broadcast SetTarget messages carrying a channel's
`requested_max_target` (~2^253) trip it every time.
In production, this surfaced on a slot running translator_sv2 with
vardiff disabled: every upstream SetTarget logs
WARN: Failed to derive hashrate from SetTarget target:
ArithmeticOverflow (channel_id=4294967295)
and the translator's SV1 hashrate gauge stops updating.
The fix widens the multiply step to U512 so the intermediate product
fits regardless of target magnitude. The numerator stays in U256 (it is
2^256 - t, which always fits), and the final result narrows back to
u128 via low_u128() exactly as before. The precision improvement from
the *100_000 scaling is preserved.
Two regression tests:
- target.rs: pin three real `maximum_target` values captured from the
affected slot's translator log, including the channel's
`requested_max_target` (0x1745d174_5d1745d1...). All previously
errored ArithmeticOverflow; they now return finite hashrates.
- vardiff/test/mod.rs: update the
test_try_vardiff_with_less_spm_than_expected_classic expected values
for the 240s and 300s checkpoints. Upstream's 74.2 / 62.327995
values came from the `try_vardiff` Err-fallback path
(`hashrate * realized_spm / shares_per_minute`) which only ran
because hash_rate_from_target overflowed at those high targets.
With overflow eliminated, the main path returns the integer-
truncated 74.0 / 62.0 from low_u128().1 parent 85d6f8b commit 2d10f57
2 files changed
Lines changed: 89 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
192 | 191 | | |
193 | 192 | | |
194 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
195 | 202 | | |
196 | 203 | | |
197 | | - | |
| 204 | + | |
198 | 205 | | |
199 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
200 | 210 | | |
201 | 211 | | |
202 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
388 | 394 | | |
389 | 395 | | |
390 | 396 | | |
| |||
399 | 405 | | |
400 | 406 | | |
401 | 407 | | |
402 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
403 | 411 | | |
0 commit comments