Skip to content

Conversation

@plebhash
Copy link
Member

@plebhash plebhash commented Oct 28, 2025

recently @Fi3 created stratum-mining/sv2-tp#47 with some questions about how to interpret CoinbaseOutputConstraints

the lengthy discussions that unfolded there made it clear that the current definition of the message is not clearly understandable

this PR aims to clarify it, hopefully leaving no room for ambiguity or confusion

for a better visualization of the tables, reviewers can refer to this rendering on my fork

@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch 4 times, most recently from fc69c3a to 94a4b26 Compare October 28, 2025 19:38
Copy link
Contributor

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to expand this.

@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch 2 times, most recently from a423ea1 to f7d6ab2 Compare October 29, 2025 14:25
@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch 2 times, most recently from 7d6a9ea to 75ba96b Compare October 29, 2025 20:47
In summary, the Template Provider MUST reserve:
- 866 + 4*`coinbase_output_max_additional_size` weight units for SegWit blocks
- 636 + 4*`coinbase_output_max_additional_size` weight units for legacy blocks
- `coinbase_output_max_additional_sigops` sigops for either case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still suggest some padding in case the above calculation or the implementation is wrong. It's very likely you won't find out for years because block templates are almost never full to the very last byte.

Copy link
Contributor

@Fi3 Fi3 Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can say that is recommended to add padding of x so that would be impossible to create an invalid block cause we calculated a too little weight? IMO if we quantify x we should say why we choose such number. Or maybe even better recommend to test against core to be sure that do not produce invalid blocks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a new paragraph along the lines of:

Additionally, the Template Provider SHOULD reserve additional X weight units as a safety margin against unexpected edge cases.

The question is: how much is an ideal value for X?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 400? That's 0.01% of the block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend to test against core

There's no easy way to make Core generate the absolute maximum size template, you'd have to populate the mempool in a specific way and deal with any weirdness in how Bitcoin constructs block from the mempool.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little bit less. Bitcoin Core reserves 2000 for coinbase, without knowing what's in it. The calculations here show that there is at least 1168 weight units, plus ~132 for a single taproot payout, so a safety margin of 700. A stratum v1 miner that wants to include lots of outputs has to be more careful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep make sense to me we can add it in the spec and be happy from what concern me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still digesting the numbers provided by @Sjors on his latest comments

I'm having the opportunity for some IRL chats with @ismaelsadeeq about this, I'll report back here soon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adapted the PR.

I'm summarizing everything into one simple note:

Please note that Bitcoin Core establishes a floor value of 2000 weight units.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I added this floor. The rationale is to prevent the creation of an invalid block template because we’re not sure what to use to finish the computation of the reserved weight, since coinbase_output_max_additional_size is unknown. If coinbase_output_max_additional_size is not calculated correctly, you risk creating an invalid block just to squeeze in a few more transactions.

@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch from 75ba96b to 7fced64 Compare November 3, 2025 14:51
@Sjors
Copy link
Contributor

Sjors commented Nov 3, 2025

Relevant to SegWit block and transaction serialization: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki

@Sjors
Copy link
Contributor

Sjors commented Nov 3, 2025

See above, just haggling over a few remaining WU, but we're pretty close.

@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch 2 times, most recently from 8ca984e to d5a1794 Compare November 3, 2025 17:55
@Sjors
Copy link
Contributor

Sjors commented Nov 3, 2025

ACK d5a1794

Though someone should double check the numbers.

@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch from d5a1794 to 8c2a576 Compare November 3, 2025 18:01
@Sjors
Copy link
Contributor

Sjors commented Nov 3, 2025

ACK 8c2a576

@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch 2 times, most recently from 52e3b0d to 67d5807 Compare December 15, 2025 14:56
@plebhash plebhash force-pushed the 2025-10-24-adapt-coinbase-transaction-constraints branch from 67d5807 to 6bca4aa Compare December 15, 2025 20:24
@plebhash plebhash merged commit aadcb32 into stratum-mining:main Dec 16, 2025
1 check passed
@plebhash plebhash deleted the 2025-10-24-adapt-coinbase-transaction-constraints branch December 16, 2025 14:20
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.

4 participants