ethereum / devp2p

Ethereum peer-to-peer networking specifications
990 stars 275 forks source link

Receiving weird RLP message from GETH client #223

Closed ana-prdekalo closed 1 year ago

ana-prdekalo commented 1 year ago

Hi,

I'm writing my own RLPX, implementation in Rust, I am able to send/receive P2P messages between my "code" and other peers. But I've noticed, that I'm receiving "weird" RLP-encoded packets from some peers.

Here is an example of a packet that is bothering me: b"\x01\x01\0\x04". I have little to no experience with RLP encoding/decoding, and I'm using the fastrlp package, but I'm unable to parse this message. I've also tried decoding this via JS RLP CLI, but to no avail.

And just looking at the packet, this looks malformed, as if the packet consists of 2 disconnect messages x01x0 and x01x04, so the first one would be Disconnect(DisconnectRequested) and the other one would be Disconnect(TooManyPeers), but as if, for some reason, they are "mixed up".

The strange thing is that this doesn't happen consistently, nor for all messages. I'm receiving and parsing "normal" Disconnect messages, as well as Hello, and ETH Status messages (this is what I've coded so far).

My question is: is it normal to receive a packet like b"\x01\x01\0\x04" (or eg. b"\x01\x01\0\x10"), or do I have an error somewhere in TCP/Framing level?

fjl commented 1 year ago

If you encounter an invalid RLP message, it is pretty likely that this indicates an error in the lower level of your implementation. I'm very sure geth does not send invalid messages, we would've noticed that in testing with other implementation and with our regression tests.

ana-prdekalo commented 1 year ago

Yeah, that does make sense, I just wanted to double-check before going down the rabbit hole of chasing a bug that sometimes appears. These are always fun 🥲 It smells to me like I scr**ed up TCP Framing.

Thanks four your help!

fjl commented 1 year ago

Let me know what you find!

ana-prdekalo commented 1 year ago

Sorry for the slow response, I'm working on this when I find time - so rarely 🥲 The issue was, for some reason, I thought that disconnect messages were not Snappy compressed 🤦‍♂️ Now everything works as expected :)