Skip to content
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

Introduce Sv2Transport #27

Closed
wants to merge 17 commits into from
Closed

Conversation

Sjors
Copy link
Owner

@Sjors Sjors commented Dec 29, 2023

This PR introduces Sv2Transport, a new subclass of Transport.

It's most similar to V2Transport, though with a simpler state machine.

In order to make it easier in the future to move the Stratum v2 integration to its own process, this PR also moves Transport out of net.h and makes it part of bitcoin-common.

This also makes for a nice decluttering of net.{h,cpp}, and useful for utilities that need a one-shot p2p connection, e.g. to fetch a specific block.

It would also allow the wallet to make a one-shot tor connection to broadcast a transaction without going through the node mempool. Though this would require a lot more changes.

Once the Sv2Transport class in this PR works, and the Template Provider switched to use it, I plan to rewrite the history of the main PR bitcoin#28983. The move-only commits should not change in that process.

w0xlt and others added 14 commits December 19, 2023 13:06
Co-authored-by: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-authored-by: Christopher Coverdale <chris.coverdale24@gmail.com>
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
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
The proposed Stratum v2 integration introduces a new Transport subclass. This commit makes it easier in the future to move this integration to its own process.

net.cpp is currently part of libbitcoin_node. Avoid a dependency on the node by moving the Transport abstract class to common.
@Sjors
Copy link
Owner Author

Sjors commented Dec 29, 2023

CI on my fork can be ignored (I wonder if I can just turn it off).

In terms of progress, I'm half-way the handshake phase. Next step is implement Act 2 of the handshake, which should be a simple call to WriteMsgES of Sv2HandshakeState m_handshake_state; and updating the cipher like Sv2NoiseSession::ProcessMaybeHandshake does. The test harness can already write it, just needs to read it.

The next challenge is actual message parsing / serialising. The Transport abstract class converts between Span<const uint8_t> and CNetMessage / CSerializedNetMsg, while sv2_messages.h introduces Sv2NetMsg with its own serialisation. I'll have to study both in more detail to figure out if Sv2NetMsg can be made into a subclass of CNetMessage, or if there's another approach.

Finally, the Sv2TemplateProvider comes with its own SendBuf and GenerateWaitSockets. This has a lot of overlap with CConnman in net.h, but CConnman has too much p2p specific stuff to be used as a whole. I might therefore extract its socket handling code into another class.

This helps reduce the size and scope net.h, as well as to make v1 and v2 transport usable outside libbitcoin_node. This is useful for utilities that need a one-shot p2p connection, e.g. to broadcast a transaction or fetch a specific block.

This commit is not necessary for Stratum v2 process separation.
@Sjors Sjors force-pushed the 2023/12/sv2-transport branch 2 times, most recently from 02bc9fd to 624f0a5 Compare January 4, 2024 22:40
Implemented starting from a copy of V2Transport and the V2TransportTester, modifying it to fit the Stratum v2 and Noise Protocol requirements.

Currently unused.
Currently broken
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.

None yet

2 participants