8000 Make Transport independent of CNetMessage and CSerializedNetMsg · Issue #30209 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Make Transport independent of CNetMessage and CSerializedNetMsg #30209
Closed
@Sjors

Description

@Sjors

Currently class Transport uses CNetMessage in one place:

bitcoin/src/net.h

Lines 278 to 285 in 62f7f59

/** Retrieve a completed message from transport.
*
* This can only be called when ReceivedMessageComplete() is true.
*
* If reject_message=true is returned the message itself is invalid, but (other than false
* returned by ReceivedBytes) the transport is not in an inconsistent state.
*/
virtual CNetMessage GetReceivedMessage(std::chrono::microseconds time, bool& reject_message) = 0;

And CSerializedNetMsg here:

bitcoin/src/net.h

Lines 287 to 295 in 62f7f59

// 2. Sending side functions, for converting messages into bytes to be sent over the wire.
/** Set the next message to send.
*
* If no message can currently be set (perhaps because the previous one is not yet done being
* sent), returns false, and msg will be unmodified. Otherwise msg is enqueued (and
* possibly moved-from) and true is returned.
*/
virtual bool SetMessageToSend(CSerializedNetMsg& msg) noexcept = 0;

This creates a problem in my Stratum v2 Template Provider implementation in #29432 which introduces class Sv2Transport : Transport. Because the sv2 noise protocol (#29346) is very similar to BIP324 I simply copied V2Transport and modified the state machine a little bit. The test and fuzz code was also very reusable.

But the above two methods don't fit because of their use of CNetMessage and CSerializedNetMsg. Stratum v2 messages (Sv2NetMsg in #29432) don't inherit from CNetMessage and I don't think they should.

So I'd like to refactor Transport to just return (decrypted) bytes and have the caller interpret them (as CNetMessage or Sv2NetMsg).

Additionally I'm not sure what to do with the std::chrono::microseconds time, bool& reject_message arguments. So far I don't use them in Sv2Transport.

  • reject_message: in v1 the transport sets this if the checksum fails. In v2 it's used for the v1 fallback, but also for unrecognized msg types. This can be done by the caller after my proposed refactor, so the argument can go away.
  • time: this is passed into GetReceivedMessage by the caller and used to set msg.m_time = time;, so can also go away.

From IRC I understand @sipa had some ideas on how to tackle this. I can take a stab at it myself, but if someone else does it I'm happy to review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0