The Gateway software is written in a combination of Python and C++. It may be installed by downloading a Docker Container with the Gateway already installed, or via installation using pip.
While the Gateway software communicates using the blockchain protocols, it does not maintain the blockchain state. Accordingly, the Gateway will connect to a remote blockchain node maintained by bloXroute to proxy messages when requested by the user’s blockchain node.
How The Gateway Decides On Best Relay To Connect To
Gateways are responsible for determining which Relay to connect to from a list provided by the Control Plane.
When starting a Gateway, a User may specify the IP address of the Gateway as a command line parameter. If the User does not specify an IP address at startup, the Gateway will attempt to determine its own IP address by reaching out to a remote IP detection service. If the Gateway cannot determine its IP address, it terminates itself with an error instructing the user to provide the IP address at the command line.
After determining it’s IP address, the Gateway connects to the Control Plane and provides its IP address. The Control Plane then looks up the geographic region of the IP address using an IP geolocation service. Based on the determined geolocation of the IP, the Control Plane returns a list of potential Relays for the Gateway to connect to. The list of potential Relays contains the top Relays closest to the Gateway, sorted by distance. If no location is returned by the IP geolocation service, the Control Plane will send the Gateway a list of potential Relays including two Relays from North America, and three Relays from other regions.
Using the list of potential Relays, the Gateway checks the latency of the provided Relays and connects to the Block and Transaction Relays with the lowest latency. Latency is measured using ping latency between the Gateway and each Relay. In addition to connecting to the Relay with the lowest ping, the Gateway additionally stores at the second lowest latency pair of Transaction and Block Relays as a backup in case the initial Relay connections are lost. If the Gateway loses a connection with a Relay, the Gateway connects to a different Relay to maintain its connection with the bloXroute BDN.