Skip to content

Conversation

Sjors
Copy link
Owner

@Sjors Sjors commented Jul 22, 2024

After reading @0xB10C's blog post on mining pool behaviour during forks, I felt motivated to implement Stratum v2's future block template functionality.

Well, this is just a very rough sketch which doesn't compile.

There's two relevant protocol messages (for the Template Provider in bitcoin#29432):

  1. NewTemplate
  2. SetNewPrevHash

Whenever the tip updates, the current working implementation first sends a NewTemplate message with future_template set to true, immediately followed by SetNewPrevHash for the new tip.

This PR tries to improve upon that for two different scenarios:

  1. We didn't win the last block
  2. We did win the last block

So prepare for either out, after we've send out the current work as described above, we send two additional templates. Both have future_template = true and both build for the block on top of the last template. The first is empty, the second has all the transactions that didn't fit in the original block.

Especially this last bit will require an overhaul of BlockAssembler::CreateNewBlock, but it would be a nice selling point for stratum v2.

So now the following things can happen:

  1. We receive a block via p2p, this means we didn't* win. The Template Provider needs to look though the template cache and send the connected client(s) a SetNewPrevHash message referring to the match.

  2. We receive a block via SubmitSolution. That means we found the block. The message handling code already finds the matching template. All we need to do is reply to the client with a NewPrevHash message.

For both (1) and (2) we then proceed as normal, creating and sending a template with non-empty block.

* = actually it's possible that the Job Declarator server reconstructed the block and broadcast it for us, so I need to add detection for this case (maybe by comparing the coinbase merkle path).

Sjors and others added 30 commits July 19, 2024 09:00
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
This commit adds the simplest stratum v2 message. The remaining messages are introduced in later commits.

Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
This allows us to subclass Transport.
Implemented starting from a copy of V2Transport and the V2TransportTester, modifying it to fit Stratum v2 and Noise Protocol requirements.

Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-Authored-By: Fi3
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
…lass

This allows reusing them in other mocked implementations.

Also move the implementation (method definitions) to
`test/util/net.cpp` to make the header `test/util/net.h` easier to follow.
…o it

And also allows gradually providing the data to be returned by `Recv()`
and sending and receiving net messages (`CNetMessage`).
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Co-authored-by: Christopher Coverdale <chris.coverdale24@gmail.com>
The template provider will listen for a Job Declarator client.
It can establish a connection and detect various protocol errors.

Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-Authored-By: Fi3
An external program that uses the Mining interface may need quick access to some information in the block template, while it can wait a bit longer for the full raw transaction data.

This would be the case for a Stratum v2 Template Provider which needs to send a NewTemplate message (which doesn't include transactions) as quickly as possible.
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
@Sjors Sjors force-pushed the sv2 branch 3 times, most recently from 4f58e3f to 9442af5 Compare November 22, 2024 14:28
@Sjors Sjors force-pushed the sv2 branch 2 times, most recently from 9dc6622 to 72b8f59 Compare December 2, 2024 20:02
@Sjors Sjors force-pushed the sv2 branch 4 times, most recently from 8cf7578 to a1c1bd9 Compare December 19, 2024 06:15
@Sjors Sjors force-pushed the sv2 branch 3 times, most recently from fe7af33 to a79388a Compare January 27, 2025 12:37
@Sjors Sjors force-pushed the sv2 branch 2 times, most recently from d0d447d to 737c02e Compare February 10, 2025 14:41
@Sjors Sjors force-pushed the sv2 branch 2 times, most recently from 6cf485f to b4eb739 Compare March 6, 2025 12:30
@Sjors Sjors force-pushed the sv2 branch 2 times, most recently from 746f691 to 93348c2 Compare April 15, 2025 13:48
@Sjors Sjors force-pushed the sv2 branch 2 times, most recently from 5dc7c03 to a5b230a Compare July 8, 2025 14:52
@Sjors
Copy link
Owner Author

Sjors commented Jul 8, 2025

Closing this for now

@Sjors Sjors closed this Jul 8, 2025
Sjors pushed a commit that referenced this pull request Aug 12, 2025
efb8ea04e4 Merge bitcoin-core/crc32c-subtree#8: Sync to upstream
4a7a05c48d Merge remote-tracking branch 'google/main' into bitcoin-fork
21fc8ef304 Fix typo (#59)
89f69843a1 Fix misspelled "Proccess" in comment
02e65f4fd3 Bump deps (#56)
b9d6e825a1 Fix Windows CI build. (#54)
bbbb93ab5d Switch CI to GitHub Actions (#55)
d46cd17d70 Add clangd cache directory to .gitignore.

git-subtree-dir: src/crc32c
git-subtree-split: efb8ea04e4a5b6a18dc4bc1908fd1cb2dcefb585
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