Ananth Vivekanand

Reth for BSC (Binance Smart Chain)

Reth is a new Rust stack for developing crypto infrastructure. I wanted to run a p2p network-only Reth node on BSC, to snoop on the mempool. Even though Reth is most well-supported for Ethereum mainnet, it's low-level primitives make it very flexible. We'll be working in the Reth repository. Also, read this great blog post from Merkle first.

Step 1: Check the examples.

Let's run `examples/bsc-p2p`. Hmm, it looks like our peers don't like us, and they immediately disconnect. As the Merkle blogpost from above suggests, we could have the wrong ForkId. Let's override the forkid with the right one that we can calculate from the BSC chainspec (or, just copy the ForkId our peers use).
Peers disconnecting
Peers disconnecting
Even though we're using our correct ForkId, looks like peers still disconnect!

Step 2: Investigate

We could be hitting this check in the Reth codebase, which forces a disconnect. Let's set our network-only node to run in PoW mode, which should sidestep this check.
Run with this, and we still get disconnected. If we snoop longer, we see that sometimes the disconnect reason is a `SubprotocolSpecific` violation. Could we maybe be doing something wrong?

BSC Reth fork

Turns out that BSC devs have forked Reth and maintain the fork here. In their commit where they add BSC compatibility, they make this interesting change!
alt text
alt text
We are indeed doing something wrong, and not sending an `UpgradeStatus` message during our handshake. Let's use the BSC Reth repository going forward so we take care of this.

Fixing the chainspec

Now, if we run `examples/bsc-p2p` with our changes and in the BSC Reth repository, we'll notice that we don't really establish any sessions with peers. This seems like a step back!
We have to fix our chainspec. Luckily, the BSC Reth fork ships with a maintained chainspec we can import.
And everything should start working!
bsc session established
bsc session established
Note peers will still eventually disconnect us after a while if we don't respond to their requests for BlockHeaders, etc, see the Merkle blog post for more details.