0x-mesh
0x-mesh copied to clipboard
mesh: Make sure Ethereum RPC URL points to configured networkId
Mesh operators can specify both a ETHEREUM_RPC_URL
and ETHEREUM_CHAIN_ID
. They could inadvertently specify an Ethereum RPC URL pointing to an Ethereum node running on a different network then the networkId specified by ETHEREUM_CHAIN_ID
.
We could either:
- Remove the
ETHEREUM_NETWORK_ID
config and on boot-up fetch thenetworkId
from the Ethereum node. OR - Fetch the networkId from the Ethereum node, compare it to the supplied
ETHEREUM_NETWORK_ID
and simply check that they are the same.
Fetch the networkId from the Ethereum node, compare it to the supplied ETHEREUM_NETWORK_ID and simply check that they are the same.
This is my preferred option because the other would incur additional start up latency which is unnecessary in most cases. (Not to say that this check is unimportant. Just that most of the time the configured networkId will be correct).
Should we crash if it turns out it isn't correct? Or simply print a warning to the console?
@albrow Can we close this now that #733 has been merged?
There are still some issues with the approach taken in #733. We made the decision to do the chainId check in a separate goroutine so that we don't slow down the rest of Mesh when first starting up. However, that also means there is currently a race condition where we can start processing blocks or incoming orders before we realize there is a chainId mismatch.
I proposed a different solution in https://github.com/0xProject/0x-mesh/issues/866. We can close this issue if we decide to go that route. Otherwise we should leave it open and address the problems with the current implementation somehow.