8000 Stratum v2 Template Provider (take 3) by Sjors · Pull Request #29432 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Stratum v2 Template Provider (take 3) #29432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 49 commits into from
Closed

Stratum v2 Template Provider (take 3) #29432

wants to merge 49 commits into from

Conversation

Sjors
Copy link
Member
@Sjors Sjors commented Feb 14, 2024

Based on on @Fi3's master...Fi3:bitcoin:PatchTemplates which is based on @ccdle12's #27854. I rebased it and re-wrote the commit history. Compared to #28983 it introduces EllSwift in the handshake and fixes various bugs. I used that opportunity to change the branch name, which makes testing against SRI slightly easier. There's no conceptual discussion on #28983 so it can be ignored by reviewers.

See docs/stratum-v2.md for a brief description of Stratum v2 and the role of Bitcoin Core in that system..

There's roughly four layers:

  1. Noise encryption Stratum v2 Noise Protocol #29346
  2. Messages and transport layer Stratum v2 Transport #30315
  3. Sv2Connman Stratum v2 connman Sjors/bitcoin#50
  4. The Template Provider Stratum v2 Template Provider common functionality Sjors/bitcoin#49
  5. Starting the Template Provider from init, and misc stuff (this PR)

What to test and review?

See the testing guide for various ways to test this PR. This branch is actively used by (testnet) pools, so it should be ready for high level review.

I split this PR into separate pull requests for easier review. Feedback on each of them is welcome, even if they're stacked on another one.

Even if we abandon the approach here in favor of a sidecar (see experimental below), it is useful to review the above changes. They are fully reusable as demonstrated in Sjors#48. And until we actually ship something else, the above is being used by people, including on (very limited) mainnet.

The pull requests below enable a sidecar approach:

These are needed with any approach:

Exploratory / experimental:

Related useful:

Contributing

If you want to help out with any of the issues below, please open a PR to my fork. I will then squash your commits into my own where needed.

Things left todo

Networking

  • add -sv2allowip
  • optional -sv2cert
  • limit number of connected clients

Template generation and updating

  • group templates with the same coinbase_tx_additional_output_size

Misc

Potential followups

@DrahtBot
Copy link
Contributor
DrahtBot commented Feb 14, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Approach NACK stickies-v, dergoegge

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30679 (fix: handle invalid -rpcbind port earlier by tdb3)
  • #30635 (rpc: add optional blockhash to waitfornewblock by Sjors)
  • #30595 (kernel: Introduce initial C header API by TheCharlatan)
  • #30546 (util: Use consteval checked format string in FatalErrorf by maflcko)
  • #30487 (ci: skip Github CI on branch pushes for forks by Sjors)
  • #30440 (Have createNewBlock() return a BlockTemplate interface by Sjors)
  • #30409 (Introduce waitTipChanged() mining interface, replace RPCNotifyBlockChange, drop CRPCSignals & g_best_block by Sjors)
  • #30157 (Fee Estimation via Fee rate Forecasters by ismaelsadeeq)
  • #30130 (contrib/signet/miner: increase miner search space by edilmedeiros)
  • #29838 (Feature: Use different datadirs for different signets by BrandonOdiwuor)
  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
  • #29039 (versionbits refactoring by ajtowns)
  • #28417 (contrib/signet/miner updates by ajtowns)
  • #27433 (getblocktemplate improvements for segwit and sigops by Sjors)
  • #26812 (test: add end-to-end tests for CConnman and PeerManager by vasild)
  • #26697 (logging: use bitset for categories by LarryRuane)
  • #26619 (log: expand BCLog::LogFlags (categories) to 64 bits by LarryRuane)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/21562393655

@Sjors Sjors force-pushed the sv2 branch 3 times, most recently from 87f0527 to 684890f Compare February 14, 2024 14:15
{
bool started = m_tp->Start(Sv2TemplateProviderOptions { .port = 18447 });
if (! started) return false;
// Avoid "Connection refused" on CI:
Copy link
Member Author

Choose a reason for hiding this comment

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

The template provider tests are quite brittle because they use a real socket.

Copy link
Member Author

Choose a reason for hiding this comment

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

For the time being I just added handling for MSG_MORE (on e.g. macOS sequential messages are sent separately while on Linux they're combined). I also made the timeouts a bit longer.

Hopefully that does the trick. This can be revisited closer to the time when the Template Provider is ready for its own PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Working on a fix in Sjors#34

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 should probably look into using StaticContentsSock

Copy link
Member Author

Choose a reason for hiding this comment

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

@vasild any thoughts on how to make mock Socks that can be used to play messages in two directions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! See the first two commits in #26812:

bee6bdf test: put the generic parts from StaticContentsSock into a separate class
f42e4f3 test: add a mocked Sock that allows inspecting what has been Send() to it

and then how to use that in the last commit of the same PR:

8b10990 test: add unit tests exercising full call chain of CConnman and PeerManager

With those it is possible to send/receive raw bytes to/from the (mocked) socket, or NetMsgs, e.g.:

pipes->recv.PushNetMsg(NetMsgType::GETBLOCKS, block_locator, hash_stop);

ss << TX_WITH_WITNESS(tx);
tx_size = ss.size();
}

Copy link
Member Author
@Sjors Sjors Feb 14, 2024

Choose a reason for hiding this comment

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

TSAN is tripping up somewhere around here. The last thing it logs is - Connect 2 transactions:. It doesn't get to - Verify ... txins:. I wonder if this is related to mock time, which I'm testing in Sjors#34

Copy link
Member Author

Choose a reason for hiding this comment

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

@maflcko shouldn't TSan on CI output something useful about why it crashed? I currently only says "error 2": https://cirrus-ci.com/task/5124733717446656?logs=ci#L3531

When running this locally on Ubuntu with clang 16.0.6 I get a WARNING: ThreadSanitizer: data race and significantly more details (still a bit cryptic, but hopefully enough to figure out what's happening).

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I guess the unit tests don't capture the tsan output?

Copy link
Member

Choose a reason for hiding this comment

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

But they should. At least back when I tested #27667

Copy link
Member

Choose a reason for hiding this comment

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

Maybe good to re-check this when/after the cmake migration is done?

@Sjors
Copy link
Member Author
Sjors commented Feb 15, 2024

Added m_tp_mutex to Sv2TemplateProvider.

@Sjors
Copy link
Member Author
Sjors commented Feb 15, 2024

Bumping macOS to 14 on the CI does not help (tried in Sjors#35). I also can't reproduce this failure on my own Intel macOS machines, not on 13.6.4 and not on 14.2.1. A Sock mock is probably the most robust solution, but it'd be nice to find another workaround.

This extra delay seems to do the trick for now: Sjors@c8d10af

Another option to consider is using the functional test framework instead, since these are not really unit tests. However that involves implementing the sv2 noise protocol in Python and a bunch of other work to export transport functions to the functional test framework. If anyone feels up to that challenge, let me know...

Sjors and others added 24 commits October 16, 2024 12:12
Move the implementation (method definitions) from `test/util/net.h` to
`test/util/net.cpp` to make the header easier to follow.
…lass

This allows reusing them in other mocked implementations.
…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>
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
Co-authored-by: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
This doesn't solve the underlying problem.
@Sjors
Copy link
Member Author
Sjors commented Oct 16, 2024

I'm moving this pull request to Sjors#68. The sv2 branch will continue to work as before for the time being. See #31098 the plan moving forward.

@Sjors Sjors closed this Oct 16, 2024
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.

0