Currently class Transport
uses CNetMessage
in one place:
https://github.com/bitcoin/bitcoin/blob/62f7f59ff495fbcbfc10c25e97bb0dc032647abf/src/net.h#L278-L285
And CSerializedNetMsg
here:
https://github.com/bitcoin/bitcoin/blob/62f7f59ff495fbcbfc10c25e97bb0dc032647abf/src/net.h#L287-L295
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 intoGetReceivedMessage
by the caller and used to setmsg.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.