Skip to content

Bound the stratum v2 target by the channel max_target. - #1244

Merged
evoskuil merged 2 commits into
libbitcoin:masterfrom
echennells:fix/sv2-max-target
Nov 28, 2026
Merged

evoskuil merged 2 commits into
libbitcoin:masterfrom
echennells:fix/sv2-max-target

Conversation

@echennells

Copy link
Copy Markdown
Contributor

A stratum v2 downstream's max_target is the largest target it accepts, and the upstream must not exceed it. The channel kept it only as a difficulty floor, and to_share_target truncates the difficulty mantissa to 32 bits, rounding the target up by up to 2^-31. So whenever the floor applied, the success target and SetTarget exceeded max_target. The SRI translator (v0.9.2) drops the upstream connection at the first such SetTarget (SetTargetAboveMaxTarget).

Each channel now keeps max_target and the last target sent, and sends the lesser of the difficulty target and max_target. SetTarget follows a change in that target, so an UpdateChannel that lowers it at unchanged difficulty refreshes the job (refresh is now protected). Shares are still checked against the difficulty target, which is not lower.

The tests use a max_target one below the difficulty-one target. They fail without the change.

Runtime on today's masters: of 300 random max_target values, 300 were exceeded before and 0 after. With the SRI translator over Noise on testnet5, master dropped at the first SetTarget; with the change it ran 20 minutes, 266 shares, 0 rejected.

@echennells
echennells requested a review from evoskuil November 27, 2026 23:55
@echennells

Copy link
Copy Markdown
Contributor Author

This conflicts with #1243 in open_channel, where add_channel gains a device argument. The changes do not overlap functionally. I will rebase once #1243 is merged.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.413% (-0.4%) from 93.797% — echennells:fix/sv2-max-target into libbitcoin:master

@evoskuil
evoskuil merged commit 6932dc7 into libbitcoin:master Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants