-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[WIP] net: implement a StratumV2 Template Provider in core #23049
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
Conversation
To build it:
To test it:
An example of how to import |
Concept NACK for Rust, until a secure bootstrap without trusted third party binaries is practical. |
Isn't that already achieved with guix? |
bd47f1b
to
c9cab9f
Compare
I think this work is interesting, that said it might need more thought on how to interface with Core. AFAICT, the proposed PR just link the library in the build system and create a new template encoder in Recently, I've made some progress in this direction by building on top of the multiprocess project (see the hacky branch https://github.com/ariard/bitcoin/commits/2021-07-altnet-lightning). Process separation is promising, though going further I'm aiming to have AltNet pluggin modules written in Rust, while interfacing in Core over the Cap'n Proto newer interfaces. The current bottleneck is re-writing I think such modules or the one proposed in the current PR could live beyond the Core repository to avoid burdening the maintenance effort and the concerns about Rust chain of trust, while consuming the stable interfaces to ease deployment across the ecosystem. Glad to see progress on the miner infrastructure, that's really needed! |
Strong Concept ACK. At a high level, this is incredibly important work for a few reasons:
As for multi-process, I don't think this is a good candidate for multi-process - block template building is incredibly latency-sensitive, plus needs full access to the mempool and block template construction. At most, I'd think we could think of doing the block template construction in Core and then handing the template off to a new process which does the StratumV2 protocol work, but (a) that adds a bunch more latency for no reason, and (b) you'd probably just use the StratumV2 protocol to communicate with that other binary, so why? In general, one reason to consider rust for the protocol side of this is precisely because you don't need to worry as much about it being in the same binary - the actual network logic itself isn't going to corrupt memory. |
Some thoughts.
So conditionally on getting some confirmation on my assumptions above, (somewhat hesitant) Concept ACK. |
No, Guix does not solve the bootstrapping problem, because Guix itself has a bootstrapping problem. You can't get Guix going without running their trusted blobs. |
That's correct (for now), but the situation is not Rust-specific. Our release builds are created with Guix, so the C++ compiler used for releases is subject to the same concerns. |
Yes I think this is exactly right. Building Rust in Guix is not any less bootstrappable than building anything else (C++) in Guix. Some context: Guix gained the ability to compile Rust v1.19 from mrustc v0.8 in 2018 (blog post), and this bootstrap method has been actively maintained, and now compiles Rust v1.29 from mrustc v0.9 (newer versions of rust (say v1.n) simply build using the previous version (v1.(n-1)) until it reaches v1.29). |
Concept ACK on implementing a Stratum v2 Template Provider in Core ignoring language. On the C++/Rust question it is dependent on other contributors being comfortable with it. This was discussed in today's Core dev meeting and has come up repeatedly in the past e.g. #17090. I would guess a C++ PR would be an easier/quicker merge but there may be a Rust approach that can work. |
We support users building their own, without using Guix's trust-required toolchain. |
Ah I see the low-latency requirement, yes effectively IPC/serialization to access the mempool is likely going to be a worrying performance penalty. That said, one advantage splitting nicely the block template/mempool subsystems behind interfaces like it has been done for GUI/wallet/node is the ability offered to the end-user to have either one fully-fledged binary or a collection of process in function what make sense as a deployment. One motivation could be to have fallback mempools connected to your block template construction in case of a malicious partition targeting your main one. |
Update build system following @dongcarl suggestions. TP is enabled via a config flag: --enable-template-provider |
Big concept ACK on supporting the use of StratumV2, but slight concept NACK on bundling it with the introduction of Rust, barring some additional context/rationale. It'd be nice to see a compelling reason why Rust should be used for this particular feature other than the standard potpourri of "Rust is safer/more ergonomic in $X_GENERAL_WAY." Edit: I do see that this change pulls in a stratum Rust library, so maybe that's why? I have a number of questions about how Rust will dovetail with the existing codebase (and this PR might not be the appropriate place to discuss them), but some that come to mind in the context of this change are
If Rust is really a critical part of doing this feature, maybe we should look at how to offer the raw data necessary (in a performant way) to construct any number of block template formats outside of Core, by supplying data in a generic format over e.g. Unix sockets. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
Hi @jamesob:
|
No objection to rust code. After all it is not different than wallet or qt code, which only a subset of all devs can understand, write and review. I guess the only thing needed here is review(ers). |
Just leaving a note that I'm currently working on an implementation of the template provider that integrates with the the rust sv2 project |
It conditionally compile the Template Provider logic into core if: * the system that compile core has rustc at least at version 0.51 * configure is called `enable-template-provider` Template Provider is optional, with default to no, so no rustc is required to compile core. When compiled with guix the Template Provider is compiled in. As guix do support rustc.
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
We are currently working on changes, should be ready for review soon. |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
we are implementing it in pure c++ without the use of the rust ffi lib so the PR is outdated |
This PR provides a simple example of how to import and use the
sv2-ffi
Rust crate which exports the Stratum V2 (Sv2) functions required by a Template Provider as a C library.Stratum V2
An introduction to Sv2
Sv2 specifiaction
Template Provider
Sv2 defines a service (role) called the Template Provider (TP), whose functionality is defined as follows:
Phase 1: PR Goals
This phase encompasses the concepts that must be agreed upon before proceeding with Phase 2.
Phase 2: PR Implementation
This phase will commence once the concepts in Phase 1 are agreed upon. Phase 2 is the final goal of this project and encompasses the the implementation steps required for a functional TP in Bitcoin Core.
sv2-ffi
API and other Rust sources.If TP in Core gets a concept NACK
A TP can be implemented as an independent service and can communicate with core via RPC.
If Rust in Core gets a concept NACK
A TP can be implemented in core without using any Rust dependency.
*1 Right now the Rust sources are in this PR and are packaged by a script before doing the guix build. Ideally these sources should live in another project repository and should be packaged by the guix script which builds a downloadable binary.