sv2: resend template pair on subsequent CoinbaseOutputConstraints#106
Open
enirox001 wants to merge 2 commits into
Open
sv2: resend template pair on subsequent CoinbaseOutputConstraints#106enirox001 wants to merge 2 commits into
enirox001 wants to merge 2 commits into
Conversation
Collaborator
|
I'd like to suggest a slightly different approach. When a new
I pushed an improvement to |
806b99f to
266b955
Compare
Previously, only the initial CoinbaseOutputConstraints from a client triggered sending a TemplatePair. Subsequent messages updated the constraint but did not send new work because the client handler was already running. This caused an issue where the JDC would send a new CoinbaseOutputConstraints but remain stuck waiting for a template pair until it arrived naturally. This change bumps an atomic constraints generation counter on Sv2Client and interrupts the client handler thread's wait when a subsequent CoinbaseOutputConstraints is received. The client handler thread checks if the generation has changed and rebuilds the template with the updated constraints.
Verify that a subsequent CoinbaseOutputConstraints message triggers a new NewTemplate + SetNewPrevHash pair immediately, rather than just the initial one.
266b955 to
f25737e
Compare
Contributor
Author
Sjors
reviewed
Jun 17, 2026
| uint64_t constraints_generation_at_build{0}; | ||
| while (!m_flag_interrupt_sv2) { | ||
| if (!block_template) { | ||
| LogPrintLevel(BCLog::SV2, BCLog::Level::Trace, "Generate initial block template for client id=%zu\n", |
Collaborator
There was a problem hiding this comment.
5f25346: nit: this is initial only when constraints_generation_at_build == 0
| client_id); | ||
|
|
||
| // Create block template and store interface reference | ||
| // TODO: reuse template_id for clients with the same coinbase constraints |
Collaborator
There was a problem hiding this comment.
5f25346: this comment is now stale, since clients no longer have a lifetime coinbase constraint. I also think that template reuse is better suited for the node (e.g. with bitcoin/bitcoin#33758), so might as well drop this comment.
| uint256 prev_hash; | ||
|
|
||
| // Track the coinbase constraints generation that was active when block_template was built. | ||
| uint64_t constraints_generation_at_build{0}; |
Collaborator
There was a problem hiding this comment.
5f25346: would it make sense to narrow the scope of this to inside the while loop, defining it closer to its first use?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the issue where sv2-tp only sends a
NewTemplate + SetNewPrevHashpair on the initialCoinbaseOutputConstraintsbut not on subsequent onesThis causes problems during JDC fallback (stratum-mining/sv2-apps#466 (comment)), where the JDC sends a new
CoinbaseOutputConstraintsto sv2-tp but remains stuck waiting for a template pair to arrive naturally.We now track the coinbase constraints generation per-client and interrupt the handler's wait loop when constraints are updated, forcing an immediate template rebuild.
Fixes #99