8000 standardize rewards to pool/solo mining into a single `scriptPubKey` by lucasbalieiro · Pull Request #1800 · stratum-mining/stratum · GitHub
[go: up one dir, main page]

Skip to content

standardize rewards to pool/solo mining into a single scriptPubKey - #1800

Merged
GitGab19 merged 18 commits into
stratum-mining:mainfrom
lucasbalieiro:issue-1793
Jul 21, 2025
Merged

GitGab19 merged 18 commits into
stratum-mining:mainfrom
lucasbalieiro:issue-1793

Conversation

@lucasbalieiro
@lucasbalieiro lucasbalieiro commented Jul 10, 2025 •
Copy link
Copy Markdown
Collaborator

closes #1793

This refactor modifies the handling of coinbase outputs across multiple roles by replacing the CoinbaseOutput type with CoinbaseRewardScript. The change simplifies the configuration and enforces a single coinbase output script, eliminating the need for a vector of outputs.

Additionally, the deserialize_vec_exactly_1 function is removed since it is no longer necessary.

Adjusted the usage of Vec<TxOut> to TxOut only to keep consistency with the CoinbaseRewardScript where possible.

In the config files for Pool, JDS, JDC the coinbase_output was renamed to coinbase_reward_script

deprecate Pool::get_coinbase_output and JDS::get_txout

@lucasbalieiro
lucasbalieiro marked this pull request as ready for review July 10, 2025 21:09
@plebhash
Copy link
Copy Markdown
Member

there's broken tests on CI

@plebhash
plebhash commented Jul 10, 2025 •
Copy link
Copy Markdown
Member

the channel APIs (e.g.: on_new_template) expecting a Vec<TxOut> is a deliberate decision

that's because those APIs were designed for more general usage that is not limited by the the simplified implementations we have on the application layer here

more specifically, aside from the pool/solo reward, some opinionated mining server could choose to add merged mining outputs, or some arbitrary OP_RETURN, or even split rewards across multiple outputs without ever relying on our CoinbaseOutput/CoinbaseRewardScript abstractions


with that said, I'd make get_txout and get_coinbase_output return TxOut, and then create the vec! only when calling on_new_template and similar functions that expect Vec<TxOut>

@plebhash
Copy link
Copy Markdown
Member

comments above are only after a high-level analysis, I haven't looked deeply at the PR yet

@lucasbalieiro
lucasbalieiro marked this pull request as draft July 11, 2025 01:35
@lucasbalieiro
lucasbalieiro force-pushed the issue-1793 branch 3 times, most recently from a4a20d2 to 7443eaa Compare July 11, 2025 04:10
Comment thread roles/pool/src/lib/mining_pool/mod.rs Resolved
@lucasbalieiro
Copy link
Copy Markdown
Collaborator Author

@plebhash , thanks for the insights!

I think this is ready for review now!

@lucasbalieiro
lucasbalieiro marked this pull request as ready for review July 11, 2025 22:21
@lucasbalieiro
lucasbalieiro force-pushed the issue-1793 branch 2 times, most recently from 427dc7b to 673ca61 Compare July 12, 2025 02:56
@plebhash
Copy link
Copy Markdown
Member

@plebhash , thanks for the insights!

I think this is ready for review now!

I guess the PR description is now outdated, which could be a bit misleading to the review process.

@lucasbalieiro
Copy link
Copy Markdown
Collaborator Author

I guess the PR description is now outdated, which could be a bit misleading to the review process.

Adjusted

@bit-aloo bit-aloo left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Minor nit.

Comment thread roles/pool/src/lib/mining_pool/mod.rs Resolved
@lucasbalieiro
Copy link
Copy Markdown
Collaborator Author

rebased and addressed @shourya742's comment

Comment thread roles/pool/src/lib/config.rs Resolved
Comment thread test/integration-tests/lib/mod.rs Resolved
@plebhash
plebhash commented Jul 15, 2025 •
Copy link
Copy Markdown
Member

while doing my final review here, I started feeling that get_coinbase_output (on Pool) and get_txout (on JDS and JDC) still feel quite redundant

so I went ahead and tried to get rid of them.


I was successful for Pool, so I'd encourage the following commits to be cherry-picked here:


for JDC that was not possible, mostly due to the fact that PoolChannelFactory expects TxOut with 0 amount, to be replaced internally... I'll take note on #1701, which feels slightly outdated but it's the best approximation sub-issue of #1674


for JDS it was possible, however JDS contains some unit tests that depend on get_txout

tbh, those unit tests are pretty generic and I feel they should belong to config-helpers rather than JDS

@lucasbalieiro can you try to migrate these unit tests from JDS to config-helpers?

  • test_get_txout_non_empty
  • test_get_txout_empty
  • test_get_txout_invalid_miniscript
  • test_get_txout_invalid_value

obviously, they should also be renamed, since strictly speaking, we don't really a need get_txout to cover for the functionality on those tests

and then, once those tests are migrated, let's also get rid of get_txout in JDS in favor of parsing the CoinbaseRewardScript into a TxOut in the place where it's needed (with 0 value, since JDS is the only place where this is actually the right thing to do)

@lucasbalieiro
Copy link
Copy Markdown
Collaborator Author

@plebhash, just following up on the points you raised in the previous #1800 (comment). Here’s what I’ve already addressed:

  • Cherry-picked the commits (thanks btw)
  • Deprecated get_txout in JDS
  • Renamed the tests for clarity

Now, regarding the migration of the tests to config-helpers: it's doable, but as I started working on it, it felt like a bit of an odd move.

The tests in question validate things like empty and non-empty scripts, which seem generic at first, but they’re really checking the parsing from text into the JobDeclaratorServerConfig struct. That’s something I think is valuable to keep in place, since it ensures we’re not missing anything during that parsing step.

Migrating these tests would also require adding stratum-common as a dependency for config-helpers (just to pull in the bitcoin crate). Plus, config-helpers would need to depend on JDS to access JobDeclaratorServerConfig, which introduces a circular dependency since JDS already uses config-helpers.

Besides that, placing these tests in config-helpers feels like it would take them out of context. They’d be testing JDS-specific config parsing in a more generic crate, which doesn’t really feel like the right scope. Also, as you mentioned, while these tests might seem generic, config-helpers already has coverage for similar edge cases (empty values, invalid miniscript, etc.), so moving them over could lead to redundancy.

With that in mind, I’d suggest keeping the tests where they are, as in this commit:
a1b57f8
I’ve updated them to reflect the deprecation of get_txout.

As I said, what you’re asking is totally doable. I just think this approach makes more sense.

What you think?

@plebhash
Copy link
Copy Markdown
Member

@lucasbalieiro thanks for the deeper analysis

I think the approach you took makes sense

lucasbalieiro and others added 15 commits July 20, 2025 14:07
…tern applied for the `CoinbaseRewardScript`
…ern applied for the `CoinbaseRewardScript`
…ern applied for the `CoinbaseRewardScript`
…nbase_reward_script` and adapt the code where needed
…eward_script` and adapt the code where needed
…eward_script` and adapt the code where needed
@GitGab19
GitGab19 merged commit 0a8b704 into stratum-mining:main Jul 21, 2025
@lucasbalieiro
lucasbalieiro deleted the issue-1793 branch July 21, 2025 12:39
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.

standardize rewards to pool/solo mining into a single scriptPubKey

4 participants

0