LimeChain / hashport-validator

Official repository containing the source code of the Hashport validators
Apache License 2.0
23 stars 11 forks source link

Implement EVM client fallback #896

Closed bibitibooo1 closed 1 year ago

bibitibooo1 commented 1 year ago

Notion detailed guide

To use a pool of clients which implements the interface of the client and redirects the requests to the specific client.

  1. Create a new struct named ClientPool, which holds an array of EVM clients implementing the client.EVM interface found in app/domain/client/evm.go. The struct will have a next index field to keep track of the next client to use.

  2. Create a NewClientPool function to initialize the ClientPool struct. The function will accept an array of nodeURLs and create a new EVM client instance for each URL. It then appends each generated client to the clients slice.

  3. Implement methods in ClientPool that delegate operations to the clients in the pool. Use the getClient method to determine which client to use.

  4. Replace the existing EVM client reference in the main implementation with the new ClientPool and update the initialization as needed.

With this approach, each time we call a method on the ClientPool, it will automatically delegate the call to the next EVM client in the pool. If there are issues with any client, it will automatically switch to the next client in the pool and retry the operation until it exhausts the available clients.

This strategy ensures that your system remains operational even if multiple EVM clients become unresponsive simultaneously. It also provides a simple way to distribute requests across multiple EVM network nodes.